std::ranges::max() algorithm
- since C++20
- Simplified
- Detailed
// (1)
constexpr const T&
max( const T& a, const T& b, Comp comp = {}, Proj proj = {} );
// (2)
constexpr const T
max( std::initializer_list<T> r, Comp comp = {}, Proj proj = {} );
// (3)
constexpr ranges::range_value_t<R> max( R&& r, Comp comp = {}, Proj proj = {} );
The type of arguments are generic and have the following constraints:
T
- (none)Proj
- (none)Comp
- (none)
The Proj
and Comp
template arguments have, the following default types for all overloads: std::identity
, ranges::less
.
Additionally, each overload has the following constraints:
- (1) -
indirect_strict_weak_order<Comp, projected<const T*, Proj>>
- (2) -
indirect_strict_weak_order<Comp, projected<const T*, Proj>>
- (3) -
indirectly_copyable_storable<ranges::iterator_t<R>, ranges::range_value_t<R>*> && indirect_strict_weak_order<Comp, projected<ranges::iterator_t<R>, Proj>>
(The std::
namespace was ommitted here for readability)
// (1)
template<
class T,
class Proj = std::identity,
class Comp = ranges::less
>
requires std::indirect_strict_weak_order<Comp, std::projected<const T*, Proj>>
constexpr const T&
max( const T& a, const T& b, Comp comp = {}, Proj proj = {} );
// (2)
template<
std::copyable T,
class Proj = std::identity,
class Comp = ranges::less
>
requires std::indirect_strict_weak_order<Comp, std::projected<const T*, Proj>>
constexpr const T
max( std::initializer_list<T> r, Comp comp = {}, Proj proj = {} );
// (3)
template<
ranges::input_range R,
class Proj = std::identity,
class Comp = ranges::less
>
requires
std::indirectly_copyable_storable<ranges::iterator_t<R>, ranges::range_value_t<R>*>
&& std::indirect_strict_weak_order<Comp, std::projected<ranges::iterator_t<R>, Proj>>
constexpr ranges::range_value_t<R> max( R&& r, Comp comp = {}, Proj proj = {} );
Returns the greater of the given projected elements.
-
(1) Returns the greatest of
a
andb
. -
(2) Returns the first greatest element in the initializer list
r
. -
(3) Returns the first greatest value in the range
r
.
The function-like entities described on this page are niebloids.
Parameters
a b | The values to compare. |
r | The range of values to compare. |
comp | Comparison to apply to the projected elements. |
proj | Projection to apply to the elements. |