title: <algorithm> function for finding last item less-than-or-equal to, like lower_bound
body: <p>Is there a function in  that uses binary search, like <code>lower_bound</code> but that returns the <em>last</em> item <em>less-than-or-equal-to</em> according to a given predicate?</p>
  
  <p><code>lower_bound</code> is defined to: </p>
  
  <blockquote>
    <p>Finds the position of the <em>first</em> element in an ordered range that has a value <em>greater than or equivalent to</em> a specified value, where the ordering criterion may be specified by a binary predicate.</p>
  </blockquote>
  
  <p>and <code>upper_bound</code>: </p>
  
  <blockquote>
    <p>Finds the position of the <em>first</em> element in an ordered range that has a value that is <em>greater than</em> a specified value, where the ordering criterion may be specified by a binary predicate.</p>
  </blockquote>
  
  <p>Specifically, I have a container of time ordered events and for a given time I want to find the last item that came before or at that point.  Can I achieve this with some combination of upper/lower bound, reverse iterators and using <code>std::greater</code> or <code>std::greater_equal</code> ?</p>
  
  <p>EDIT: 
  A tweak was needed to user763305's suggestion to cope with if you ask for a point before the start of the array:</p>
  
  <pre><code>iterator it=upper_bound(begin(), end(), val, LessThanFunction());
  if (it!=begin()) {
    it--; // not at end of array so rewind to previous item
  } else {
    it=end(); // no items before this point, so return end()
  }
  return it;
  </code></pre>