我正在尝试将 lambda 传递给采用模板函数类型的模板函数。编译时出现错误candidate template ignored: could not match...。
但是,当我尝试将相同的 lambda 传递给采用模板函数类型的模板类时,它会编译并运行。
考虑以下代码 (c++17)
#include <functional>
// define the template function type
template<typename T, typename...S>
using compose_fn_t = std::function<T(S...)>;
// define a template function which accepts the template function type
template<typename T, typename... S>
void compose(compose_fn_t<T, S...> fn) {};
// define a template class which accepts the template function type
template<typename T, typename... S>
class Compose {
public:
Compose(compose_fn_t<T, S...> fn) {};
}; …Run Code Online (Sandbox Code Playgroud)