I have been using the highly concise and intuitive C++ syntax for finding the intersection of two sorted vector
s and putting the result in a third vector<
back_inserter
inserts the element in the range by calling push_back
( that's why you can't use back_inserter
with the range which doesn't provide push_back
operation).
So, you won't care about going past the end of the range as push_back
automatically expands the container. However, that's not the case with insert using begin()
.
If you are using begin()
, then you have to make sure that destination range is big enough to hold all elements. Failing to do so would instantly transport your code to the realm of undefined behavior.