# 11 Algorithms library [algorithms]

## 11.4 Mutating sequence operations [alg.modifying.operations]

### 11.4.8 Remove [alg.remove]

``` template <ForwardIterator I, Sentinel<I> S, class T, class Proj = identity> requires Permutable<I> && IndirectRelation<equal_to<>, projected<I, Proj>, const T*> I remove(I first, S last, const T& value, Proj proj = Proj{}); template <ForwardRange Rng, class T, class Proj = identity> requires Permutable<iterator_t<Rng>> && IndirectRelation<equal_to<>, projected<iterator_t<Rng>, Proj>, const T*> safe_iterator_t<Rng> remove(Rng&& rng, const T& value, Proj proj = Proj{}); template <ForwardIterator I, Sentinel<I> S, class Proj = identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> requires Permutable<I> I remove_if(I first, S last, Pred pred, Proj proj = Proj{}); template <ForwardRange Rng, class Proj = identity, IndirectUnaryPredicate<projected<iterator_t<Rng>, Proj>> Pred> requires Permutable<iterator_t<Rng>> safe_iterator_t<Rng> remove_if(Rng&& rng, Pred pred, Proj proj = Proj{}); ```

Effects: Eliminates all the elements referred to by iterator i in the range [first,last) for which the following corresponding conditions hold: invoke(proj, *i) == value, invoke(pred, invoke(proj, *i)) != false.

Returns: The end of the resulting range.

Remarks: Stable ( ISO/IEC 14882:2014 §[algorithm.stable]).

Complexity: Exactly last - first applications of the corresponding predicate and projection.

Note: each element in the range [ret,last), where ret is the returned value, has a valid but unspecified state, because the algorithms can eliminate elements by moving from elements that were originally in that range.

``` template <InputIterator I, Sentinel<I> S, WeaklyIncrementable O, class T, class Proj = identity> requires IndirectlyCopyable<I, O> && IndirectRelation<equal_to<>, projected<I, Proj>, const T*> tagged_pair<tag::in(I), tag::out(O)> remove_copy(I first, S last, O result, const T& value, Proj proj = Proj{}); template <InputRange Rng, WeaklyIncrementable O, class T, class Proj = identity> requires IndirectlyCopyable<iterator_t<Rng>, O> && IndirectRelation<equal_to<>, projected<iterator_t<Rng>, Proj>, const T*> tagged_pair<tag::in(safe_iterator_t<Rng>), tag::out(O)> remove_copy(Rng&& rng, O result, const T& value, Proj proj = Proj{}); template <InputIterator I, Sentinel<I> S, WeaklyIncrementable O, class Proj = identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> requires IndirectlyCopyable<I, O> tagged_pair<tag::in(I), tag::out(O)> remove_copy_if(I first, S last, O result, Pred pred, Proj proj = Proj{}); template <InputRange Rng, WeaklyIncrementable O, class Proj = identity, IndirectUnaryPredicate<projected<iterator_t<Rng>, Proj>> Pred> requires IndirectlyCopyable<iterator_t<Rng>, O> tagged_pair<tag::in(safe_iterator_t<Rng>), tag::out(O)> remove_copy_if(Rng&& rng, O result, Pred pred, Proj proj = Proj{}); ```

Requires: The ranges [first,last) and [result,result + (last - first)) shall not overlap.

Effects: Copies all the elements referred to by the iterator i in the range [first,last) for which the following corresponding conditions do not hold: invoke(proj, *i) == value, invoke(pred, invoke(proj, *i)) != false.

Returns: A pair consisting of last and the end of the resulting range.

Complexity: Exactly last - first applications of the corresponding predicate and projection.

Remarks: Stable ( ISO/IEC 14882:2014 §[algorithm.stable]).