Return an iterator from std::lower_bound : lower_bound « STL Algorithms Binary search « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <algorithm>
#include <vector>
#include <iterator>

int main()
{
   int a1[ 10 ] = { 2, 2, 4, 4, 4, 6, 6, 6, 6, 8 };
   std::vector< int > v( a1, a1 + 10 );
   std::ostream_iterator< int > output( cout, " " );

   std::copy( v.begin(), v.end(), output );

   std::vector< int >::iterator lower;
   lower = std::lower_bound( v.begin(), v.end(), 6 );
   cout << ( lower - v.begin() );

   return 0;
}
2 2 4 4 4 6 6 6 6 8 5








26.3.lower_bound
26.3.1.Return an iterator from std::lower_bound
26.3.2.Use lower_bound to locate the first point at which 5 can be inserted in order
26.3.3.Lower bound of 6