开发者

Does hash_map.erase invalidate all iterators?

开发者 https://www.devze.com 2023-02-12 02:29 出处:网络
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::h

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号