|
ALINK="#ff0000">
replace_if
Prototypetemplate <class ForwardIterator, class Predicate, class T> void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred const T& new_value) DescriptionReplace_if replaces every element in the range [first, last) for which pred returns true with new_value. That is: for every iterator i, if pred(*i) is true then it performs the assignment *i = new_value.DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.Requirements on types
Preconditions
ComplexityLinear. Replace_if performs exactly last - first applications of pred, and at most last - first assignments.ExampleReplace every negative number with 0.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 alsoreplace, replace_copy, replace_copy_ifCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|