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<
It compiles fine because you get a valid iterator back from the begin
function, but if the vector is empty then you will get back the end
iterator, and then continue from there.
It will work only if the destination vector already contains at least as many elements as you try to add, and then it will actually overwrite those elements and not add new.
And adding elements is just what the back_inserter iterator does, it returns an iterator that basically does push_back
on the vector.