thrust

◆ replace_copy() [2/2]

template<typename InputIterator , typename OutputIterator , typename T >
OutputIterator thrust::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 to old_value is not copied; new_value is copied instead.

More precisely, for every integer n such that 0 <= n < last-first, replace_copy performs the assignment *(result+n) = new_value if *(first+n) == old_value, and *(result+n) = *(first+n) otherwise.

Parameters
firstThe beginning of the sequence to copy from.
lastThe end of the sequence to copy from.
resultThe beginning of the sequence to copy to.
old_valueThe value to replace.
new_valueThe replacement value for which *i == old_value evaluates to true.
Returns
result + (last-first)
Template Parameters
InputIteratoris a model of Input Iterator.
OutputIteratoris a model of Output Iterator.
Tis a model of Assignable, T is a model of Equality Comparable, T may be compared for equality with InputIterator's value_type, and T is convertible to OutputIterator's value_type.
Precondition
first may equal result, but the ranges [first, last) and [result, result + (last - first)) shall not overlap otherwise.
#include <thrust/replace.h>
...
thrust::device_vector<int> A(4);
A[0] = 1;
A[1] = 2;
A[2] = 3;
A[3] = 1;
thrust::replace_copy(A.begin(), A.end(), B.begin(), 1, 99);
// B contains [99, 2, 3, 99]
See also
http://www.sgi.com/tech/stl/replace_copy.html
copy
replace
replace_if
replace_copy_if