C++ containers' iterators
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
).
精彩评论