thrust

◆ replace() [2/2]

template<typename ForwardIterator , typename T >
void thrust::replace ( ForwardIterator  first,
ForwardIterator  last,
const T &  old_value,
const T &  new_value 
)

replace replaces every element in the range [first, last) equal to old_value with new_value. That is: for every iterator i, if *i == old_value then it performs the assignment *i = new_value.

Parameters
firstThe beginning of the sequence of interest.
lastThe end of the sequence of interest.
old_valueThe value to replace.
new_valueThe new value to replace old_value.
Template Parameters
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable.
Tis a model of Assignable, T is a model of EqualityComparable, objects of T may be compared for equality with objects of ForwardIterator's value_type, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use replace to replace a value of interest in a device_vector with another.

#include <thrust/replace.h>
...
thrust::device_vector<int> A(4);
A[0] = 1;
A[1] = 2;
A[2] = 3;
A[3] = 1;
thrust::replace(A.begin(), A.end(), 1, 99);
// A contains [99, 2, 3, 99]
See also
http://www.sgi.com/tech/stl/replace.html
replace_if
replace_copy
replace_copy_if