Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
find_if.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_IF_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FIND_IF_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#include "arene/base/constraints/constraints.hpp"
13#include "arene/base/iterator/advance.hpp"
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/iterator_traits.hpp"
16#include "arene/base/type_traits/denotes_range.hpp"
17#include "arene/base/type_traits/is_invocable.hpp"
18#include "arene/base/type_traits/iterator_category_traits.hpp"
19// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
20
21namespace arene {
22namespace base {
23
24// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
25/// @brief Returns an iterator to the first element in the range [first, last)
26/// that satisfies equality criteria: an element for which predicate @c pred
27/// returns @c true
28/// @tparam Iterator The type of the Iterator to conduct the search
29/// @tparam Value Value to find
30/// @tparam Predicate Condition predicate to find a value
31/// @param first Start of the range to find the value
32/// @param last End (exclusive) of the range to find the value
33/// @param pred Unary predicate which returns @c true for the elements to find
34/// @return Iterator for the first found item
35template <
36 typename Iterator,
37 class Predicate,
41 base::is_invocable_r_v<bool, Predicate&, typename std::iterator_traits<Iterator>::reference>>> = nullptr>
42constexpr auto find_if(Iterator first, Iterator last, Predicate pred) // CODEQLFP(A15-4-4)
44 -> Iterator {
45 // parasoft-begin-suppress AUTOSAR-A6_5_2-a-2 "False Positive: The loop counter is 'pos'"
46 for (Iterator& pos{first}; pos != last; arene::base::advance(pos, 1)) { // CODEQLFP(M6-5-5) CODEQLFP(CTR55-CPP)
47 if (pred(*pos)) {
48 return pos;
49 }
50 } // CODEQLFP(A5-0-2)
51 // parasoft-end-suppress AUTOSAR-A6_5_2-a-2
52 return last;
53}
54// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
55
56} // namespace base
57} // namespace arene
58
59#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FIND_IF_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10