Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
find.hpp
Go to the documentation of this file.
1
// Copyright 2024, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FIND_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FIND_HPP_
7
8
// IWYU pragma: private, include "arene/base/algorithm.hpp"
9
// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12
13
#
include
"arene/base/constraints/constraints.hpp"
14
#
include
"arene/base/iterator/advance.hpp"
15
#
include
"arene/base/stdlib_choice/enable_if.hpp"
16
#
include
"arene/base/stdlib_choice/is_copy_constructible.hpp"
17
#
include
"arene/base/stdlib_choice/iterator_traits.hpp"
18
#
include
"arene/base/type_traits/comparison_traits.hpp"
19
#
include
"arene/base/type_traits/denotes_range.hpp"
20
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
21
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
22
23
namespace
arene
{
24
namespace
base
{
25
26
/// @brief Constexpr-compatible implementation of @c std::find.
27
/// @tparam Iterator The type of the iterators
28
/// @tparam Value The type of the value being searched for
29
/// @param first The iterator for the start of the range
30
/// @param last The iterator for the end of the range
31
/// @param value_to_find The value to search for
32
/// @return Iterator The first iterator for which @c *it==value, or @c last if there is
33
/// no such iterator
34
template
<
35
typename
Iterator
,
36
typename
Value
,
37
constraints
<
38
std
::
enable_if_t
<
base
::
is_input_iterator_v
<
Iterator
>>,
39
std
::
enable_if_t
<
40
base
::
is_equality_comparable_v
<
typename
std
::
iterator_traits
<
Iterator
>::
reference
,
Value
const
&>>> =
41
nullptr
>
42
constexpr
auto
find
(
43
Iterator
first
,
44
Iterator
last
,
// CODEQLFP(DCL51-CPP) CODEQLFP(A7-1-1) CODEQLFP(A15-4-4)
45
Value
const
&
value_to_find
46
)
//
47
noexcept
(
48
denotes_nothrow_iterable_range_v
<
Iterator
,
Iterator
>&&
noexcept
(*
first
==
value_to_find
) &&
49
std
::
is_nothrow_copy_constructible
<
Iterator
>::
value
50
) ->
Iterator
{
// CODEQLFP(EXP52-CPP)
51
// CODEQLFP(A5-2-6)
52
// parasoft-begin-suppress AUTOSAR-A6_5_2-a-2 "False positive: The loop counter is 'pos'"
53
for
(
Iterator
&
pos
{
first
};
pos
!=
last
;
arene
::
base
::
advance
(
pos
, 1)) {
// CODEQLFP(CTR55-CPP) CODEQLFP(M6-5-5)
54
if
(*
pos
==
value_to_find
) {
55
return
pos
;
56
}
57
}
// CODEQLFP(A5-0-2)
58
// parasoft-end-suppress AUTOSAR-A6_5_2-a-2
59
return
last
;
60
}
61
62
}
// namespace base
63
}
// namespace arene
64
65
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FIND_HPP_
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
algorithm
find.hpp
Generated by
1.13.2