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/traits.hpp"
22
23// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
24// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
25
26// IWYU pragma: private, include <algorithm>
27// IWYU pragma: friend "stdlib_detail/.*"
28
29namespace std {
30
31// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
32
33/// @brief removes elements satisfying specific criteria
34/// @tparam I forward iterator type
35/// @tparam P removal predicate type
36/// @param first beginning of the range of elements
37/// @param last end of the range of elements
38/// @param pred unary predicate which returns @c true if the element should be
39/// removed
40///
41/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
42/// @pre <tt>[begin, end)</tt> must be a valid range.
43/// @pre The expression <tt>pred(v)</tt> must be convertible to @c bool
44/// for every argument @c r of type @c RT, where @c RT is the reference type
45/// of @c I, regardless of value category, and must not modify @c r.
46///
47/// Removes all elements satisfying specific criteria from the range <tt>[first,
48/// last)</tt> and returns a past-the-end iterator for the new end of the range.
49///
50/// Removal is performed by shifting the elements in the range in such a way
51/// that the elements that are not to be removed appear in the beginning of the
52/// range. The relative ordering of non removed elements is maintained by
53/// @c std::remove_if.
54///
55/// @return past-the-end iterator for the new range of values. If this is not
56/// @c end(), then it points to an unspecified value, and so do iterators to
57/// any values between this iterator and @c end().
58///
59/// @note Complexity
60/// Given N as <tt>std::distance(first, last)</tt>, exactly @c N
61/// applications of the predicate @c pred.
62///
63template <
64 class I,
65 class P,
71 nullptr>
72auto remove_if(I first, I last, P pred) noexcept( //
74 noexcept(!std::declval<P&>()(*std::declval<I&>())) && //
77 arene::base::algorithm_detail::iter_reference_t<I>,
78 std::remove_reference_t<arene::base::algorithm_detail::iter_reference_t<I>>&&> //
79) -> I {
80 first = arene::base::find_if(first, last, pred);
81 if (first != last) {
82 for (auto iter = arene::base::next(first); iter != last; ++iter) {
83 if (!pred(*iter)) {
84 *first = std::move(*iter);
85 arene::base::advance(first, arene::base::algorithm_detail::iter_difference_t<I>{1});
86 }
87 }
88 }
89 return first;
90}
91
92// parasoft-end-suppress AUTOSAR-M3_3_2-a
93
94} // namespace std
95
96#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_REMOVE_IF_HPP_
Provides a backport of C++17's constexpr std::advance.
Public export header for the constraints subpackage.
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
constexpr auto find_if(Iterator first, Iterator last, Predicate pred) noexcept(denotes_nothrow_iterable_range_v< Iterator > &&base::is_nothrow_invocable_v< Predicate &, typename std::iterator_traits< Iterator >::reference >) -> Iterator
Returns an iterator to the first element in the range [first, last) that satisfies equality criteria:...
Definition find_if.hpp:42
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
constexpr bool is_move_assignable_v
determine if a type satisfies the MoveAssignable named requirement
STL namespace.
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
auto remove_if(I first, I last, P pred) noexcept(//noexcept(arene::base::find_if(std::declval< I & >(), std::declval< I & >(), std::declval< P & >())) &&//noexcept(!std::declval< P & >()(*std::declval< I & >())) &&//std::is_nothrow_move_assignable_v< I > &&//std::is_nothrow_assignable_v< arene::base::algorithm_detail::iter_reference_t< I >, std::remove_reference_t< arene::base::algorithm_detail::iter_reference_t< I > > && >//) -> I
removes elements satisfying specific criteria
Definition remove_if.hpp:72
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
constexpr bool is_nothrow_assignable_v
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
constexpr bool is_nothrow_move_assignable_v
Type trait to detect if an instance of T is move assignable without throwing.
typename remove_reference< T >::type remove_reference_t
An alias for T, but with top-level reference qualifiers removed.
Definition remove_reference.hpp:47