The behavior of overlapped vector::insert
c++, vector
Solution
23.1.1/4 Sequence requirements has:
expression: a.insert(p,i,j)
return type: void
precondition: i,j are not iterators into a. inserts copies of elements in[i,j) before p.
So `i` and `j` cannot be iterators into your vector.
It makes sense, as during the insert operation, the vector may need to resize itself, and so the existing elements may first be copied to a new memory location (there by invalidating the current iterators).
Problem
Where does the C++ standard declare that the pair of iterators passed to `std::vector::insert` must not overlap the original sequence? Edit: To elaborate, I'm pretty sure that the standard does not require the standard library to handle situations like this: ``` std::vector<int> v(10); std::vector<int>::iterator first = v.begin() + 5; std::vector<int>::iterator last = v.begin() + 8; v.insert(v.begin() + 2, first, last); ``` However, I was unable to find anything in the standard, that would prohibit the ranges `[first, last)` and `[v.begin(), v.end())` to overlap.