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