|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-02-09 15:34:34
Author: eric_niebler
Date: 2008-02-09 15:34:33 EST (Sat, 09 Feb 2008)
New Revision: 43200
URL: http://svn.boost.org/trac/boost/changeset/43200
Log:
document how to access children of proto expressions
Text files modified:
trunk/libs/xpressive/proto/doc/construction.qbk | 174 +++++++++++++++++++++++++++++++++++++++
trunk/libs/xpressive/proto/doc/proto.qbk | 1
trunk/libs/xpressive/proto/doc/protodoc.xml | 118 ++++++++++++++++----------
3 files changed, 246 insertions(+), 47 deletions(-)
Modified: trunk/libs/xpressive/proto/doc/construction.qbk
==============================================================================
--- trunk/libs/xpressive/proto/doc/construction.qbk (original)
+++ trunk/libs/xpressive/proto/doc/construction.qbk 2008-02-09 15:34:33 EST (Sat, 09 Feb 2008)
@@ -141,7 +141,179 @@
[section:left_right_arg Accessing Children Nodes]
[/==============================================]
-// TODO describe tag_of, arg, arg_c, left and right. Also Fusion compatibility.
+After assembling an expression into a tree, you'll naturally want to be
+able to do the reverse, and access its children.
+You may even want to be able to iterate over the children with algorithms
+from the Boost.Fusion library. This section shows how.
+
+[heading [^tag_of<>]]
+
+A node in an expression tree is nothing more than a collection of children
+nodes and a tag type. You can access the tag type of any Proto expression type
+`Expr` directly as `typename Expr::proto_tag`, or you can use the _tag_of_
+metafunction, as shown below:
+
+ template<typename Expr>
+ typename proto::result_of::tag_of<Expr>::type
+ get_tag_of(Expr const &)
+ {
+ // Tag types are required to be default-constructible
+ return typename proto::result_of::tag_of<Expr>::type();
+ }
+
+ proto::terminal<int>::type const i = {0};
+
+ // Addition nodes have the "plus" tag type:
+ proto::tag::plus plus_tag = get_tag_of( i + 2 );
+
+[heading [^arg_c()]]
+
+Each node in an expression tree corresponds to an operator in an expression,
+and the children correspond to the operands, or arguments of the operator.
+To access them, you can use the _arg_c_ function template, as demonstrated
+below:
+
+ proto::terminal<int>::type i = {0};
+
+ // Get the 0-th operand of an addition operation:
+ proto::terminal<int>::type &ri = proto::arg_c<0>( i + 2 );
+
+ // Assert that we got back what we put in:
+ assert( &i == &ri );
+
+You can use the `result_of::arg_c<>` metafunction to get the type of the Nth
+child of an expression node. The nested `::type` of the `arg_c<>` metafunction
+gives you the type after references and cv-qualifiers have been stripped from
+the child's type.
+
+ template<typename Expr>
+ void test_result_of_arg_c(Expr const &expr)
+ {
+ typedef typename proto::result_of::arg_c<Expr, 0>::type type;
+
+ // ::type is a non-cv qualified, non-reference
+ BOOST_MPL_ASSERT((is_same< type, terminal<int>::type>));
+ }
+
+ // ...
+ terminal<int>::type i = {0};
+ test_result_of_arg_c( i + 2 );
+
+Why does the `arg_c<>` metafunction strip cv-qualifiers and references? The
+reason is one of practicality. Because expression trees are most typically
+built by holding references to temporary objects, lifetime management of these
+children nodes can be problematic. If `arg_c<>::type` were a reference, it
+would be very simple to create dangling references. Avoiding dangling
+references results in tedious and verbose applications of `remove_reference<>`
+and `remove_const<>`. This is especially problematic when building transforms
+that operate on ephemeral constelations of temporary objects. The current
+behavior of the `arg_c<>` metafunction makes it much simpler to write correct
+code.
+
+If you would like to know exactly the type of the Nth argument, including
+references and cv-qualifiers, you can use
+`fusion::result_of::value_at<Expr, N>::type`. This way, you can tell whether
+a child is stored by value or by reference. And if you would like to know
+the exact type that _arg_c_ returns, you can use
+`fusion::result_of::at_c<Expr, N>::type`. It will always be a reference type,
+and its cv-qualification depends on the cv-qualification of `Expr` and
+whether the child is stored by reference or not.
+
+[heading [^arg()], [^left()], and [^right()]]
+
+Most operators in C++ are unary or binary. For that reason, accesing the
+only operand, or the left and right operands, are very common operations. For
+this reason, Proto provides the _arg_, _left_, and _right_ functions. _arg_
+and _left_ are synonomous with `arg_c<0>()`, and _right_ is synonomous with
+`arg_c<1>()`.
+
+There are also `result_of::arg<>`, `result_of::left<>`, and `result_of::right<>`
+metafunctions that merely forward to their `result_of::arg_c<>` counterparts.
+
+[heading Expression Nodes as Fusion Sequences]
+
+Proto expression nodes are valid Fusion random-access sequences of their
+children nodes. That means you can apply Fusion algorithms to them,
+transform them, apply Fusion filters and views to them, and access their
+elements using `fusion::at()`. The things Fusion can do to heterogeneous
+sequences is beyond the scope of this users' guide, but here is an example:
+
+ struct display
+ {
+ template<typename T>
+ void operator()(T const &t) const
+ {
+ std::cout << t << std::endl;
+ }
+ };
+
+ struct fun_t {};
+ terminal<fun_t>::type const fun = {{}};
+
+ // ...
+ fusion::for_each(
+ fusion::transform(
+ // pop_front() removes the "fun" child
+ fusion::pop_front(fun(1,2,3,4))
+ // Extract the ints from the terminal nodes
+ , functional::arg<>()
+ )
+ , display()
+ );
+
+The above invocation of `fusion::for_each()` displays the following:
+
+[pre
+1
+2
+3
+4
+]
+
+[heading Flattening Proto Expression Tress]
+
+Imagine a slight variation of the above example where, instead of iterating
+over the arguments of a lazy function invocation, we would like to iterate
+over the terminals in an addition expression:
+
+ terminal<int>::type const _1 = {1};
+
+ // ERROR: this doesn't work! Why?
+ fusion::for_each(
+ fusion::transform(
+ _1 + 2 + 3 + 4
+ , functional::arg<>()
+ )
+ , display()
+ );
+
+The reason this doesn't work is because the expression `_1 + 2 + 3 + 4` does
+not describe a flat sequence of terminals --- it describes a binary tree. We
+can treat it as a flat sequence of terminals, however, using Proto's _flatten_
+function. _flatten_ returns a view which makes a tree appear as a flat Fusion
+sequence. If the top-most node has a tag type `T`, then the elements of the
+flattened sequence are the children nodes that do *not* have tag type `T`. This
+process is evaluated recursively. So the above can correctly be written as:
+
+ terminal<int>::type const _1 = {1};
+
+ // OK, iterate over a flattened view
+ fusion::for_each(
+ fusion::transform(
+ proto::flatten(_1 + 2 + 3 + 4)
+ , functional::arg<>()
+ )
+ , display()
+ );
+
+The above invocation of `fusion::for_each()` displays the following:
+
+[pre
+1
+2
+3
+4
+]
[endsect]
Modified: trunk/libs/xpressive/proto/doc/proto.qbk
==============================================================================
--- trunk/libs/xpressive/proto/doc/proto.qbk (original)
+++ trunk/libs/xpressive/proto/doc/proto.qbk 2008-02-09 15:34:33 EST (Sat, 09 Feb 2008)
@@ -71,6 +71,7 @@
[def _callable_context_ [classref boost::proto::context::callable_context `callable_context<>`]]
[def _null_context_ [classref boost::proto::context::null_context `null_context<>`]]
[def _when_ [classref boost::proto::transform::when `when<>`]]
+[def _flatten_ [funcref boost::proto::flatten `flatten()`]]
[include preface.qbk]
Modified: trunk/libs/xpressive/proto/doc/protodoc.xml
==============================================================================
--- trunk/libs/xpressive/proto/doc/protodoc.xml (original)
+++ trunk/libs/xpressive/proto/doc/protodoc.xml 2008-02-09 15:34:33 EST (Sat, 09 Feb 2008)
@@ -297,7 +297,7 @@
</template><specialization><template-arg>This(Expr</template-arg><template-arg>Context)</template-arg></specialization><typedef name="type"><type><classname>proto::result_of::eval</classname>< typename remove_reference< Expr >::type, typename remove_reference< Context >::type >::type</type></typedef></struct-specialization><typedef name="proto_is_callable_"><type>void</type></typedef><method-group name="public member functions"><method name="operator()" cv="const"><type><classname>proto::result_of::eval</classname>< Expr, Context >::type</type><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="Context"/>
- </template><parameter name="expr"><paramtype>Expr &</paramtype></parameter><parameter name="context"><paramtype>Context &</paramtype></parameter><purpose>Evaluate a given Proto expression with a given context. </purpose><description><para>
+ </template><parameter name="expr"><paramtype>Expr &</paramtype><description><para>The Proto expression to evaluate </para></description></parameter><parameter name="context"><paramtype>Context &</paramtype><description><para>The context in which the expression should be evaluated. </para></description></parameter><purpose>Evaluate a given Proto expression with a given context. </purpose><description><para>
</para></description><returns><para><computeroutput>typename Context::template eval<Expr>()(expr, context)</computeroutput> </para></returns></method><method name="operator()" cv="const"><type><classname>proto::result_of::eval</classname>< Expr, Context >::type</type><template>
<template-type-parameter name="Expr"/>
@@ -924,7 +924,7 @@
<template-type-parameter name="B4"/>
</template><parameter name="b0"><paramtype>const B0 &</paramtype></parameter><parameter name="b1"><paramtype>const B1 &</paramtype></parameter><parameter name="b2"><paramtype>const B2 &</paramtype></parameter><parameter name="b3"><paramtype>const B3 &</paramtype></parameter><parameter name="b4"><paramtype>const B4 &</paramtype></parameter></signature><description><para>make_expr </para></description></overloaded-function></namespace></namespace></header><header name="boost/xpressive/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-type-parameter name="Grammar"/>
- </template><struct-specialization name="result"><template>
+ </template><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-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -935,11 +935,32 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name=""><paramtype>State const &</paramtype></parameter><parameter name=""><paramtype>Visitor &</paramtype></parameter><description><para>
-</para></description><returns><para>expr </para></returns></method></method-group></struct><struct name="if_"><template>
+
+</para></description><requires><para><computeroutput>matches<Expr,not_>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></requires><returns><para><computeroutput>expr</computeroutput> </para></returns></method></method-group></struct><struct name="if_"><template>
<template-type-parameter name="If"/>
<template-type-parameter name="Then"/>
<template-type-parameter name="Else"/>
- </template><struct-specialization name="result"><template>
+ </template><purpose>Used to select one grammar or another based on the result of a compile-time Boolean. When used as a transform, <computeroutput>if_<></computeroutput> selects between two transforms based on a compile-time Boolean. </purpose><description><para>When <computeroutput>if_<If,Then,Else></computeroutput> is used as a grammar, <computeroutput>If</computeroutput> must be a Proto transform and <computeroutput>Then</computeroutput> and <computeroutput>Else</computeroutput> must be grammars. An expression type <computeroutput>E</computeroutput> matches <computeroutput>if_<If,Then,Else></computeroutput> if <computeroutput>when<_,If>::result<void(E,int,int)>::type::value</computeroutput> is <computeroutput>true</computeroutput> and <computeroutput>E</computeroutput> matches <computeroutput>U</computeroutput>; or, if <computeroutput>when<_,If>::result<void(E,int,int)>::type::value</computeroutput> is <computeroutput>false</computeroutput> and <computeroutpu
t>E</computeroutput> matches <computeroutput>V</computeroutput>.</para><para>The template parameter <computeroutput>Then</computeroutput> defaults to <computeroutput>_</computeroutput> and <computeroutput>Else</computeroutput> defaults to <computeroutput>not<_></computeroutput>, so an expression type <computeroutput>E</computeroutput> will match <computeroutput>if_<If></computeroutput> if and only if <computeroutput>when<_,If>::result<void(E,int,int)>::type::value</computeroutput> is <computeroutput>true</computeroutput>.</para><para><programlisting> // A grammar that only matches integral terminals,
+ // using is_integral<> from Boost.Type_traits.
+ struct IsIntegral
+ : and_<
+ terminal<_>
+ , if_< is_integral<_arg>() >
+ >
+ {};
+</programlisting></para><para>When <computeroutput>if_<If,Then,Else></computeroutput> is used as a transform, <computeroutput>If</computeroutput>, <computeroutput>Then</computeroutput> and <computeroutput>Else</computeroutput> must be Proto transforms. When applying the transform to an expression <computeroutput>E</computeroutput>, state <computeroutput>S</computeroutput> and visitor <computeroutput>V</computeroutput>, if <computeroutput>when<_,If>::result<void(E,S,V)>::type::value</computeroutput> is <computeroutput>true</computeroutput> then the <computeroutput>Then</computeroutput> transform is applied; otherwise the <computeroutput>Else</computeroutput> transform is applied.</para><para><programlisting> // Match a terminal. If the terminal is integral, return
+ // mpl::true_; otherwise, return mpl::false_.
+ struct IsIntegral2
+ : when<
+ terminal<_>
+ , if_<
+ is_integral<_arg>()
+ , mpl::true_()
+ , mpl::false_()
+ >
+ >
+ {};
+</programlisting> </para></description><struct-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -950,7 +971,7 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>State const &</paramtype><description><para>The current state </para></description></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype><description><para>A visitor of arbitrary type </para></description></parameter><description><para>
-</para></description><returns><para>result<void(Expr, State, Visitor)>which()(expr, state, visitor) </para></returns></method></method-group></struct><struct name="or_"><template>
+</para></description><returns><para><computeroutput>result<void(Expr, State, Visitor)>::which()(expr, state, visitor)</computeroutput> </para></returns></method></method-group></struct><struct name="or_"><template>
<template-type-parameter name="G0"/>
<template-type-parameter name="G1"/>
<template-type-parameter name="G2"/>
@@ -959,7 +980,7 @@
<template-type-parameter name="G5"/>
<template-type-parameter name="G6"/>
<template-type-parameter name="G7"/>
- </template><struct-specialization name="result"><template>
+ </template><purpose>For matching one of a set of alternate grammars. Alternates tried in order to avoid ambiguity. When used as a transform, <computeroutput>or_<></computeroutput> applies the transform associated with the first grammar that matches the expression. </purpose><description><para>An expression type <computeroutput>E</computeroutput> matches <computeroutput>or_<B0,B1,...Bn></computeroutput> if <computeroutput>E</computeroutput> matches any <computeroutput>Bx</computeroutput> for <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>.</para><para>When applying <computeroutput>or_<B0,B1,...Bn></computeroutput> as a transform with an expression <computeroutput>e</computeroutput> of type <computeroutput>E</computeroutput>, state <computeroutput>s</computeroutput> and visitor <computeroutput>v</computeroutput>, it is equivalent to <computeroutput>Bx()(e, s, v)</computeroutput>, where <computeroutput>x</computeroutput> is the lowest number such that <compute
routput>matches<E,Bx>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></description><struct-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -970,7 +991,8 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>State const &</paramtype><description><para>The current state </para></description></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype><description><para>A visitor of arbitrary type </para></description></parameter><description><para>
-</para></description><returns><para>result<void(Expr, State, Visitor)>which()(expr, state, visitor) </para></returns></method></method-group></struct><struct name="and_"><template>
+
+</para></description><requires><para><computeroutput>matches<Expr,or_>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></requires><returns><para><computeroutput>result<void(Expr, State, Visitor)>::which()(expr, state, visitor)</computeroutput> </para></returns></method></method-group></struct><struct name="and_"><template>
<template-type-parameter name="G0"/>
<template-type-parameter name="G1"/>
<template-type-parameter name="G2"/>
@@ -979,7 +1001,7 @@
<template-type-parameter name="G5"/>
<template-type-parameter name="G6"/>
<template-type-parameter name="G7"/>
- </template><struct-specialization name="result"><template>
+ </template><purpose>For matching all of a set of grammars. When used as a transform, <computeroutput>and_<></computeroutput> applies the transform associated with the last grammar in the set. </purpose><description><para>An expression type <computeroutput>E</computeroutput> matches <computeroutput>and_<B0,B1,...Bn></computeroutput> if <computeroutput>E</computeroutput> matches all <computeroutput>Bx</computeroutput> for <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>.</para><para>When applying <computeroutput>and_<B0,B1,...Bn></computeroutput> as a transform with an expression <computeroutput>e</computeroutput>, state <computeroutput>s</computeroutput> and visitor <computeroutput>v</computeroutput>, it is equivalent to <computeroutput>Bn()(e, s, v)</computeroutput>. </para></description><struct-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -990,9 +1012,11 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>State const &</paramtype><description><para>The current state </para></description></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype><description><para>A visitor of arbitrary type </para></description></parameter><description><para>
-</para></description><returns><para>result<void(Expr, State, Visitor)>which()(expr, state, visitor) </para></returns></method></method-group></struct><struct name="switch_"><template>
+
+</para></description><requires><para><computeroutput>matches<Expr,and_>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></requires><returns><para><computeroutput>result<void(Expr, State, Visitor)>::which()(expr, state, visitor)</computeroutput> </para></returns></method></method-group></struct><struct name="switch_"><template>
<template-type-parameter name="Cases"/>
- </template><struct-specialization name="result"><template>
+ </template><purpose>For matching one of a set of alternate grammars, which are looked up based on an expression's tag type. When used as a transform, <computeroutput>switch_<></computeroutput> applies the transform associated with the grammar that matches the expression. </purpose><description><para>
+An expression type <computeroutput>E</computeroutput> matches <computeroutput>switch_<C></computeroutput> if <computeroutput>E</computeroutput> matches <computeroutput>C::case_<E::proto_tag></computeroutput>.</para><para>When applying <computeroutput>switch_<C></computeroutput> as a transform with an expression <computeroutput>e</computeroutput> of type <computeroutput>E</computeroutput>, state <computeroutput>s</computeroutput> and visitor <computeroutput>v</computeroutput>, it is equivalent to <computeroutput>C::case_<E::proto_tag>()(e, s, v)</computeroutput>. </para></description><struct-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -1003,23 +1027,29 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name="state"><paramtype>State const &</paramtype><description><para>The current state </para></description></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype><description><para>A visitor of arbitrary type </para></description></parameter><description><para>
-</para></description><returns><para>result<void(Expr, State, Visitor)>which()(expr, state, visitor) </para></returns></method></method-group></struct><struct name="exact"><template>
+
+</para></description><requires><para><computeroutput>matches<Expr,switch_>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></requires><returns><para><computeroutput>result<void(Expr, State, Visitor)>::which()(expr, state, visitor)</computeroutput> </para></returns></method></method-group></struct><struct name="exact"><template>
<template-type-parameter name="T"/>
- </template></struct><struct name="convertible_to"><template>
+ </template><purpose>For forcing exact matches of terminal types. </purpose><description><para>By default, matching terminals ignores references and cv-qualifiers. For instance, a terminal expression of type <computeroutput>terminal<int const &>type</computeroutput> will match the grammar <computeroutput>terminal<int></computeroutput>. If that is not desired, you can force an exact match with <computeroutput>terminal<exact<int> ></computeroutput>. This will only match integer terminals where the terminal is held by value. </para></description></struct><struct name="convertible_to"><template>
<template-type-parameter name="T"/>
- </template></struct><struct name="vararg"><template>
+ </template><purpose>For matching terminals that are convertible to a type. </purpose><description><para>Use <computeroutput>convertible_to<></computeroutput> to match a terminal that is convertible to some type. For example, the grammar <computeroutput>terminal<convertible_to<int> ></computeroutput> will match any terminal whose argument is convertible to an integer.</para><para>
+</para></description></struct><struct name="vararg"><template>
<template-type-parameter name="Grammar"/>
- </template><typedef name="proto_is_vararg_"><type>void</type></typedef></struct></namespace><namespace name="result_of"><struct name="matches"><template>
+ </template><purpose>For matching a Grammar to a variable number of sub-expressions. </purpose><description><para>An expression type <computeroutput>expr<AT, argsN<A0,...An,U0,...Um> ></computeroutput> matches a grammar <computeroutput>expr<BT, argsM<B0,...Bn,vararg<V> > ></computeroutput> if <computeroutput>BT</computeroutput> is <computeroutput>_</computeroutput> or <computeroutput>AT</computeroutput>, and if <computeroutput>Ax</computeroutput> matches <computeroutput>Bx</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput> and if <computeroutput>Ux</computeroutput> matches <computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,m)</computeroutput>.</para><para>For example:</para><para><programlisting> // Match any function call expression, irregardless
+ // of the number of function arguments:
+ struct Function
+ : function< vararg<_> >
+ {};
+</programlisting></para><para>When used as a transform, <computeroutput>vararg<G></computeroutput> applies <computeroutput>G</computeroutput>'s transform. </para></description><typedef name="proto_is_vararg_"><type>void</type></typedef></struct></namespace><namespace name="result_of"><struct name="matches"><template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="Grammar"/>
- </template><purpose>A Boolean metafunction that evaluates whether a given expression type matches a a grammar. </purpose><description><para><computeroutput>matches<Expr,Grammar></computeroutput> inherits (indirectly) from <computeroutput>mpl::true_</computeroutput> if <computeroutput>Expr::proto_base_expr</computeroutput> matches <computeroutput>Grammar::proto_base_expr</computeroutput>, and from <computeroutput>mpl::false_</computeroutput> otherwise.</para><para>Non-terminal expressions are matched against a grammar according to the following rules:</para><para><itemizedlist>
+ </template><purpose>A Boolean metafunction that evaluates whether a given expression type matches a grammar. </purpose><description><para><computeroutput>matches<Expr,Grammar></computeroutput> inherits (indirectly) from <computeroutput>mpl::true_</computeroutput> if <computeroutput>Expr::proto_base_expr</computeroutput> matches <computeroutput>Grammar::proto_base_expr</computeroutput>, and from <computeroutput>mpl::false_</computeroutput> otherwise.</para><para>Non-terminal expressions are matched against a grammar according to the following rules:</para><para><itemizedlist>
<listitem><para>The wildcard pattern, <computeroutput>_</computeroutput>, matches any expression. </para></listitem>
<listitem><para>An expression <computeroutput>expr<AT, argsN<A0,A1,...An> ></computeroutput> matches a grammar <computeroutput>expr<BT, argsN<B0,B1,...Bn> ></computeroutput> if <computeroutput>BT</computeroutput> is <computeroutput>_</computeroutput> or <computeroutput>AT</computeroutput>, and if <computeroutput>Ax</computeroutput> matches <computeroutput>Bx</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>. </para></listitem>
<listitem><para>An expression <computeroutput>expr<AT, argsN<A0,...An,U0,...Um> ></computeroutput> matches a grammar <computeroutput>expr<BT, argsM<B0,...Bn,vararg<V> > ></computeroutput> if <computeroutput>BT</computeroutput> is <computeroutput>_</computeroutput> or <computeroutput>AT</computeroutput>, and if <computeroutput>Ax</computeroutput> matches <computeroutput>Bx</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput> and if <computeroutput>Ux</computeroutput> matches <computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,m)</computeroutput>. </para></listitem>
<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>or_<B0,B1,...Bn></computeroutput> if <computeroutput>E</computeroutput> matches some <computeroutput>Bx</computeroutput> for <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>. </para></listitem>
<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>and_<B0,B1,...Bn></computeroutput> if <computeroutput>E</computeroutput> matches all <computeroutput>Bx</computeroutput> for <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>. </para></listitem>
-<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>if_<T></computeroutput> if <computeroutput>when<_,T>result<void(E,int,int)>type::value</computeroutput> is <computeroutput>true</computeroutput>. </para></listitem>
-<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>if_<T,U,V></computeroutput> if <computeroutput>when<_,T>result<void(E,int,int)>type::value</computeroutput> is <computeroutput>true</computeroutput> and matches <computeroutput>U</computeroutput>; or, if <computeroutput>when<_,T>result<void(E,int,int)>type::value</computeroutput> is <computeroutput>false</computeroutput> and matches <computeroutput>V</computeroutput>. </para></listitem>
+<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>if_<T,U,V></computeroutput> if <computeroutput>when<_,T>::result<void(E,int,int)>::type::value</computeroutput> is <computeroutput>true</computeroutput> and <computeroutput>E</computeroutput> matches <computeroutput>U</computeroutput>; or, if <computeroutput>when<_,T>::result<void(E,int,int)>::type::value</computeroutput> is <computeroutput>false</computeroutput> and <computeroutput>E</computeroutput> matches <computeroutput>V</computeroutput>. (Note: <computeroutput>U</computeroutput> defaults to <computeroutput>_</computeroutput> and <computeroutput>V</computeroutput> defaults to <computeroutput>not<_></computeroutput>.) </para></listitem>
<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>not_<T></computeroutput> if <computeroutput>E</computeroutput> does not match <computeroutput>T</computeroutput>. </para></listitem>
<listitem><para>An expression <computeroutput>E</computeroutput> matches <computeroutput>switch_<C></computeroutput> if <computeroutput>E</computeroutput> matches <computeroutput>C::case_<E::proto_tag></computeroutput>.</para></listitem>
</itemizedlist>
@@ -1029,18 +1059,38 @@
<listitem><para><computeroutput>A</computeroutput> is <computeroutput>B &</computeroutput> </para></listitem>
<listitem><para><computeroutput>A</computeroutput> is <computeroutput>B const &</computeroutput> </para></listitem>
<listitem><para><computeroutput>B</computeroutput> is <computeroutput>exact<A></computeroutput> </para></listitem>
-<listitem><para><computeroutput>B</computeroutput> is <computeroutput>convertible_to<X></computeroutput> and <computeroutput>is_convertible<A,X>value</computeroutput> is <computeroutput>true</computeroutput>. </para></listitem>
+<listitem><para><computeroutput>B</computeroutput> is <computeroutput>convertible_to<X></computeroutput> and <computeroutput>is_convertible<A,X>::value</computeroutput> is <computeroutput>true</computeroutput>. </para></listitem>
<listitem><para><computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or <computeroutput>X(&)[M]</computeroutput> and <computeroutput>B</computeroutput> is <computeroutput>X[proto::N]</computeroutput>. </para></listitem>
<listitem><para><computeroutput>A</computeroutput> is <computeroutput>X(&)[M]</computeroutput> and <computeroutput>B</computeroutput> is <computeroutput>X(&)[proto::N]</computeroutput>. </para></listitem>
<listitem><para><computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or <computeroutput>X(&)[M]</computeroutput> and <computeroutput>B</computeroutput> is <computeroutput>X*</computeroutput>. </para></listitem>
<listitem><para><computeroutput>B</computeroutput> lambda-matches <computeroutput>A</computeroutput> (see below).</para></listitem>
</itemizedlist>
-A type <computeroutput>B</computeroutput> lambda-matches <computeroutput>A</computeroutput> one of the following is true:</para><para><itemizedlist>
+A type <computeroutput>B</computeroutput> lambda-matches <computeroutput>A</computeroutput> if one of the following is true:</para><para><itemizedlist>
<listitem><para><computeroutput>B</computeroutput> is <computeroutput>A</computeroutput> </para></listitem>
<listitem><para><computeroutput>B</computeroutput> is the wildcard pattern, <computeroutput>_</computeroutput> </para></listitem>
<listitem><para><computeroutput>B</computeroutput> is <computeroutput>T<B0,B1,...Bn></computeroutput> and <computeroutput>A</computeroutput> is <computeroutput>T<A0,A1,...An></computeroutput> and for each <computeroutput>x</computeroutput> in <computeroutput>[0,n)</computeroutput>, <computeroutput>Ax</computeroutput> and <computeroutput>Bx</computeroutput> are types such that <computeroutput>Ax</computeroutput> lambda-matches <computeroutput>Bx</computeroutput> </para></listitem>
</itemizedlist>
-</para></description></struct></namespace><namespace name="wildcardns_"><struct name="_"><struct-specialization name="result"><template>
+</para></description></struct></namespace><namespace name="wildcardns_"><struct name="_"><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-specialization name="result"><template>
<template-type-parameter name="This"/>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
@@ -1051,7 +1101,7 @@
<template-type-parameter name="Visitor"/>
</template><parameter name="expr"><paramtype>Expr const &</paramtype><description><para>An expression </para></description></parameter><parameter name=""><paramtype>State const &</paramtype></parameter><parameter name=""><paramtype>Visitor &</paramtype></parameter><description><para>
-</para></description><returns><para>expr </para></returns></method></method-group></struct></namespace></namespace></namespace></header><header name="boost/xpressive/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>
+</para></description><returns><para><computeroutput>expr</computeroutput> </para></returns></method></method-group></struct></namespace></namespace></namespace></header><header name="boost/xpressive/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><namespace name="exprns_"><function name="operator+"><type><emphasis>unspecified</emphasis></type><template>
<template-type-parameter name="Arg"/>
@@ -2068,31 +2118,7 @@
<template-type-parameter name="Sequence"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Fun"/>
- </template><inherit access="public">boost::proto::transform::fold< Sequence, State0, Fun ></inherit></struct><struct-specialization name="fold"><template>
- <template-type-parameter name="State0"/>
- <template-type-parameter name="Fun"/>
- </template><specialization><template-arg>_</template-arg><template-arg>State0</template-arg><template-arg>Fun</template-arg></specialization><description><para>This specialization is only for improved compile-time performance in the commom case when the Sequence transform is <computeroutput>proto::_</computeroutput>.</para><para>INTERNAL ONLY </para></description><struct-specialization name="result"><template>
- <template-type-parameter name="This"/>
- <template-type-parameter name="Expr"/>
- <template-type-parameter name="State"/>
- <template-type-parameter name="Visitor"/>
- </template><specialization><template-arg>This(Expr</template-arg><template-arg>State</template-arg><template-arg>Visitor)</template-arg></specialization><typedef name="type"><type><emphasis>unspecified</emphasis></type></typedef></struct-specialization><method-group name="public member functions"><method name="operator()" cv="const"><type>result< void(Expr, State, Visitor) >::type</type><template>
- <template-type-parameter name="Expr"/>
- <template-type-parameter name="State"/>
- <template-type-parameter name="Visitor"/>
- </template><parameter name="expr"><paramtype>Expr const &</paramtype></parameter><parameter name="state"><paramtype>State const &</paramtype></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype></parameter></method></method-group></struct-specialization><struct-specialization name="reverse_fold"><template>
- <template-type-parameter name="State0"/>
- <template-type-parameter name="Fun"/>
- </template><specialization><template-arg>_</template-arg><template-arg>State0</template-arg><template-arg>Fun</template-arg></specialization><description><para>This specialization is only for improved compile-time performance in the commom case when the Sequence transform is <computeroutput>proto::_</computeroutput>.</para><para>INTERNAL ONLY </para></description><struct-specialization name="result"><template>
- <template-type-parameter name="This"/>
- <template-type-parameter name="Expr"/>
- <template-type-parameter name="State"/>
- <template-type-parameter name="Visitor"/>
- </template><specialization><template-arg>This(Expr</template-arg><template-arg>State</template-arg><template-arg>Visitor)</template-arg></specialization><typedef name="type"><type><emphasis>unspecified</emphasis></type></typedef></struct-specialization><method-group name="public member functions"><method name="operator()" cv="const"><type>result< void(Expr, State, Visitor) >::type</type><template>
- <template-type-parameter name="Expr"/>
- <template-type-parameter name="State"/>
- <template-type-parameter name="Visitor"/>
- </template><parameter name="expr"><paramtype>Expr const &</paramtype></parameter><parameter name="state"><paramtype>State const &</paramtype></parameter><parameter name="visitor"><paramtype>Visitor &</paramtype></parameter></method></method-group></struct-specialization></namespace></namespace></namespace></header><header name="boost/xpressive/proto/transform/fold_tree.hpp"><namespace name="boost"><namespace name="proto"><namespace name="transform"><struct name="fold_tree"><template>
+ </template><inherit access="public">boost::proto::transform::fold< Sequence, State0, Fun ></inherit></struct></namespace></namespace></namespace></header><header name="boost/xpressive/proto/transform/fold_tree.hpp"><namespace name="boost"><namespace name="proto"><namespace name="transform"><struct name="fold_tree"><template>
<template-type-parameter name="Sequence"/>
<template-type-parameter name="State0"/>
<template-type-parameter name="Fun"/>
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