]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <!-- | |
3 | Copyright 2012 Eric Niebler | |
4 | ||
5 | Distributed under the Boost | |
6 | Software License, Version 1.0. (See accompanying | |
7 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | --> | |
9 | <header name="boost/proto/transform/pass_through.hpp"> | |
10 | <para>Definition of the | |
11 | <computeroutput><classname alt="boost::proto::pass_through">proto::pass_through<></classname></computeroutput> | |
12 | transform, which is the default transform of all of the expression generator metafunctions such as | |
13 | <computeroutput><classname alt="boost::proto::unary_plus">proto::unary_plus<></classname></computeroutput>, | |
14 | <computeroutput><classname alt="boost::proto::plus">proto::plus<></classname></computeroutput> and | |
15 | <computeroutput><classname alt="boost::proto::nary_expr">proto::nary_expr<></classname></computeroutput>.</para> | |
16 | <namespace name="boost"> | |
17 | <namespace name="proto"> | |
18 | <struct name="pass_through"> | |
19 | <template> | |
20 | <template-type-parameter name="Grammar"/> | |
21 | <template-type-parameter name="Domain"> | |
22 | <default><classname>proto::deduce_domain</classname></default> | |
23 | </template-type-parameter> | |
24 | </template> | |
25 | <inherit><type><classname>proto::transform</classname>< pass_through<Grammar, Domain> ></type></inherit> | |
26 | <purpose>A <conceptname>PrimitiveTransform</conceptname> that transforms the child expressions of an expression | |
27 | node according to the corresponding children of a Grammar. The resulting expression is in the specified domain.</purpose> | |
28 | <description> | |
29 | <para> | |
30 | Given a Grammar such as <computeroutput><classname>proto::plus</classname><T0, T1></computeroutput>, | |
31 | an expression type that matches the grammar such as | |
32 | <computeroutput><classname>proto::plus</classname><E0, E1>::type</computeroutput>, a state | |
33 | <computeroutput>S</computeroutput> and a data <computeroutput>D</computeroutput>, the result of applying | |
34 | the <computeroutput>proto::pass_through<<classname>proto::plus</classname><T0, T1> ></computeroutput> | |
35 | transform is: <programlisting><classname>proto::plus</classname>< | |
36 | boost::result_of<T0(E0, S, D)>::type, | |
37 | boost::result_of<T1(E1, S, D)>::type | |
38 | >::type</programlisting> | |
39 | </para> | |
40 | <para> | |
41 | The above demonstrates how child transforms and child expressions are applied pairwise, and how the | |
42 | results are reassembled into a new expression node with the same tag type as the original. | |
43 | </para> | |
44 | <para> | |
45 | The <code>Domain</code> template parameter determines which domain the resulting expression should | |
46 | be in. If it is <code><classname>proto::deduce_domain</classname></code>, which is the default, | |
47 | the resulting expression is in the same domain as the expression passed in. Otherwise, the resulting | |
48 | expression is in the specified domain. Practically, that means the specified domain's generator is | |
49 | used to post-process the resulting expression. | |
50 | </para> | |
51 | <para> | |
52 | The explicit use of <computeroutput>proto::pass_through<></computeroutput> is not usually | |
53 | needed, since the expression generator metafunctions such as | |
54 | <computeroutput><classname>proto::plus</classname><></computeroutput> have | |
55 | <computeroutput>proto::pass_through<></computeroutput> as their default transform. So, | |
56 | for instance, these are equivalent: | |
57 | <itemizedlist> | |
58 | <listitem> | |
59 | <computeroutput> | |
60 | <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y>, proto::pass_through< <classname>proto::plus</classname><X, Y> > > | |
61 | </computeroutput> | |
62 | </listitem> | |
63 | <listitem> | |
64 | <computeroutput> | |
65 | <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y>, <classname>proto::plus</classname><X, Y> > | |
66 | </computeroutput> | |
67 | </listitem> | |
68 | <listitem> | |
69 | <computeroutput> | |
70 | <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y> > // because of proto::when<class X, class Y=X> | |
71 | </computeroutput> | |
72 | </listitem> | |
73 | <listitem> | |
74 | <computeroutput> | |
75 | <classname>proto::plus</classname><X, Y> // because plus<> is both a grammar and a transform | |
76 | </computeroutput> | |
77 | </listitem> | |
78 | </itemizedlist> | |
79 | </para> | |
80 | <para> | |
81 | For example, consider the following transform that promotes all | |
82 | <computeroutput>float</computeroutput> terminals in an expression to | |
83 | <computeroutput>double</computeroutput>. | |
84 | <programlisting>// This transform finds all float terminals in an expression and promotes | |
85 | // them to doubles. | |
86 | struct Promote : | |
87 | <classname>proto::or_</classname>< | |
88 | <classname>proto::when</classname><<classname>proto::terminal</classname><float>, <classname>proto::terminal</classname><double>::type(<classname>proto::_value</classname>) >, | |
89 | // terminal<>'s default transform is a no-op: | |
90 | <classname>proto::terminal</classname><<classname>proto::_</classname>>, | |
91 | // nary_expr<> has a pass_through<> transform: | |
92 | <classname>proto::nary_expr</classname><<classname>proto::_</classname>, <classname>proto::vararg</classname><Promote> > | |
93 | > | |
94 | {};</programlisting> | |
95 | </para> | |
96 | </description> | |
97 | <struct name="impl"> | |
98 | <template> | |
99 | <template-type-parameter name="Expr"/> | |
100 | <template-type-parameter name="State"/> | |
101 | <template-type-parameter name="Data"/> | |
102 | </template> | |
103 | <inherit><type><classname>proto::transform_impl</classname><Expr, State, Data></type></inherit> | |
104 | <typedef name="GN"> | |
105 | <purpose>For each N in [0,Expr arity), for exposition only</purpose> | |
106 | <type>typename proto::result_of::child_c<Grammar, N>::type</type> | |
107 | </typedef> | |
108 | <typedef name="EN"> | |
109 | <purpose>For each N in [0,Expr arity), for exposition only</purpose> | |
110 | <type>typename proto::result_of::child_c<Expr, N>::type</type> | |
111 | </typedef> | |
112 | <typedef name="RN"> | |
113 | <purpose>For each N in [0,Expr arity), for exposition only</purpose> | |
114 | <type>typename boost::result_of<GN(EN,State,Data)>::type</type> | |
115 | </typedef> | |
116 | <typedef name="T"> | |
117 | <purpose>For exposition only</purpose> | |
118 | <type>typename Expr::proto_tag</type> | |
119 | </typedef> | |
120 | <typedef name="Deduce"> | |
121 | <purpose>For exposition only</purpose> | |
122 | <type>boost::is_same<Domain, <classname>deduce_domain</classname>></type> | |
123 | </typedef> | |
124 | <typedef name="DD"> | |
125 | <purpose>For exposition only</purpose> | |
126 | <type>typename Expr::proto_domain</type> | |
127 | </typedef> | |
128 | <typedef name="D"> | |
129 | <purpose>For exposition only</purpose> | |
130 | <type>typename mpl::if_<Deduce, DD, Domain>::type</type> | |
131 | </typedef> | |
132 | <typedef name="G"> | |
133 | <purpose>For exposition only</purpose> | |
134 | <type>typename D::proto_generator</type> | |
135 | </typedef> | |
136 | <typedef name="A"> | |
137 | <purpose>For exposition only</purpose> | |
138 | <type><classname>proto::listN</classname><R0,...RN></type> | |
139 | </typedef> | |
140 | <typedef name="E"> | |
141 | <purpose>For exposition only</purpose> | |
142 | <type><classname>proto::expr</classname><T, A></type> | |
143 | </typedef> | |
144 | <typedef name="BE"> | |
145 | <purpose>For exposition only</purpose> | |
146 | <type><classname>proto::basic_expr</classname><T, A></type> | |
147 | </typedef> | |
148 | <typedef name="expr_type"> | |
149 | <purpose>For exposition only</purpose> | |
150 | <type>typename mpl::if_<<classname>proto::wants_basic_expr</classname><G>, BE, E>::type</type> | |
151 | </typedef> | |
152 | <typedef name="result_type"> | |
153 | <type>typename boost::result_of<D(expr_type)>::type</type> | |
154 | </typedef> | |
155 | <method-group name="public member functions"> | |
156 | <method name="operator()" cv="const"> | |
157 | <type>result_type</type> | |
158 | <parameter name="expr"> | |
159 | <paramtype>typename impl::expr_param</paramtype> | |
160 | </parameter> | |
161 | <parameter name="state"> | |
162 | <paramtype>typename impl::state_param</paramtype> | |
163 | </parameter> | |
164 | <parameter name="data"> | |
165 | <paramtype>typename impl::data_param</paramtype> | |
166 | </parameter> | |
167 | <requires> | |
168 | <para> | |
169 | <computeroutput> | |
170 | <classname>proto::matches</classname><Expr, Grammar>::value | |
171 | </computeroutput> is <computeroutput>true</computeroutput>. | |
172 | </para> | |
173 | </requires> | |
174 | <returns> | |
175 | <para> | |
176 | <programlisting>D()(expr_type::make( | |
177 | G0()(<functionname>proto::child_c</functionname><0>(expr), state, data), | |
178 | ... | |
179 | GN()(<functionname>proto::child_c</functionname><N>(expr), state, data) | |
180 | ))</programlisting> | |
181 | </para> | |
182 | </returns> | |
183 | </method> | |
184 | </method-group> | |
185 | </struct> | |
186 | </struct> | |
187 | </namespace> | |
188 | </namespace> | |
189 | </header> |