Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
internal_relative_find.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_INTERNAL_RELATIVE_FIND_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTERNAL_RELATIVE_FIND_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_predicate.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/is_copy_assignable.hpp"
15
#
include
"stdlib/include/stdlib_detail/is_copy_constructible.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: friend "stdlib_detail/.*"
21
22
namespace
std
{
23
namespace
internal
{
24
25
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
26
27
/// @brief finds the element that best satisfies a relative metric
28
/// @tparam ForwardIterator iterator type
29
/// @tparam BinaryPredicate binary predicate type
30
/// @param first beginning of the range of elements
31
/// @param last end of the range of elements
32
/// @param pred binary predicate type implementing the relative metric
33
///
34
/// @return iterator to the first element that best satisfies @c pred.
35
///
36
template
<
37
class
ForwardIterator
,
38
class
BinaryPredicate
,
39
arene
::
base
::
constraints
<
40
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
41
std
::
enable_if_t
<
arene
::
base
::
is_predicate_v
<
42
BinaryPredicate
&,
43
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>,
44
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>>>> =
nullptr
>
45
constexpr
auto
relative_find
(
ForwardIterator
first
,
ForwardIterator
last
,
BinaryPredicate
pred
)
noexcept
(
46
std
::
is_nothrow_copy_constructible_v
<
ForwardIterator
> &&
//
47
std
::
is_nothrow_copy_assignable_v
<
ForwardIterator
>&&
//
48
noexcept
(
first
==
last
) &&
//
49
noexcept
(++
first
!=
last
) &&
//
50
noexcept
(
pred
(*
first
, *
first
))
51
) ->
ForwardIterator
{
52
if
(
first
==
last
) {
53
return
first
;
54
}
55
56
auto
best
=
first
;
57
58
// parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
59
++
first
;
60
// parasoft-end-suppress AUTOSAR-M5_0_15-a-2
61
while
(
first
!=
last
) {
62
if
(
pred
(*
first
, *
best
)) {
63
best
=
first
;
64
}
65
// parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
66
++
first
;
67
// parasoft-end-suppress AUTOSAR-M5_0_15-a-2
68
}
69
70
return
best
;
71
}
72
73
// parasoft-end-suppress AUTOSAR-M3_3_2-a
74
75
}
// namespace internal
76
}
// namespace std
77
78
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTERNAL_RELATIVE_FIND_HPP_
std::internal
Definition
internal_named_requirements.hpp:19
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
internal_relative_find.hpp
Generated by
1.13.2