Home » C++ algorithm replace_if() function

C++ algorithm replace_if() function

by Online Tutorials Library

C++ Algorithm replace_if()

C++ Algorithm replace_if() function is used to assign new_value to all the elements in the range [first, last) for which pred predicate returns true.

This function examines each element in a range and replaces it if it satisfies a specified predicate.

Syntax

Parameter

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

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

pred: The unary predicate function that must be satisfied is the value of the element is to be replaced.

new_value: The new value assigned to the elements whose old value satisfies the predicate.

Return value

None

You may also like