Subject: Re: [proto] fold_tree and grammar using external_transforms and state
From: Eric Niebler (eric_at_[hidden])
Date: 2012-07-26 14:12:49
On 7/26/2012 10:30 AM, Mathias Gaunard wrote:
> On 26/07/2012 17:28, Joel Falcou wrote:
>> Here is the deal:
> Doesn't fold_tree normally take template arguments? I can't see any in
> the code here.
Right, this code seems like it can't possibly work as-is. But to get to
Joel's original question. ..
Yes, fold is using the state parameter and yours is getting dropped on
the floor. You have some control over this, however. Both fold and
tree_fold are used like ...
fold< sequence, state0, fun >
All three are transforms. The third is called at each iteration, but the
first two are called before the iteration begins, so they have access to
the state before the fold algorithm nukes it. If you want to save it off
somewhere, you can. You could, for instance, make state0 something like
Then you'll need to use functional::first and functional::second to get
at the parts. Kind of a pain. The long-sought let<> transform would give
you an easier way around this.
I've wanted a way for fold and fold_tree to automatically save off the
state and restore it later, but without let<> there really isn't a good
place. And I'm not too enamored with that idea either since it would
change the data parameter, which would be a breaking change -- and a
somewhat surprising one. Probably better to let the state drop and tell
folks to use let<> explicitly if they need it.
Gotta write let<> first, tho. :-P
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Proto list run by eric at boostpro.com