插入到STL映射是否使其他现有迭代器无效? [英] Does insertion to STL map invalidate other existing iterator?

查看:122
本文介绍了插入到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 has the important property that inserting a new element into a map does not invalidate iterators that point to existing elements.

映射中擦除元素也不会使任何迭代器无效,当然,指向正在擦除的元素。

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 ++标准库容器的行为,但是,除了不是C ++标准库的一部分的STL部分之外,差异通常是微不足道的。

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映射是否使其他现有迭代器无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆