Simply put, this is not possible.
A function template is not a function, it's a template of a function -- and thus it does not have a function pointer until you specify which instantiation you want. At which point, the pointer is fixed to a specific number of arguments of specific types.
It is not possible in the C++ language to type-erase templates into a singular type, such as a pointer that you can pass around and lazily instantiate.
That is, code such as:
some_discrete_variadic_type x = var_func_1;
x(1);
x(1, "2");
x = var_func_2;
x(1);
x(1, "2");
Is not possible, because for type-erasure to work you must normalize the erasure to a fixed number of types (in this case, it would be instantiations).
Depending on what the problem is you are trying to solve, however, there might be workarounds -- though this would require more information.
If your uses are more limited -- such as to pass the functionality into other functions that are only ever known at compile-time, then you can use Functor objects instead and pass them into function templates where the arguments are deduced. For example:
struct var_func
{
template <typename...Args>
auto operator()(Args&&...args) -> void
{
// do something
}
};
Where an example of it being called could be:
template <typename T>
auto consume(T var_func_p) -> void
{
var_func_p("Test");
var_func_p(0.3, 5);
var_func_p('c', "Another test", 1.3, 3);
}
int main()
{
consume(var_func{});
consume(some_other_var_func{});
}
Note that in this case, you're not passing a function template around anymore. You're passing a static object, var_func
, which contains a call-operator (operator()
) that is a function template.