Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-30 11:26:29


Larry Evans wrote:
> The doc file:
>
> libs/xpressive/proto/doc/html/boost_proto/user_s_guide/tree_transformations.html
>
> contains:
>
> Second, unary_expr< _, CalculatorGrammar >, has a default transform
> associated with it. It is a pass-through transform. Given an
> expression of the form expr< T, arg1< X > >, the transform will invoke
> the CalculatorGrammar transform (which we haven't completely defined
> yet -- patience) on X resulting in Y, and then reassemble the
> expression as expr< T, arg1< Y > >.
>
> yet unary_expr<_, CalculatorGrammar >, defined in traits.hpp, is:
>
> template<typename Tag, typename T>
> struct unary_expr
> : has_pass_through_transform<unary_expr<Tag, T> >
> {...};
>
> so it isn't of the form, expr<T,arg1<X> > for any T or X. OTOH,
> the nested unary_expr typedef:
>
> typedef expr<Tag, args1<T> > type;
>
> is of this form; so, I guess what's meant by "Given an expression of the
> form.." is "Given an expression of type, E, where E::type is of the
> form..."?

What this is trying to say is that unary_expr< _, CalculatorGrammar >
IS-A transform, in addition to being a pattern. unary_expr<> also is a
meta-function for constructing expr<> types. The three roles are related
as follows:

1) unary_expr<T, X>::type is a typedef for expr<T, args1<X> >.
2) unary_expr<T', X'> is a pattern that matches expr<T, args1<X> >
    IFF T' is T or proto::_, and X' is a pattern that matches X.
3) unary_expr<T', X'>::apply<expr<T, args1<X> >, S, V>::type applies
    unary_expr<>'s pass-through transform to expr<T, args1<X> > with
    state S and visitor V. The result is:
      expr<T, args1< X'::apply<X, S, V>::type> >

By "given an expression of the form ...," I mean "when and expression of
form ... is passed to the transform's apply<> member template."

Sorry for the confusion. I'll make this clearer.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk