Extend D's switch statement?
Yuxuan Shui via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 8 11:06:52 PDT 2015
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.
More information about the Digitalmars-d
mailing list