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 映射是否会使其他现有迭代器无效?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
