小编And*_* A.的帖子

在 C++11 中将 std::vector 移动到 std::deque

如果我有std::deque并且std::vector想要将它们组合到std::deque,我可以通过以下方式进行:

typedef int T; // type int will serve just for illustration
std::deque< T > deq(100); // just some random size here
std::vector< T > vec(50);
// ... doing some filling ...
// now moving vector to the end of queue:
deq.insert( 
    deq.end(), 
    std::make_move_iterator( vec.begin() ),
    std::make_move_iterator( vec.end() )
);
std::cout << deq.size() << std::endl;
Run Code Online (Sandbox Code Playgroud)

我们知道向量的大小,但我们不能在最后std::deque使用之前保留内存std::deque.insert(...)。那么这是将所有元素移动std::vector到末尾的最快方法std::deque吗?还是我错过了什么?

谢谢你。

c++ stdvector c++-standard-library c++11 stddeque

7
推荐指数
1
解决办法
3892
查看次数

标签 统计

c++ ×1

c++-standard-library ×1

c++11 ×1

stddeque ×1

stdvector ×1