The name of a function template, like Algorithm::One
, is treated like the name of a set of overloaded functions here. To select one of the overloads from that set, you need to put that name in a context where a specific function type (signature) is required. This is not possible with std::function
, as it can take any argument in its ctor (with some "callable" requirements).
Additionally, using std::function
as a parameter type is not required and not useful if the function is a template. It would just add an unnecessary type erasure and a level of indirection. The standard idiom of passing functions is:
template <typename Fun, typename IntegerType>
void Run_Algorithm(Fun fun, IntegerType a, IntegerType b);
But this doesn't help you selecting one overload of the overload set. You could select the overload at call site, as Dieter Lücking suggested, and then use this idiom.
However, you can provide an overload/alternatively:
template < typename IntegerType >
void Run_Algorithm(IntegerType(*)(IntegerType, IntegerType),
IntegerType, IntegerType);
which is more specialized and therefore preferred, if possible. Here, the function type is strictly IntegerType(IntegerType, IntegerType)
, therefore the compiler can select an overload of the overload set (from the name Algorithm::One
).
Note: As per [temp.deduct.type]/5, IntegerType
is in the first parameter in a non-deduced context for the argument Algorithm::One
. Therefore, the second and third parameter are used to deduce IntegerType
. After this deduction, the function type is fully specified and the overload can be selected.
The questions remain 1) if that's what you want and 2) if there's a better way to do what you intent to do.