Ranges, constantly frustrating
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Fri Feb 14 13:37:15 PST 2014
On Friday, 14 February 2014 at 17:42:53 UTC, bearophile wrote:
> Isn't this discussion about adding an index to a range? If it
> is, then I have shown why adding it in the language is a bad
> idea.
As far as I understand it, it's about adding an index to
_foreach_, as is already supported for arrays:
foreach(v; [1,2,3,4])
writeln(v);
foreach(i, v; [1,2,3,4])
writeln(i, " => ", v);
But for ranges, the second form is not possible:
foreach(v; iota(4)) // ok
writeln(v);
foreach(i, v; iota(4)) // Error: cannot infer argument
types
writeln(i, " => ", v);
More information about the Digitalmars-d-learn
mailing list