[Issue 9009] allow foreach without identifier
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jun 12 10:08:58 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=9009
--- Comment #7 from bearophile_hugs at eml.cc ---
With a little breaking change "_" could become a name that can't be referenced,
so you can do:
foreach (_; 0 .. 10) { // OK
foreach (_; 0 .. 20) { // OK
writeln(_); // syntax error
}
}
Such _ can also be used as "don't care" for tuple unpacking:
t{_, b} = fooAB();
And in switch on structs (that contain the optional "unapply" method):
switch (foo) {
case Foo(x, _, _): writeln(x); break;
default:
}
--
More information about the Digitalmars-d-bugs
mailing list