Reputation: 674
I have the following code snippet:
template <class T>
int foo(T (*f)()) {
typedef T (*func)();
typedef functor<T, func> F; //this line
// ...
}
As you can see, I use typedef
for a function pointer (func
), but I want to remove it to simplify my code. I tried this:
template <class T>
int foo(T (*f)()) {
typedef functor<T, typename f> F;
// ...
}
But that doesn't compile. What is the right way to to spell that full typedef
for F
in a single line?
Upvotes: 1
Views: 161
Reputation: 304142
Just put in the actual type of f
:
typedef functor<T, T(*)()> F;
Or you could use decltype
:
typedef functor<T, decltype(f)> F;
Or you could write an alias for such a thing:
template <typename T>
using ReturnT = T(*)();
template <typename T>
int foo(ReturnT<T> f) {
using F = functor<T, ReturnT<T>>;
// ...
}
Upvotes: 2