c++ - std::set.find() 返回的迭代器存在多长时间?

标签 c++ stl set stdset

我需要通过保存 set.find() 返回的迭代器来跟踪 std::set 元素。

我的问题是插入和移除other 元素是否会使获得的迭代器失效?从我所做的简单测试中我可以看出它不是,但我想确保此功能是设计使然。

最佳答案

它永远不会使元素的迭代器或指针/引用失效。只有当您删除元素本身时,迭代器或指针/引用才会变得无效。

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.

关于c++ - std::set.find() 返回的迭代器存在多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2364662/

相关文章:

c++ - vector 中的 STL Push_back 字符串

c++ - 将两个键与 std::map 一起使用的最佳方法是什么?

arrays - Ruby - 比较数组并根据条件获取索引

c++ - 如何复制红黑树,它的分配器应该是什么

c++ - 使用 STL 的类模板无法编译

c++ - 在 C++ 中制作对象列表

python - 按给定顺序检查列表的超集

dictionary - 有没有更好的 pythonic 方法来做到这一点?

python - "No module named ' osmium._osmium '"尝试使用 PyOsmium 时出错

c# - 如何将函数返回值编码到非托管 dll