minmax.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_ALGORITHM_MINMAX_HPP 00010 #define ADOBE_ALGORITHM_MINMAX_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <boost/range/begin.hpp> 00015 #include <boost/range/end.hpp> 00016 #include <boost/bind.hpp> 00017 00018 #include <algorithm> 00019 00020 /*************************************************************************************************/ 00021 00022 namespace adobe { 00023 00024 /*************************************************************************************************/ 00057 /*************************************************************************************************/ 00058 00065 template <class T> 00066 inline const T& (min)(const T& a, const T& b) 00067 { return a < b ? a : b; } 00068 00075 template <class T> 00076 inline T& (min)(T& a, T& b) 00077 { return a < b ? a : b; } 00078 00085 template <class T> 00086 inline const T& (max)(const T& a, const T& b) 00087 { return b < a ? a : b; } 00088 00095 template <class T> 00096 inline T& (max)(T& a, T& b) 00097 { return b < a ? a : b; } 00098 00105 template <class T, class Compare> 00106 inline const T& (min)(const T& a, const T& b, Compare comp) 00107 { 00108 return (std::min)(a, b, boost::bind(comp, _1, _2)); 00109 } 00110 00117 template <class T, class Compare> 00118 inline T& (min)(T& a, T& b, Compare comp) 00119 { 00120 return (std::min)(a, b, boost::bind(comp, _1, _2)); 00121 } 00122 00129 template <class T, class Compare> 00130 inline const T& (max)(const T& a, const T& b, Compare comp) 00131 { 00132 return boost::bind(comp, _1, _2)(b, a) ? a : b; 00133 } 00134 00141 template <class T, class Compare> 00142 inline T& (max)(T& a, T& b, Compare comp) 00143 { 00144 return boost::bind(comp, _1, _2)(b, a) ? a : b; 00145 } 00146 00152 template <class ForwardRange> 00153 inline typename boost::range_iterator<ForwardRange>::type min_element(ForwardRange& range) 00154 { 00155 return std::min_element(boost::begin(range), boost::end(range)); 00156 } 00157 00163 template <class ForwardRange> 00164 inline typename boost::range_const_iterator<ForwardRange>::type 00165 min_element(const ForwardRange& range) 00166 { 00167 return std::min_element(boost::begin(range), boost::end(range)); 00168 } 00169 00175 template <class ForwardIterator, class Compare> 00176 inline ForwardIterator min_element(ForwardIterator first, ForwardIterator last, Compare comp) 00177 { 00178 return std::min_element(first, last, boost::bind(comp, _1, _2)); 00179 } 00180 00186 template <class ForwardRange, class Compare> 00187 inline typename boost::range_iterator<ForwardRange>::type 00188 min_element(ForwardRange& range, Compare comp) 00189 { 00190 return adobe::min_element(boost::begin(range), boost::end(range), comp); 00191 } 00192 00198 template <class ForwardRange, class Compare> 00199 inline typename boost::range_const_iterator<ForwardRange>::type 00200 min_element(const ForwardRange& range, Compare comp) 00201 { 00202 return adobe::min_element(boost::begin(range), boost::end(range), comp); 00203 } 00204 00210 template <class ForwardRange> 00211 inline typename boost::range_iterator<ForwardRange>::type max_element(ForwardRange& range) 00212 { 00213 return std::max_element(boost::begin(range), boost::end(range)); 00214 } 00215 00221 template <class ForwardRange> 00222 inline typename boost::range_const_iterator<ForwardRange>::type 00223 max_element(const ForwardRange& range) 00224 { 00225 return std::max_element(boost::begin(range), boost::end(range)); 00226 } 00227 00233 template <class ForwardIterator, class Compare> 00234 inline ForwardIterator max_element(ForwardIterator first, ForwardIterator last, Compare comp) 00235 { 00236 return std::max_element(first, last, boost::bind(comp, _1, _2)); 00237 } 00238 00244 template <class ForwardRange, class Compare> 00245 inline typename boost::range_iterator<ForwardRange>::type 00246 max_element(ForwardRange& range, Compare comp) 00247 { 00248 return adobe::max_element(boost::begin(range), boost::end(range), comp); 00249 } 00250 00256 template <class ForwardRange, class Compare> 00257 inline typename boost::range_const_iterator<ForwardRange>::type 00258 max_element(const ForwardRange& range, Compare comp) 00259 { 00260 return adobe::max_element(boost::begin(range), boost::end(range), comp); 00261 } 00262 00263 /*************************************************************************************************/ 00264 00265 } // namespace adobe 00266 00267 /*************************************************************************************************/ 00268 00269 #endif 00270 00271 /*************************************************************************************************/ |