switch case for constants-only?

BCS none at anon.com
Sat Dec 5 16:40:58 PST 2009


Hello Nick,

> Also, I still don't see how there's any semantic difference between
> the current switch and the switch-like if-else chain other than just
> the fact that switch currently carries the restriction that the values
> being checked against must be unique and known at compile time.
> 

For one; fall thought (but that can be done with gotos or some really ugly 
nested if's:

The other thing is that a compiler is free to be implemented a switch statement 
any way it wants including things like perfect hashes or (for strings) a 
RegEx style DFA. This does have semantic effects in the O() of the construct.

I'll grant that what you are asking for is useful. But I will not go so far 
as to say that the current switch construct or even it's name (it has about 
as much to do with switch as for has to do with while) should be co opted 
for it. I'll even go so far as to say that I really doubt that the current 
switch will atrophy even if another construct is added with these features.





More information about the Digitalmars-d mailing list