foreach_reverse is better than ever

bearophile bearophileHUGS at lycos.com
Sun Feb 14 04:15:55 PST 2010


Daniel Murphy:
> What about where foreach is being done over something other than a range?
> eg.
> foreach(i; 1..100)
> foreach(v; structwithopapply)

The first can be done turning an interval into syntax sugar for iota(1,100):
The foreach(i; retro(1 .. 100))
Otherwise the interval syntax can grow the step, as in Python and other languages (in D the step might even be a compile-time constant):
The foreach(i; 1 .. 100 : -1)

The second gives no problems if retro is well done:
foreach(v; retro(structWithopApplyReverse))

Bye,
bearophile



More information about the Digitalmars-d mailing list