I have some template code that takes a function as an argument. I'd like to extend it to use a function template as an argument.
The existing code is:
int add1( int i ) { return i+1; }
template <typename Func, typename Integer>
Integer call_func( Func f, Integer i ) { return f(i); }
// Usage is
auto four = call_func( add1, 3 );
It works fine. If I add a version of add1 that takes a template parameter, I get:
template <typename Integer>
Integer add1_t( Integer i ) { return i+1; }
// Usage is
auto four = call_func( add1_t<int>, 3 );
What I would really like to do, however, is to not specify the full type of the function, only the template, as in:
auto four = call_func( add1_t, 3 );
and let call_func apply the template argument. Is there a way to do that?
My best guess is:
template <template <typename> typename Func, typename Integer>
Integer call_func( Func<Integer> f, Integer i ) { return f(i); }
but the type of f cannot be deduced when I do that. Even if I wanted to supply an explicit "type" at the call-site, I'm not sure what that would be.