提升"签名"问题

Emi*_*ano 2 c++ boost

我试图找出许多boost类如何能够接受函数签名作为模板参数,然后从那里"提取"结果类型,第一个参数类型等等.

template <class Signature>
class myfunction_ptr
{
   Signature* fn_ptr;
public:
   typedef /*something*/  result_type;  // How can I define this?
   typedef /*something*/  arg1_type;  // And this?
};
Run Code Online (Sandbox Code Playgroud)

我知道boost还提供了一个更加可移植的实现,使用每个函数参数的模板参数,这很容易理解.有人能解释我超越这个魔力吗?

Geo*_*che 6

核心只是专业化和重复:

template<class S> struct Sig;

template<class R> struct Sig<R ()> {
    typedef R result_type;
};

template<class R, class T0> struct Sig<R (T0)> {
    typedef R result_type;
    typedef T0 first_type;
};

// ...
Run Code Online (Sandbox Code Playgroud)