unique_copy
#
Overloads#
unique_copy(exec, first, last, result)
#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator>
OutputIterator thrust::unique_copy( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
unique_copy
copies elements from the range[first, last)
to a range beginning withresult
, 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.The reason there are two different versions of unique_copy is that there are two different definitions of what it means for a consecutive group of elements to be duplicates. In the first version, the test is simple equality: the elements in a range
[f, l)
are duplicates if, for every iteratori
in the range, eitheri == f
or else*i == *(i-1)
. In the second, the test is an arbitraryBinaryPredicate
binary_pred:
the elements in[f, l)
are duplicates if, for every iteratori
in the range, eitheri == f
or elsebinary_pred(*i, *(i-1))
istrue
.This version of
unique_copy
usesoperator==
to test for equality.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
unique_copy
to compact a sequence of numbers to remove consecutive duplicates using thethrust::host
execution policy for parallelization:#include <thrust/unique.h> #include <thrust/execution_policy.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; int B[N]; int *result_end = thrust::unique_copy(thrust::host, A, A + N, B); // 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 also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the input range.
last – The end of the input range.
result – The beginning of the output range.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator, and
InputIterator's
value_type
is a model of Equality Comparable.OutputIterator – is a model of Output Iterator and and
InputIterator's
value_type
is convertible toOutputIterator's
value_type
.
- Returns:
The end of the unique range
[result, result_end)
.- Pre:
The range
[first,last)
and the range[result, result + (last - first))
shall not overlap.
unique_copy(first, last, result)
#
-
template<typename InputIterator, typename OutputIterator>
OutputIterator thrust::unique_copy( - InputIterator first,
- InputIterator last,
- OutputIterator result,
unique_copy
copies elements from the range[first, last)
to a range beginning withresult
, 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.The reason there are two different versions of unique_copy is that there are two different definitions of what it means for a consecutive group of elements to be duplicates. In the first version, the test is simple equality: the elements in a range
[f, l)
are duplicates if, for every iteratori
in the range, eitheri == f
or else*i == *(i-1)
. In the second, the test is an arbitraryBinaryPredicate
binary_pred:
the elements in[f, l)
are duplicates if, for every iteratori
in the range, eitheri == f
or elsebinary_pred(*i, *(i-1))
istrue
.This version of
unique_copy
usesoperator==
to test for equality.The following code snippet demonstrates how to use
unique_copy
to compact a sequence of numbers to remove consecutive duplicates.#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); // 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 also
- Parameters:
first – The beginning of the input range.
last – The end of the input range.
result – The beginning of the output range.
- Template Parameters:
InputIterator – is a model of Input Iterator, and
InputIterator's
value_type
is a model of Equality Comparable.OutputIterator – is a model of Output Iterator and and
InputIterator's
value_type
is convertible toOutputIterator's
value_type
.
- Returns:
The end of the unique range
[result, result_end)
.- Pre:
The range
[first,last)
and the range[result, result + (last - first))
shall not overlap.
unique_copy(exec, first, last, result, binary_pred)
#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename BinaryPredicate>
OutputIterator thrust::unique_copy( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
- BinaryPredicate binary_pred,
unique_copy
copies elements from the range[first, last)
to a range beginning withresult
, 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 objectbinary_pred
to test for equality.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
unique_copy
to compact a sequence of numbers to remove consecutive duplicates using thethrust::host
execution policy for parallelization:#include <thrust/unique.h> #include <thrust/execution_policy.h> ... const int N = 7; int A[N] = {1, 3, 3, 3, 2, 2, 1}; int B[N]; int *result_end = thrust::unique_copy(thrust::host, A, A + N, B, ::cuda::std::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 also
- Parameters:
exec – The execution policy to use for parallelization.
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:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator, and
InputIterator's
value_type
is a model of Equality Comparable.OutputIterator – is a model of Output Iterator and and
InputIterator's
value_type
is convertible toOutputIterator's
value_type
.BinaryPredicate – is a model of Binary Predicate.
- Returns:
The end of the unique range
[result, result_end)
.- Pre:
The range
[first,last)
and the range[result, result + (last - first))
shall not overlap.
unique_copy(first, last, result, binary_pred)
#
-
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 withresult
, 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 objectbinary_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.#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, ::cuda::std::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 also
- 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:
InputIterator – is a model of Input Iterator, and
InputIterator's
value_type
is a model of Equality Comparable.OutputIterator – is a model of Output Iterator and and
InputIterator's
value_type
is convertible toOutputIterator's
value_type
.BinaryPredicate – is a model of Binary Predicate.
- Returns:
The end of the unique range
[result, result_end)
.- Pre:
The range
[first,last)
and the range[result, result + (last - first))
shall not overlap.