title: C++ iterating with changing vector.size()
body: <p>I've written some perhaps naive code that is meant to remove elements from a vector that are too similar. The functionality is fine, but I think I may get unexpected results now and then because of the dynamic resizing of the vector. </p>
  
  <pre><code>for (size_t i = 0 ; i &lt; vec.size(); i++) {
      for(size_t j = i+1; j &lt; vec.size(); j++) {
          if(norm(vec[i]-vec[j]) &lt;= 20 ) {
              vec.erase(vec.begin()+j);
          }
      }
  }
  </code></pre>
  
  <p>Is this safe to do? I'm concerned about i and j correctly adapting as I erase elements.</p>