unique_copy
copies elements from the range [first, last)
to a range beginning with result
, except that in a consecutive group of duplicate elements only the first one is copied. The return value is the end of the range to which the elements are copied.
This version of unique_copy
uses the function object binary_pred
to test for equality.
- Parameters
-
first | The beginning of the input range. |
last | The end of the input range. |
result | The beginning of the output range. |
binary_pred | The binary predicate used to determine equality. |
- Returns
- The end of the unique range
[result, result_end)
.
- Template Parameters
-
- Precondition
- The range
[first,last)
and the range [result, result + (last - first))
shall not overlap.
The following code snippet demonstrates how to use unique_copy
to compact a sequence of numbers to remove consecutive duplicates.
...
const int N = 7;
int A[N] = {1, 3, 3, 3, 2, 2, 1};
int B[N];
- See also
- unique
-
https://en.cppreference.com/w/cpp/algorithm/unique_copy