Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:26

0001 //  (C) Copyright Herve Bronnimann 2004.
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 /*
0007  Revision history:
0008    1 July 2004
0009       Split the code into two headers to lessen dependence on
0010       Boost.tuple. (Herve)
0011    26 June 2004
0012       Added the code for the boost minmax library. (Herve)
0013 */
0014 
0015 #ifndef BOOST_ALGORITHM_MINMAX_HPP
0016 #define BOOST_ALGORITHM_MINMAX_HPP
0017 
0018 /* PROPOSED STANDARD EXTENSIONS:
0019  *
0020  * minmax(a, b)
0021  * Effect: (b<a) ? std::make_pair(b,a) : std::make_pair(a,b);
0022  *
0023  * minmax(a, b, comp)
0024  * Effect: comp(b,a) ? std::make_pair(b,a) : std::make_pair(a,b);
0025  *
0026  */
0027 
0028 #include <boost/config.hpp>
0029 #include <boost/tuple/tuple.hpp> // for using pairs with boost::cref
0030 #include <boost/ref.hpp>
0031 
0032 namespace boost {
0033 
0034   template <typename T>
0035   tuple< T const&, T const& >
0036   minmax(T const& a, T const& b) {
0037     return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
0038   }
0039 
0040   template <typename T, class BinaryPredicate>
0041   tuple< T const&, T const& >
0042   minmax(T const& a, T const& b, BinaryPredicate comp) {
0043     return comp(b,a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
0044   }
0045 
0046 } // namespace boost
0047 
0048 #endif // BOOST_ALGORITHM_MINMAX_HPP