...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

template< typename Sequence , typename OldType , typename NewType > struct replace { typedefunspecifiedtype; };

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.

#include "boost/mpl/replace.hpp"

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 | 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;` . |

Linear. Performs exactly `size<Sequence>::type::value`

comparisons for equality, and at most `size<Sequence>::type::value`

insertions.

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));

Algorithms, `replace_if`

, `transform`

Table of Contents

Last edited July 17, 2002 5:38 am