title: How to remove an element from std::vector if the element id matches a search parameter
body: <p>I'm trying to write an algorithm which will search for, and remove an item from a vector of items, if the item ID matches an argument. See example code below:</p>
  
  <pre><code>struct item{
      item(int newID){id = newID;}
      bool operator==(const item&amp; other){return id = other.id;}
      int id
  };
  
  std::vector&lt;std::unique_ptr&lt;item&gt;&gt; vec;
  
  vec.push_back(std::unique_ptr&lt;item&gt;(new item(10));
  vec.push_back(std::unique_ptr&lt;item&gt;(new item(15));
  vec.push_back(std::unique_ptr&lt;item&gt;(new item(20));
  </code></pre>
  
  <p>so, using the above code, I want to be able to search for the item which stores the value 15, and remove it from the vector, deleting it.</p>
  
  <p>How would I go about doing this?</p>
  
  <p>Admittedly, I probably need to brush up on the use of unique pointers too, so please feel free to correct me if my syntax is incorrect.</p>
  
  <p>Some of the solutions I have attempted are as follows:</p>
  
  <pre><code>void remove_item(int id){
      vec.erase(
                 std::remove_if(
                                 vec.begin(),
                                 vec.end(),
                                 [](const item&amp; e){
                                       return id==e.id;
                                 }),
                 vec.end()
                );
  </code></pre>
  
  <p>The above code produces an error stating that the variable id is not part of the capture list for lambda expression.</p>
  
  <p>Secondly, I've tried:</p>
  
  <pre><code>void remove_item(item e){
      auto iter = std::find(vec.begin(), vec.end(), e);
      vec.erase(iter);
  }
  </code></pre>
  
  <p>The above code in this case produces type mismatch errors in the == operator member function.</p>