Does hash_map.erase invalidate all iterators?
std::hash_map
is not part of the C++ standard
but is part of extensions to standard library. For example it is defined for VS2005. Would normally std::hash_map.erase
invalidate all iterators to std::hash_map
? Presumably, the memory can be reallocated to a smaller a开发者_JS百科rray when elements are removed to optimize for memory usage.
So does hash_map.erase
actually invalidate all iterators?
It looks like it is specified in VS2005 example in the documentation:
Each element contains a separate key and a mapped value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations that is independent of the number of elements in the sequence (constant time) -- at least in the best of cases. Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators which point at the removed element.
精彩评论