11 Algorithms library [algorithms]

11.4 Mutating sequence operations [alg.modifying.operations]

11.4.9 Unique [alg.unique]

template <ForwardIterator I, Sentinel<I> S, class Proj = identity, IndirectRelation<projected<I, Proj>> R = equal_to<>> requires Permutable<I> I unique(I first, S last, R comp = R{}, Proj proj = Proj{}); template <ForwardRange Rng, class Proj = identity, IndirectRelation<projected<iterator_t<Rng>, Proj>> R = equal_to<>> requires Permutable<iterator_t<Rng>> safe_iterator_t<Rng> unique(Rng&& rng, R comp = R{}, Proj proj = Proj{});

Effects: For a nonempty range, eliminates all but the first element from every consecutive group of equivalent elements referred to by the iterator i in the range [first + 1,last) for which the following conditions hold: invoke(proj, *(i - 1)) == invoke(proj, *i) or invoke(pred, invoke(proj, *(i - 1)), invoke(proj, *i)) != false.

Returns: The end of the resulting range.

Complexity: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate and no more than twice as many applications of the projection.

template <InputIterator I, Sentinel<I> S, WeaklyIncrementable O, class Proj = identity, IndirectRelation<projected<I, Proj>> R = equal_to<>> requires IndirectlyCopyable<I, O> && (ForwardIterator<I> || (InputIterator<O> && Same<value_type_t<I>, value_type_t<O>>) || IndirectlyCopyableStorable<I, O>) tagged_pair<tag::in(I), tag::out(O)> unique_copy(I first, S last, O result, R comp = R{}, Proj proj = Proj{}); template <InputRange Rng, WeaklyIncrementable O, class Proj = identity, IndirectRelation<projected<iterator_t<Rng>, Proj>> R = equal_to<>> requires IndirectlyCopyable<iterator_t<Rng>, O> && (ForwardIterator<iterator_t<Rng>> || (InputIterator<O> && Same<value_type_t<iterator_t<Rng>>, value_type_t<O>>) || IndirectlyCopyableStorable<iterator_t<Rng>, O>) tagged_pair<tag::in(safe_iterator_t<Rng>), tag::out(O)> unique_copy(Rng&& rng, O result, R comp = R{}, Proj proj = Proj{});

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

Effects: Copies only the first element from every consecutive group of equal elements referred to by the iterator i in the range [first,last) for which the following corresponding conditions hold:

invoke(proj, *i) == invoke(proj, *(i - 1))

or

invoke(pred, invoke(proj, *i), invoke(proj, *(i - 1))) != false.

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

Complexity: For nonempty ranges, exactly last - first - 1 applications of the corresponding predicate and no more than twice as many applications of the projection.