Sane C++ Libraries
C++ Platform Abstraction Libraries
AlgorithmRemove.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/Compiler.h" // move
5#include "AlgorithmFind.h"
6
7namespace SC
8{
9namespace Algorithms
10{
13
21template <typename ForwardIterator, typename UnaryPredicate>
22ForwardIterator removeIf(ForwardIterator first, ForwardIterator last, UnaryPredicate&& predicate)
23{
24 auto found = findIf(first, last, forward<UnaryPredicate>(predicate));
25 if (found != last)
26 {
27 auto it = found;
28 while (++it != last)
29 {
30 if (not predicate(*it))
31 {
32 *found++ = move(*it);
33 }
34 }
35 }
36 return found;
37}
38
40
41} // namespace Algorithms
42} // namespace SC
ForwardIterator removeIf(ForwardIterator first, ForwardIterator last, UnaryPredicate &&predicate)
Removes all items in the given range, satisfying the given predicate.
Definition: AlgorithmRemove.h:22
constexpr ForwardIterator findIf(ForwardIterator first, ForwardIterator last, UnaryPredicate &&predicate)
Find item satisfying the given predicate.
Definition: AlgorithmFind.h:23
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition: Compiler.h:269