title: find_if can not detect the vector is empty
body: <p>I want to use <code>find_if</code> from <code>#include &lt;algorithm&gt;</code>, however the problem is it can not recognize that the vector is empty or not.</p>
  
  <p>Assume the following snippet</p>
  
  <pre><code>typedef std::vector&lt; std::pair&lt;int , int &gt; &gt; myVector;
  myVector aVector;
  struct equal: std::unary_function&lt; std::pair&lt;int , int &gt;,bool &gt;
  {
    equal(const int &amp;aNum) : theNum(aNum) {}
    bool operator()(const std::pair&lt;int , int &gt; &amp;arg) const { return arg.first == theNum; }
    const int &amp;theNum;
  };
  ...
  
  void check_and_insert(int num) {
     myVector::iterator it = find_if( aVector.begin(), aVector.end(), equal(num));
     if (it == aVector.end())
       aVector.push_back( std::make_pair(num, 1) );
     else
       ++dit-&gt;second;
  }
  </code></pre>
  
  <p>Assume <code>aVector</code> is empty. I see that result of <code>find_if</code> is not <code>aVector.end()</code> so it goes to <code>else</code> which is wrong. Is this the way that find_if work? It is strange but I can fix that by inserting the first element:</p>
  
  <pre><code>if (aVector.empty()) {
    aVector.push_back( std::make_pair(num, 1) );
    return;
  }
  // find_if...
  </code></pre>
  
  <p>Is this the only solution? Is there any better idea?   </p>
  
  <p><strong>UPDATE</strong> 
  As stated in the comments, the find_if works properly. The bug was that <code>aVector</code> was modified by a call by reference in another function. Thanks for all helps and sorry for disturbance </p>