why does stdcopy require stdbackinserter to insert into a vector with sufficient capacity?

Why can’t I use d_arr.begin() as the OutputIt in std::copy when the underlying vector has sufficient capacity?

Because the destination vector is empty, and thus std::copy overflows the vector (because assignment of any element is outside the bounds of an empty vector).

Is the std::back_inserter() operation optimized to just memmove

It could be. It might even be optimised to something faster.

Is use std::back_inserter() optimized to bulk copy ranges?

Given smart enough optimiser, yes.


Using the appropriate constructor of vector would be simpler than std::copy. Both for the reader of the code, and the optimiser.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top