No index for cycle ranges

bearophile bearophileHUGS at lycos.com
Thu Jun 2 15:47:51 PDT 2011


Steven Schveighoffer:

> So I'm not sure how this would be solved, but it's definitely complicated.

To solve this problem Python uses the enumerate function:

>>> for c in "abc":
...   print c
...
a
b
c
>>> for i,c in enumerate("abc"):
...   print i, c
...
0 a
1 b
2 c

In D it's easy to create something similar to enumerate, that yields tuple(index,item). But in D there is no syntax sugar for tuple unpacking yet, so here the index management becomes less nice.

I suggest to add enumerate to std.range, see:
http://d.puremagic.com/issues/show_bug.cgi?id=5550

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list