I have a function wrapper that takes a function and a list of arguments and calls the function with those arguments:
template<typename R, typename... Args>
R wrapper(std::function<R(Args...)> f, Args... args) {
auto ret = f(args...);
return ret;
}
But the following does nott compile:
int f1(int a, int b) { return a+b; }
wrapper(f1, 1, 2);
It says:
mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘int (*)(int, int)’
However, if I do:
wrapper(std::function<int(int, int)>(f1), 5, 10);
...it will be well-formed, which is contradictory with the compiler error.
Why doesn't the compiler accept the first version?
Demo trace: https://onlinegdb.com/rJWzZIQX4