Can we extent switch statements to support (compile-time known) values with type other than {,w,d}char[] or int?
I suggest we can support any types that implement toHash and opEquals. Switch statements like this:
switch(a) {
case a1:
break;
case a2:
break;
case a3:
break;
...
}
are thus lowered to:
switch(a.toHash) {
case a1.toHash:
if (a1 == a) {...}
break;
case a2.toHash:
if (a2 == a) {...}
break;
case a3.toHash:
if (a3 == a) {...}
break;
...
}
Hash collisions can be resolved into an if-ladder.
Comment #1 by robert.schadek — 2024-12-13T18:43:45Z