gpt4 book ai didi

c++ - 将 boost::bind 与构造函数一起使用

转载 作者:可可西里 更新时间:2023-11-01 18:09:55 25 4
gpt4 key购买 nike

我正在尝试创建新对象并将它们添加到使用 boost::bind 的对象列表中。例如。

struct Stuff {int some_member;};
struct Object{
Object(int n);
};
....
list<Stuff> a;
list<Object> objs;
....
transform(a.begin(),a.end(),back_inserter(objs),
boost::bind(Object,
boost::bind(&Stuff::some_member,_1)
)
);

这似乎不起作用。有什么方法可以使用带有 boost::bind 的构造函数,还是我应该尝试其他方法?

最佳答案

如果您使用的是 boost 1.43,则可以使用 boost::factory 和 boost::value_factory,它们可以封装构造函数调用。像这样:

 transform(a.begin(),a.end(),back_inserter(objs), 
boost::bind(boost::value_factory<Object>(),
boost::bind(&Stuff::some_member,_1)
)
);

关于c++ - 将 boost::bind 与构造函数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1335301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com