Is there a standard way of moving a range into a vector?

You use a move_iterator with insert: v1.insert(v1.end(), make_move_iterator(v2.begin()), make_move_iterator(v2.end())); The example in 24.5.3 is almost exactly this. You’ll get the optimization you want if (a) vector::insert uses iterator-tag dispatch to detect the random-access iterator and precalculate the size (which you’ve assumed it does in your example that copies), and (b) move_iterator preserves the iterator category … Read more

std::dynarray vs std::vector

So what are the benefits and the usage of std::dynarray, when we can use std::vector which is more dynamic (Re-sizable)? dynarray is smaller and simpler than vector, because it doesn’t need to manage separate size and capacity values, and it doesn’t need to store an allocator. However the main performance benefit is intended to come … Read more

std::vector resize downward

Calling resize() with a smaller size has no effect on the capacity of a vector. It will not free memory. The standard idiom for freeing memory from a vector is to swap() it with an empty temporary vector: std::vector<T>().swap(vec);. If you want to resize downwards you’d need to copy from your original vector into a … Read more