It seems dangerous to me also, because vector.back () returns a link and
inserts at positions other than the end of the vector are performed by moving all the elements between the position and the end of the vector to their new positions, and then inserting a new element (s) (from here )
If I do not understand, the link passed to insert becomes "invalid" (if redistribution does not occur, it may contain not the last element but the previous one, otherwise it may still be right, but I think this is not guaranteed.
Perhaps, in some cases, some optimizers may hide the error (I think this never happens with objects, but it can happen with primitives), so you get the expected results, but in general I did not rely on this behavior.
source share