On Sunday 06 March 2011 18:26:26 Bekenn wrote: > 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.
Yeah. While I can see how you might want to use a final switch here, final switches were really intended for enums, and I'm not sure that they really work properly with anything else (I'm not even sure that they work properly with enums - IIRC last time I tried to use one, it didn't enforce anything; hopefully that's changed by now though). - Jonathan M Davis