final switch and straight integers
Basile Burg via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 20 10:42:03 PDT 2016
On Wednesday, 20 April 2016 at 10:19:17 UTC, Dominikus Dittes
Scherkl wrote:
>
> Anyway, something need to be changed.
> a) allow Range Cases (nice for ints but bad idea for enums)
> b) require also non-enum types to explicitly state all cases
> (bad idea for any multi-byte type, even near useless for single
> bytes)
> c) forbid other types than enum in final switch
>
> I strongly vote for (c).
A good `int` value for a variable `int x` can be enforced (min(),
max(), clamping, warping, etc) **before** a final switch(x). If
c) is done then the compiler in this cas would disallow something
that's completly safe (generally speaking I mean, here safe == no
SwitchException possible).
More information about the Digitalmars-d
mailing list