unique_copy

unique_copy

template<class InIt, class OutIt>
    OutIt unique_copy(InIt first, InIt last, OutIt x);
template<class InIt, class OutIt, class Pred>
    OutIt unique_copy(InIt first, InIt last, OutIt x, Pred pr);

The first template function effectively executes the statement:

if (N == 0 || !(*(first + N) == V))
    V = *(first + N), *x++ = V;

once for each N in the range [0, last - first). It then returns x. Thus, the function repeatedly removes from the sequence it copies the second of a pair of elements for which the predicate *(first + N) == *(first + N - 1) is true, until only the first of a sequence of equal elements survives. It does so without altering the relative order of remaining elements, and returns the iterator value that designates the end of the copied sequence.

If x and first designate regions of storage, the range [x, x + (last - first)) must not overlap the range [first, last).

The second template function behaves the same, except that it executes the statement:

if (N == 0 || !pr(*(first + N), V))
    V = *(first + N), *x++ = V;