Template Function thrust::replace_copy_if(InputIterator, InputIterator, OutputIterator, Predicate, const T&)¶
Function Documentation¶
-
template<typename
InputIterator
, typenameOutputIterator
, typenamePredicate
, typenameT
>
OutputIteratorthrust
::
replace_copy_if
(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T &new_value) replace_copy_if
copies elements from the range[first, last)
to the range[result, result + (last-first))
, except that any element for whichpred
istrue
is not copied;new_value
is copied instead.More precisely, for every integer
n
such that 0 <= n < last-first,replace_copy_if
performs the assignment*(result+n) = new_value
ifpred(*(first+n))
, and*(result+n) = *(first+n)
otherwise.#include <thrust/replace.h> #include <thrust/device_vector.h> struct is_less_than_zero { __host__ __device__ bool operator()(int x) { return x < 0; } }; ... thrust::device_vector<int> A(4); A[0] = 1; A[1] = -3; A[2] = 2; A[3] = -1; thrust::device_vector<int> B(4); is_less_than_zero pred; thrust::replace_copy_if(A.begin(), A.end(), B.begin(), pred, 0); // B contains [1, 0, 2, 0]
- Return
result + (last-first)
- Pre
first
may equalresult
, but the ranges[first, last)
and[result, result + (last - first))
shall not overlap otherwise.- Parameters
first
: The beginning of the sequence to copy from.last
: The end of the sequence to copy from.result
: The beginning of the sequence to copy to.pred
: The predicate to test on every value of the range[first,last)
.new_value
: The replacement value to assignpred(*i)
evaluates totrue
.
- Template Parameters
InputIterator
: is a model of Input Iterator, andInputIterator's
value_type
is convertible toPredicate's
argument_type
.OutputIterator
: is a model of Output Iterator.Predicate
: is a model of Predicate.T
: is a model of Assignable, andT
is convertible toOutputIterator's
value_type
.
- See
- See
replace
- See
replace_if
- See
replace_copy