I strongly suggest to "burn with fire", I mean, warn and then deprecate the special case of automatic tuple unpacking in foreach loops in dmd 2.067:

void main() {
    import std.typecons, std.range;

    auto data1 = [tuple("red", 10), tuple("blue", 20)];
    foreach (x, y; data1) {
        pragma(msg, typeof(x), " ", typeof(y));
    }

    auto data2 = only(tuple("red", 10), tuple("blue", 20));
    foreach (x, y; data2) {
        pragma(msg, typeof(x), " ", typeof(y));
    }
}



Output:

uint Tuple!(string, int)
string int


See issues:

https://issues.dlang.org/show_bug.cgi?id=9817
https://issues.dlang.org/show_bug.cgi?id=7361

It causes troubles today because it's a special-cased trap. And it will cause even more troubles in future if/when we add built-in tuple unpacking to D. So please remove this wart, thank you.

Bye,
bearophile

Reply via email to