I couldn't quite understand your question, but to respond to the understanding you listed: Your understanding may be correct on a particular compiler/day/build. It is unspecified whether you will insert at begin
or begin + 1
(which then results in the value returned from insert
being one of two different possible values) because the compiler may evaluate the arguments to insert
in any order it likes. Instead of trying to work out exactly what will happen, split the code into appropriate pieces the make it perfectly clear what you're trying to do and let the optimizer take care of things for you. Almost certainly the reason it core dumped is because when you increment by two you skip over end
and never detect that you passed the end of the container.
I feel I should also point out that "luckily" there's a sequence point after the evaluation of function arguments, or begin = target.insert(begin, *begin++);
would be undefined behavior with two writes to begin
and no intervening sequence point (for example i = i++
is UB).