Boost logo

Boost Users :

Subject: Re: [Boost-users] Defining Statements with Proto
From: David A. Greene (greened_at_[hidden])
Date: 2010-01-06 20:54:00


On Tuesday 05 January 2010 03:47:39 Eric Niebler wrote:

> In your code, you have:
>
> #ifdef NO_SPECIALIZATION
> template<>
> struct
> ConstructStatementGrammarCases::case_<boost::proto::tag::subscript>
>
> I'm sure if you change your ifdef to ifndef, or just remove the PP gunk,
> you'll see that it works.

<brownpaperbag>
  Oh, bother.
</brownpaperbag>

It works now. And I think I grok proto! I've successfully added more
statement-type rules and it works great.

A couple of questions:

Is there any advantage to doing:

     // An if_ "operator"
     template<typename Expr>
     typename boost::proto::result_of::make_expr<
       boost::proto::tag::function,
       Domain,
       keyword::if_,
       Expr>::type
     if_(Expr const &expr)
     {
       return boost::proto::make_expr<boost::proto::tag::function, Domain>(
         keyword::if_(),
         expr);
     }

over:

     typedef Wrapper<boost::proto::terminal<keyword::if_>::type> IfTerminal;

    // An if_ "operator."
    namespace {
       const IfTerminal if_ = {{}};
    }

and letting proto take care of creating the function expression?
Perhaps the former has one or two less template instantiations
but the latter is certainly easier to maintain.

Also, we can get something akin to synthesized attributes with
the grammar semantics actions:

  struct case_ : boost::proto::when<
    IfRule,
    ConstructBinary<If>(ConstructExpressionGrammar(boost::proto::_right(boost::proto::_left)),
                        ConstructStatementGrammar(boost::proto::_right))> {};

where Construct*Grammar is a transform grammar that returns some
result (so it's a transform too, right?).

Is there any way to get something akin to inherited attributes that
one can pass down the expression tree?

Finally, I think the wrapper metafunction problem I posted about is
still an issue, though I seem to be getting by without the dummy
template argument to do the ADL trick.

                                         -Dave


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net