Home » C++ algorithm replace_copy() function

C++ algorithm replace_copy() function

by Online Tutorials Library

C++ Algorithm replace_copy()

C++ Algorithm replace_copy() function is used to make a copy of the range [first, last) and replaces all old_value by the value new_value into it. It uses operator= to make the copy and to compare the elements it uses operator==.

This function examines each element in a source range and replaces it if it matches a specified value while copying the result into a new destination range.

Syntax

Parameter

first: An input iterator pointing to the initial position in the range from which elements are being replaced.

last: A input iterator pointing to the final position in the range from which elements are being replaced.

result: An output iterator pointing to the first element of the range where the resulting sequence is stored.

old_value: The old value of the element being replaced.

new_value: The new value assigned to the elements with the old value.

Return value

replace_copy() function returns an output iterator pointing to the position that points to the last element written in the result sequence.

You may also like