File indexing completed on 2025-01-18 09:28:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_ALGORITHM_SORT_SUBRANGE_HPP
0019 #define BOOST_ALGORITHM_SORT_SUBRANGE_HPP
0020
0021 #include <functional> // For std::less
0022 #include <iterator> // For std::iterator_traits
0023 #include <algorithm> // For nth_element and partial_sort
0024
0025 #include <boost/config.hpp>
0026 #include <boost/range/begin.hpp>
0027 #include <boost/range/end.hpp>
0028
0029 namespace boost { namespace algorithm {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 template<typename Iterator, typename Pred>
0046 void sort_subrange (
0047 Iterator first, Iterator last,
0048 Iterator sub_first, Iterator sub_last,
0049 Pred p)
0050 {
0051 if (sub_first == sub_last) return;
0052
0053 if (sub_first != first) {
0054 (void) std::nth_element(first, sub_first, last, p);
0055 ++sub_first;
0056 }
0057 std::partial_sort(sub_first, sub_last, last, p);
0058 }
0059
0060
0061
0062 template<typename Iterator>
0063 void sort_subrange (Iterator first, Iterator last, Iterator sub_first, Iterator sub_last)
0064 {
0065 typedef typename std::iterator_traits<Iterator>::value_type value_type;
0066 return sort_subrange(first, last, sub_first, sub_last, std::less<value_type>());
0067 }
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 template<typename Iterator, typename Pred>
0087 void partition_subrange (
0088 Iterator first, Iterator last,
0089 Iterator sub_first, Iterator sub_last,
0090 Pred p)
0091 {
0092 if (sub_first != first) {
0093 (void) std::nth_element(first, sub_first, last, p);
0094 ++sub_first;
0095 }
0096
0097 if (sub_last != last)
0098 (void) std::nth_element(sub_first, sub_last, last, p);
0099 }
0100
0101 template<typename Iterator>
0102 void partition_subrange (Iterator first, Iterator last, Iterator sub_first, Iterator sub_last)
0103 {
0104 typedef typename std::iterator_traits<Iterator>::value_type value_type;
0105 return partition_subrange(first, last, sub_first, sub_last, std::less<value_type>());
0106 }
0107
0108 }}
0109
0110 #endif