title: Using std::remove_if with lambda predicate to delete multiple elements
body: <p>What would be the fastest and most efficient way of using std::remove_if with lambda predicate to delete multiple elements at the same time? At the moment I have a point struct with position and unique id. Inside an update loop we fill the points vector and we add points to be deleted at the end of the update loop. At the moment I have to call remove_if inside a loop to remove all the deleted points from the points vector. For example if we add 10 points per frame and after that we loop all the points to check if the point is outside screen bounds, if it is its added to deletedPoints_.</p>
  
  <pre><code>struct Point
  {
      /// Position.
      Vector3 position_;
      /// Unique id per point
      int id_;
  }
  
  /// Current max id
  int maxId_;
  
  /// All points
  std::vector&lt;Point&gt; points_;
  /// Deleted points
  std::vector&lt;Point&gt; deletedPoints_;
  
  
  //Updates with 60fps
  void App::Update()
  {
      /// Add 10 points per frame
      for (int i = 0; i &lt; 10; ++i)
      {
          Point newPoint;
          /// Add position
          newPoint.position_ = worldPosition;
          /// Add id starts from 1
          maxId_ += 1;
          startPoint.id_ = maxId_;
          /// Add new point in points
          points_.push(newPoint);
      }
  
      /// If points outside of screen bounds add them to deletedPoints_
      if (points_.size() &gt; 0)
      {
          for (int i = 0; i &lt; points_.size(); ++i)
          {
              /// Bounds
              Vector2 min = Vector2(0.00,0.00);
              Vector2 max = Vector2(1.00,1.00);
              /// Check Bounds 
              if(points_[i].x &lt; min.x || points_[i].y &lt; min.y || points_[i].x &gt; max.x || points_[i].y &gt; max.y)
              {   
                  deletedPoints_.push(points_[i]);
              }
  
          }
  
          /// Loop deleted points
          for (int i = 0; i &lt; deletedPoints_.size(); ++i)
          {
              int id = deletedPoints_[i].id_;
              /// Remove by id
              auto removeIt = std::remove_if(points_.begin(), points_.end(),
                                    [id](const TrailPoint2&amp; point)
                                    { return point.id_ == id; });
              points_.erase(removeIt, points_.end());
          }
      }
  
  
   }
  </code></pre>