Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:16

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 // Copyright 2019 Glen Joseph Fernandes (glenjofe@gmail.com)
0007 //
0008 // For more information, see http://www.boost.org/libs/range/
0009 //
0010 #ifndef BOOST_RANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED
0011 #define BOOST_RANGE_ALGORITHM_MAX_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 max_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(*result, *first)) {
0038             result = first;
0039         }
0040     }
0041     return result;
0042 }
0043 
0044 } // namespace detail
0045 
0046 /// \brief template function max_element
0047 ///
0048 /// range-based version of the max_element std algorithm
0049 ///
0050 /// \pre ForwardRange is a model of the ForwardRangeConcept
0051 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
0052 template<class ForwardRange>
0053 inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
0054 max_element(ForwardRange& rng)
0055 {
0056     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0057     return detail::max_element(boost::begin(rng), boost::end(rng), detail::less());
0058 }
0059 
0060 /// \overload
0061 template<class ForwardRange>
0062 inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
0063 max_element(const ForwardRange& rng)
0064 {
0065     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0066     return detail::max_element(boost::begin(rng), boost::end(rng), detail::less());
0067 }
0068 
0069 /// \overload
0070 template<class ForwardRange, class BinaryPredicate>
0071 inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
0072 max_element(ForwardRange& rng, BinaryPredicate pred)
0073 {
0074     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0075     return detail::max_element(boost::begin(rng), boost::end(rng), pred);
0076 }
0077 
0078 /// \overload
0079 template<class ForwardRange, class BinaryPredicate>
0080 inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
0081 max_element(const ForwardRange& rng, BinaryPredicate pred)
0082 {
0083     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0084     return detail::max_element(boost::begin(rng), boost::end(rng), pred);
0085 }
0086 
0087 // range_return overloads
0088 
0089 /// \overload
0090 template<range_return_value re, class ForwardRange>
0091 inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
0092 max_element(ForwardRange& rng)
0093 {
0094     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0095     return range_return<ForwardRange,re>::pack(
0096         detail::max_element(boost::begin(rng), boost::end(rng), detail::less()),
0097         rng);
0098 }
0099 
0100 /// \overload
0101 template<range_return_value re, class ForwardRange>
0102 inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
0103 max_element(const ForwardRange& rng)
0104 {
0105     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
0106     return range_return<const ForwardRange,re>::pack(
0107         detail::max_element(boost::begin(rng), boost::end(rng), detail::less()),
0108         rng);
0109 }
0110 
0111 /// \overload
0112 template<range_return_value re, class ForwardRange, class BinaryPredicate>
0113 inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
0114 max_element(ForwardRange& rng, BinaryPredicate pred)
0115 {
0116     BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
0117     return range_return<ForwardRange,re>::pack(
0118         detail::max_element(boost::begin(rng), boost::end(rng), pred),
0119         rng);
0120 }
0121 
0122 /// \overload
0123 template<range_return_value re, class ForwardRange, class BinaryPredicate>
0124 inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
0125 max_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::max_element(boost::begin(rng), boost::end(rng), pred),
0130         rng);
0131 }
0132 
0133     } // namespace range
0134     using range::max_element;
0135 } // namespace boost
0136 
0137 #endif // include guard