title: How to use correct pointer for find and find_if when dealing with vector
body: <p>I have a structure like this:</p>
  
  <pre><code>struct client
  {
      string name;
      double money;
  };
  </code></pre>
  
  <p>I also have 2 predicates:</p>
  
  <pre><code>bool less_10(const client&amp; a)
  {
      return a.money &lt; 10;
  }
  
  bool not_a(const client&amp; a)
  {
      return a.name.at(0) != 'A';
  }
  </code></pre>
  
  <p>In my main function I use this to filter out the result stored in vector client_list (everyone with money &lt; 10 (choice 1) or everyone with name not start with A (else))</p>
  
  <pre><code>if (choice_filter == 1)
      {
          vector&lt;client&gt;::iterator it3;
          it3 = find_if(client_list.begin(), client_list.end(), less_10);
          while (it3 != client_list.end())
          {
              **client_list.erase(it3); 
              it3 = find_if(it3 + 1, client_list.end(), less_10);
          }
          client_list.erase(it3);**
      }
  
      else
      {
          vector&lt;client&gt;::iterator it4;
          it4 = find_if(client_list.begin(), client_list.end(), not_a);
  
          while (it4 != client_list.end())
          {
              **client_list.erase(it4);
              it4 = find_if(it4 + 1, client_list.end(), not_a);
          }
          client_list.erase(it4);**
  }
  </code></pre>
  
  <p>I notice that if I erase first, then find_if, i'll lost the last client. So i added 1 more line to erase, but the program crashes as iterator is now at the end, cant erase. </p>
  
  <p>Is there any way to get around this? I want to keep using find_if with predicates as well as while loop like above as they are required.</p>