sort.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_SORT_HPP 00010 #define ADOBE_ALGORITHM_SORT_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 /*************************************************************************************************/ 00034 /*************************************************************************************************/ 00040 template <class RandomAccessRange> 00041 inline void sort(RandomAccessRange& range) 00042 { 00043 return std::sort(boost::begin(range), boost::end(range)); 00044 } 00045 00051 template <class RandomAccessIterator, class Compare> 00052 inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) 00053 { 00054 return std::sort(first, last, boost::bind(comp, _1, _2)); 00055 } 00056 00062 template <typename I, // I models RandomAccessIterator 00063 typename C, // C models StrictWeakOrdering(T, T) 00064 typename P> // P models UnaryFunction(value_type(I)) -> T 00065 inline void sort(I f, I l, C c, P p) 00066 { 00067 return std::sort(f, l, boost::bind(c, boost::bind(p, _1), boost::bind(p, _2))); 00068 } 00069 00075 template <typename R, // I models RandomAccessRange 00076 typename C, // C models StrictWeakOrdering(T, T) 00077 typename P> // P models UnaryFunction(value_type(I)) -> T 00078 inline void sort(R& r, C c, P p) 00079 { 00080 return adobe::sort(boost::begin(r), boost::end(r), boost::bind(c, boost::bind(p, _1), 00081 boost::bind(p, _2))); 00082 } 00083 00089 template <class RandomAccessRange, class Compare> 00090 inline void sort(RandomAccessRange& range, Compare comp) 00091 { 00092 return adobe::sort(boost::begin(range), boost::end(range), comp); 00093 } 00094 00100 template <class RandomAccessRange> 00101 inline void stable_sort(RandomAccessRange& range) 00102 { 00103 return std::stable_sort(boost::begin(range), boost::end(range)); 00104 } 00105 00111 template <class RandomAccessIterator, class Compare> 00112 inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) 00113 { 00114 return std::stable_sort(first, last, boost::bind(comp, _1, _2)); 00115 } 00116 00122 template <class RandomAccessRange, class Compare> 00123 inline void stable_sort(RandomAccessRange& range, Compare comp) 00124 { 00125 return adobe::stable_sort(boost::begin(range), boost::end(range), comp); 00126 } 00127 00133 template <class InputRange, class RandomAccessRange> 00134 inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range) 00135 { 00136 return std::partial_sort_copy( boost::begin(range), boost::end(range), 00137 boost::begin(result_range), boost::end(result_range)); 00138 } 00139 00145 template <class InputRange, class RandomAccessRange> 00146 inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range) 00147 { 00148 return std::partial_sort_copy( boost::begin(range), boost::end(range), 00149 boost::begin(result_range), boost::end(result_range)); 00150 } 00151 00157 template <class InputIterator, class RandomAccessIterator, class Compare> 00158 inline void partial_sort_copy( InputIterator first, InputIterator last, 00159 RandomAccessIterator result_first, RandomAccessIterator result_last, 00160 Compare comp) 00161 { 00162 return std::partial_sort_copy(first, last, result_first, result_last, boost::bind(comp, _1, _2)); 00163 } 00164 00170 template <class InputRange, class RandomAccessRange, class Compare> 00171 inline void partial_sort_copy(InputRange& range, RandomAccessRange& result_range, Compare comp) 00172 { 00173 return adobe::partial_sort_copy(boost::begin(range), boost::end(range), 00174 boost::begin(result_range), boost::end(result_range), 00175 comp); 00176 } 00177 00183 template <class InputRange, class RandomAccessRange, class Compare> 00184 inline void partial_sort_copy(const InputRange& range, RandomAccessRange& result_range, Compare comp) 00185 { 00186 return adobe::partial_sort_copy(boost::begin(range), boost::end(range), 00187 boost::begin(result_range), boost::end(result_range), 00188 comp); 00189 } 00190 00191 /*************************************************************************************************/ 00192 00193 } // namespace adobe 00194 00195 /*************************************************************************************************/ 00196 00197 #endif 00198 00199 /*************************************************************************************************/ |