Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

replace_copy


Algorithm

Summary

Substitutes elements in a collection with new values, and moves the revised sequence into result.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class InputIterator,
          class OutputIterator,
          class T>
OutputIterator replace_copy (InputIterator first,
                             InputIterator last,
                             OutputIterator result,
                             const T& old_value,
                             const T& new_value);

Description

The replace_copy algorithm leaves the original sequence intact and places the revised sequence into result. For the range [first, last), the algorithm compares elements referred to by iterator i with old_value. If *i does not equal old_value, then replace_copy copies *i to result+(first-i). If *i==old_value, then replace_copy copies new_value to result+(first-i). replace_copy returns result+(last-first).

Complexity

Exactly last - first comparisons between values are done.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

replace, replace_if, replace_copy_if



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998