Basically, I would like to be able to be able to pass a function_A with any parameter to T_function, so that T_function could execute some commands, then call the passed-in function
This is what I came up with (which might make my goal more clear) :
template <typename t_return, typename t_param>
void foo(t_return (*func)(t_param), t_param p)
{
//do code
func(p);
}
foo<void, int>(&someFunc, someInt);
The above code works great, but it seems bothersome. I’m also not sure how fool-proof it is. Does anyone with a little more understanding have an improvement?
I’ve tried looking this up online, however it has proved difficult to search for.
You could just make the whole function type a template parameter. Then the compiler can deduce the template parameters using the input arguments.
This also has an advantage that function objects can be supported. (This is also how the standard library (“STL”) supports passing functions to the algorithms.)