std::set.find() 返回的迭代器存在多久?

发布于 2024-08-23 11:26:34 字数 129 浏览 3 评论 0原文

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

我的问题是插入和删除其他元素是否会使获得的迭代器无效?从我所做的简单测试中我可以看出事实并非如此,但我想确保此功能是设计使然。

I need to keep track of std::set element by saving the iterator returned by set.find().

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2024-08-30 11:26:35

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

23.1.2/8:

insert 成员不应影响迭代器和对容器的引用的有效性,而擦除成员应仅使迭代器和对已擦除元素的引用无效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文