29 KiB
[alg.min.max]
26 Algorithms library [algorithms]
26.8 Sorting and related operations [alg.sorting]
26.8.9 Minimum and maximum [alg.min.max]
`template constexpr const T& min(const T& a, const T& b); template<class T, class Compare> constexpr const T& min(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr const T& ranges::min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); `
Preconditions: For the first form, T meets theCpp17LessThanComparable requirements (Table 29).
Returns: The smaller value.
Returns the first argument when the arguments are equivalent.
Complexity: Exactly one comparison and two applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr T min(initializer_list r); template<class T, class Compare> constexpr T min(initializer_list r, Compare comp);
template<copyable T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr T ranges::min(initializer_list r, Comp comp = {}, Proj proj = {}); template<input_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> constexpr range_value_t ranges::min(R&& r, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> range_value_t ranges::min(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Preconditions: ranges::distance(r) > 0.
For the overloads in namespace std,T meets the Cpp17CopyConstructible requirements.
For the first form, T meets the Cpp17LessThanComparable requirements (Table 29).
Returns: The smallest value in the input range.
Returns a copy of the leftmost element when several elements are equivalent to the smallest.
Complexity: Exactly ranges::distance(r) - 1 comparisons and twice as many applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr const T& max(const T& a, const T& b); template<class T, class Compare> constexpr const T& max(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr const T& ranges::max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); `
Preconditions: For the first form, T meets theCpp17LessThanComparable requirements (Table 29).
Returns: The larger value.
Returns the first argument when the arguments are equivalent.
Complexity: Exactly one comparison and two applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr T max(initializer_list r); template<class T, class Compare> constexpr T max(initializer_list r, Compare comp);
template<copyable T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr T ranges::max(initializer_list r, Comp comp = {}, Proj proj = {}); template<input_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> constexpr range_value_t ranges::max(R&& r, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> range_value_t ranges::max(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Preconditions: ranges::distance(r) > 0.
For the overloads in namespace std,T meets the Cpp17CopyConstructible requirements.
For the first form, T meets the Cpp17LessThanComparable requirements (Table 29).
Returns: The largest value in the input range.
Returns a copy of the leftmost element when several elements are equivalent to the largest.
Complexity: Exactly ranges::distance(r) - 1 comparisons and twice as many applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr pair<const T&, const T&> minmax(const T& a, const T& b); template<class T, class Compare> constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr ranges::minmax_result<const T&> ranges::minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); `
Preconditions: For the first form, T meets theCpp17LessThanComparable requirements (Table 29).
Returns: {b, a} if b is smaller than a, and{a, b} otherwise.
Complexity: Exactly one comparison and two applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr pair<T, T> minmax(initializer_list t); template<class T, class Compare> constexpr pair<T, T> minmax(initializer_list t, Compare comp);
template<copyable T, class Proj = identity, indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less> constexpr ranges::minmax_result ranges::minmax(initializer_list r, Comp comp = {}, Proj proj = {}); template<input_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> constexpr ranges::minmax_result<range_value_t> ranges::minmax(R&& r, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> requires indirectly_copyable_storable<iterator_t, range_value_t> ranges::minmax_result<range_value_t> ranges::minmax(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Preconditions: ranges::distance(r) > 0.
For the overloads in namespace std,T meets the Cpp17CopyConstructible requirements.
For the first form, type T meets the Cpp17LessThanComparable requirements (Table 29).
Returns: Let X be the return type.
Returns X{x, y}, where x is a copy of the leftmost element with the smallest value andy a copy of the rightmost element with the largest value in the input range.
Complexity: At most (3/2)ranges::distance(r) applications of the corresponding predicate and twice as many applications of the projection, if any.
Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.
`template constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator> ForwardIterator min_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare> constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last, Compare comp); template<class ExecutionPolicy, class ForwardIterator, class Compare> ForwardIterator min_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Compare comp);
template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> constexpr I ranges::min_element(I first, S last, Comp comp = {}, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> constexpr borrowed_iterator_t ranges::min_element(R&& r, Comp comp = {}, Proj proj = {});
template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> I ranges::min_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> borrowed_iterator_t ranges::min_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.
Returns: The first iterator i in the range [first, last) such that for every iterator j in the range [first, last),bool(invoke(comp, invoke(proj, *j), invoke(proj, *i))) is false.
Returns last if first == last.
Complexity: Exactly max(last - first - 1,0) comparisons and twice as many projections.
`template constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator max_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare> constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last, Compare comp); template<class ExecutionPolicy, class ForwardIterator, class Compare> ForwardIterator max_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Compare comp);
template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> constexpr borrowed_iterator_t ranges::max_element(R&& r, Comp comp = {}, Proj proj = {});
template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> I ranges::max_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> borrowed_iterator_t ranges::max_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.
Returns: The first iterator i in the range [first, last) such that for every iterator j in the range [first, last),bool(invoke(comp, invoke(proj, *i), invoke(proj, *j))) is false.
Returns last if first == last.
Complexity: Exactly max(last - first - 1,0) comparisons and twice as many projections.
`template constexpr pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> pair<ForwardIterator, ForwardIterator> minmax_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare> constexpr pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); template<class ExecutionPolicy, class ForwardIterator, class Compare> pair<ForwardIterator, ForwardIterator> minmax_element(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Compare comp);
template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> constexpr ranges::minmax_element_result ranges::minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> constexpr ranges::minmax_element_result<borrowed_iterator_t> ranges::minmax_element(R&& r, Comp comp = {}, Proj proj = {});
template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> ranges::minmax_element_result ranges::minmax_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_strict_weak_order<projected<iterator_t, Proj>> Comp = ranges::less> ranges::minmax_element_result<borrowed_iterator_t> ranges::minmax_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `
Returns: {first, first} if [first, last) is empty, otherwise{m, M}, where m is the first iterator in [first, last) such that no iterator in the range refers to a smaller element, and where M is the last iterator204 in [first, last) such that no iterator in the range refers to a larger element.
Complexity: Let N be last - first.
At most max(â32(Nâ1)â,0) comparisons and twice as many applications of the projection, if any.
This behavior intentionally differs from max_element.