[英]How to combine two vectors containing std::unique_ptr?
If I have two vector containing std::unique_ptr<>, is there a way to add vector b to the end of vector a, thereby deleting vector b? 如果我有两个包含std :: unique_ptr <>的向量,是否可以将向量b添加到向量a的末尾,从而删除向量b?
For example: 例如:
std::unique_ptr<std::vector<int>> a(&someintvector);
std::unique_ptr<std::vector<int>> b(&someotherintvector);
How would I go about moving vector b to the end of vector a? 我将如何将向量b移动到向量a的末尾?
您将b
的内容移动到a
:
std::move(std::begin(*b), std::end(*b), std::back_inserter(*a));
将元素移动到a
另一种方法:
a->insert(a->end(), std::make_move_iterator(b->begin()), std::make_move_iterator(b->end()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.