If I have std::deque and std::vector and want to combine them to std::deque, I can do it the following way:
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;
We know the size of the vector but we can't reserve memory at the end of std::deque before using std::deque.insert(...).
So is it the fastest way to move all elements of std::vector to the end of std::deque? Or did I miss something?
Thank you.
I would use
resizemethod as follows, because than isdequereallocated only once: