final switch and straight integers

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 21 07:27:26 PDT 2016


On Thursday, 21 April 2016 at 12:45:34 UTC, Steven Schveighoffer 
wrote:
> On 4/19/16 6:04 PM, Stefan Koch wrote:
>> On Tuesday, 19 April 2016 at 14:53:18 UTC, Steven 
>> Schveighoffer wrote:
>>
>>> or we
>>> should do away with requiring handling all enum cases.
>>
>>
>> Are you suggesting getting rid of final switch ?
>
> No, what I'm suggesting is that final switch behave 
> consistently. For integers, final switch doesn't require all 
> possible values be handled, but for enums it does. One way to 
> make this consistent is to not require all enums be handled. 
> I'm not suggesting that this is the best answer, just that it 
> is a possible way to square the inconsistency.
>
> Note that even with final switch on an enum, you have issues, 
> especially if the enum is considered to be a bitfield:
>
> enum bitfield {
>    flag1 = 1 << 0,
>    flag2 = 1 << 1
> }

`final enum` was suggested for strict enums that can't be used as 
flags. If we had that, we could phase out `final switch` on 
non-strict enums.


More information about the Digitalmars-d mailing list