# replace

### Synopsis

    template<
          typename Sequence
        , typename OldType
        , typename NewType
        >
    struct replace
    {
        typedef unspecified type;
    };

### Description

Performs a replacement operation on the sequence. The algorithm returns a new sequence which contains all the elements from `[begin<Sequence>::type, end<Sequence>::type)` range where every type identical to `OldType` has been replaced with a `NewType`. The result sequence preserves all the functional and performance characteristics of the original `Sequence`, including its size, but not identity.

### Definition

    #include "boost/mpl/replace.hpp"

### Parameters

Parameter | Requirement | Description
--- | --- | ---
`Sequence` | A model of Extensible Sequence | The original sequence.
`OldType` | A type | A type to be replaced.
`NewType` | A type | A type to replace with.

### Expression semantics

Expression | Expression type | Precondition | Semantics | Postcondition
--- | --- | --- | --- | ---
`typedef replace<Sequence,OldType,NewType>::type s;` | A model of Extensible Sequence |  | Equivalent to `typedef replace_if< Sequence,NewType,is_same<_,OldType> >::type t;`. |

### Complexity

Linear. Performs exactly `size<Sequence>::type::value` comparisons for equality, and at most `size<Sequence>::type::value` insertions.

### Example

    typedef list<int,float,char,float,float,double>::type types;
    typedef replace< types,float,double >::type result;
    typedef list<int,double,char,double,double,double>::type answer;
    BOOST_STATIC_ASSERT((equal< result,answer >::type::value));

### See also

Algorithms, `replace_if`, `transform`

Table of Contents
Last edited July 17, 2002 5:38 am