Mutable enums

Timon Gehr timon.gehr at gmx.ch
Mon Nov 14 01:36:38 PST 2011


On 11/14/2011 10:20 AM, so wrote:
> On Mon, 14 Nov 2011 10:27:21 +0200, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> It is the right design. Why should enum imply const or immutable? (or
>> inout, for that matter). They are completely orthogonal.
>>
>> enum Enum{
>> opt1,
>> opt2,
>> }
>>
>> void main(){
>> auto moo = Enum.opt1;
>> moo = Enum.opt2; // who would seriously want an error here???
>> }
>
> You are missing the point, nobody asked that.

I think you are missing the point. What else are you asking for?

> You are assigning it to
> auto, a runtime variable.
> Which was asked was about modifying a constant, sort(a) means sort a
> in-place. So you cant do:
>
> immutable a;
> sort(a);
>
> But with current design you can do:
>
> enum a;
> sort(a);
>
> Which is to me, quite wrong.

It is just as right or wrong as doing

enum a;
sort([1,2,3]);

The design of enums is probably even irrelevant for this discussion.











More information about the Digitalmars-d-learn mailing list