开发者

C++ containers' iterators

开发者 https://www.devze.com 2023-02-06 07:09 出处:网络
This question may sounds lame, but I haven\'t found clear answer. Can I assume, that iterator returned by map\'s find() method will this points at the开发者_如何学Python same data even if I\'ll add (o

This question may sounds lame, but I haven't found clear answer. Can I assume, that iterator returned by map's find() method will this points at the开发者_如何学Python same data even if I'll add (or remove) other elements to the same map? It's unclear for me if map's iterator points at position in map or at specific data...


You can keep using the same iterator after insert or erase operations. The standard says (C++03 standard, Section 23.1.2, paragraph 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.

This is true for all associative containers (map, set, multimap, multiset).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号