我一直在查看一个函数的 C++ 文档,该函数使用 move 语义将一系列元素从一个容器 move 到另一个容器。但是,我还没有找到这样的功能。我错过了什么?
如果不复制和使用显式循环,我将如何执行以下操作?
// Move 10 elements from beginning of source to end of dest
dest.end() <- move(source.begin(), source.begin() + 10)
最佳答案
我认为您正在寻找 std::move
在 <algorithm>
:
std::move(source.begin(), source.begin() + 10,
std::insert_iterator(dest, dest.end()));
就像std::copy
, 除了它 move 分配而不是复制分配。
关于c++ - 在容器之间 move 一系列元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4139130/