C++ 为什么可以';t boost::bind在绑定构造函数时推断返回类型<&燃气轮机;函子?

C++ 为什么可以';t boost::bind在绑定构造函数时推断返回类型<&燃气轮机;函子?,c++,boost,constructor,lambda,bind,C++,Boost,Constructor,Lambda,Bind,。。。尽管库提供了constructorfunctor适配器定义了sig模板 struct Porc { Porc(int x) {} }; boost::bind ( boost::lambda::constructor<Porc>(), _1 )(1); struct-proc { 门廊(int x){} }; boost::bind ( boost::lambda::构造函数(), _1 )(1); 错误:“struct boost::lambda

。。。尽管库提供了
constructor
functor适配器定义了
sig
模板

struct Porc
{
    Porc(int x) {}
};

boost::bind
(
    boost::lambda::constructor<Porc>(),
    _1
)(1);
struct-proc
{
门廊(int x){}
};
boost::bind
(
boost::lambda::构造函数(),
_1
)(1);
错误:“struct boost::lambda::constructor”中没有名为“result\u type”的类型

我要做的是创建一个接受int的函子,并使用该int创建并返回一个Porc对象。 注意:如果我显式指定函子的返回类型(即Porc),如下所示,它会工作:

boost::bind<Porc>
(
    boost::lambda::constructor<Porc>(),
    _1
)(1);
boost::bind
(
boost::lambda::构造函数(),
_1
)(1);

我对lambda表达式比较陌生,但我想/希望我掌握了基本知识。它说,一般来说,BLL不能推断任意函数对象的返回类型。但是,对于某个函数对象类,有两种方法可以为BLL提供此功能。[…]结果键入typedef和[…]sig模板。既然
构造函数
是库提供的,他们当然声明了一个
sig
模板。

您是否尝试过
boost::lambda::bind
?为了echo@David,您为什么认为
boost::bind
会了解boost.lambda库?(还有FWIW,Boost.Lambda死了,改用。)你说得对,我把Boost::bind和Boost::Lambda::bind混合在一起了。我看到lambda库容纳了定义result_类型的functor(比如STL和boost::bind中的functor),但是boost::bind和其他库不理解
sig
这件事。这里我指的是boost::range迭代器适配器,比如
transform
,它也需要返回类型。最后,对于我来说,放弃lambda并使用boost::bind和
boost::value_factory
作为
boost::lambda::constructor.
的替代方法更简单。为什么说boost::lambda是“死的”?我没有在其他地方找到这些信息——只是它们非常相似,在某个时候会被合并?@haelix:有关详细信息,请参阅及其评论。