Boost logo

Boost Users :

Subject: [Boost-users] [Proto] Processing Lists
From: David Greene (greened_at_[hidden])
Date: 2010-02-22 06:29:04


I want to process a list that looks something like this:

struct List : or_<
  comma<
    List,
    Item
>,
  Item
> {};

But rather than processing each item separately, I want to pass a fusion (or
some other) sequence to a semantic action:

when<
  List,
  SomeAction(...)
> {};

Ideally the argument to SomeAction would be a fusion sequence but I don't
know how to produce one. This doesn't work:

when<
  List,
  SomeAction(flatten(_))
> {};

because flatten is not a transform. I don't want to use fold_tree because I
don't want to actually fold the sequence. SomeAction is something like this:

struct SomeAction : callable {
  template<typename Seq>
  void operator()(Seq range) {
    typedef ... iterator;

    // Is this legal for fusion sequences?
    for(iterator i = begin(range), iend = end(range);
         i != iend;
         i = next(i)) {
        ...
    }
  }
}

Is there a way to do this?

On a related note, I know I can use varag<> to match a function call
expression with an arbitrary number of operands and invoke a transform
on each operand. But how would I generate a fusion sequence of all
the operands? In other words, with:

proto::function< X, proto::vararg<Y> >

how do I talk about the vararg<> part in a semantic action? CalculatorGrammar
has a use of vararg but it uses fold<> to process it. I don't want to fold a
sequence, I want to pass it to a transform.

Thanks!

                                           -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