Name
replace_if function template — Replaces values that satisfy a predicate
Synopsis
template<typename FwdIter, typename Predicate, typename T>
void replace_if(FwdIter first, FwdIter last, Predicate pred,
const T& new_value);
The replace_if
function
template replaces all values in [first
, last
) for which pred
is true with new_value
. See Figure 13-14 (under replace_copy
) for an example of the
replacement process.
Technical Notes
The replace_if
function
template assigns *i = pred
(*i) ? new_value : *i for all i in [first, last).
Complexity is linear: exactly last - first comparisons are performed.
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.