iteration over a string
bearophile
bearophileHUGS at lycos.com
Tue May 28 10:31:53 PDT 2013
Timothee Cour:
> Where do you think it can cause clashing?
I don't know.
But my solution is to introduce a simple "enumerate" range:
http://d.puremagic.com/issues/show_bug.cgi?id=5550
So if you have a range and you don't need indexes you use:
foreach (item; myrange) {}
If you also want an index:
foreach (index, item; myrange.enumerate) {}
This is the solution used by Python, it's clean, and it doesn't
make the foreach syntax & compiler more complex. Later the
compiler should optimize this idiom well.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list