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
mapdoes 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 映射是否会使其他现有迭代器无效?
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
