|
ALINK="#ff0000">
replace_copy
Prototypetemplate <class InputIterator, class OutputIterator, class T> OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value); DescriptionReplace_copy copies elements from the range [first, last) to the range [result, result + (last-first)), except that any element equal to old_value is not copied; new_value is copied instead. More precisely, for every integer n such that 0 <= n < last-first, replace_copy performs the assignment *(result+n) = new_value if *(first+n) == old_value, and *(result+n) = *(first+n) otherwise.DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.Requirements on types
Preconditions
ComplexityLinear. Replace_copy performs exactly last - first comparisons for equality and exactly last - first assignments.Examplevector<int> V1; V1.push_back(1); V1.push_back(2); V1.push_back(3); V1.push_back(1); vector<int> V2(4); replace_copy(V1.begin(), V1.end(), V2.begin(), 1, 99); assert(V[0] == 99 && V[1] == 2 && V[2] == 3 && V[3] == 99); NotesSee alsocopy, replace, replace_if, replace_copy_ifCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|