c++ - 在容器之间 move 一系列元素?

标签 c++ algorithm c++11 move move-semantics

我一直在查看一个函数的 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/

相关文章:

c++ - 您如何确定由 'std::map' 创建的用于 'boost::pool_allocator' 的节点的大小(以跨平台方式)?

c++ - 关于模板代码组织 : where to put code that a template uses

c++ - 在 C++ 中以编程方式从 DLL 中获取 DLL 版本 - 再次

c++ - 当找不到映射键时,我可以做出以下假设吗?

algorithm - 需要帮助计算该算法的操作复杂性

algorithm - A* 启发式创建 Bresenham 线

c++ - 对 constexpr 函数的嵌套调用

c++ - 如何正确检测 GCC 版本中可用的 C++11 功能?

algorithm - Cassandra 的 token 功能背后的算法是什么?

c++ - 如何在现代 C++ 中基于另一组可变参数模板参数来表示可变参数模板类型?