]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Transformation Algorithms//replace |40 |
2 | ||
3 | replace | |
4 | ======= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename OldType | |
14 | , typename NewType | |
15 | , typename In = |unspecified| | |
16 | > | |
17 | struct replace | |
18 | { | |
19 | typedef |unspecified| type; | |
20 | }; | |
21 | ||
22 | ||
23 | ||
24 | Description | |
25 | ----------- | |
26 | ||
27 | Returns a copy of the original sequence where every type identical to ``OldType`` | |
28 | has been replaced with ``NewType``. | |
29 | ||
30 | |transformation algorithm disclaimer| | |
31 | ||
32 | Header | |
33 | ------ | |
34 | ||
35 | .. parsed-literal:: | |
36 | ||
37 | #include <boost/mpl/replace.hpp> | |
38 | ||
39 | ||
40 | Model of | |
41 | -------- | |
42 | ||
43 | |Reversible Algorithm| | |
44 | ||
45 | ||
46 | Parameters | |
47 | ---------- | |
48 | ||
49 | +---------------+-----------------------------------+-------------------------------+ | |
50 | | Parameter | Requirement | Description | | |
51 | +===============+===================================+===============================+ | |
52 | | ``Sequence`` | |Forward Sequence| | A original sequence. | | |
53 | +---------------+-----------------------------------+-------------------------------+ | |
54 | | ``OldType`` | Any type | A type to be replaced. | | |
55 | +---------------+-----------------------------------+-------------------------------+ | |
56 | | ``NewType`` | Any type | A type to replace with. | | |
57 | +---------------+-----------------------------------+-------------------------------+ | |
58 | | ``In`` | |Inserter| | An inserter. | | |
59 | +---------------+-----------------------------------+-------------------------------+ | |
60 | ||
61 | ||
62 | Expression semantics | |
63 | -------------------- | |
64 | ||
65 | |Semantics disclaimer...| |Reversible Algorithm|. | |
66 | ||
67 | For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary types ``x`` and ``y``: | |
68 | ||
69 | ||
70 | .. parsed-literal:: | |
71 | ||
72 | typedef replace<s,x,y,in>::type r; | |
73 | ||
74 | :Return type: | |
75 | A type. | |
76 | ||
77 | :Semantics: | |
78 | Equivalent to | |
79 | ||
80 | .. parsed-literal:: | |
81 | ||
82 | typedef replace_if< s,y,is_same<_,x>,in >::type r; | |
83 | ||
84 | ||
85 | Complexity | |
86 | ---------- | |
87 | ||
88 | Linear. Performs exactly ``size<s>::value`` comparisons for | |
89 | identity / insertions. | |
90 | ||
91 | ||
92 | Example | |
93 | ------- | |
94 | ||
95 | .. parsed-literal:: | |
96 | ||
97 | typedef vector<int,float,char,float,float,double> types; | |
98 | typedef vector<int,double,char,double,double,double> expected; | |
99 | typedef replace< types,float,double >::type result; | |
100 | ||
101 | BOOST_MPL_ASSERT(( equal< result,expected > )); | |
102 | ||
103 | ||
104 | See also | |
105 | -------- | |
106 | ||
107 | |Transformation Algorithms|, |Reversible Algorithm|, |reverse_replace|, |replace_if|, |remove|, |transform| | |
108 | ||
109 | ||
110 |