File indexing completed on 2025-12-16 10:27:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ALGORITHM_MAX_HPP
0015 #define RANGES_V3_ALGORITHM_MAX_HPP
0016
0017 #include <initializer_list>
0018
0019 #include <range/v3/range_fwd.hpp>
0020
0021 #include <range/v3/functional/comparisons.hpp>
0022 #include <range/v3/functional/identity.hpp>
0023 #include <range/v3/functional/invoke.hpp>
0024 #include <range/v3/iterator/concepts.hpp>
0025 #include <range/v3/iterator/traits.hpp>
0026 #include <range/v3/range/access.hpp>
0027 #include <range/v3/range/concepts.hpp>
0028 #include <range/v3/range/traits.hpp>
0029 #include <range/v3/utility/static_const.hpp>
0030
0031 #include <range/v3/detail/prologue.hpp>
0032
0033 namespace ranges
0034 {
0035
0036
0037 RANGES_FUNC_BEGIN(max)
0038
0039
0040 template(typename T, typename C = less, typename P = identity)(
0041 requires indirect_strict_weak_order<C, projected<T const *, P>>)
0042 constexpr T const & RANGES_FUNC(max)(
0043 T const & a, T const & b, C pred = C{}, P proj = P{})
0044 {
0045 return invoke(pred, invoke(proj, b), invoke(proj, a)) ? a : b;
0046 }
0047
0048
0049 template(typename Rng, typename C = less, typename P = identity)(
0050 requires input_range<Rng> AND
0051 indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>> AND
0052 indirectly_copyable_storable<iterator_t<Rng>, range_value_t<Rng> *>)
0053 constexpr range_value_t<Rng>
0054 RANGES_FUNC(max)(Rng && rng, C pred = C{}, P proj = P{})
0055 {
0056 auto first = ranges::begin(rng);
0057 auto last = ranges::end(rng);
0058 RANGES_EXPECT(first != last);
0059 range_value_t<Rng> result = *first;
0060 while(++first != last)
0061 {
0062 auto && tmp = *first;
0063 if(invoke(pred, invoke(proj, result), invoke(proj, tmp)))
0064 result = (decltype(tmp) &&)tmp;
0065 }
0066 return result;
0067 }
0068
0069
0070 template(typename T, typename C = less, typename P = identity)(
0071 requires copyable<T> AND
0072 indirect_strict_weak_order<C, projected<T const *, P>>)
0073 constexpr T RANGES_FUNC(max)(
0074 std::initializer_list<T> const && rng, C pred = C{}, P proj = P{})
0075 {
0076 return (*this)(rng, std::move(pred), std::move(proj));
0077 }
0078
0079 RANGES_FUNC_END(max)
0080
0081 namespace cpp20
0082 {
0083 using ranges::max;
0084 }
0085
0086 }
0087
0088 #include <range/v3/detail/epilogue.hpp>
0089
0090 #endif