开发者

The boost "signature" question

I'm trying to figure out how could many boost classes be able to accept a function signature as template argument and then "extract" from there the result type, first argument type and so on.

template <class Signature>
class myfunction_ptr
{
  开发者_StackOverflow Signature* fn_ptr;
public:
   typedef /*something*/  result_type;  // How can I define this?
   typedef /*something*/  arg1_type;  // And this?
};

I know that boost also provides a more portable implementation, using a template argument for each function argument and that's easy to understand. Can someone explain me the magic beyond this?


At the core its just specialization and repetition:

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;
};

// ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜