c++ - hash_map.erase 是否会使所有迭代器无效?

标签 c++ iterator hashmap

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/

相关文章:

c++ - 无法将迭代器设置为 std::map 的 std::pair

java - 我想从以下 HashMap 中获取常见时间集的工作日

c++ - BlackBerry 10 Development Switch 外壳

python - Python 是否提供 "free"默认迭代器?

c++ - macOS 版本返回为 10.16,而不是 12.0

c++ - 共享迭代器相同的可迭代?

java - 在Map线性或常量上调用values().size()

java - 如何一次将一个字符串添加到 HashMap<Integer, List<String>> 中?

c++ - 在 C++ 中定义多个组合对象的最佳方式?

c++ - VS2008 C++ "interface"作为参数名编译失败