开发者

Function like template parametrs

Can anyone exp开发者_开发知识库lain me, how to write template parameters like in boost::function (for example boost::function<int (float,bool)> ). What is a right syntax?

I try this:

template <typename T (typename Arg1,typename Arg2)>
struct func{};

but it doesn't working.


template <typename T>
struct func {};

int (float, bool) itself is already a type.


If you only want to match types being a function with 2 parameters, create a specialization like this:

template <typename T>
struct func;

template <typename R, typename T1, typename T2>
struct func<R(T1,T2)> {
   typedef R return_type;
   typedef T1 first_argument_type;
   typedef T2 second_argument_type;
};
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜