Improvement to switch-case statement

John Reimer terminal.node at gmail.com
Wed Dec 31 17:13:59 PST 2008


Hello Michel,

> On 2008-12-31 18:22:32 -0500, "Adam D. Ruppe"
> <destructionator at gmail.com> said:
> 
>> This wouldn't be any less efficient than any other switch statement;
>> writing
>> 
>> case 2..5:
>> code;
>> break;
>> could just be magically converted into
>> 
>> case 2:
>> case 3:
>> case 4:
>> case 5:
>> code;
>> break;
> Except that if you want to keep consistency with array slices, 2..5
> should probably not include 5 in the range, thus should be equivalent
> "case 2,3,4". Unfortunatly, that's generally not what you want when
> creating such cases. Imagine writting:
> 
> case 'a'..'{':
> case 'A'..'[':
> Concistent, yes; but not very appealing. What you want to be able to
> write is this:
> 
> case 'a'..'z':
> case 'A'..'Z':
> But then it doesn't work as elsewhere in the language anymore.
> 


Good point.  So while the '..' is potentially useful, it may just be simpler 
to implement something like a range macro rather than suffer the risk of 
such an inconsistancy.

-JJR





More information about the Digitalmars-d mailing list