16.3.11. lower_bound, upper_bound and equal_range

Figure 16.11 demonstrates algorithms lower_bound, upper_bound and equal_range.

 1   // Fig. 16.11: fig16_11.cpp 2   // Algorithms lower_bound, upper_bound and 3   // equal_range for a sorted sequence of values. 4   #include <iostream> 5   #include <algorithm> // algorithm definitions 6   #include <array> // aray class-template definition 7   #include <iterator> // ostream_iterator 8   using namespace std; 9 10   int main()11   {12      const size_t SIZE = 10;13      array< int, SIZE > a = { 2, 2, 4, 4, 4, 6, 6, 6, 6, 8 };14      ostream_iterator< int > output( cout, " " );15 16      cout << "array a contains:\n";17      copy( a.cbegin(), a.cend(), output );18 19 ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.