1// (C) Copyright Herve Bronnimann 2004.
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6/*
7 Revision history:
8 1 July 2004
9 Split the code into two headers to lessen dependence on
10 Boost.tuple. (Herve)
11 26 June 2004
12 Added the code for the boost minmax library. (Herve)
13*/
14
15#ifndef BOOST_ALGORITHM_MINMAX_HPP
16#define BOOST_ALGORITHM_MINMAX_HPP
17
18/* PROPOSED STANDARD EXTENSIONS:
19 *
20 * minmax(a, b)
21 * Effect: (b<a) ? std::make_pair(b,a) : std::make_pair(a,b);
22 *
23 * minmax(a, b, comp)
24 * Effect: comp(b,a) ? std::make_pair(b,a) : std::make_pair(a,b);
25 *
26 */
27
28#include <boost/tuple/tuple.hpp> // for using pairs with boost::cref
29#include <boost/ref.hpp>
30
31namespace boost {
32
33 template <typename T>
34 tuple< T const&, T const& >
35 minmax(T const& a, T const& b) {
36 return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
37 }
38
39 template <typename T, class BinaryPredicate>
40 tuple< T const&, T const& >
41 minmax(T const& a, T const& b, BinaryPredicate comp) {
42 return comp(b,a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
43 }
44
45} // namespace boost
46
47#endif // BOOST_ALGORITHM_MINMAX_HPP
48