14#ifndef RANGES_V3_ALGORITHM_MINMAX_HPP
15#define RANGES_V3_ALGORITHM_MINMAX_HPP
17#include <initializer_list>
21#include <range/v3/algorithm/result_types.hpp>
30#include <range/v3/utility/static_const.hpp>
32#include <range/v3/detail/prologue.hpp>
39 using minmax_result = detail::min_max_result<T, T>;
41 RANGES_FUNC_BEGIN(minmax)
44 template(
typename T,
typename C =
less,
typename P = identity)(
45 requires indirect_strict_weak_order<C, projected<T const *, P>>)
46 constexpr minmax_result<T const &> RANGES_FUNC(minmax)(
47 T
const & a, T
const & b, C pred = C{}, P proj = P{})
49 using R = minmax_result<T const &>;
54 template(
typename Rng,
typename C =
less,
typename P = identity)(
55 requires input_range<Rng> AND
56 indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>> AND
57 indirectly_copyable_storable<iterator_t<Rng>, range_value_t<Rng> *>)
58 constexpr minmax_result<range_value_t<Rng>>
59 RANGES_FUNC(minmax)(Rng && rng, C pred = C{}, P proj = P{})
61 using R = minmax_result<range_value_t<Rng>>;
62 auto first = ranges::begin(rng);
63 auto last = ranges::end(rng);
64 RANGES_EXPECT(first != last);
71 result.min = (
decltype(tmp) &&)tmp;
73 result.max = (
decltype(tmp) &&)tmp;
75 while(++first != last)
77 range_value_t<Rng> tmp1 = *
first;
81 result.min = std::move(tmp1);
84 result.max = std::move(tmp1);
88 auto && tmp2 = *
first;
92 result.min = (
decltype(tmp2) &&)tmp2;
94 result.max = std::move(tmp1);
99 result.min = std::move(tmp1);
101 result.max = (
decltype(tmp2) &&)tmp2;
109 template(
typename T,
typename C =
less,
typename P = identity)(
110 requires copyable<T> AND
111 indirect_strict_weak_order<C, projected<T const *, P>>)
112 constexpr minmax_result<T> RANGES_FUNC(minmax)(
113 std::initializer_list<T>
const && rng, C pred = C{}, P proj = P{})
115 return (*
this)(rng, std::move(pred), std::move(proj));
118 RANGES_FUNC_END(minmax)
122 using ranges::minmax;
123 using ranges::minmax_result;
128#include <range/v3/detail/epilogue.hpp>
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition meta.hpp:2251
bool_<(T::type::value< U::type::value)> less
A Boolean integral constant wrapper around true if T::type::value is less than U::type::value; false,...
Definition meta.hpp:255