繁体   English   中英

如何合并两个包含std :: unique_ptr的向量?

[英]How to combine two vectors containing std::unique_ptr?

如果我有两个包含std :: unique_ptr <>的向量,是否可以将向量b添加到向量a的末尾,从而删除向量b?

例如:

std::unique_ptr<std::vector<int>> a(&someintvector);

std::unique_ptr<std::vector<int>> b(&someotherintvector);

我将如何将向量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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM