title: Using lower_bound, upper_bound, and binary_search to find the object with an equal member field
body: <p>I have a struct that looks like this,</p>
  
  <pre><code>struct Foo {
      int a;
  };
  </code></pre>
  
  <p>I have a vector of these structs that look like this,</p>
  
  <pre><code>vector&lt;Foo&gt; foos;
  </code></pre>
  
  <p>All of the <code>Foo</code>s are sorted by the integer <code>a</code> in ascending order using the STL sort() function. Now I want to get the <code>Foo</code> object that has the member field <code>a</code> less than or equal to a given number, like the STL lower_bound() function. The problem is that the STL lower_bound function declaration looks like this:</p>
  
  <pre><code>template &lt;class ForwardIterator, class T, class Compare&gt;
    ForwardIterator lower_bound ( ForwardIterator first, ForwardIterator last,
                                  const T&amp; value, Compare comp );
  </code></pre>
  
  <p>So while I want to do something like,</p>
  
  <pre><code>lower_bound(foos.begin(), foos.end(), 5, custom_comp);
  </code></pre>
  
  <p>I can't because the int I'm looking for (5 in this case) is not of the type <code>Foo</code>. I'm having this issue with lower_bound(), upper_bound(), and binary_search(). custom_comp only defines the ordering and doesn't define that an object with a = 5 actually equals the int 5.</p>
  
  <p>Is there any elegant way of doing this with STL?</p>
  
  <p>Edit:</p>
  
  <p>I realized my example doesn't completely represent my problem. What I actually have is that Foo contains two ints, a and b. When I call lower_bound, I don't have access to b (because I don't care about it). Now the issue with billz answer is that I'd have to define a constructor that takes only <code>a</code> as a parameter, which isn't very elegant in my opinion (because b is left undefined or abitrary, and this constructor can be used anywhere in the code). But if this is the only option, I'll take it.</p>