template<typename ReturnT, typename... ParamT>
void foo(std::function<ReturnT(ParamT...)> callback)
{}
template<typename ReturnT, typename ParamT>
void bar(std::function<ReturnT(ParamT)> callback)
{}
main()
{
foo<int, int>([](int x){ return x; }); // no instance of function
// template matches argument list
bar<int, int>([](int x){ return x; }); // OK
}
foo和bar之间唯一的区别在于foo有可变参数。但不知何故,编译器能够将bar中的lambda转换为std::function。
据我理解,模板类型推导不考虑类型转换。那么两者都应该失败,对吗?
std::function
作为参数,而是看看标准库如何仅使用单个模板参数处理可调用对象。 - Some programmer dude