Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-07-07 23:52:06


Replying to myself ...

Eric Niebler wrote:
> template<typename Expr>
> struct Expression<Expr, typename enable_if<matches<Expr, DoGrammar>
> >::type>
> : extends<Expr, Expression<Expr>, Domain>
> {
> explicit Expression(Expr const &expr = Expr())
> : extends<Expr, Expression<Expr>, Domain>(expr)
> , while_(make_expr<WhileTag, Domain>(This()))
> {}
>
> using extends<Expr, Expression<Expr>, Domain>::operator =;
> typename proto::result_of::make_expr<WhileTag, Domain,
> Expression const>::type while_;
>
> private:
> Expression const &This() const { return *this; }
> };
>
> struct DoWhileGrammar
> : function<
> unary_expr<
> WhileTag
> , DoGrammar
> >
> , Grammar
> >
> {};

Or perhaps try the following, which is a little cleaner IMO ...

     template<typename Expr>
     struct Expression<Expr
       , typename enable_if<matches<Expr, DoGrammar> >::type
>
       : extends<Expr, Expression<Expr>, Domain>
     {
         explicit Expression(Expr const &expr = Expr())
           : extends<Expr, Expression<Expr>, Domain>(expr)
         {}

         using extends<Expr, Expression<Expr>, Domain>::operator =;

         template< typename A0 >
         typename proto::result_of::make_expr<
             WhileTag, Domain, Expression const, A0 const
>::type const
         while_(A0 const &a0) const
         {
             return make_expr<WhileTag, Domain>(*this, a0);
         }
     };

     struct DoWhileGrammar
       : binary_expr<
             WhileTag
           , DoGrammar
           , Grammar
>
     {};

HTH,

-- 
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