title: C++, count_if, and equals
body: <p>I have a <code>struct</code> with a name and number:</p>
  
  <pre><code>struct S {
    string name;
    int number;
  };
  </code></pre>
  
  <p>Objects of <code>S</code> are stored in a vector. The vector is sorted based on <code>name</code>. There may be more than 1 item with the same <code>name</code>.</p>
  
  <p>When iterating over the items in the vector, I'm trying to use <code>count_if</code> to detect duplicates:</p>
  
  <pre><code>for(size_t i = 0; i &lt; v.size(); ++i)
  {
    const S&amp; s = v[i];
    int count = count_if(v.begin(), v.end(), XXX);
    // do something with count
  }
  </code></pre>
  
  <p>In the above, I can't figure out what XXX should be. I tried to create a predicate, but its pretty useless since there's nothing to compare:</p>
  
  <pre><code>bool IsEqualName(const S&amp; s) {
    return s.name == ???;
  }
  </code></pre>
  
  <p>The documentation I'm finding <a href="http://www.cplusplus.com/reference/algorithm/count_if/" rel="nofollow">leaves a lot to be desired</a>.</p>
  
  <p>I feel like I am missing something very obvious, but I don't see what it is. Could anyone point out my mistake?</p>
  
  <p>Jeff</p>