对于std :: set.find()返回的迭代器有多长时间? [英] For how long the iterator returned by std::set.find() lives?
问题描述
我需要通过保存set.find()返回的迭代器来跟踪std :: set元素。
I need to keep track of std::set element by saving the iterator returned by set.find().
我的问题是插入和删除 other 元素使得到的迭代器无效?从一个简单的测试我可以看到它不是,但我想确保这个功能是设计。
My questions is does insertion and removing other elements invalidates the obtained iterator? From a simple test I did I can see it is not, but I'd like to ensure this feature is by design.
推荐答案
它永远不会使迭代器或指针/对元素的引用无效。只有当你删除元素本身时,迭代器或指针/引用才会变得无效。
It never invalidates iterators or pointers/references to the elements. Only if you remove the element itself does the iterator or pointer/reference become invalid.
23.1.2 / 8
:
插入成员不应影响迭代器和对容器的引用的有效性,并且擦除成员应仅使迭代器和对已删除元素的引用无效。
The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
这篇关于对于std :: set.find()返回的迭代器有多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!