On Wednesday, 8 July 2015 at 17:30:59 UTC, Timon Gehr wrote:
On 07/08/2015 10:31 AM, Martin Nowak wrote:
On Wednesday, 8 July 2015 at 07:15:27 UTC, Yuxuan Shui wrote:
[...]

Hardly anyone wants switch to be a better if-else ladder.
https://issues.dlang.org/show_bug.cgi?id=5862

I don't think this is what is being asked for.

switch(x){
    case a:
        ...;
        break;
    case b:
        ...;
        break;
    default: break;
}

->

switch(x.toHash()){
    case a.toHash():
        if(x!=a) goto default;
        ...;
        break;
    case b.toHash():
        if(x!=b) goto default;
        ...;
        break;
    default: break;
}

(a and b are known at compile time here, and so are their hash values. Hash collisions between e.g. a and b would need to be dealt with of course.)

Yes, this is what I meant.

Reply via email to