How to write a function calling any specified function (or function object) with specified arguments?
Here's what I tried:
#include <iostream>
#include <functional>
using namespace std;
template <typename RetType, typename... ArgTypes>
RetType q(function<RetType(ArgTypes...)> f, ArgTypes... args)
{
return f(args...);
}
int h(int a, int b, int c) { return a + b + c; }
int main()
{
auto r = q(h, 1, 2, 3);
cout << "called, result = " << r;
return 0;
}
The compiler says, that template argument deduction/substitution failed due to mismatched types 'std::function<_Res(_ArgTypes ...)>' and 'int (*)(int, int, int)'.
I'm not sure why template arguments can't be deduced in my code.