如何检测 nullary 和 unary 函数指针、std::function 对象和仿函数(包括 lambda)的返回类型和参数类型?
Boost 的function_traits和功能特征并不能完全让我开箱即用,但我愿意补充或替换它们。
我可以做这样的事情:
namespace nsDetail
{
class Dummy { Dummy(); };
}
template<class Fn> struct FnTraits;
template<class R>
struct FnTraits<R(*)()>
{
typedef nsDetail::Dummy ParamType;
typedef R ReturnType;
typedef R Signature();
};
template<class R, class P>
struct FnTraits<R(*)(P)>
{
typedef P ParamType;
typedef R ReturnType;
typedef R Signature( P );
};
template<class R>
struct FnTraits< std::function<R()> >
{
typedef nsDetail::Dummy ParamType;
typedef R ReturnType;
typedef R Signature();
};
template<class R, class P>
struct FnTraits< std::function<R(P)> >
{
typedef P ParamType;
typedef R ReturnType;
typedef R Signature( P );
};
但是我应该如何专注于仿函数/lambdas?
更新:也许类似于this answer to a different question,但从重载转换为专业化?