thrust

Functions  
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename Predicate >  
__host__ __device__ OutputIterator  thrust::copy_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename InputIterator , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
__host__ __device__ OutputIterator  thrust::copy_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::copy_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename DerivedPolicy , typename ForwardIterator , typename T >  
__host__ __device__ ForwardIterator  thrust::remove (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, const T &value) 
template<typename ForwardIterator , typename T >  
ForwardIterator  thrust::remove (ForwardIterator first, ForwardIterator last, const T &value) 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename T >  
__host__ __device__ OutputIterator  thrust::remove_copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, const T &value) 
template<typename InputIterator , typename OutputIterator , typename T >  
OutputIterator  thrust::remove_copy (InputIterator first, InputIterator last, OutputIterator result, const T &value) 
template<typename DerivedPolicy , typename ForwardIterator , typename Predicate >  
__host__ __device__ ForwardIterator  thrust::remove_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, Predicate pred) 
template<typename ForwardIterator , typename Predicate >  
ForwardIterator  thrust::remove_if (ForwardIterator first, ForwardIterator last, Predicate pred) 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename Predicate >  
__host__ __device__ OutputIterator  thrust::remove_copy_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename InputIterator , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::remove_copy_if (InputIterator first, InputIterator last, OutputIterator result, Predicate pred) 
template<typename DerivedPolicy , typename ForwardIterator , typename InputIterator , typename Predicate >  
__host__ __device__ ForwardIterator  thrust::remove_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred) 
template<typename ForwardIterator , typename InputIterator , typename Predicate >  
ForwardIterator  thrust::remove_if (ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred) 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
__host__ __device__ OutputIterator  thrust::remove_copy_if (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename Predicate >  
OutputIterator  thrust::remove_copy_if (InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred) 
template<typename DerivedPolicy , typename ForwardIterator >  
__host__ __device__ ForwardIterator  thrust::unique (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last) 
template<typename ForwardIterator >  
ForwardIterator  thrust::unique (ForwardIterator first, ForwardIterator last) 
template<typename DerivedPolicy , typename ForwardIterator , typename BinaryPredicate >  
__host__ __device__ ForwardIterator  thrust::unique (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) 
template<typename ForwardIterator , typename BinaryPredicate >  
ForwardIterator  thrust::unique (ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >  
__host__ __device__ OutputIterator  thrust::unique_copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result) 
template<typename InputIterator , typename OutputIterator >  
OutputIterator  thrust::unique_copy (InputIterator first, InputIterator last, OutputIterator result) 
template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename BinaryPredicate >  
__host__ __device__ OutputIterator  thrust::unique_copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred) 
template<typename InputIterator , typename OutputIterator , typename BinaryPredicate >  
OutputIterator  thrust::unique_copy (InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred) 
template<typename DerivedPolicy , typename ForwardIterator1 , typename ForwardIterator2 >  
__host__ __device__ thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first) 
template<typename ForwardIterator1 , typename ForwardIterator2 >  
thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first) 
template<typename DerivedPolicy , typename ForwardIterator1 , typename ForwardIterator2 , typename BinaryPredicate >  
__host__ __device__ thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first, BinaryPredicate binary_pred) 
template<typename ForwardIterator1 , typename ForwardIterator2 , typename BinaryPredicate >  
thrust::pair< ForwardIterator1, ForwardIterator2 >  thrust::unique_by_key (ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first, BinaryPredicate binary_pred) 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 >  
__host__ __device__ thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_result, OutputIterator2 values_result) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 >  
thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_result, OutputIterator2 values_result) 
template<typename DerivedPolicy , typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 , typename BinaryPredicate >  
__host__ __device__ thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_result, OutputIterator2 values_result, BinaryPredicate binary_pred) 
template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator1 , typename OutputIterator2 , typename BinaryPredicate >  
thrust::pair< OutputIterator1, OutputIterator2 >  thrust::unique_by_key_copy (InputIterator1 keys_first, InputIterator1 keys_last, InputIterator2 values_first, OutputIterator1 keys_result, OutputIterator2 values_result, BinaryPredicate binary_pred) 
__host__ __device__ OutputIterator thrust::copy_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator  first,  
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that any element which causes pred
to be false
is not copied. copy_if
is stable, meaning that the relative order of elements that are copied is unchanged.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(first+n))
. Otherwise, no assignment occurs and result
is not advanced.
The algorithm's execution is parallelized as determined by system
.
exec  The execution policy to use for parallelization. 
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [first, last) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [first, last)
.DerivedPolicy  The name of the derived execution policy. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
and [result, result + (last  first))
shall not overlap.The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy even numbers to an output range using the thrust::host
parallelization policy:
remove_copy_if
OutputIterator thrust::copy_if  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that any element which causes pred
to false
is not copied. copy_if
is stable, meaning that the relative order of elements that are copied is unchanged.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(first+n))
. Otherwise, no assignment occurs and result
is not advanced.
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [first, last) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [first, last)
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
and [result, result + (last  first))
shall not overlap.The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy even numbers to an output range.
remove_copy_if
__host__ __device__ OutputIterator thrust::copy_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  first,  
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that any element whose corresponding stencil element causes pred
to be false
is not copied. copy_if
is stable, meaning that the relative order of elements that are copied is unchanged.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(stencil+n))
. Otherwise, no assignment occurs and result
is not advanced.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
stencil  The beginning of the stencil sequence. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [stencil, stencil + (lastfirst)) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [stencil, stencil + (lastfirst))
.DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator. 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
and [result, result + (last  first))
shall not overlap. [stencil, stencil + (last  first))
and [result, result + (last  first))
shall not overlap.The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy numbers to an output range when corresponding stencil elements are even using the thrust::host
execution policy:
remove_copy_if
OutputIterator thrust::copy_if  (  InputIterator1  first, 
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
This version of copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that any element whose corresponding stencil element causes pred
to be false
is not copied. copy_if
is stable, meaning that the relative order of elements that are copied is unchanged.
More precisely, for every integer n
such that 0 <= n < lastfirst
, copy_if
performs the assignment *result = *(first+n)
and result
is advanced one position if pred(*(stencil+n))
. Otherwise, no assignment occurs and result
is not advanced.
first  The beginning of the sequence from which to copy. 
last  The end of the sequence from which to copy. 
stencil  The beginning of the stencil sequence. 
result  The beginning of the sequence into which to copy. 
pred  The predicate to test on every value of the range [stencil, stencil + (lastfirst)) . 
result + n
, where n
is equal to the number of times pred
evaluated to true
in the range [stencil, stencil + (lastfirst))
.InputIterator1  is a model of Input Iterator. 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
and [result, result + (last  first))
shall not overlap. [stencil, stencil + (last  first))
and [result, result + (last  first))
shall not overlap.The following code snippet demonstrates how to use copy_if
to perform stream compaction to copy numbers to an output range when corresponding stencil elements are even:
remove_copy_if
__host__ __device__ ForwardIterator thrust::remove  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator  first,  
ForwardIterator  last,  
const T &  value  
) 
remove
removes from the range [first, last)
all elements that are equal to value
. That is, remove
returns an iterator new_last
such that the range [first, new_last)
contains no elements equal to value
. The iterators in the range [new_first,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove
is stable, meaning that the relative order of elements that are not equal to value
is unchanged.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
value  The value to remove from the range [first, last) . Elements which are equal to value are removed from the sequence. 
ForwardIterator
pointing to the end of the resulting range of elements which are not equal to value
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of ForwardIterator's value_type . 
The following code snippet demonstrates how to use remove
to remove a number of interest from a range using the thrust::host
execution policy for parallelization:
remove
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove(V.begin(), V.end(), 0)
does not change V.size()
: V
will contain just as many elements as it did before. remove
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove(S.begin(), S.end(), x), S.end())
.ForwardIterator thrust::remove  (  ForwardIterator  first, 
ForwardIterator  last,  
const T &  value  
) 
remove
removes from the range [first, last)
all elements that are equal to value
. That is, remove
returns an iterator new_last
such that the range [first, new_last)
contains no elements equal to value
. The iterators in the range [new_first,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove
is stable, meaning that the relative order of elements that are not equal to value
is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
value  The value to remove from the range [first, last) . Elements which are equal to value are removed from the sequence. 
ForwardIterator
pointing to the end of the resulting range of elements which are not equal to value
.ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of ForwardIterator's value_type . 
The following code snippet demonstrates how to use remove
to remove a number of interest from a range.
remove
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove(V.begin(), V.end(), 0)
does not change V.size()
: V
will contain just as many elements as it did before. remove
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove(S.begin(), S.end(), x), S.end())
.__host__ __device__ OutputIterator thrust::remove_copy  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator  first,  
InputIterator  last,  
OutputIterator  result,  
const T &  value  
) 
remove_copy
copies elements that are not equal to value
from the range [first, last)
to a range beginning at result
. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as in the range [first, last)
.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
value  The value to omit from the copied range. 
value
.DerivedPolicy  The name of the derived execution policy. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types . 
OutputIterator  is a model of Output Iterator. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of InputIterator's value_type . 
[first, last)
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy
to copy a sequence of numbers to an output range while omitting a value of interest using the thrust::host
execution policy for parallelization:
OutputIterator thrust::remove_copy  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
const T &  value  
) 
remove_copy
copies elements that are not equal to value
from the range [first, last)
to a range beginning at result
. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as in the range [first, last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
value  The value to omit from the copied range. 
value
.InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types . 
OutputIterator  is a model of Output Iterator. 
T  is a model of Equality Comparable, and objects of type T can be compared for equality with objects of InputIterator's value_type . 
[first, last)
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy
to copy a sequence of numbers to an output range while omitting a value of interest.
__host__ __device__ OutputIterator thrust::remove_copy_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator  first,  
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
DerivedPolicy  The name of the derived execution policy. 
InputIterator  is a model of Input Iterator, InputIterator's value_type is convertible to a type in OutputIterator's set of value_types , and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting even numbers using the thrust::host
execution policy for parallelization:
OutputIterator thrust::remove_copy_if  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
InputIterator  is a model of Input Iterator, InputIterator's value_type is convertible to a type in OutputIterator's set of value_types , and InputIterator's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[first, last)
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting even numbers.
__host__ __device__ OutputIterator thrust::remove_copy_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  first,  
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
of the corresponding stencil value is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
The algorithm's execution policy is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator, InputIterator1's value_type is convertible to a type in OutputIterator's set of value_types . 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[stencil, stencil + (last  first))
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting specific elements using the thrust::host
execution policy for parallelization.
OutputIterator thrust::remove_copy_if  (  InputIterator1  first, 
InputIterator1  last,  
InputIterator2  stencil,  
OutputIterator  result,  
Predicate  pred  
) 
remove_copy_if
copies elements from the range [first,last)
to a range beginning at result
, except that elements for which pred
of the corresponding stencil value is true
are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last)
.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
result  The resulting range is copied to the sequence beginning at this location. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are not copied to the resulting sequence. 
InputIterator1  is a model of Input Iterator, InputIterator1's value_type is convertible to a type in OutputIterator's set of value_types . 
InputIterator2  is a model of Input Iterator, and InputIterator2's value_type is convertible to Predicate's argument_type . 
OutputIterator  is a model of Output Iterator. 
Predicate  is a model of Predicate. 
[stencil, stencil + (last  first))
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_copy_if
to copy a sequence of numbers to an output range while omitting specific elements.
__host__ __device__ ForwardIterator thrust::remove_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator  first,  
ForwardIterator  last,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first,new_last)
contains no elements for which pred
is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are removed from the sequence. 
pred
evaluated to true
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator  is a model of Forward Iterator, ForwardIterator is mutable, and ForwardIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_if
to remove all even numbers from an array of integers using the thrust::host
execution policy for parallelization:
remove_if
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove_if(V.begin(), V.end(), pred)
does not change V.size()
: V
will contain just as many elements as it did before. remove_if
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove_if(S.begin(), S.end(), pred), S.end())
.ForwardIterator thrust::remove_if  (  ForwardIterator  first, 
ForwardIterator  last,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first,new_last)
contains no elements for which pred
is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
pred  A predicate to evaluate for each element of the range [first,last) . Elements for which pred evaluates to false are removed from the sequence. 
pred
evaluated to true
.ForwardIterator  is a model of Forward Iterator, ForwardIterator is mutable, and ForwardIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
The following code snippet demonstrates how to use remove_if
to remove all even numbers from an array of integers.
remove_if
does not destroy any iterators, and does not change the distance between first
and last
. (There's no way that it could do anything of the sort.) So, for example, if V
is a device_vector, remove_if(V.begin(), V.end(), pred)
does not change V.size()
: V
will contain just as many elements as it did before. remove_if
returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove_if(S.begin(), S.end(), pred), S.end())
.__host__ __device__ ForwardIterator thrust::remove_if  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator  first,  
ForwardIterator  last,  
InputIterator  stencil,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first, new_last)
contains no elements for which pred
of the corresponding stencil value is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
pred  A predicate to evaluate for each element of the range [stencil, stencil + (last  first)) . Elements for which pred evaluates to false are removed from the sequence [first, last) 
pred
evaluated to true
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator  is a model of Forward Iterator and ForwardIterator is mutable. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
[first, last)
shall not overlap the range [result, result + (last  first))
. [stencil, stencil + (last  first))
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_if
to remove specific elements from an array of integers using the thrust::host
execution policy for parallelization:
[first, last)
is not permitted to overlap with the range [stencil, stencil + (last  first))
.ForwardIterator thrust::remove_if  (  ForwardIterator  first, 
ForwardIterator  last,  
InputIterator  stencil,  
Predicate  pred  
) 
remove_if
removes from the range [first, last)
every element x
such that pred(x)
is true
. That is, remove_if
returns an iterator new_last
such that the range [first, new_last)
contains no elements for which pred
of the corresponding stencil value is true
. The iterators in the range [new_last,last)
are all still dereferenceable, but the elements that they point to are unspecified. remove_if
is stable, meaning that the relative order of elements that are not removed is unchanged.
first  The beginning of the range of interest. 
last  The end of the range of interest. 
stencil  The beginning of the stencil sequence. 
pred  A predicate to evaluate for each element of the range [stencil, stencil + (last  first)) . Elements for which pred evaluates to false are removed from the sequence [first, last) 
pred
evaluated to true
.ForwardIterator  is a model of Forward Iterator and ForwardIterator is mutable. 
InputIterator  is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type . 
Predicate  is a model of Predicate. 
[first, last)
shall not overlap the range [result, result + (last  first))
. [stencil, stencil + (last  first))
shall not overlap the range [result, result + (last  first))
.The following code snippet demonstrates how to use remove_if
to remove specific elements from an array of integers.
[first, last)
is not permitted to overlap with the range [stencil, stencil + (last  first))
.__host__ __device__ ForwardIterator thrust::unique  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator  first,  
ForwardIterator  last  
) 
For each group of consecutive elements in the range [first, last)
with the same value, unique
removes all but the first element of the group. The return value is an iterator new_last
such that no two consecutive elements in the range [first, new_last)
are equal. The iterators in the range [new_last, last)
are all still dereferenceable, but the elements that they point to are unspecified. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses operator==
to test for equality.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the input range. 
last  The end of the input range. 
[first, new_last)
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
The following code snippet demonstrates how to use unique
to compact a sequence of numbers to remove consecutive duplicates using the thrust::host
execution policy for parallelization:
ForwardIterator thrust::unique  (  ForwardIterator  first, 
ForwardIterator  last  
) 
For each group of consecutive elements in the range [first, last)
with the same value, unique
removes all but the first element of the group. The return value is an iterator new_last
such that no two consecutive elements in the range [first, new_last)
are equal. The iterators in the range [new_last, last)
are all still dereferenceable, but the elements that they point to are unspecified. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses operator==
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
[first, new_last)
.ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
The following code snippet demonstrates how to use unique
to compact a sequence of numbers to remove consecutive duplicates.
__host__ __device__ ForwardIterator thrust::unique  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator  first,  
ForwardIterator  last,  
BinaryPredicate  binary_pred  
) 
For each group of consecutive elements in the range [first, last)
with the same value, unique
removes all but the first element of the group. The return value is an iterator new_last
such that no two consecutive elements in the range [first, new_last)
are equal. The iterators in the range [new_last, last)
are all still dereferenceable, but the elements that they point to are unspecified. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses the function object binary_pred
to test for equality.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
first  The beginning of the input range. 
last  The end of the input range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
DerivedPolicy  The name of the derived execution policy. 
ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, and ForwardIterator's value_type is convertible to BinaryPredicate's first_argument_type and to BinaryPredicate's second_argument_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique
to compact a sequence of numbers to remove consecutive duplicates using the thrust::host
execution policy for parallelization:
ForwardIterator thrust::unique  (  ForwardIterator  first, 
ForwardIterator  last,  
BinaryPredicate  binary_pred  
) 
For each group of consecutive elements in the range [first, last)
with the same value, unique
removes all but the first element of the group. The return value is an iterator new_last
such that no two consecutive elements in the range [first, new_last)
are equal. The iterators in the range [new_last, last)
are all still dereferenceable, but the elements that they point to are unspecified. unique
is stable, meaning that the relative order of elements that are not removed is unchanged.
This version of unique
uses the function object binary_pred
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
ForwardIterator  is a model of Forward Iterator, and ForwardIterator is mutable, and ForwardIterator's value_type is convertible to BinaryPredicate's first_argument_type and to BinaryPredicate's second_argument_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique
to compact a sequence of numbers to remove consecutive duplicates.
__host__ __device__ thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator1  keys_first,  
ForwardIterator1  keys_last,  
ForwardIterator2  values_first  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
The return value is a pair
of iterators (new_keys_last,new_values_last)
such that no two consecutive elements in the range [keys_first, new_keys_last)
are equal.
This version of unique_by_key
uses operator==
to test for equality and project1st
to reduce values with equal keys.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
[key_first, keys_new_last)
and [values_first, values_new_last)
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
[keys_first, keys_last)
and the range [values_first, values_first + (keys_last  keys_first))
shall not overlap.The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates using the thrust::host
execution policy for parallelization:
thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  ForwardIterator1  keys_first, 
ForwardIterator1  keys_last,  
ForwardIterator2  values_first  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
The return value is a pair
of iterators (new_keys_last,new_values_last)
such that no two consecutive elements in the range [keys_first, new_keys_last)
are equal.
This version of unique_by_key
uses operator==
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
[key_first, keys_new_last)
and [values_first, values_new_last)
.ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
[keys_first, keys_last)
and the range [values_first, values_first + (keys_last  keys_first))
shall not overlap.The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates.
__host__ __device__ thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
ForwardIterator1  keys_first,  
ForwardIterator1  keys_last,  
ForwardIterator2  values_first,  
BinaryPredicate  binary_pred  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
This version of unique_by_key
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
.DerivedPolicy  The name of the derived execution policy. 
ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
BinaryPredicate  is a model of Binary Predicate. 
[keys_first, keys_last)
and the range [values_first, values_first + (keys_last  keys_first))
shall not overlap.The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates using the thrust::host
execution policy for parallelization:
thrust::pair<ForwardIterator1,ForwardIterator2> thrust::unique_by_key  (  ForwardIterator1  keys_first, 
ForwardIterator1  keys_last,  
ForwardIterator2  values_first,  
BinaryPredicate  binary_pred  
) 
unique_by_key
is a generalization of unique
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key
removes all but the first element of the group. Similarly, the corresponding values in the range [values_first, values_first + (keys_last  keys_first))
are also removed.
This version of unique_by_key
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the key range. 
keys_last  The end of the key range. 
values_first  The beginning of the value range. 
binary_pred  The binary predicate used to determine equality. 
[first, new_last)
.ForwardIterator1  is a model of Forward Iterator, and ForwardIterator1 is mutable, and ForwardIterator's value_type is a model of Equality Comparable. 
ForwardIterator2  is a model of Forward Iterator, and ForwardIterator2 is mutable. 
BinaryPredicate  is a model of Binary Predicate. 
[keys_first, keys_last)
and the range [values_first, values_first + (keys_last  keys_first))
shall not overlap.The following code snippet demonstrates how to use unique_by_key
to compact a sequence of key/value pairs to remove consecutive duplicates.
__host__ __device__ thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  keys_first,  
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_result,  
OutputIterator2  values_result  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_result
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_result
.
This version of unique_by_key_copy
uses operator==
to test for equality and project1st
to reduce values with equal keys.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_result  The beginning of the output key range. 
values_result  The beginning of the output value range. 
[keys_result, keys_result_last)
and [values_result, values_result_last)
.DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys using the thrust::host
execution policy for parallelization:
thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  InputIterator1  keys_first, 
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_result,  
OutputIterator2  values_result  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_result
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_result
.
This version of unique_by_key_copy
uses operator==
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_result  The beginning of the output key range. 
values_result  The beginning of the output value range. 
[keys_result, keys_result_last)
and [values_result, values_result_last)
.InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys.
__host__ __device__ thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  const thrust::detail::execution_policy_base< DerivedPolicy > &  exec, 
InputIterator1  keys_first,  
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_result,  
OutputIterator2  values_result,  
BinaryPredicate  binary_pred  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_result
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_result
.
This version of unique_by_key_copy
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
The algorithm's execution is parallelized as determined by exec
.
exec  The execution policy to use for parallelization. 
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_result  The beginning of the output key range. 
values_result  The beginning of the output value range. 
binary_pred  The binary predicate used to determine equality. 
[keys_result, keys_result_last)
and [values_result, values_result_last)
.DerivedPolicy  The name of the derived execution policy. 
InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys using the thrust::host
execution policy for parallelization:
thrust::pair<OutputIterator1,OutputIterator2> thrust::unique_by_key_copy  (  InputIterator1  keys_first, 
InputIterator1  keys_last,  
InputIterator2  values_first,  
OutputIterator1  keys_result,  
OutputIterator2  values_result,  
BinaryPredicate  binary_pred  
) 
unique_by_key_copy
is a generalization of unique_copy
to keyvalue pairs. For each group of consecutive keys in the range [keys_first, keys_last)
that are equal, unique_by_key_copy
copies the first element of the group to a range beginning with keys_result
and the corresponding values from the range [values_first, values_first + (keys_last  keys_first))
are copied to a range beginning with values_result
.
This version of unique_by_key_copy
uses the function object binary_pred
to test for equality and project1st
to reduce values with equal keys.
keys_first  The beginning of the input key range. 
keys_last  The end of the input key range. 
values_first  The beginning of the input value range. 
keys_result  The beginning of the output key range. 
values_result  The beginning of the output value range. 
binary_pred  The binary predicate used to determine equality. 
[keys_result, keys_result_last)
and [values_result, values_result_last)
.InputIterator1  is a model of Input Iterator, 
InputIterator2  is a model of Input Iterator, 
OutputIterator1  is a model of Output Iterator and and InputIterator1's value_type is convertible to OutputIterator1's value_type . 
OutputIterator2  is a model of Output Iterator and and InputIterator2's value_type is convertible to OutputIterator2's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
The following code snippet demonstrates how to use unique_by_key_copy
to compact a sequence of key/value pairs and with equal keys.
__host__ __device__ 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 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.
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 iterator i
in the range, either i == f
or else *i == *(i1)
. In the second, the test is an arbitrary BinaryPredicate
binary_pred:
the elements in [f, l)
are duplicates if, for every iterator i
in the range, either i == f
or else binary_pred(*i, *(i1))
is true
.
This version of unique_copy
uses operator==
to test for equality.
The algorithm's execution is parallelized as determined by exec
.
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. 
[result, result_end)
.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 to OutputIterator's value_type . 
[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 using the thrust::host
execution policy for parallelization:
OutputIterator thrust::unique_copy  (  InputIterator  first, 
InputIterator  last,  
OutputIterator  result  
) 
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.
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 iterator i
in the range, either i == f
or else *i == *(i1)
. In the second, the test is an arbitrary BinaryPredicate
binary_pred:
the elements in [f, l)
are duplicates if, for every iterator i
in the range, either i == f
or else binary_pred(*i, *(i1))
is true
.
This version of unique_copy
uses operator==
to test for equality.
first  The beginning of the input range. 
last  The end of the input range. 
result  The beginning of the output range. 
[result, result_end)
.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 to OutputIterator's value_type . 
[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.
__host__ __device__ 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 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 algorithm's execution is parallelized as determined by exec
.
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. 
[result, result_end)
.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 to OutputIterator's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
[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 using the thrust::host
execution policy for parallelization:
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.
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. 
[result, result_end)
.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 to OutputIterator's value_type . 
BinaryPredicate  is a model of Binary Predicate. 
[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.