File indexing completed on 2025-01-30 09:59:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_RANGE_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED
0011 #define BOOST_RANGE_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED
0012
0013 #include <boost/concept_check.hpp>
0014 #include <boost/range/begin.hpp>
0015 #include <boost/range/end.hpp>
0016 #include <boost/range/concepts.hpp>
0017 #include <boost/range/detail/less.hpp>
0018 #include <boost/range/detail/range_return.hpp>
0019
0020 namespace boost
0021 {
0022 namespace range
0023 {
0024
0025 namespace detail
0026 {
0027
0028 template<typename Iterator, class Predicate>
0029 inline Iterator
0030 min_element(Iterator first, Iterator last, Predicate comp)
0031 {
0032 if (first == last) {
0033 return last;
0034 }
0035 Iterator result = first;
0036 while (++first != last) {
0037 if (comp(*first, *result)) {
0038 result = first;
0039 }
0040 }
0041 return result;
0042 }
0043
0044 }
0045
0046
0047
0048
0049
0050
0051
0052 template<class ForwardRange>
0053 inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
0054 min_element(ForwardRange& rng)
0055 {
0056 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0057 return detail::min_element(boost::begin(rng), boost::end(rng), detail::less());
0058 }
0059
0060
0061 template<class ForwardRange>
0062 inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
0063 min_element(const ForwardRange& rng)
0064 {
0065 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0066 return detail::min_element(boost::begin(rng), boost::end(rng), detail::less());
0067 }
0068
0069
0070 template<class ForwardRange, class BinaryPredicate>
0071 inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
0072 min_element(ForwardRange& rng, BinaryPredicate pred)
0073 {
0074 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0075 return detail::min_element(boost::begin(rng), boost::end(rng), pred);
0076 }
0077
0078
0079 template<class ForwardRange, class BinaryPredicate>
0080 inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
0081 min_element(const ForwardRange& rng, BinaryPredicate pred)
0082 {
0083 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0084 return detail::min_element(boost::begin(rng), boost::end(rng), pred);
0085 }
0086
0087
0088
0089
0090 template<range_return_value re, class ForwardRange>
0091 inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
0092 min_element(ForwardRange& rng)
0093 {
0094 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0095 return range_return<ForwardRange,re>::pack(
0096 detail::min_element(boost::begin(rng), boost::end(rng), detail::less()),
0097 rng);
0098 }
0099
0100
0101 template<range_return_value re, class ForwardRange>
0102 inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
0103 min_element(const ForwardRange& rng)
0104 {
0105 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0106 return range_return<const ForwardRange,re>::pack(
0107 detail::min_element(boost::begin(rng), boost::end(rng), detail::less()),
0108 rng);
0109 }
0110
0111
0112 template<range_return_value re, class ForwardRange, class BinaryPredicate>
0113 inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
0114 min_element(ForwardRange& rng, BinaryPredicate pred)
0115 {
0116 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0117 return range_return<ForwardRange,re>::pack(
0118 detail::min_element(boost::begin(rng), boost::end(rng), pred),
0119 rng);
0120 }
0121
0122
0123 template<range_return_value re, class ForwardRange, class BinaryPredicate>
0124 inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
0125 min_element(const ForwardRange& rng, BinaryPredicate pred)
0126 {
0127 BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0128 return range_return<const ForwardRange,re>::pack(
0129 detail::min_element(boost::begin(rng), boost::end(rng), pred),
0130 rng);
0131 }
0132
0133 }
0134 using range::min_element;
0135 }
0136
0137 #endif