c++ - How to use typename instead of typedef? -
i have following code snippet:
template <class t> int foo(t (*f)()) { typedef t (*func)(); typedef functor<t, func> f; //this line // ... } as can see, use typedef function pointer (func), want remove simplify code. tried this:
template <class t> int foo(t (*f)()) { typedef functor<t, typename f> f; // ... } but doesn't compile. right way to spell full typedef f in single line?
just put in actual type of f:
typedef functor<t, t(*)()> f; or use decltype:
typedef functor<t, decltype(f)> f; or write alias such thing:
template <typename t> using returnt = t(*)(); template <typename t> int foo(returnt<t> f) { using f = functor<t, returnt<t>>; // ... }
Comments
Post a Comment