replace_if
Prototypetemplate <class ForwardIterator, class Predicate, class T>
void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred
const T& new_value)
Description
DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h. Requirements on types
Preconditions
ComplexityLinear. ExampleReplace every negative number with Vector<int> V;
V.push_back(1);
V.push_back(-3);
V.push_back(2);
V.push_back(-1);
replace_if(V.begin(), V.end(), bind2nd(less<int>(), 0), -1);
assert(V[1] == 0 && V[3] == 0);
NotesSee also |