I am passing a pointer to function into a function template:
int f(int a) { return a+1; }
template<typename F>
void use(F f) {
static_assert(std::is_function<F>::value, "Function required");
}
int main() {
use(&f); // Plain f does not work either.
}
But the template argument F
is not recognized by is_function
to be a function and the static assertion fails. Compiler error message says that F
is int(*)(int)
which is a pointer to function. Why does it behave like that? How can I recognize the function or pointer to function in this case?