enum
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Apr 9 08:38:54 PDT 2014
On 4/9/14, 5:18 AM, w0rp wrote:
> On Wednesday, 9 April 2014 at 11:39:37 UTC, Jonathan M Davis wrote:
>> On Tuesday, April 08, 2014 12:08:46 Andrei Alexandrescu wrote:
>>> 1. Is the current design damaging enough (= allows enough wrong/buggy
>>> code to pass through) to warrant a breaking tightening?
>>
>> What I would very much like to see happen is that any time that any
>> operation
>> is done on a variable of an enum type and that operation is not
>> _guaranteed_
>> to result in a valid enum value, the result should be the enum's base
>> type and
>> and not the enum type - e.g. or-ing enum flags together isn't going to
>> result
>> in a valid enum and shouldn't be typed as such, but unfortunately, it
>> currently _is_ typed as such.
>>
>> And I expect that the vast majority of cases where such a change would
>> break
>> code would catch bugs.
>>
>> - Jonathan M Davis
>
> I think this is a good idea. That way I think you'd only be able to get
> undefined enum values by casting.
Too restrictive. What is a valid enum value? Would an enum flags need to
ascribe a name to every possible combination?
One possibility would be to guarantee all operations are between
TheEnum.min and TheEnum.max. Users who need operations would need to
define those limits.
Andrei
More information about the Digitalmars-d
mailing list