difference between C++ template partial specialization for function and functor -
i have been using c++ template class partial specialization function argument while. surprised find same syntax used partial specialize functors.
in case 1 below, easy see f(t) function type. since type, used substitute template parameter, in case 2, semantics of f(t) changed, not type still can pass compiler , work.
i googled few hours, not found valuable info in regard. explain why case 2 worked?
template<class> struct func; template<class f, class t> struct func<f(t)> //1. partial specialization function { //with signature f(t) using type = f(t); }; template<class> struct ftor; template<class f, class t> struct ftor<f(t)> //2. f(t) type? { using type = f; }; struct foo { void operator()(int) {} }; int main() { //1 void(int) function signature cout<<typeid(typename func<void(int)>::type).name()<<endl; //2 foo(int)? cout<<typeid(typename ftor<foo(int)>::type).name()<<endl; return 0; }
in 2 cases, f(t) signature of function taking t , returning f.
you may rename class func identity , ftor result_of , f returntype better match naming/implementation.
Comments
Post a Comment