How can I eliminate an element in a vector if a condition is met
<p>I have a vector of Rect: <code>vector&lt;Rect&gt; myRecVec;</code></p>

<p>I would like to remove the ones which are overlapping in the vector:</p>

<p>So I have 2 nested loop like this:</p>

<pre><code>vector&lt;Rect&gt;::iterator iter1 = myRecVec.begin();
vector&lt;Rect&gt;::iterator iter2 = myRecVec.begin();

while( iter1 != myRecVec.end() ) {
    Rectangle r1 = *iter1;

    while( iter2 != myRecVec.end() ) {
        Rectangle r2 = *iter1;

        if (r1 != r2) { 
             if (r1.intersects(r2)) {
                 // remove r2 from myRectVec
             }
        }
    }
}
</code></pre>

<p>My question is how can I remove r2 from the myRectVect without screwing up both my iterators? Since I am iterating a vector and modifying the vector at the same time?
I have thought about putting r2 in a temp rectVect and then remove them from the rectVect later (after the iteration). But how can I skip the ones in this temp rectVect during iteration?</p>
