Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The interesting question is really what does it mean for an iterator to be invalidated. And I truly don't have a good answer from the standard. What I do know is that to some extent the standard considers an iterator not as a pointer to a location inside the container, but rather as a proxy to a particular element that lives within the container.</p> <p>With that in mind, after erasing of a single element in the middle of a vector, all iterators after the point of removal become <em>invalidated</em> as they no longer refer to the same element that they referred to before.</p> <p>Support for this line of reasoning comes from the iterator invalidation clauses of other operations in the container. For example, on <code>insert</code>, the standard guarantees that if there is no reallocation the iterators <em>before</em> the point of insertion remain valid. <em>Exceptio probat regulam in casibus non exceptis</em>, it invalidates all iterators <em>after</em> the point of insertion.</p> <p>If the validity of iterators was only related to the fact that there is an element of the container where the iterator points, then <em>none</em> of the iterators would be invalidated with that operation (again, in the absence of reallocations). </p> <p>Going even further in that line of reasoning, if you consider iterator validity as <em>pointer validity</em>, then none of the iterators into a vector would be invalidated during an <code>erase</code> operation. The <code>end()-1</code> iterator would become non-dereferencable, but it could remain valid, which is not the case.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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