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
3#ifndef TETL_ALGORITHM_REMOVE_IF_HPP
4#define TETL_ALGORITHM_REMOVE_IF_HPP
5
8
9namespace etl {
10
15template <typename ForwardIt, typename Predicate>
16[[nodiscard]] constexpr auto remove_if(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
17{
18 first = find_if(first, last, pred);
19
20 if (first != last) {
21 for (auto i = first; ++i != last;) {
22 if (not pred(*i)) {
23 *first++ = etl::move(*i);
24 }
25 }
26 }
27
28 return first;
29}
30
31} // namespace etl
32
33#endif // TETL_ALGORITHM_REMOVE_IF_HPP
constexpr auto find_if(InputIt first, InputIt last, Predicate pred) noexcept -> InputIt
Searches for an element for which predicate p returns true.
Definition find_if.hpp:18
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:16
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
Definition adjacent_find.hpp:8