3 ms·
I think you have a point here, not for the vector version (though the resulting vector may not be sorted), but for the insert-then-erase and extract-then-insert
by mannykannot 8y ago
I think you have a point here, not for the vector version (though the resulting vector may not be sorted), but for the insert-then-erase and extract-then-insert versions (though the author does not have complete solutions for the original problem using these approaches).
The erase() method invalidates iterators to the erased element, but returns an iterator to the next one. If you resume iterating with that, there is the possibility of finding the updated Employee again. Extract() also invalidates iterators, but does not return one. If, as in the example, you use the iterator returned by insert() to resume iteration, you may skip over some eligible employees. If you use iterator++ in the extract() call (if that's not undefined behavior), you will presumably be in the same situation as using the iterator returned by erase().