std::hash_map
不是 C++ 标准
的一部分,而是标准库扩展的一部分。例如,它被定义为 VS2005 。通常 std::hash_map.erase
会使 std::hash_map
的所有迭代器失效吗?据推测,当删除元素以优化内存使用时,可以将内存重新分配到较小的数组。
那么hash_map.erase
实际上会使所有迭代器失效吗?
最佳答案
看起来它是在 VS2005 中指定的文档中的示例:
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.
关于c++ - hash_map.erase 是否会使所有迭代器无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5041984/