且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我的C ++编译器不能推导boost函数的模板参数?

更新时间:2023-11-13 21:36:58

While C++ lambdas are strictly monomorphic, they are merely shorthand for function objects (aka functors), and in general functors can be polymorphic; i.e., their call operators can be overloaded or templated. As a result, functors (and, consequently, lambdas) are never implicitly convertible to templated std::function<> (or boost::function<>) instances because functors' operator() argument types are not automatically inferable.

To phrase it slightly differently, the natural type of your lambda expression is a functor with a parameterless constructor and an operator() with the signature void operator ()(int) const. However obvious this fact may be to you and I, it's not automatically inferrable that ArgT should resolve to int because lambdas are functors and functors' operator()s are possible to overload and template.

TL;DR: What you want isn't possible.

相关阅读

推荐文章