简体   繁体   English

在容器之间移动一系列元素?

[英]Move a range of elements between containers?

I've been looking at the C++ documentation for a function which would move a range of elements from one container to another, using move semantics. 我一直在查看一个函数的C ++文档,该函数可以使用移动语义将一系列元素从一个容器移动到另一个容器。 However, I have not found such a function. 但是,我还没有找到这样的功能。 What am I missing? 我错过了什么?

How would I do the following without copying and using explicit loops? 如果不复制和使用显式循环,我将如何执行以下操作?

// Move 10 elements from beginning of source to end of dest
dest.end() <- move(source.begin(), source.begin() + 10) 

I think you're looking for std::move in <algorithm> : 我想你正在寻找<algorithm> std::move

std::move(source.begin(), source.begin() + 10,
            std::insert_iterator(dest, dest.end()));

It's just like std::copy , except it move-assigns instead of copy-assigns. 它就像std::copy ,除了它是move-assign而不是copy-assign。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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