Template Function thrust::replace_copy(InputIterator, InputIterator, OutputIterator, const T&, const T&)¶
Function Documentation¶
-
template<typename
InputIterator
, typenameOutputIterator
, typenameT
>
OutputIteratorthrust
::
replace_copy
(InputIterator first, InputIterator last, OutputIterator result, const T &old_value, const T &new_value) replace_copy
copies elements from the range[first, last)
to the range[result, result + (last-first))
, except that any element equal toold_value
is not copied;new_value
is copied instead.More precisely, for every integer
n
such that0 <= n < last-first
,replace_copy
performs the assignment*(result+n) = new_value
if*(first+n) == old_value
, and*(result+n) = *(first+n)
otherwise.#include <thrust/replace.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> A(4); A[0] = 1; A[1] = 2; A[2] = 3; A[3] = 1; thrust::device_vector<int> B(4); thrust::replace_copy(A.begin(), A.end(), B.begin(), 1, 99); // B contains [99, 2, 3, 99]
- 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.old_value
: The value to replace.new_value
: The replacement value for which*i == old_value
evaluates totrue
.
- Template Parameters
InputIterator
: is a model of Input Iterator.OutputIterator
: is a model of Output Iterator.T
: is a model of Assignable,T
is a model of Equality Comparable,T
may be compared for equality withInputIterator's
value_type
, andT
is convertible toOutputIterator's
value_type
.
- See
- See
copy
- See
replace
- See
replace_if
- See
replace_copy_if