Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You write (emphasis by me): </p> <blockquote> <p>§23.1.2.8 in the standard states that insertion/deletion operations on a set/map will not invalidate any iterators <em>to those objects</em> (except iterators pointing to a deleted element).</p> </blockquote> <p>Actually, the text of 23.1.2/8 is a bit different (again, emphasis by me): </p> <blockquote> <p>The insert members shall not affect the validity of iterators and references <em>to the container</em>, and the erase members shall invalidate only iterators and references to the erased elements.</p> </blockquote> <p>I read this as: If you have a map, and somehow obtain an iterator into this map (again: it doesn't say <em>to an object</em> in the map), this iterator will stay valid despite insertion and removal of elements. Assuming <code>std::map&lt;K,V&gt;::end()</code> obtains an "iterator into the map", it should not be invalidated by insertion/removal. </p> <p>This, of course, leaves the question whether "not invalidated" means it will always have the same value. My personal assumption is that this is not specified. However, in order for the "not invalidated" phrase to make sense, all results of <code>std::map&lt;K,V&gt;::end()</code> for the same map must always compare equal even in the face of insertions/removal: </p> <pre><code>my_map_t::iterator old_end = my_map.end(); // wildly change my_map assert( old_end == my_map.end() ); </code></pre> <p>My interpretation is that, if <code>old_end</code> remains "valid" throughout changes to the map (as the standard promisses), then that assertion should pass. </p> <p><em>Disclaimer</em>: I am not a native speaker and have a <em>very</em> hard time digesting that dreaded legaleze of the Holy PDF. In fact, in general I avoid it like the plague. </p> <p>Oh, and my first thought also was: The question is interesting from an academic POV, but why doesn't he simply store keys instead of iterators? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload