• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright Herve Bronnimann 2004.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <list>
7 #include <algorithm>
8 #include <cstdlib>
9 #include <cassert>
10 #include <iostream>
11 #include <iterator>
12 
13 #include <boost/algorithm/minmax.hpp>
14 #include <boost/algorithm/minmax_element.hpp>
15 
main()16 int main()
17 {
18   using namespace std;
19 
20   // Demonstrating minmax()
21   boost::tuple<int const&, int const&> result1 = boost::minmax(1, 0);
22   assert( result1.get<0>() == 0 );
23   assert( result1.get<1>() == 1 );
24 
25 
26   // Demonstrating minmax_element()
27   list<int> L;
28   typedef list<int>::const_iterator iterator;
29   generate_n(front_inserter(L), 1000, rand);
30   pair< iterator, iterator > result2 = boost::minmax_element(L.begin(), L.end());
31 
32   cout << "The smallest element is " << *(result2.first) << endl;
33   cout << "The largest element is  " << *(result2.second) << endl;
34 
35   assert( result2.first  == std::min_element(L.begin(), L.end()) );
36   assert( result2.second == std::max_element(L.begin(), L.end()) );
37 }
38