]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Transformation Algorithms//transform |30 |
2 | ||
3 | transform | |
4 | ========= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename Op | |
14 | , typename In = |unspecified| | |
15 | > | |
16 | struct transform | |
17 | { | |
18 | typedef |unspecified| type; | |
19 | }; | |
20 | ||
21 | template< | |
22 | typename Seq1 | |
23 | , typename Seq2 | |
24 | , typename BinaryOp | |
25 | , typename In = |unspecified| | |
26 | > | |
27 | struct transform | |
28 | { | |
29 | typedef |unspecified| type; | |
30 | }; | |
31 | ||
32 | ||
33 | Description | |
34 | ----------- | |
35 | ||
36 | ``transform`` is an |overloaded name|: | |
37 | ||
38 | * ``transform<Sequence,Op>`` returns a transformed copy of the original sequence | |
39 | produced by applying an unary transformation ``Op`` to every element | |
40 | in the |begin/end<Sequence>| range. | |
41 | ||
42 | * ``transform<Seq1,Seq2,BinaryOp>`` returns a new sequence produced by applying a | |
43 | binary transformation ``BinaryOp`` to a pair of elements (e\ :sub:`1`, e2\ :sub:`1`) | |
44 | from the corresponding |begin/end<Seq1>| and |begin/end<Seq2>| ranges. | |
45 | ||
46 | |transformation algorithm disclaimer| | |
47 | ||
48 | ||
49 | Header | |
50 | ------ | |
51 | ||
52 | .. parsed-literal:: | |
53 | ||
54 | #include <boost/mpl/transform.hpp> | |
55 | ||
56 | ||
57 | Model of | |
58 | -------- | |
59 | ||
60 | |Reversible Algorithm| | |
61 | ||
62 | ||
63 | Parameters | |
64 | ---------- | |
65 | ||
66 | +-------------------+-----------------------------------+-----------------------------------+ | |
67 | | Parameter | Requirement | Description | | |
68 | +===================+===================================+===================================+ | |
69 | | ``Sequence``, | |Forward Sequence| | Sequences to transform. | | |
70 | | ``Seq1``, ``Seq2``| | | | |
71 | +-------------------+-----------------------------------+-----------------------------------+ | |
72 | | ``Op``, | |Lambda Expression| | A transformation. | | |
73 | | ``BinaryOp`` | | | | |
74 | +-------------------+-----------------------------------+-----------------------------------+ | |
75 | | ``In`` | |Inserter| | An inserter. | | |
76 | +-------------------+-----------------------------------+-----------------------------------+ | |
77 | ||
78 | ||
79 | Expression semantics | |
80 | -------------------- | |
81 | ||
82 | |Semantics disclaimer...| |Reversible Algorithm|. | |
83 | ||
84 | For any |Forward Sequence|\ s ``s``, ``s1`` and ``s2``, |Lambda Expression|\ s ``op`` and ``op2``, | |
85 | and an |Inserter| ``in``: | |
86 | ||
87 | .. parsed-literal:: | |
88 | ||
89 | typedef transform<s,op,in>::type r; | |
90 | ||
91 | :Return type: | |
92 | A type. | |
93 | ||
94 | :Postcondition: | |
95 | Equivalent to | |
96 | ||
97 | .. parsed-literal:: | |
98 | ||
99 | typedef lambda<op>::type f; | |
100 | typedef lambda<in::operation>::type in_op; | |
101 | ||
102 | typedef fold< | |
103 | s | |
104 | , in::state | |
105 | , bind< in_op, _1, bind<f, _2> > | |
106 | >::type r; | |
107 | ||
108 | ||
109 | .. parsed-literal:: | |
110 | ||
111 | typedef transform<s1,s2,op,in>::type r; | |
112 | ||
113 | :Return type: | |
114 | A type. | |
115 | ||
116 | :Postcondition: | |
117 | Equivalent to | |
118 | ||
119 | .. parsed-literal:: | |
120 | ||
121 | typedef lambda<op2>::type f; | |
122 | typedef lambda<in::operation>::type in_op; | |
123 | ||
124 | typedef fold< | |
125 | pair_view<s1,s2> | |
126 | , in::state | |
127 | , bind< | |
128 | in_op | |
129 | , _1 | |
130 | , bind<f, bind<first<>,_2>, bind<second<>,_2> > | |
131 | > | |
132 | >::type r; | |
133 | ||
134 | ||
135 | Complexity | |
136 | ---------- | |
137 | ||
138 | Linear. Exactly ``size<s>::value`` / ``size<s1>::value`` applications of | |
139 | ``op`` / ``op2`` and ``in::operation``. | |
140 | ||
141 | ||
142 | Example | |
143 | ------- | |
144 | ||
145 | .. parsed-literal:: | |
146 | ||
147 | typedef vector<char,short,int,long,float,double> types; | |
148 | typedef vector<char*,short*,int*,long*,float*,double*> pointers; | |
149 | typedef transform< types,boost::add_pointer<_1> >::type result; | |
150 | ||
151 | BOOST_MPL_ASSERT(( equal<result,pointers> )); | |
152 | ||
153 | ||
154 | See also | |
155 | -------- | |
156 | ||
157 | |Transformation Algorithms|, |Reversible Algorithm|, |reverse_transform|, |copy|, |replace_if| | |
158 | ||
159 | ||
160 |