Why does callB(f)
compile and callA(f)
does not compile? Aren't they kind of the same?
I have tried with gcc and MSVC... same results.
#include <functional>
template<typename T>
struct Function
{
typedef std::function<void(T)> type;
};
template<typename T = int>
void callA(std::function<void(T)> f)
{
f(T());
}
template<typename T = int>
void callB(typename Function<T>::type f)
{
f(T());
}
int main()
{
auto f = [](int) { };
callA(f); // compile error: "template argument deduction/substitution failed: main()::<lambda(int)>’ is not derived from ‘std::function<void(T)>"
callB(f); // compiles
return 0;
}