implement template class like std::tr1::function
Hi,
I'm trying to implement a simple signal class, here's the code:
1 2 3
|
//R=return value, T1=arg type1, T2=arg type2
template<typename R, typename T1, typename T2>
struct sig {...}
|
and I see the std::tr1::function looks like:
|
tr1::function<R(T1,T2)> fn;
|
<R(T1,T2)> makes more sense than <R,T1,T2>, but how to implement this?
I tried to look into the source <functional> but failed to understand that.
Thanks in advance.
Last edited on
First it makes an empty general template definition
1 2
|
template<typename _Signature>
class function;
|
Then, it specializes it for functions
1 2
|
template<typename _Res, typename... _ArgTypes>
class function<_Res(_ArgTypes...)>
|
You can do this:
1 2 3 4 5 6 7 8
|
template<typename T>
struct sig;//empty for a reason
template<typename R, typename T1, typename T2>
struct sig<R(T1, T2)>
{
//implement it here
};
|
Last edited on
That's it. Thanks viliml.
Topic archived. No new replies allowed.