One can pass callback to other function using template to abstract from real callback type:
float foo(int x, int y) {return x*y;}
template<class F>
void call_it(F f, int a, int b)
{
f(a,b);
}
There is a cost of passing f
as an argument and calling it indirectly. I wonder if, in case f
is a static function it is possible to pass it somehow to template function "directly", without adding a callable to the function argument list, so that the call could be bound statically.
I see the analogy to passing an integer value as template argument. It doesn't require adding any new function arguments because it passes the integer just as immediate value into the function code:
template<int X> int foo(int y) {return X+y;}
Here is a non-working code presenting what I'd like to achieve:
template<class F>
void call_it(int a, int b)
{
F(a,b); // Assume that F is a static function and can be called directly
}
Is there any way to achieve it?