我需要通过保存 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/