## unique_copy
## Prototype
template <class InputIterator, class OutputIterator> OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result); template <class InputIterator, class OutputIterator, class BinaryPredicate> OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred); ## Description
The reason there are two different versions of ## DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h. ## Requirements on typesFor the first version: -
`InputIterator` is a model of InputIterator. -
`InputIterator` 's value type is EqualityComparable. -
`OutputIterator` is a model of OutputIterator. -
`InputIterator` 's value type is convertible to a type in`OutputIterator` 's set of value types.
For the second version: -
`InputIterator` is a model of InputIterator. -
`BinaryPredicate` is a model of BinaryPredicate. [2] -
`InputIterator` 's value type is convertible to first argument type and to`BinaryPredicate` 's second argument type. -
`OutputIterator` is a model of OutputIterator. -
`InputIterator` 's value type is convertible to a type in`OutputIterator` 's set of value types.
## Preconditions-
`[first, last)` is a valid range. -
There is enough space to hold all of the elements being copied. More formally, if there are
`n` elements in the range`[first, last)` after duplicates are removed from consecutive groups, then`[result, result + n)` must be a valid range.
## ComplexityLinear. Exactly ## ExamplePrint all of the numbers in an array, but only print the first one in a consecutive group of identical numbers. const int A[] = {2, 7, 7, 7, 1, 1, 8, 8, 8, 2, 8, 8}; unique_copy(A, A + sizeof(A) / sizeof(int), ostream_iterator<int>(cout, " ")); // The output is "2 7 1 8 2 8". ## Notes[1] Strictly speaking, the first version of [2] ## See alsoBinaryPredicate, |