Name
replace function template — Replaces all occurrences of one value with another value
Synopsis
template<typename FwdIter, typename T>
void replace(FwdIter first, FwdIter last, const T& old_value,
const T& new_value);
The replace
function
template replaces all occurrences of old_value
in [first
, last
) with new_value
. See Figure 13-14 (under replace_copy
) for an example of the
replacement process.
Technical Notes
The replace
function
template assigns *i =
(*i == old_value) ? 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.