STL iterators remove elements

This is mainly on the issue of iterators failure.

1. For the container sequence vector, deque, the post-use erase (itertor), each element behind the iterator will fail, but behind each element will move forward one position, but will return the next valid erase iteration device;

2. For each map set associative containers, the use of the erase (iterator), the current iterator element failure, but its structure is a red-black tree, delete the current element, it will not affect the iterator to the next element, so before calling erase, record iterator to the next element.

3. For the list, it is not continuous use of the memory allocation, and its erase method also returns the next valid Iterator, so the above two kinds of the correct way may be used.

Guess you like

Origin www.cnblogs.com/pacino12134/p/11258830.html