I'm learning concepts and templates. I'm trying to make a function template that will call another function template. Currently it works with lambda but not with a normal function.
// This also works with lambda but not the normal function:
//void callFunc(std::regular_invocable<T> auto invocable)
template<typename T>
void callFunc(auto invocable)
{
invocable(T(5));
}
// Doesn't work, whether I use "T" or "auto"
//template<typename T>
void testFuncToPass(const auto& a)
{
std::cout << a << " CALLED\n";
}
//...
auto lambda = [](const auto& a){std::cout << a << " CALLED\n";};
//callFunc<int>(testFuncToPass); // ERROR
callFunc<int>([](const auto& a){std::cout << a << " CALLED\n";});
callFunc<int>(lambda);
It says: "error : no matching function for call to 'callFunc'. candidate template ignored: couldn't infer template argument 'invocable:auto'"
Is what I'm trying to do doable? I also tried to use template template parameter but seems that only works for types, not for functions.