|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-08-30 16:30:01
Author: eric_niebler
Date: 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
New Revision: 48479
URL: http://svn.boost.org/trac/boost/changeset/48479
Log:
more doc improvements
Text files modified:
trunk/boost/proto/matches.hpp | 7
trunk/libs/proto/doc/proto.qbk | 8 +
trunk/libs/proto/doc/protodoc.xml | 78 +++++-----
trunk/libs/proto/doc/resources.qbk | 10 +
trunk/libs/proto/doc/transforms.qbk | 283 +++++++++++++++++++++++++++++++++++----
5 files changed, 311 insertions(+), 75 deletions(-)
Modified: trunk/boost/proto/matches.hpp
==============================================================================
--- trunk/boost/proto/matches.hpp (original)
+++ trunk/boost/proto/matches.hpp 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
@@ -484,8 +484,8 @@
{};
}
- namespace wildcardns_
- {
+ BOOST_PROTO_BEGIN_ADL_NAMESPACE(wildcardns_)
+
/// \brief A wildcard grammar element that matches any expression,
/// and a transform that returns the current expression unchanged.
///
@@ -548,7 +548,8 @@
}
};
};
- }
+
+ BOOST_PROTO_END_ADL_NAMESPACE(wildcardns_)
namespace control
{
Modified: trunk/libs/proto/doc/proto.qbk
==============================================================================
--- trunk/libs/proto/doc/proto.qbk (original)
+++ trunk/libs/proto/doc/proto.qbk 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
@@ -91,10 +91,16 @@
[funcref boost::proto::value `proto::value()`]]
[def _terminal_
[classref boost::proto::op::terminal `proto::terminal<>`]]
+[def _unary_plus_
+ [classref boost::proto::op::unary_plus `proto::unary_plus<>`]]
+[def _plus_
+ [classref boost::proto::op::plus `proto::plus<>`]]
[def _unary_expr_
[classref boost::proto::op::unary_expr `proto::unary_expr<>`]]
[def _binary_expr_
[classref boost::proto::op::binary_expr `proto::binary_expr<>`]]
+[def _nary_expr_
+ [classref boost::proto::op::nary_expr `proto::nary_expr<>`]]
[def _literal_
[classref boost::proto::utility::literal `proto::literal<>`]]
[def _lit_
@@ -149,6 +155,8 @@
[classref boost::proto::reverse_fold_tree [^proto::reverse_fold_tree<>]]]
[def _lazy_pt_
[classref boost::proto::lazy [^proto::lazy<>]]]
+[def _SYB_
+ [link boost_proto.users_guide.resources.SYB ["Scrap Your Boilerplate]]]
[include preface.qbk]
Modified: trunk/libs/proto/doc/protodoc.xml
==============================================================================
--- trunk/libs/proto/doc/protodoc.xml (original)
+++ trunk/libs/proto/doc/protodoc.xml 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
@@ -1453,7 +1453,33 @@
<template-type-parameter name="A2"/>
<template-type-parameter name="A3"/>
<template-type-parameter name="A4"/>
- </template><parameter name="a0"><paramtype>A0 &</paramtype></parameter><parameter name="a1"><paramtype>A1 &</paramtype></parameter><parameter name="a2"><paramtype>A2 &</paramtype></parameter><parameter name="a3"><paramtype>A3 &</paramtype></parameter><parameter name="a4"><paramtype>A4 &</paramtype></parameter></signature><purpose>Return a proxy object that holds its arguments by reference and is implicitly convertible to an expression. </purpose></overloaded-function></namespace></namespace></header><header name="boost/proto/matches.hpp"><para>Contains definition of matches<> metafunction for determining if a given expression matches a given pattern. </para><namespace name="boost"><namespace name="proto"><namespace name="control"><struct name="not_"><template>
+ </template><parameter name="a0"><paramtype>A0 &</paramtype></parameter><parameter name="a1"><paramtype>A1 &</paramtype></parameter><parameter name="a2"><paramtype>A2 &</paramtype></parameter><parameter name="a3"><paramtype>A3 &</paramtype></parameter><parameter name="a4"><paramtype>A4 &</paramtype></parameter></signature><purpose>Return a proxy object that holds its arguments by reference and is implicitly convertible to an expression. </purpose></overloaded-function></namespace></namespace></header><header name="boost/proto/matches.hpp"><para>Contains definition of matches<> metafunction for determining if a given expression matches a given pattern. </para><namespace name="boost"><namespace name="proto"><struct name="_"><inherit access="public">boost::proto::transform< PrimitiveTransform, Base ></inherit><purpose>A wildcard grammar element that matches any expression, and a transform that returns the current expression unchanged. </purpose><description><para>The wild
card type, <computeroutput>_</computeroutput>, is a grammar element such that <computeroutput>matches<E,_>::value</computeroutput> is <computeroutput>true</computeroutput> for any expression type <computeroutput>E</computeroutput>.</para><para>The wildcard can also be used as a stand-in for a template argument when matching terminals. For instance, the following is a grammar that will match any <computeroutput>std::complex<></computeroutput> terminal:</para><para><programlisting> BOOST_MPL_ASSERT((
+ matches<
+ terminal<std::complex<double> >::type
+ , terminal<std::complex< _ > >
+ >
+ ));
+</programlisting></para><para>When used as a transform, <computeroutput>_</computeroutput> returns the current expression unchanged. For instance, in the following, <computeroutput>_</computeroutput> is used with the <computeroutput>fold<></computeroutput> transform to fold the children of a node:</para><para><programlisting> struct CountChildren
+ : or_<
+ // Terminals have no children
+ when<terminal<_>, mpl::int_<0>()>
+ // Use fold<> to count the children of non-terminals
+ , otherwise<
+ fold<
+ _ // <-- fold the current expression
+ , mpl::int_<0>()
+ , mpl::plus<_state, mpl::int_<1> >()
+ >
+ >
+ >
+ {};
+</programlisting> </para></description><struct name="impl"><template>
+ <template-type-parameter name="Expr"/>
+ <template-type-parameter name="State"/>
+ <template-type-parameter name="Data"/>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="result_type"><type>Expr</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>impl::expr_param</type><parameter name="expr"><paramtype>typename impl::expr_param</paramtype><description><para>An expression </para></description></parameter><parameter name=""><paramtype>typename impl::state_param</paramtype></parameter><parameter name=""><paramtype>typename impl::data_param</paramtype></parameter><description><para>
+
+</para></description><returns><para><computeroutput>expr</computeroutput> </para></returns></method></method-group></struct><typedef name="proto_base_expr"><type><classname>_</classname></type></typedef></struct><namespace name="control"><struct name="not_"><template>
<template-type-parameter name="Grammar"/>
</template><inherit access="public">boost::proto::transform< PrimitiveTransform, Base ></inherit><purpose>Inverts the set of expressions matched by a grammar. When used as a transform, <computeroutput>not_<></computeroutput> returns the current expression unchanged. </purpose><description><para>If an expression type <computeroutput>E</computeroutput> does not match a grammar <computeroutput>G</computeroutput>, then <computeroutput>E</computeroutput> does match <computeroutput>not_<G></computeroutput>. For example, <computeroutput>not_<terminal<_> ></computeroutput> will match any non-terminal. </para></description><struct name="impl"><template>
<template-type-parameter name="Expr"/>
@@ -1490,7 +1516,7 @@
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="condition"><type><classname>when</classname>< _, If >::template <classname>impl</classname>< Expr, State, Data >::result_type</type></typedef><typedef name="which"><type>mpl::if_c< remove_reference< condition >::type::value, <classname>when</classname>< _, Then >, <classname>when</classname>< _, Else >>::type</type></typedef><typedef name="result_type"><type>which::template <classname>impl</classname>< Expr, State, Data >::result_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><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="da
ta"><paramtype>typename impl::data_param</paramtype><description><para>A data of arbitrary type </para></description></parameter><description><para>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="condition"><type><classname>when</classname>< <classname>_</classname>, If >::template <classname>impl</classname>< Expr, State, Data >::result_type</type></typedef><typedef name="which"><type>mpl::if_c< remove_reference< condition >::type::value, <classname>when</classname>< <classname>_</classname>, Then >, <classname>when</classname>< <classname>_</classname>, Else >>::type</type></typedef><typedef name="result_type"><type>which::template <classname>impl</classname>< Expr, State, Data >::result_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><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>T
he current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>A data of arbitrary type </para></description></parameter><description><para>
</para></description><returns><para><computeroutput>which::impl<Expr, State, Data>()(expr, state, data)</computeroutput> </para></returns></method></method-group></struct><typedef name="proto_base_expr"><type><classname>if_</classname></type></typedef></struct><struct name="or_"><template>
<template-type-parameter name="G0"/>
@@ -1584,33 +1610,7 @@
</para></description></struct><struct-specialization name="matches"><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="Grammar"/>
- </template><specialization><template-arg>Expr &</template-arg><template-arg>Grammar</template-arg></specialization></struct-specialization></namespace><namespace name="wildcardns_"><struct name="_"><inherit access="public">boost::proto::transform< PrimitiveTransform, Base ></inherit><purpose>A wildcard grammar element that matches any expression, and a transform that returns the current expression unchanged. </purpose><description><para>The wildcard type, <computeroutput>_</computeroutput>, is a grammar element such that <computeroutput>matches<E,_>::value</computeroutput> is <computeroutput>true</computeroutput> for any expression type <computeroutput>E</computeroutput>.</para><para>The wildcard can also be used as a stand-in for a template argument when matching terminals. For instance, the following is a grammar that will match any <computeroutput>std::complex<></computeroutput> terminal:</para><para><programlisting> BOOST_MPL_ASSERT((
- matches<
- terminal<std::complex<double> >::type
- , terminal<std::complex< _ > >
- >
- ));
-</programlisting></para><para>When used as a transform, <computeroutput>_</computeroutput> returns the current expression unchanged. For instance, in the following, <computeroutput>_</computeroutput> is used with the <computeroutput>fold<></computeroutput> transform to fold the children of a node:</para><para><programlisting> struct CountChildren
- : or_<
- // Terminals have no children
- when<terminal<_>, mpl::int_<0>()>
- // Use fold<> to count the children of non-terminals
- , otherwise<
- fold<
- _ // <-- fold the current expression
- , mpl::int_<0>()
- , mpl::plus<_state, mpl::int_<1> >()
- >
- >
- >
- {};
-</programlisting> </para></description><struct name="impl"><template>
- <template-type-parameter name="Expr"/>
- <template-type-parameter name="State"/>
- <template-type-parameter name="Data"/>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="result_type"><type>Expr</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>impl::expr_param</type><parameter name="expr"><paramtype>typename impl::expr_param</paramtype><description><para>An expression </para></description></parameter><parameter name=""><paramtype>typename impl::state_param</paramtype></parameter><parameter name=""><paramtype>typename impl::data_param</paramtype></parameter><description><para>
-
-</para></description><returns><para><computeroutput>expr</computeroutput> </para></returns></method></method-group></struct><typedef name="proto_base_expr"><type><classname>_</classname></type></typedef></struct></namespace></namespace></namespace></header><header name="boost/proto/operators.hpp"><para>Contains all the overloaded operators that make it possible to build Proto expression trees. </para><namespace name="boost"><namespace name="proto"><struct name="is_extension"><template>
+ </template><specialization><template-arg>Expr &</template-arg><template-arg>Grammar</template-arg></specialization></struct-specialization></namespace></namespace></namespace></header><header name="boost/proto/operators.hpp"><para>Contains all the overloaded operators that make it possible to build Proto expression trees. </para><namespace name="boost"><namespace name="proto"><struct name="is_extension"><template>
<template-type-parameter name="T"/>
</template><inherit access="public">boost::mpl::false_</inherit></struct><function name="operator+"><type><emphasis>unspecified</emphasis></type><template>
<template-type-parameter name="Arg"/>
@@ -2917,11 +2917,11 @@
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
<template-nontype-parameter name="B"><type>bool</type></template-nontype-parameter>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct><struct-specialization name="impl2"><template>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct><struct-specialization name="impl2"><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, State, Data >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
+ </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, State, Data >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
<template-type-parameter name="Fun"/>
<template-type-parameter name="A0"/>
<template-type-parameter name="A1"/>
@@ -2935,11 +2935,11 @@
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
<template-nontype-parameter name="B"><type>bool</type></template-nontype-parameter>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct><struct-specialization name="impl2"><template>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct><struct-specialization name="impl2"><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, a1, Data >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method>
</method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
+ </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, a1, Data >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl
2::data_param</paramtype></parameter></method></method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
<template-type-parameter name="Fun"/>
<template-type-parameter name="A0"/>
<template-type-parameter name="A1"/>
@@ -2954,11 +2954,11 @@
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
<template-nontype-parameter name="B"><type>bool</type></template-nontype-parameter>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< _, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-gr
oup></struct><struct-specialization name="impl2"><template>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< <classname>_</classname>, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>t
ypename impl2::data_param</paramtype></parameter></method></method-group></struct><struct-specialization name="impl2"><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< _, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, a1, a2 >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_param</paramtype></parameter><parameter name="state"><paramtype>typenam
e impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
+ </template><specialization><template-arg>Expr</template-arg><template-arg>State</template-arg><template-arg>Data</template-arg><template-arg>true</template-arg></specialization><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< <classname>_</classname>, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>Fun::template impl< a0, a1, a2 >::result_type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl2::expr_pa
ram</paramtype></parameter><parameter name="state"><paramtype>typename impl2::state_param</paramtype></parameter><parameter name="data"><paramtype>typename impl2::data_param</paramtype></parameter></method></method-group></struct-specialization></struct-specialization><struct-specialization name="call"><template>
<template-type-parameter name="Fun"/>
<template-type-parameter name="A0"/>
<template-type-parameter name="A1"/>
@@ -2968,7 +2968,7 @@
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< _, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a3"><type><classname>when</classname>< _, A3 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2, a3)>::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><description><para>The current expression </para></descripti
on></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>ax</computeroutput> be <computeroutput>when<_, Ax>()(expr, state, data)</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,N]</computeroutput>. Return <computeroutput>Fun()(a0, a1,... aN)</computeroutput>.</para><para>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< <classname>_</classname>, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a3"><type><classname>when</classname>< <classname>_</classname>, A3 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2, a3)>::type</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typen
ame impl::expr_param</paramtype><description><para>The current expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>ax</computeroutput> be <computeroutput>when<_, Ax>()(expr, state, data)</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,N]</computeroutput>. Return <computeroutput>Fun()(a0, a1,... aN)</computeroutput>.</para><para>
</para></description></method></method-group></struct></struct-specialization><struct-specialization name="call"><template>
<template-type-parameter name="Fun"/>
<template-type-parameter name="A0"/>
@@ -2980,7 +2980,7 @@
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< _, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< _, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< _, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a3"><type><classname>when</classname>< _, A3 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a4"><type><classname>when</classname>< _, A4 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2, a3, a4)>::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><description><para>The current expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>ax</computeroutput> be <computeroutput>when<_, Ax>()(expr, state, data)</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,N]</computeroutput>. Return <computeroutput>Fun()(a0, a1,... aN)</computeroutput>.</para><para>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="a0"><type><classname>when</classname>< <classname>_</classname>, A0 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a1"><type><classname>when</classname>< <classname>_</classname>, A1 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a2"><type><classname>when</classname>< <classname>_</classname>, A2 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a3"><type><classname>when</classname>< <classname>_</classname>, A3 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="a4"><type><classname>when</classname>< <classname>_</classname>, A4 >::template impl< Expr, State, Data >::result_type</type></typedef><typedef name="result_type"><type>boost::result_of< <classname>Fun</classname>(a0, a1, a2, a3, a4)>::
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><description><para>The current expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>ax</computeroutput> be <computeroutput>when<_, Ax>()(expr, state, data)</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,N]</computeroutput>. Return <computeroutput>Fun()(a0, a1,... aN)</computeroutput>.</para><para>
</para></description></method></method-group></struct></struct-specialization></namespace></namespace></header><header name="boost/proto/transform/fold.hpp"><para>Contains definition of the fold<> and reverse_fold<> transforms. </para><namespace name="boost"><namespace name="proto"><struct name="fold"><template>
<template-type-parameter name="Sequence"/>
<template-type-parameter name="State0"/>
@@ -2989,7 +2989,7 @@
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
- </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="sequence"><purpose>A Fusion sequence. </purpose><type>remove_reference< typename <classname>when</classname>< _, Sequence >::template <classname>impl</classname>< Expr, State, Data >::result_type >::type</type></typedef><typedef name="state0"><purpose>An initial state for the fold. </purpose><type>remove_reference< typename <classname>when</classname>< _, State0 >::template <classname>impl</classname>< Expr, State, Data >::result_type >::type</type></typedef><typedef name="fun"><purpose><computeroutput>fun(v)(e,s) == when<_,Fun>()(e,s,v)</computeroutput> </purpose><type><emphasis>unspecified</emphasis></type></typedef><typedef name="result_type"><type>fusion::result_of::fold< sequence, state0, <classname>fun</classname> >::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><description><para>The current expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>seq</computeroutput> be <computeroutput>when<_, Sequence>()(expr, state, data)</computeroutput>, let <computeroutput>state0</computeroutput> be <computeroutput>when<_, State0>()(expr, state, data)</computeroutput>, and let <computeroutput>fun(data)</computeroutput> be an object such that <computeroutput>fun(data)(expr, state)</computeroutput> is equivalent to <computeroutput>when<_, Fun>()(expr, state, data)</computeroutput>. Then, this function returns <computeroutput>fusion::fold(seq, state0, fun(data))</computeroutput>.</
para><para>
+ </template><inherit access="public">boost::proto::transform_impl< Expr, State, Data ></inherit><typedef name="sequence"><purpose>A Fusion sequence. </purpose><type>remove_reference< typename <classname>when</classname>< <classname>_</classname>, Sequence >::template <classname>impl</classname>< Expr, State, Data >::result_type >::type</type></typedef><typedef name="state0"><purpose>An initial state for the fold. </purpose><type>remove_reference< typename <classname>when</classname>< <classname>_</classname>, State0 >::template <classname>impl</classname>< Expr, State, Data >::result_type >::type</type></typedef><typedef name="fun"><purpose><computeroutput>fun(v)(e,s) == when<_,Fun>()(e,s,v)</computeroutput> </purpose><type><emphasis>unspecified</emphasis></type></typedef><typedef name="result_type"><type>fusion::result_of::fold< sequence, state0, <classname>fun</classname> >::type</type></typedef><method-group name="public member functions"><method n
ame="operator()" cv="const"><type>result_type</type><parameter name="expr"><paramtype>typename impl::expr_param</paramtype><description><para>The current expression </para></description></parameter><parameter name="state"><paramtype>typename impl::state_param</paramtype><description><para>The current state </para></description></parameter><parameter name="data"><paramtype>typename impl::data_param</paramtype><description><para>An arbitrary data </para></description></parameter><description><para>Let <computeroutput>seq</computeroutput> be <computeroutput>when<_, Sequence>()(expr, state, data)</computeroutput>, let <computeroutput>state0</computeroutput> be <computeroutput>when<_, State0>()(expr, state, data)</computeroutput>, and let <computeroutput>fun(data)</computeroutput> be an object such that <computeroutput>fun(data)(expr, state)</computeroutput> is equivalent to <computeroutput>when<_, Fun>()(expr, state, data)</computeroutput>. Then, this function returns <computeroutput>fusion::fo
ld(seq, state0, fun(data))</computeroutput>.</para><para>
</para></description></method></method-group></struct></struct><struct name="reverse_fold"><template>
<template-type-parameter name="Sequence"/>
<template-type-parameter name="State0"/>
@@ -3301,7 +3301,7 @@
<template-type-parameter name="Fun"/>
</template><specialization><template-arg>Grammar</template-arg><template-arg>Fun *</template-arg></specialization><inherit access="public">boost::proto::when< Grammar, Fun ></inherit><purpose>A specialization that treats function pointer Transforms as if they were function type Transforms. </purpose><description><para>This specialization requires that <computeroutput>Fun</computeroutput> is actually a function type.</para><para>This specialization is required for nested transforms such as <computeroutput>when<G, T0(T1(_))></computeroutput>. In C++, functions that are used as parameters to other functions automatically decay to funtion pointer types. In other words, the type <computeroutput>T0(T1(_))</computeroutput> is indistinguishable from <computeroutput>T0(T1(*)(_))</computeroutput>. This specialization is required to handle these nested function pointer type transforms properly. </para></description></struct-specialization><struct name="otherwise"><template>
<template-type-parameter name="Fun"/>
- </template><inherit access="public">boost::proto::when< _, Fun ></inherit><purpose>Syntactic sugar for <computeroutput>when<_, Fun></computeroutput>, for use in grammars to handle all the cases not yet handled. </purpose><description><para>Use <computeroutput>otherwise<T></computeroutput> in your grammars as a synonym for <computeroutput>when<_, T></computeroutput> as in the following transform which counts the number of terminals in an expression.</para><para><programlisting> // Count the terminals in an expression tree.
+ </template><inherit access="public">boost::proto::when< Grammar, PrimitiveTransform ></inherit><purpose>Syntactic sugar for <computeroutput>when<_, Fun></computeroutput>, for use in grammars to handle all the cases not yet handled. </purpose><description><para>Use <computeroutput>otherwise<T></computeroutput> in your grammars as a synonym for <computeroutput>when<_, T></computeroutput> as in the following transform which counts the number of terminals in an expression.</para><para><programlisting> // Count the terminals in an expression tree.
// Must be invoked with initial state == mpl::int_<0>().
struct CountLeaves
: or_<
Modified: trunk/libs/proto/doc/resources.qbk
==============================================================================
--- trunk/libs/proto/doc/resources.qbk (original)
+++ trunk/libs/proto/doc/resources.qbk 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
@@ -22,9 +22,17 @@
algorithms.
The syntax for the grammar-matching features of `proto::matches<>` is inspired by
-MPL's lambda expressions, and by Aleksey Gurtovoy's
+MPL's lambda expressions.
+
+The idea for using function types for Proto's composite transforms is inspired by Aleksey Gurtovoy's
[@http://lists.boost.org/Archives/boost/2002/11/39718.php "round" lambda] notation.
+[/=================]
+[heading References]
+[/=================]
+
+[:[#boost_proto.users_guide.resources.SYB]Ren, D. and Erwig, M. 2006. A generic recursion toolbox for Haskell or: scrap your boilerplate systematically. In ['Proceedings of the 2006 ACM SIGPLAN Workshop on Haskell] (Portland, Oregon, USA, September 17 - 17, 2006). Haskell '06. ACM, New York, NY, 13-24. DOI=[@http://doi.acm.org/10.1145/1159842.1159845]]
+
[/======================]
[heading Further Reading]
[/======================]
Modified: trunk/libs/proto/doc/transforms.qbk
==============================================================================
--- trunk/libs/proto/doc/transforms.qbk (original)
+++ trunk/libs/proto/doc/transforms.qbk 2008-08-30 16:30:00 EDT (Sat, 30 Aug 2008)
@@ -247,7 +247,7 @@
This is an object transform; it default-constructs ... what exactly? The `mpl::max<>` template is an MPL metafunction that accepts two compile-time integers. It has a nested `::type` typedef (not shown) that is the maximum of the two. But here, we appear to be passing it two things that are /not/ compile-time integers; they're Proto callable transforms. Proto is smart enough to recognize that fact. It first evaluates the two nested callable transforms, computing the arities of the left and right child expressions. Then it puts the resulting integers into `mpl::max<>` and evaluates the metafunction by asking for the nested `::type`. That is the type of the object that gets default-constructed and returned.
-More generally, when evaluating object transforms, Proto looks as the object type and checks whether it is a template specialization, like `mpl::max<>`. If it is, Proto looks for nested transforms that it can evaluate. After any nested transforms have been evaluated and substituted back into the template, the new template specialization is the result type, unless that type has a nested `::type`, in which case that becomes the result.
+More generally, when evaluating object transforms, Proto looks at the object type and checks whether it is a template specialization, like `mpl::max<>`. If it is, Proto looks for nested transforms that it can evaluate. After any nested transforms have been evaluated and substituted back into the template, the new template specialization is the result type, unless that type has a nested `::type`, in which case that becomes the result.
Now that we can calculate the arity of a calculator expression, let's redefine the `calculator<>` expression wrapper we wrote in the Getting Started guide to use the `CalcArity` grammar and some macros from Boost.MPL to issue compile-time errors when users specify too many or too few arguments.
@@ -420,7 +420,7 @@
In the last section, we saw that we can pass a second parameter to grammars with transforms: an accumulation variable or /state/ that gets updated as your transform executes. There are times when your transforms will need to access auxiliary data that does /not/ accumulate, so bundling it with the state parameter is impractical. Instead, you can pass auxiliary data as a third parameter, known as the /data/ parameter. Below we show an example involving string processing where the data parameter is essential.
-[note All Proto grammars are function objects that take one, two or three arguments: the expression, the state, and the data. There are no additional arguments to know about, we promise. In Haskell, there is set of a tree traversal technologies known collectively as "Scrap Your Boilerplate". In that framework, there are also three parameters: the tree, the accumulation, and the context. These are Proto's expression, state and data parameters under different names.]
+[note All Proto grammars are function objects that take one, two or three arguments: the expression, the state, and the data. There are no additional arguments to know about, we promise. In Haskell, there is set of a tree traversal technologies known collectively as _SYB_. In that framework, there are also three parameters: the term, the accumulator, and the context. These are Proto's expression, state and data parameters under different names.]
Expression templates are often used as an optimization to eliminate temporary objects. Condsier the problem of string concatenation: a series of concatenations would result in the needless creation of temporary strings. We can use Proto to make string concatenation very efficient. To make the problem more interesting, we can apply a locale-sensitive transformation to each character during the concatenation. The locale information will be passed as the data parameter.
@@ -428,7 +428,7 @@
proto::lit("hello") + " " + "world";
-We would like to concatenate this string into a statically allocated wide buffer, widening each charater in turn using the current locale. The first step is to write a grammar that describes this expression, with transforms that calculate the total string length. Here it is:
+We would like to concatenate this string into a statically allocated wide character buffer, widening each charater in turn using the specified locale. The first step is to write a grammar that describes this expression, with transforms that calculate the total string length. Here it is:
// A grammar that matches string concatenation expressions, and
// a transform that calculates the total string length.
@@ -455,7 +455,7 @@
Notice the use of _fold_pt_. It is a primitive transform that takes a sequence, a state, and function, just like `std::accumulate()`. The three template parameters are transforms. The first yields the sequence of expressions over which to fold, the second yields the initial state of the fold, and the third is the function to apply at each iteration. The use of `proto::_` as the first parameter might have you confused. In addition to being Proto's wildcard, `proto::_` is also a primitive transform that returns the current expression, which (if it is a non-terminal) is a sequence of its child expressions.
-Next, we need a function object that accepts a narrow string, a wide buffer, and a `std::ctype<>` facet for doing the locale-specific stuff. It's fairly straightforward.
+Next, we need a function object that accepts a narrow string, a wide character buffer, and a `std::ctype<>` facet for doing the locale-specific stuff. It's fairly straightforward.
// A function object that writes a narrow string
// into a wide buffer.
@@ -573,7 +573,7 @@
[note *Not All Function Objects Are Primitive Transforms*
-You might be tempted now to drop the `_state` and `_data` parameters to `WidenCopy(proto::_value, proto::_state, proto::_data)`. That would be an error. `WidenCopy` is just a plain function object, not a primimtive transform, so you must specify all its arguments. We'll see later how to write your own primitive transforms.]
+You might be tempted now to drop the `_state` and `_data` parameters to `WidenCopy(proto::_value, proto::_state, proto::_data)`. That would be an error. `WidenCopy` is just a plain function object, not a primitive transform, so you must specify all its arguments. We'll see later how to write your own primitive transforms.]
Once you know that primitive transforms will always receive all three parameters -- expression, state, and data -- it makes things possible that wouldn't be otherwise. For instance, consider that for binary expressions, these two transforms are equivalent. Can you see why?
@@ -592,27 +592,250 @@
[section:built_in Proto's Built-In Transforms]
[/===========================================]
-Primitive transforms are the building blocks for more interesting composite transforms. Proto defines a bunch of generally useful primitive transforms. The following table summarizes them.
+[def _N_ [~N]]
+[def _G_ [~G]]
+[def _G0_ [~G0]]
+[def _G1_ [~G1]]
+[def _CT_ [~CT]]
+[def _OT_ [~OT]]
+[def _ET_ [~ET]]
+[def _ST_ [~ST]]
+[def _FT_ [~FT]]
+
+Primitive transforms are the building blocks for more interesting composite transforms. Proto defines a bunch of generally useful primitive transforms. They are summarized below.
+
+[variablelist
+ [[_value_pt_]
+ [Given a terminal expression, return the value of the terminal.]]
+ [[_child_c_pt_]
+ [Given a non-terminal expression, `proto::_child_c<_N_>` returns the _N_-th
+ child.]]
+ [[_child_pt_]
+ [A synonym for `proto::_child_c<0>`.]]
+ [[_left_pt_]
+ [A synonym for `proto::_child_c<0>`.]]
+ [[_right_pt_]
+ [A synonym for `proto::_child_c<1>`.]]
+ [[_expr_pt_]
+ [Returns the current expression unmodified.]]
+ [[_state_pt_]
+ [Returns the current state unmodified.]]
+ [[_data_pt_]
+ [Returns the current data unmodified.]]
+ [[_call_pt_]
+ [For a given callable transform `_CT_`, `proto::call<_CT_>` turns the
+ callable transform into a primitive transform. This is useful for
+ disambiguating callable transforms from object transforms, and also for
+ working around compiler bugs with nested function types.]]
+ [[_make_pt_]
+ [For a given object transform `_OT_`, `proto::make<_OT_>` turns the
+ object transform into a primitive transform. This is useful for
+ disambiguating object transforms from callable transforms, and also for
+ working around compiler bugs with nested function types.]]
+ [[_default_pt_]
+ [Given a grammar _G_, `proto::_default<G>` evaluates the current node
+ according to the standard C++ meaning of the operation the node represents.
+ For instance, if the current node is a binary plus node, the two children
+ will both be evaluated according to `_G_` and the results will be added and
+ returned. The return type is deduced with the help of the Boost.Typeof
+ library.]]
+ [[_fold_pt_]
+ [Given three transforms `_ET_`, `_ST_`, and `_FT_`,
+ `proto::fold<_ET_, _ST_, _FT_>` first evaluates `_ET_` to obtain a Fusion
+ sequence and `_ST_` to obtain an initial state for the fold, and then
+ evaluates `_FT_` for each element in the sequnce to generate the next
+ state from the previous.]]
+ [[_reverse_fold_pt_]
+ [Like _fold_pt_, except the elements in the Fusion sequence are iterated in
+ reverse order.]]
+ [[_fold_tree_pt_]
+ [Like `proto::fold<_ET_, _ST_, _FT_>`, except that the result of the `_ET_`
+ transform is treated as an expression tree that is /flattened/ to generate
+ the sequence to be folded. Flattening an expression tree causes child nodes
+ with the same tag type as the parent to be put into sequence. For instance,
+ `a >> b >> c` would be flattened to the sequence \[`a`, `b`, `c`\], and this
+ is the sequence that would be folded.]]
+ [[_reverse_fold_tree_pt_]
+ [Like _fold_tree_pt_, except that the flattened sequence is iterated in
+ reverse order.]]
+ [[_lazy_pt_]
+ [A combination of _make_pt_ and _call_pt_ that is useful when the nature of
+ the transform depends on the expression, state and/or data parameters.
+ `proto::lazy<R(A0,A1...An)>` first evaluates `proto::make<R()>` to compute a
+ callable type `R2`. Then, it evaluates `proto::call<R2(A0,A1...An)>`.]]
+]
-[table Built-In Primitive Transforms
- [[Primitive Transform] [Description]]
- [[_value_pt_] [Blah]]
- [[_child_c_pt_] [Blah]]
- [[_child_pt_] [Blah]]
- [[_left_pt_] [Blah]]
- [[_right_pt_] [Blah]]
- [[_wild_pt_] [Blah]]
- [[_expr_pt_] [Blah]]
- [[_state_pt_] [Blah]]
- [[_data_pt_] [Blah]]
- [[_call_pt_] [Blah]]
- [[_make_pt_] [Blah]]
- [[_default_pt_] [Blah]]
- [[_fold_pt_] [Blah]]
- [[_reverse_fold_pt_] [Blah]]
- [[_fold_tree_pt_] [Blah]]
- [[_reverse_fold_tree_pt_] [Blah]]
- [[_lazy_pt_] [Blah]]
+[/============================================]
+[heading All Grammars Are Primitive Transforms]
+[/============================================]
+
+In addition to the above primitive transforms, all of Proto's grammar elements are also primitive transforms. Their behaviors are described below.
+
+[variablelist
+ [[_wild_pt_]
+ [Returns the current expression unmodified.]]
+ [[_or_]
+ [For the specified set of alternate sub-grammars, find the one that matches
+ the given expression and apply its associated transform.]]
+ [[_and_]
+ [For the given set of sub-grammars, take the /last/ sub-grammar and apply its
+ associated transform.]]
+ [[_not_]
+ [Returns the current expression unmodified.]]
+ [[_if_]
+ [Given three transforms, evaluate the first and treat the result as a
+ compile-time Boolean value. If it is true, evaluate the second transform.
+ Otherwise, evaluate the third.]]
+ [[_terminal_]
+ [Returns the current terminal expression unmodified.]]
+ [[_plus_, _nary_expr_, et. al.]
+ [A Proto grammar that matches a non-terminal such as
+ `proto::plus<_G0_, _G1_>`, when used as a primitive transform, creates a new
+ plus node where the left child is transformed according to `_G0_` and the
+ right child with `_G1_`.]]
+]
+
+[/=================================]
+[heading The Pass-Through Transform]
+[/=================================]
+
+Note the primitive transform associated with grammar elements such as _plus_ described above. They possess a so-called /pass-through/ transform. The pass-through transform accepts an expression of a certain tag type (say, `proto::tag::plus`) and creates a new expression of the same tag type, where each child expression is transformed according to the corresponding child grammar of the pass-through transform. So for instance this grammar ...
+
+ proto::function< X, proto::vararg<Y> >
+
+... matches function expressions where the first child matches the `X` grammar and the rest match the `Y` grammar. When used as a transform, the above grammar will create a new function expression where the first child is transformed according to `X` and the rest are transformed according to `Y`.
+
+The following class templates in Proto can be used as grammars with pass-through transforms:
+
+[table Class Templates With Pass-Through Transforms
+ [[Templates with Pass-Through Transforms]]
+ [[`proto::unary_plus<>`]]
+ [[`proto::negate<>`]]
+ [[`proto::dereference<>`]]
+ [[`proto::complement<>`]]
+ [[`proto::address_of<>`]]
+ [[`proto::logical_not<>`]]
+ [[`proto::pre_inc<>`]]
+ [[`proto::pre_dec<>`]]
+ [[`proto::post_inc<>`]]
+ [[`proto::post_dec<>`]]
+ [[`proto::shift_left<>`]]
+ [[`proto::shift_right<>`]]
+ [[`proto::multiplies<>`]]
+ [[`proto::divides<>`]]
+ [[`proto::modulus<>`]]
+ [[`proto::plus<>`]]
+ [[`proto::minus<>`]]
+ [[`proto::less<>`]]
+ [[`proto::greater<>`]]
+ [[`proto::less_equal<>`]]
+ [[`proto::greater_equal<>`]]
+ [[`proto::equal_to<>`]]
+ [[`proto::not_equal_to<>`]]
+ [[`proto::logical_or<>`]]
+ [[`proto::logical_and<>`]]
+ [[`proto::bitwise_and<>`]]
+ [[`proto::bitwise_or<>`]]
+ [[`proto::bitwise_xor<>`]]
+ [[`proto::comma<>`]]
+ [[`proto::mem_ptr<>`]]
+ [[`proto::assign<>`]]
+ [[`proto::shift_left_assign<>`]]
+ [[`proto::shift_right_assign<>`]]
+ [[`proto::multiplies_assign<>`]]
+ [[`proto::divides_assign<>`]]
+ [[`proto::modulus_assign<>`]]
+ [[`proto::plus_assign<>`]]
+ [[`proto::minus_assign<>`]]
+ [[`proto::bitwise_and_assign<>`]]
+ [[`proto::bitwise_or_assign<>`]]
+ [[`proto::bitwise_xor_assign<>`]]
+ [[`proto::subscript<>`]]
+ [[`proto::if_else_<>`]]
+ [[`proto::function<>`]]
+ [[`proto::unary_expr<>`]]
+ [[`proto::binary_expr<>`]]
+ [[`proto::nary_expr<>`]]
+]
+
+[/=====================================================]
+[heading The Many Roles of Proto Operator Metafunctions]
+[/=====================================================]
+
+We've seen templates such as _terminal_, _plus_ and _nary_expr_ fill many roles. They are metafunction that generate expression types. They are grammars that match expression types. And they are primitive transforms. The following code samples show examples of each.
+
+[*As Metafunctions ...]
+
+ // proto::terminal<> and proto::plus<> are metafunctions
+ // that generate expression types:
+ typedef proto::terminal<int>::type int_;
+ typedef proto::plus<int_, int_>::type plus_;
+
+ int_ i = {42}, j = {24};
+ plus_ p = {i, j};
+
+[*As Grammars ...]
+
+ // proto::terminal<> and proto::plus<> are grammars that
+ // match expression types
+ struct Int : proto::terminal<int> {};
+ struct Plus : proto::plus<Int, Int> {};
+
+ BOOST_MPL_ASSERT(( proto::matches< int_, Int > ));
+ BOOST_MPL_ASSERT(( proto::matches< plus_, Plus > ));
+
+[*As Primitive Transforms ...]
+
+ // A transform that removes all unary_plus nodes in an expression
+ struct RemoveUnaryPlus
+ : proto::or_<
+ proto::when<
+ proto::unary_plus<RemoveUnaryPlus>
+ , RemoveUnaryPlus(proto::_child)
+ >
+ // Use proto::terminal<> and proto::nary_expr<>
+ // both as grammars and as primitive transforms.
+ , proto::terminal<_>
+ , proto::nary_expr<_, proto::vararg<RemoveUnaryPlus> >
+ >
+ {};
+
+ int main()
+ {
+ proto::literal<int> i(0);
+
+ proto::display_expr(
+ +i - +(i - +i)
+ );
+
+ proto::display_expr(
+ RemoveUnaryPlus()( +i - +(i - +i) )
+ );
+ }
+
+The above code displays the following, which shows that unary plus nodes have been stripped from the expression:
+
+[pre
+minus(
+ unary_plus(
+ terminal(0)
+ )
+ , unary_plus(
+ minus(
+ terminal(0)
+ , unary_plus(
+ terminal(0)
+ )
+ )
+ )
+)
+minus(
+ terminal(0)
+ , minus(
+ terminal(0)
+ , terminal(0)
+ )
+)
]
[endsect]
@@ -625,8 +848,6 @@
[note There are a few reasons why you might want to write your own primitive transforms. For instance, your transform may be complicated, and composing it out of primitives becomes unwieldy. You might also need to work around compiler bugs on legacy compilers that makes composing transforms using function types problematic. Finally, you might also decide to define your own primitive transforms to improve compile times. Since Proto can simply invoke a primitive transform directly without having to process arguments or differentiate callable transforms from object transforms, primitive transforms are more efficient.]
-[def _N_ [~N]]
-
Primitive transforms inherit from `proto::transform<>` and have a nested `impl<>` template that inherits from `proto::transform_impl<>`. For example, this is how Proto defines the `_child_c<_N_>` transform, which returns the _N_-th child of the current expression:
namespace boost { namespace proto
@@ -655,7 +876,7 @@
};
// Note that _child_c<N> is callable, so that
- // it can be used with arguments, as:
+ // it can be used in callable transforms, as:
// _child_c<0>(_child_c<1>)
template<int N>
struct is_callable<_child_c<N> >
@@ -691,8 +912,7 @@
For most types `R`, `proto::is_callable<R>` checks for inheritence from `proto::callable`. However, if the type `R` is a template specialization, Proto assumes that it is /not/ callable ['even if the template inherits from `proto::callable`]. We'll see why in a minute. Consider the following erroneous callable object:
- // Proto can't tell this defines
- // something callable!
+ // Proto can't tell this defines something callable!
template<typename T>
struct times2 : proto::callable
{
@@ -704,8 +924,7 @@
}
};
- // ERROR! This is not going to
- // multiply the int by 2.
+ // ERROR! This is not going to multiply the int by 2:
struct IntTimes2
: proto::when<
proto::terminal<int>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk