~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/algorithm/minmax/example/minmax_ex.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
12
#include <boost/algorithm/minmax.hpp>
 
13
#include <boost/algorithm/minmax_element.hpp>
 
14
 
 
15
int main()
 
16
{
 
17
  using namespace std;
 
18
 
 
19
  // Demonstrating minmax()
 
20
  boost::tuple<int const&, int const&> result1 = boost::minmax(1, 0);
 
21
  assert( result1.get<0>() == 0 );
 
22
  assert( result1.get<1>() == 1 );
 
23
 
 
24
 
 
25
  // Demonstrating minmax_element()
 
26
  list<int> L;
 
27
  typedef list<int>::const_iterator iterator;
 
28
  generate_n(front_inserter(L), 1000, rand);
 
29
  pair< iterator, iterator > result2 = boost::minmax_element(L.begin(), L.end());
 
30
 
 
31
  cout << "The smallest element is " << *(result2.first) << endl;
 
32
  cout << "The largest element is  " << *(result2.second) << endl;
 
33
 
 
34
  assert( result2.first  == std::min_element(L.begin(), L.end()) );
 
35
  assert( result2.second == std::max_element(L.begin(), L.end()) );
 
36
}