enum

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 11 20:07:39 PDT 2014


On Fri, 11 Apr 2014 15:53:13 -0400, deadalnix <deadalnix at gmail.com> wrote:

> On Friday, 11 April 2014 at 12:21:59 UTC, Steven Schveighoffer wrote:
>> Idea just came to me. What about notifying the compiler which enums can  
>> be used in final switches (and perhaps should be more stringent in  
>> allowing math operations):
>>
>> final enum name { ... }
>>
>> -Steve
>
> I unerstand what you are trying to do here. You are solving a political  
> problem, with a solution that is inferior (but won't require anyone to  
> be proven wrong, so that have greater chance to be accepted).

I don't really understand this statement. The problem I'm trying to solve  
is that final switch doesn't do what it's supposed to do.

> The problem is that is increase language complexity, plus make the most  
> common use case of enum nit the most direct, obvious one. It is going to  
> break every single piece of code that use final switch. And the default  
> behavior of enum still remain a useless 3 headed monster, that could be  
> created as a library solution, and that nobody really want anyway.

final switch is fundamentally broken. It is supposed to be an input  
condition to final switch that the value MUST be one of the enum values.  
By allowing arbitrary math on enums, this is not the case, even in @safe  
code.

In any case, it doesn't solve all enum problems, just that one. Will it  
break code? Code that is written correctly, it will break trivially (just  
add final to the enum declaration). Code that is not written correctly,  
you will either have to use normal switch, or fix the code.

-Steve


More information about the Digitalmars-d mailing list