thrust::replace
Defined in thrust/replace.h
- 
template<typename DerivedPolicy, typename ForwardIterator, typename T>
 void thrust::replace(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, ForwardIterator first, ForwardIterator last, const T &old_value, const T &new_value)
- replacereplaces every element in the range [first, last) equal to- old_valuewith- new_value. That is: for every iterator- i, if- *i == old_valuethen it performs the- assignment *i = new_value.- The algorithm’s execution is parallelized as determined by - exec.- The following code snippet demonstrates how to use - replaceto replace a value of interest in a- device_vectorwith another using the- thrust::deviceexecution policy for parallelization:- #include <thrust/replace.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> A(4); A[0] = 1; A[1] = 2; A[2] = 3; A[3] = 1; thrust::replace(thrust::device, A.begin(), A.end(), 1, 99); // A contains [99, 2, 3, 99] - See also - replace_if- See also - replace_copy- See also - replace_copy_if- Parameters
- exec – The execution policy to use for parallelization. 
- first – The beginning of the sequence of interest. 
- last – The end of the sequence of interest. 
- old_value – The value to replace. 
- new_value – The new value to replace - old_value.
 
- Template Parameters
- DerivedPolicy – The name of the derived execution policy. 
- ForwardIterator – is a model of Forward Iterator, and - ForwardIteratoris mutable.
- T – is a model of Assignable, - Tis a model of EqualityComparable, objects of- Tmay be compared for equality with objects of- ForwardIterator's- value_type, and- Tis convertible to- ForwardIterator's- value_type.