title: is it safe to call delete inside a remove_if predicate?
body: <p>I have a vector</p>
  <pre class="lang-cpp prettyprint-override"><code>std::vector&lt;Object*&gt; objects;
  </code></pre>
  <p>And a method that removes an object if it's found:</p>
  <pre class="lang-cpp prettyprint-override"><code>void Remove(Object *o)
  {
      objects.erase(
          std::remove_if(
              objects.begin(), objects.end(),
              [&amp;o](Object *_object) {
                  if (o == _object)
                  {
                      delete _object;
                      return true;
                  }
                  return false;
              }
          ),
          objects.end()
      );
  }
  </code></pre>
  <p>Is this safe? Should I not call <code>delete</code>? But then would <code>erase</code> call <code>delete</code> for me? I'm a bit confused. Would this invalidate the iterator or leak memory?</p>