tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
remove_if.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_REMOVE_IF_HPP
5#define TETL_ALGORITHM_REMOVE_IF_HPP
6
7#include <etl/_algorithm/find_if.hpp>
8#include <etl/_utility/move.hpp>
9
10namespace etl {
11
12/// \brief Removes all elements satisfying specific criteria from the range
13/// `[first, last)` and returns a past-the-end iterator for the new end of the
14/// range.
15/// \ingroup algorithm
16template <typename ForwardIt, typename Predicate>
17[[nodiscard]] constexpr auto remove_if(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
18{
19 first = find_if(first, last, pred);
20
21 if (first != last) {
22 for (auto i = first; ++i != last;) {
23 if (not pred(*i)) {
24 *first++ = etl::move(*i);
25 }
26 }
27 }
28
29 return first;
30}
31
32} // namespace etl
33
34#endif // TETL_ALGORITHM_REMOVE_IF_HPP
constexpr auto remove_if(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
Removes all elements satisfying specific criteria from the range [first, last) and returns a past-the...
Definition remove_if.hpp:17
Definition adjacent_find.hpp:9