Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is probably worth adding that an insert iterator of any kind (<code>std::back_insert_iterator</code>, <code>std::front_insert_iterator</code>, <code>std::insert_iterator</code>) is guaranteed to remain valid as long as all insertions are performed through this iterator and no other iterator-invalidating event occurs.</p> <p>For example, when you are performing a series of insertion operations into a <code>std::vector</code> by using <code>std::insert_iterator</code> it is quite possible that the vector will experience a reallocation event, which will invalidate all iterators that "point" into that vector. However, the insert iterator in question is guaranteed to remain valid, i.e. you can safely continue the sequence of insertions. There's no need to worry about triggering vector reallocation at all.</p> <p>This, again, applies only to insertions performed through the insert iterator itself. If iterator-invalidating event is triggered by some independent action on the container, then the insert iterator becomes invalidated as well in accordance with the general rules.</p> <p>For example, this code</p> <pre><code>std::vector&lt;int&gt; v(10); std::vector&lt;int&gt;::iterator it = v.begin() + 5; std::insert_iterator&lt;std::vector&lt;int&gt; &gt; it_ins(v, it); for (unsigned n = 20; n &gt; 0; --n) *it_ins++ = rand(); </code></pre> <p>is guaranteed to perform a valid sequence of insertions into the vector, even if the vector "decides" to reallocate somewhere in the middle of this process.</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. 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.
    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