Does insertion to STL map invalidate other existing iterator?(插入 STL 映射是否会使其他现有迭代器无效?)
问题描述
我在 STL 中使用了 std::map.我可以在将其他元素插入地图后使用迭代器吗?还有效吗?
I used std::map in STL. Can I use iterator after some other element inserted to the map? Is it still valid?
推荐答案
如果对容器操作的语义有疑问,请咨询 文档:
When in doubt as to the semantics of an operation on a container, consult the documentation:
Map 有一个重要的特性,即在 map
中插入新元素不会使指向现有元素的迭代器失效.
Map has the important property that inserting a new element into a
map
does not invalidate iterators that point to existing elements.
从 map
中擦除元素也不会使任何迭代器失效,当然,实际上指向被擦除元素的迭代器除外.
Erasing an element from a map
also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.
这取自 SGI STL 文档.虽然本文档在技术上没有指定 C++ 标准库容器的行为,但除了 STL 中不属于 C++ 标准库的部分之外,这些差异通常是微不足道的.
This is taken from the SGI STL documentation. While this documentation technically does not specify the behavior of the C++ Standard Library containers, the differences are generally insignificant, aside from the parts of the STL that are not part of the C++ Standard Library, of course.
SGI STL 文档是必不可少的参考,尤其是在您没有 C++ 标准副本的情况下.
The SGI STL documentation is an indispensable reference, especially if you don't have a copy of the C++ Standard.
这篇关于插入 STL 映射是否会使其他现有迭代器无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:插入 STL 映射是否会使其他现有迭代器无效?


- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01