Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

replace_copy_if


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 Predicate,
          class T>
OutputIterator replace_copy_if (InputIterator first,
                                InputIterator last,
                                OutputIterator result,
                                Predicate pred,
                                const T& new_value);

Description

The replace_copy_if algorithm leaves the original sequence intact and places a revised sequence into result. For the range [first,last), the algorithm compares each element *i with the conditions specified by pred. If pred(*i)==false, replace_copy_if copies *i to result+(first-i). If pred(*i)==true, then replace_copy copies new_value to result+(first-i). replace_copy_if returns result+(last-first).

Complexity

Exactly last - first applications of the predicate are performed.

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



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