No case ranges in final switches?

Bekenn leaveme at alone.com
Sun Mar 6 18:26:26 PST 2011


On 3/6/2011 1:11 PM, bearophile wrote:
> Do you know why final switches disallow case ranges? Case ranges are not bug-prone:
>
>
> void main() {
>      ubyte u;
>      final switch (u) {
>          case 0: .. case 100:
>              break;
>          case 101: .. case 255:
>              break;
>      }
> }
>

Final switch is really just meant to be used with enums; since 
enumeration values don't have to cover the whole range of possible base 
type values, and enumeration values don't often have a natural ordering, 
ranges make little sense there.


More information about the Digitalmars-d-learn mailing list