简体   繁体   中英

std::map erase preserving iterators

I'm implementing my own std::map, using a basic binary search tree.

The erase method is supposed to

invalidate the iterators referring to element removed and preserve the validity of all other iterators

Yet here is what the BST "classic" delete algorithm is doing:

If node to be deleted A has two children, "replace" A by its in-order successor / predecessor B and the delete B.

In the end, iterators to B are invalidated. So validity of "other" iterator is not preserved.

Is the algorithm I've found not suitable?

Is the algorithm I've found not suitable?

Correct. The algorithm that you describe would not be suitable for implementing std::map .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM