I would suggest a minor rewrite into something like this:
#include <iostream>
template<class Fun, class... Args>
void CallFunction(Fun fun, Args&&... args)
{
fun(std::forward<Args>(args)...);
}
void fn(int a1, bool a2, char const* a3)
{
std::cout << a1 << a2 << a3;
}
int main()
{
CallFunction(fn, 10, true, "Hello");
}
Live Example. I think you can deduce from this the proper ...
syntax (after class...
in the paramter list, but after arg...
for unpacking arguments at the call site.
The std::forward
is to distinguish between lvalues and rvalues. It's also better in general to use argument deduction by passing the function pointer (or callable object in general) as a regular function argument, rather than as an explicit template argument.