replace_copy
Replaces elements that have a special value while copying the whole range
Definition
The replace_copy() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class InputIterator, class OutputIterator, class Type >
OutputIterator replace_copy(
InputIterator first,
InputIterator last,
OutputIterator result,
const Type& oldVal,
const Type& newVal
);Parameters:
| Parameter | Description |
| first | An input iterator pointing to the position of the first element in the range from which elements are being replaced |
| last | An input iterator pointing to the position one past the final element in the range from which elements are being replaced |
| result | An output iterator pointing to the first element in the destination range to where the altered sequence of elements is being copied |
| oldVal | The old value of the elements being replaced |
| newVal | The new value being assigned to the elements with the old value |
Description
Replace_copy algorithm makes a copy of a range and replaces all oldVal values by the value newVal into it. It uses operator= to make the copy and operator== to compare elements.
Return Value
The value return is an output iterator pointing to the position one past the final element in the destination range to where the altered sequence of elements is being copied.
Complexity
The complexity is linear; there are last - first comparisons for equality and last - first assignments.