equal_range( v.begin(), v.end(), 6 ) : equal_range « STL Algorithms Binary search « C++ Tutorial






#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
   const int SIZE = 10;
   int a1[] = { 2, 2, 4, 4, 4, 6, 6, 6, 6, 8 };
   vector< int > v( a1, a1 + SIZE );

   pair< vector< int >::iterator, vector< int >::iterator > eq;
   eq = equal_range( v.begin(), v.end(), 6 );
   cout << "\nUsing equal_range:\n" << "   Lower bound of 6 is element "
        << ( eq.first - v.begin() ) << " of vector v";
   cout << "\n   Upper bound of 6 is element "
        << ( eq.second - v.begin() ) << " of vector v";

   return 0;
}








26.2.equal_range
26.2.1.Use equal_range to determine both the lower- and upper-bound insertion points
26.2.2.equal_range and distance
26.2.3.Use equal function to check whether both collections are equal
26.2.4.Use equal function to check for corresponding even and odd elements
26.2.5.Use equal_range to locate the first and last point at which 5 can be inserted in order
26.2.6.equal_range( v.begin(), v.end(), 6 )