| <?xml version="1.0" encoding="utf-8"?> |
| <header name="boost/proto/transform/pass_through.hpp"> |
| <para>Definition of the |
| <computeroutput><classname alt="boost::proto::pass_through">proto::pass_through<></classname></computeroutput> |
| transform, which is the default transform of all of the expression generator metafunctions such as |
| <computeroutput><classname alt="boost::proto::unary_plus">proto::unary_plus<></classname></computeroutput>, |
| <computeroutput><classname alt="boost::proto::plus">proto::plus<></classname></computeroutput> and |
| <computeroutput><classname alt="boost::proto::nary_expr">proto::nary_expr<></classname></computeroutput>.</para> |
| <namespace name="boost"> |
| <namespace name="proto"> |
| <struct name="pass_through"> |
| <template> |
| <template-type-parameter name="Grammar"/> |
| </template> |
| <inherit><type><classname>proto::transform</classname>< pass_through<Grammar> ></type></inherit> |
| <purpose>A <conceptname>PrimitiveTransform</conceptname> that transforms the child expressions of an expression |
| node according to the corresponding children of a Grammar.</purpose> |
| <description> |
| <para> |
| Given a Grammar such as <computeroutput><classname>proto::plus</classname><T0, T1></computeroutput>, |
| an expression type that matches the grammar such as |
| <computeroutput><classname>proto::plus</classname><E0, E1>::type</computeroutput>, a state |
| <computeroutput>S</computeroutput> and a data <computeroutput>D</computeroutput>, the result of applying |
| the <computeroutput>proto::pass_through<<classname>proto::plus</classname><T0, T1> ></computeroutput> |
| transform is: <programlisting><classname>proto::plus</classname>< |
| boost::result_of<T0(E0, S, D)>::type, |
| boost::result_of<T1(E1, S, D)>::type |
| >::type</programlisting> |
| </para> |
| <para> |
| The above demonstrates how child transforms and child expressions are applied pairwise, and how the |
| results are reassembled into a new expression node with the same tag type as the original. |
| </para> |
| <para> |
| The explicit use of <computeroutput>proto::pass_through<></computeroutput> is not usually |
| needed, since the expression generator metafunctions such as |
| <computeroutput><classname>proto::plus</classname><></computeroutput> have |
| <computeroutput>proto::pass_through<></computeroutput> as their default transform. So, |
| for instance, these are equivalent: |
| <itemizedlist> |
| <listitem> |
| <computeroutput> |
| <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y>, proto::pass_through< <classname>proto::plus</classname><X, Y> > > |
| </computeroutput> |
| </listitem> |
| <listitem> |
| <computeroutput> |
| <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y>, <classname>proto::plus</classname><X, Y> > |
| </computeroutput> |
| </listitem> |
| <listitem> |
| <computeroutput> |
| <classname>proto::when</classname>< <classname>proto::plus</classname><X, Y> > // because of proto::when<class X, class Y=X> |
| </computeroutput> |
| </listitem> |
| <listitem> |
| <computeroutput> |
| <classname>proto::plus</classname><X, Y> // because plus<> is both a grammar and a transform |
| </computeroutput> |
| </listitem> |
| </itemizedlist> |
| </para> |
| <para> |
| For example, consider the following transform that promotes all |
| <computeroutput>float</computeroutput> terminals in an expression to |
| <computeroutput>double</computeroutput>. |
| <programlisting>// This transform finds all float terminals in an expression and promotes |
| // them to doubles. |
| struct Promote : |
| <classname>proto::or_</classname>< |
| <classname>proto::when</classname><<classname>proto::terminal</classname><float>, <classname>proto::terminal</classname><double>::type(<classname>proto::_value</classname>) >, |
| // terminal<>'s default transform is a no-op: |
| <classname>proto::terminal</classname><<classname>proto::_</classname>>, |
| // nary_expr<> has a pass_through<> transform: |
| <classname>proto::nary_expr</classname><<classname>proto::_</classname>, <classname>proto::vararg</classname><Promote> > |
| > |
| {};</programlisting> |
| </para> |
| </description> |
| <struct name="impl"> |
| <template> |
| <template-type-parameter name="Expr"/> |
| <template-type-parameter name="State"/> |
| <template-type-parameter name="Data"/> |
| </template> |
| <inherit><type><classname>proto::transform_impl</classname><Expr, State, Data></type></inherit> |
| <typedef name="GN"> |
| <purpose>For each N in [0,Expr arity), for exposition only</purpose> |
| <type>typename proto::result_of::child_c<Grammar, N>::type</type> |
| </typedef> |
| <typedef name="EN"> |
| <purpose>For each N in [0,Expr arity), for exposition only</purpose> |
| <type>typename proto::result_of::child_c<Expr, N>::type</type> |
| </typedef> |
| <typedef name="RN"> |
| <purpose>For each N in [0,Expr arity), for exposition only</purpose> |
| <type>typename boost::result_of<GN(EN,State,Data)>::type</type> |
| </typedef> |
| <typedef name="T"> |
| <purpose>For exposition only</purpose> |
| <type>typename Expr::proto_tag</type> |
| </typedef> |
| <typedef name="D"> |
| <purpose>For exposition only</purpose> |
| <type>typename Expr::proto_domain</type> |
| </typedef> |
| <typedef name="G"> |
| <purpose>For exposition only</purpose> |
| <type>typename D::proto_generator</type> |
| </typedef> |
| <typedef name="A"> |
| <purpose>For exposition only</purpose> |
| <type><classname>proto::listN</classname><R0,...RN></type> |
| </typedef> |
| <typedef name="E"> |
| <purpose>For exposition only</purpose> |
| <type><classname>proto::expr</classname><T, A></type> |
| </typedef> |
| <typedef name="BE"> |
| <purpose>For exposition only</purpose> |
| <type><classname>proto::basic_expr</classname><T, A></type> |
| </typedef> |
| <typedef name="expr_type"> |
| <purpose>For exposition only</purpose> |
| <type>typename mpl::if_<<classname>proto::wants_basic_expr</classname><G>, BE, E>::type</type> |
| </typedef> |
| <typedef name="result_type"> |
| <type>typename boost::result_of<D(expr_type)>::type</type> |
| </typedef> |
| <method-group name="public member functions"> |
| <method name="operator()" cv="const"> |
| <type>result_type</type> |
| <parameter name="expr"> |
| <paramtype>typename impl::expr_param</paramtype> |
| </parameter> |
| <parameter name="state"> |
| <paramtype>typename impl::state_param</paramtype> |
| </parameter> |
| <parameter name="data"> |
| <paramtype>typename impl::data_param</paramtype> |
| </parameter> |
| <requires> |
| <para> |
| <computeroutput> |
| <classname>proto::matches</classname><Expr, Grammar>::value |
| </computeroutput> is <computeroutput>true</computeroutput>. |
| </para> |
| </requires> |
| <returns> |
| <para> |
| <programlisting>D()(expr_type::make( |
| G0()(<functionname>proto::child_c</functionname><0>(expr), state, data), |
| ... |
| GN()(<functionname>proto::child_c</functionname><N>(expr), state, data) |
| ))</programlisting> |
| </para> |
| </returns> |
| </method> |
| </method-group> |
| </struct> |
| </struct> |
| </namespace> |
| </namespace> |
| </header> |