Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
remove_if.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_REMOVE_IF_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_REMOVE_IF_HPP_
7
8
#
include
"arene/base/algorithm/detail/functional.hpp"
9
#
include
"arene/base/algorithm/detail/traits.hpp"
10
#
include
"arene/base/algorithm/find_if.hpp"
11
#
include
"arene/base/constraints.hpp"
12
#
include
"arene/base/iterator/advance.hpp"
13
#
include
"arene/base/iterator/next.hpp"
14
#
include
"arene/base/type_traits/is_predicate.hpp"
15
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
16
#
include
"stdlib/include/stdlib_detail/declval.hpp"
17
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
18
#
include
"stdlib/include/stdlib_detail/internal_named_requirements.hpp"
19
#
include
"stdlib/include/stdlib_detail/is_assignable.hpp"
20
#
include
"stdlib/include/stdlib_detail/is_move_assignable.hpp"
21
#
include
"stdlib/include/stdlib_detail/move.hpp"
22
#
include
"stdlib/include/stdlib_detail/remove_reference.hpp"
23
24
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
25
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
26
27
// IWYU pragma: private, include <algorithm>
28
// IWYU pragma: friend "stdlib_detail/.*"
29
30
namespace
std
{
31
32
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
33
34
/// @brief removes elements satisfying specific criteria
35
/// @tparam I forward iterator type
36
/// @tparam P removal predicate type
37
/// @param first beginning of the range of elements
38
/// @param last end of the range of elements
39
/// @param pred unary predicate which returns @c true if the element should be
40
/// removed
41
///
42
/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
43
/// @pre <tt>[begin, end)</tt> must be a valid range.
44
/// @pre The expression <tt>pred(v)</tt> must be convertible to @c bool
45
/// for every argument @c r of type @c RT, where @c RT is the reference type
46
/// of @c I, regardless of value category, and must not modify @c r.
47
///
48
/// Removes all elements satisfying specific criteria from the range <tt>[first,
49
/// last)</tt> and returns a past-the-end iterator for the new end of the range.
50
///
51
/// Removal is performed by shifting the elements in the range in such a way
52
/// that the elements that are not to be removed appear in the beginning of the
53
/// range. The relative ordering of non removed elements is maintained by
54
/// @c std::remove_if.
55
///
56
/// @return past-the-end iterator for the new range of values. If this is not
57
/// @c end(), then it points to an unspecified value, and so do iterators to
58
/// any values between this iterator and @c end().
59
///
60
/// @note Complexity
61
/// Given N as <tt>std::distance(first, last)</tt>, exactly @c N
62
/// applications of the predicate @c pred.
63
///
64
template
<
65
class
I
,
66
class
P
,
67
arene
::
base
::
constraints
<
68
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
I
>>,
69
std
::
enable_if_t
<
70
std
::
internal
::
named_requirement
::
is_move_assignable_v
<
arene
::
base
::
algorithm_detail
::
iter_value_t
<
I
>>>,
71
std
::
enable_if_t
<
arene
::
base
::
is_predicate_v
<
P
&,
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>>> =
72
nullptr
>
73
auto
remove_if
(
I
first
,
I
last
,
P
pred
)
noexcept
(
//
74
noexcept
(
arene
::
base
::
find_if
(
std
::
declval
<
I
&>(),
std
::
declval
<
I
&>(),
std
::
declval
<
P
&>())) &&
//
75
noexcept
(!
std
::
declval
<
P
&>()(*
std
::
declval
<
I
&>())) &&
//
76
std
::
is_nothrow_move_assignable_v
<
I
> &&
//
77
std
::
is_nothrow_assignable_v
<
78
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>,
79
std
::
remove_reference_t
<
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>&&>
//
80
) ->
I
{
81
first
=
arene
::
base
::
find_if
(
first
,
last
,
pred
);
82
if
(
first
!=
last
) {
83
for
(
auto
iter
=
arene
::
base
::
next
(
first
);
iter
!=
last
; ++
iter
) {
84
if
(!
pred
(*
iter
)) {
85
*
first
=
std
::
move
(*
iter
);
86
arene
::
base
::
advance
(
first
,
arene
::
base
::
algorithm_detail
::
iter_difference_t
<
I
>{1});
87
}
88
}
89
}
90
return
first
;
91
}
92
93
// parasoft-end-suppress AUTOSAR-M3_3_2-a
94
95
}
// namespace std
96
97
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_REMOVE_IF_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
remove_if.hpp
Generated by
1.13.2