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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -