Repost: make foreach(i, a; range) "just work"

w0rp devw0rp at gmail.com
Thu Feb 20 11:34:17 PST 2014


On Thursday, 20 February 2014 at 16:30:42 UTC, Justin Whear wrote:

> Tuple unpacking already works in foreach.  This code has 
> compiled since
> at least 2.063.2:
>
> import std.stdio;
> import std.range;
> void main(string[] args)
> {
>     auto tuples = ["a", "b", "c"].zip(iota(0, 3));
>
>     // unpack the string into `s`, the integer into `i`
>     foreach (s, i; tuples)
>         writeln(s, ", ", i);
> }

I did not know that. When did that happen? It didn't appear in
any changelogs and it works when I tried it in 2.064 on my
machine too. I suppose the next step after that would be to
support nested unpacking, but that would require a change in
syntax so it would be much more complicated.


More information about the Digitalmars-d mailing list