Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2007-06-01 12:54:36


On 06/01/2007 09:36 AM, Eric Niebler wrote:
> Larry Evans wrote:
[snip]
>> where the expression tree node argument remains "packaged":
>>
>> (expr<Tag, Left, Right> const &expr)
>>
[snip]
> different, though. You'll need something like:
>
> struct my_context
> {
> template<typename Expr>
> struct eval
> {
> typedef ... result_type;
> result_type
> operator()(Expr &expr, my_context &ctx) const
> {
> return ...;
> }
> };
> };
>
[snip]
Great! I started coding and then thought about creating
a "catchall" method to handle any node. I got to here:

struct xmpl_context
{
     explicit xmpl_context(unsigned& a_indent)
       : indent(a_indent)
     {
     }

     template<typename Expr, long Arity = Expr::arity::value>
     struct eval
     {

         typedef void result_type;
         result_type
         operator()(Expr &expr, xmpl_context &ctx) const
         {
             typedef proto::tagof<Expr>::type tag_type;
             const char*tag_name=std::typeid(tag_type).name()
             std::cout<<std::setw(indent)
               <<""<<tag_name<<".get_instance="
               <<expr.get_instance()<<"\n";
             indent+=2;
             for(long ichild=0; ichild<Arity; ++ichild)
             {
                 proto::eval(proto::arg_c<Expr,ichild>(expr), *this);
             }
             indent-=2;
         }
     };

  private:
     unsigned& indent;

};

...then realized I needed something like mpl's for_each.
I noticed in boost/xpressive/proto/fusion.hpp there's
children templates, but they don't look like they'd help.
How do I do what's implied by the above for loop?

Thanks again.

-regards,
Larry


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