Template Function thrust::unique_copy(InputIterator, InputIterator, OutputIterator, BinaryPredicate)

Function Documentation

template<typename InputIterator, typename OutputIterator, typename BinaryPredicate>
OutputIterator thrust::unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred)

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.

The following code snippet demonstrates how to use

unique_copy to compact a sequence of numbers to remove consecutive duplicates.
Return

The end of the unique range [result, result_end).

Pre

The range [first,last) and the range [result, result + (last - first)) shall not overlap.

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.

Template Parameters

#include <thrust/unique.h>
...
const int N = 7;
int A[N] = {1, 3, 3, 3, 2, 2, 1};
int B[N];
int *result_end = thrust::unique_copy(A, A + N, B, thrust::equal_to<int>());
// The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4
// Values beyond result_end are unspecified.

See

unique

See

http://www.sgi.com/tech/stl/unique_copy.html