Proposal: delegates as aggregates in foreach statements
Oskar Linde
oskar.lindeREM at OVEgmail.com
Mon May 15 02:43:37 PDT 2006
Chris Nicholson-Sauls skrev:
> I think what I had in mind (and just didn't "vocalize") in using
> anonymous delegates, was to use them like wrappers around a list of
> other delegate calls or the like (multi-phase looping, perhaps). I do
> see your point that in most cases if you were going to do that, you may
> as well just write the logic into the iteration block itself. The
> tree-walkers and suchlike that you mention, though -- that's exactly the
> sort of thing I'm after. Being able to just do (foreach (i, x;
> &tree.walkInOrder) {...}) with .walkInOrder() being a simple method
> would be, pardon the colloquialism, wicked sweet.
You get it almost as sweet and simple by using a a wrapper struct. See
for instance Andrew Fedoniouk's tree implementation:
http://www.digitalmars.com/d/archives/digitalmars/D/dtl/378.html
That allows:
foreach(Node n; parent.forward) // all children from first to last
foreach(Node n; parent.backward) // all children from last to first
foreach(Node n; parent.deep) // all descendants - children and their
/Oskar
More information about the Digitalmars-d
mailing list