28 Algorithms library [algorithms]

28.6 Mutating sequence operations [alg.modifying.operations]

28.6.5 Replace [alg.replace]

template<class ForwardIterator, class T> void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); template<class ExecutionPolicy, class ForwardIterator, class T> void replace(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); template<class ForwardIterator, class Predicate, class T> void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T> void replace_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
Requires: The expression *first = new_­value shall be valid.
Effects: Substitutes elements referred by the iterator i in the range [first, last) with new_­value, when the following corresponding conditions hold: *i == old_­value, pred(*i) != false.
Complexity: Exactly last - first applications of the corresponding predicate.
template<class InputIterator, class OutputIterator, class T> OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T> ForwardIterator2 replace_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, const T& old_value, const T& new_value); template<class InputIterator, class OutputIterator, class Predicate, class T> OutputIterator replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate, class T> ForwardIterator2 replace_copy_if(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, Predicate pred, const T& new_value);
Requires: The results of the expressions *first and new_­value shall be writable to the result output iterator.
The ranges [first, last) and [result, result + (last - first)) shall not overlap.
Effects: Assigns to every iterator i in the range [result, result + (last - first)) either new_­value or *​(first + (i - result)) depending on whether the following corresponding conditions hold:
*(first + (i - result)) == old_value
pred(*(first + (i - result))) != false
Returns: result + (last - first).
Complexity: Exactly last - first applications of the corresponding predicate.