SGI Techpubs Library

IRIX 6.5  »  Books  »  Developer  »  
Standard Template Library Programmer's Guide
(document number: 007-3426-004 / published: 1999-05-21)    table of contents  |  additional info  |  download
find in page

SGI

replace

Category: algorithms Component type: function

Prototype

template <class ForwardIterator, class T>
void replace(ForwardIterator first, ForwardIterator last, const T& old_value,
             const T& new_value)

Description

Replace replaces every element in the range [first, last) equal to old_value with new_value. That is: for every iterator i, if *i == old_value then it performs the assignment *i = new_value.

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

Preconditions

Complexity

Linear. Replace performs exactly last - first comparisons for equality, and at most last - first assignments.

Example

vector<int> V;
V.push_back(1);
V.push_back(2);
V.push_back(3);
V.push_back(1);

replace(V.begin(), V.end(), 1, 99);
assert(V[0] == 99 && V[3] == 99);

Notes

See also

replace_if, replace_copy, replace_copy_if
[Silicon Surf] [STL Home]
Copyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation

Standard Template Library Programmer's Guide
(document number: 007-3426-004 / published: 1999-05-21)    table of contents  |  additional info  |  download


home/search | what's new | help

Contact Us | Site Map | Trademarks | Privacy | Using this site means you accept its Terms of Use

Copyright © 1993-2007 SGI, Inc. All rights reserved.