title: How do iterators update after vector reallocation
body: <p>Here is a code snippet that I was looking at: </p>
  
  <pre><code>vector&lt;int&gt; iv = {1,2,3,4,5,6,7,8,9,10};
  auto iter = iv.begin(), mid = iv.begin() + iv.size()/2;
  for(int count = 100; count; --count ) {
      iter = iv.insert(iter, - 1);
      cout &lt;&lt; "capacity = " &lt;&lt; iv.capacity() &lt;&lt; "*mid = " &lt;&lt; *mid &lt;&lt; endl;
  
  }
  </code></pre>
  
  <p>As per iterator invalidation rules:<br>
  vector: all iterators and references before the point of insertion are unaffected, unless the new container size is greater than the previous capacity (in which case all iterators and references are invalidated)[23.2.4.3/1] <a href="https://stackoverflow.com/questions/6438086/iterator-invalidation-rules">Iterator invalidation rules</a> </p>
  
  <p>I understand that since I am reassigning the value of "iter" at each insert operation, perhaps I am able to maintain it's validity  (please correct me if I am wrong). However, the iterator "mid" remain valid in this case even when I am not tampering with it in the loop and also when the capacity of the vector is changing. </p>
  
  <p>So, how is "mid" able to update itself after reallocation ?</p>
  
  <p>To know whether mid is changing at all or not, I changed  line 4 in the code to:</p>
  
  <pre><code>iv.insert(iter, -1); // Did not assign it back to iter.
  </code></pre>
  
  <p>Printing the results of dereferencing the value at mid suggests the change and perhaps also that iter is invalidated. (Again, please correct me if I am wrong).</p>