Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
max_element.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAX_ELEMENT_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAX_ELEMENT_HPP_
7
8
#
include
"arene/base/algorithm/detail/functional.hpp"
9
#
include
"arene/base/algorithm/detail/traits.hpp"
10
#
include
"arene/base/constraints.hpp"
11
#
include
"arene/base/type_traits/is_compare.hpp"
12
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
13
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
14
#
include
"stdlib/include/stdlib_detail/internal_relative_find.hpp"
15
#
include
"stdlib/include/stdlib_detail/move.hpp"
16
17
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
18
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
19
20
// IWYU pragma: private, include <algorithm>
21
// IWYU pragma: friend "stdlib_detail/.*"
22
23
namespace
std
{
24
25
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
26
27
/// @brief returns the largest element in a range
28
/// @tparam ForwardIterator iterator type
29
/// @tparam Compare binary predicate type
30
/// @param first beginning of the range of elements
31
/// @param last end of the range of elements
32
/// @param comp binary predicate which returns @c true if the first argument is ordered before the second
33
///
34
/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
35
/// @pre <tt>[begin, end)</tt> must be a valid range.
36
/// @pre The expression <tt>comp(e1, e2)</tt> must be convertible to @c bool
37
/// for every argument @c e1, @c e2 of type @c RT, where @c RT is the
38
/// reference type of @c ForwardIterator, regardless of value category, and
39
/// must not modify @c e1 or @c e2.
40
///
41
/// Finds the largest element, i.e. the element ordered after all other
42
/// elements, in the range <tt>[first, last)</tt>.
43
///
44
/// @return iterator to the largest element of the range <tt>[first, last)</tt>.
45
/// If several elements in the range are equivalent to the largest element,
46
/// returns the iterator to the first such element. Returns @c last if the
47
/// range is empty.
48
///
49
/// @note Complexity
50
/// Given N as <tt>std::distance(first, last)</tt>, exactly <tt>max(N - 1,
51
/// 0)</tt> applications of the comparator @c comp.
52
///
53
template
<
54
class
ForwardIterator
,
55
class
Compare
,
56
arene
::
base
::
constraints
<
57
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
58
std
::
enable_if_t
<
59
arene
::
base
::
is_compare_v
<
Compare
&,
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>>>> =
60
nullptr
>
61
constexpr
auto
max_element
(
ForwardIterator
first
,
ForwardIterator
last
,
Compare
comp
)
noexcept
(
62
noexcept
(
std
::
internal
::
relative_find
(
first
,
last
,
arene
::
base
::
algorithm_detail
::
flip
(
comp
)))
63
) ->
ForwardIterator
{
64
return
std
::
internal
::
relative_find
(
first
,
last
,
arene
::
base
::
algorithm_detail
::
flip
(
comp
));
65
}
66
67
/// @brief returns the largest element in a range
68
/// @tparam ForwardIterator iterator type
69
/// @tparam Compare binary predicate type
70
/// @param first beginning of the range of elements
71
/// @param last end of the range of elements
72
///
73
/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
74
/// @pre <tt>[begin, end)</tt> must be a valid range.
75
/// @pre The expression <tt>e1 < e2</tt> must be convertible to @c bool
76
/// for every argument @c e1, @c e2 of type @c RT, where @c RT is the
77
/// reference type of @c ForwardIterator, regardless of value category, and
78
/// must not modify @c e1 or @c e2.
79
///
80
/// Finds the largest element, i.e. the element ordered after all other
81
/// elements, in the range <tt>[first, last)</tt>.
82
///
83
/// @return iterator to the largest element of the range <tt>[first, last)</tt>.
84
/// If several elements in the range are equivalent to the largest element,
85
/// returns the iterator to the first such element. Returns @c last if the
86
/// range is empty.
87
///
88
/// @note Complexity
89
/// Given N as <tt>std::distance(first, last)</tt>, exactly <tt>max(N - 1,
90
/// 0)</tt> comparisons using @c operator<.
91
///
92
template
<
93
class
ForwardIterator
,
94
arene
::
base
::
constraints
<
95
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
96
std
::
enable_if_t
<
arene
::
base
::
is_compare_v
<
97
decltype
(
arene
::
base
::
algorithm_detail
::
operator_less
)&,
98
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>>>> =
nullptr
>
99
constexpr
auto
max_element
(
ForwardIterator
first
,
ForwardIterator
last
)
noexcept
(
100
noexcept
(
std
::
max_element
(
std
::
move
(
first
),
std
::
move
(
last
),
arene
::
base
::
algorithm_detail
::
operator_less
))
101
) ->
ForwardIterator
{
102
return
std
::
max_element
(
std
::
move
(
first
),
std
::
move
(
last
),
arene
::
base
::
algorithm_detail
::
operator_less
);
103
}
104
105
// parasoft-end-suppress AUTOSAR-M3_3_2-a
106
107
}
// namespace std
108
109
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAX_ELEMENT_HPP_
std::hash<::arene::base::result< void, E > >::operator()
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition
result.hpp:1827
stdlib
include
stdlib_detail
max_element.hpp
Generated by
1.13.2