Template Function thrust::replace(ForwardIterator, ForwardIterator, const T&, const T&)¶
Function Documentation¶
-
template<typename
ForwardIterator, typenameT>
voidthrust::replace(ForwardIterator first, ForwardIterator last, const T &old_value, const T &new_value) replacereplaces every element in the range [first, last) equal toold_valuewithnew_value. That is: for every iteratori, if*i == old_valuethen it performs theassignment *i = new_value.The following code snippet demonstrates how to use
replaceto replace a value of interest in adevice_vectorwith another.- Parameters
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 replaceold_value.
- Template Parameters
ForwardIterator: is a model of Forward Iterator, andForwardIteratoris mutable.T: is a model of Assignable,Tis a model of EqualityComparable, objects ofTmay be compared for equality with objects ofForwardIterator'svalue_type, andTis convertible toForwardIterator'svalue_type.
#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::replace(A.begin(), A.end(), 1, 99); // A contains [99, 2, 3, 99]
- See
- See
replace_if- See
replace_copy- See
replace_copy_if