Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.



      typename Sequence
    , typename OldType
    , typename NewType
struct replace
    typedef unspecified type;


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  
SequenceA model of Extensible SequenceThe original sequence.
OldTypeA typeA type to be replaced.
NewTypeA typeA type to replace with.

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef replace<Sequence,OldType,NewType>::type s;A model of Extensible SequenceEquivalent 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));

See also

Algorithms, replace_if, transform

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