另一种复制算法
我有两个向量。
vector<Object> objects;
vector<string> names;
这两个向量已填充并且具有相同的大小。 我需要一些对对象变量进行赋值的算法。它可以使用 boost::lambda。 我们说:
some_algoritm(objects.begin(), objects.end(), names.begin(), bind(&Object::Name, _1) = _2);
有什么建议吗?
I have two vectors.
vector<Object> objects;
vector<string> names;
These two vectors are populated and have the same size.
I need some algorithm which does assignment to the object variable. It could be using boost::lambda.
Let's say:
some_algoritm(objects.begin(), objects.end(), names.begin(), bind(&Object::Name, _1) = _2);
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要
std::for_each
因为每个Object
实例都在就地修改:这是一个完整的、可编译的示例:
输出:
I think that you want
std::for_each
because eachObject
instance is being modified in-place:Here is a complete, compilable example:
Outputs:
我想不出为此的
std::
算法。但是,您始终可以编写自己的:EDIT: Another alternative, if you are able to define
operator=
appropriately, isstd::copy
:I can't think of a
std::
algorithm for this. But, you can always write your own:EDIT: Another alternative, if you are able to define
operator=
appropriately, isstd::copy
: