Figure 4: Function lower_bound_find

template<class RanIt, class T> inline
RanIt lower_bound_find(RanIt first, RanIt last, const T& val)
{
   RanIt lb = std::lower_bound(first, last, val);
   if( lb == last)
      return last;
   else if( *lb != val )
      return last;
   else
      return lb;
}