Enum literals, good? bad? what do you think?

Paul Backus snarwin at gmail.com
Thu Jul 22 03:28:44 UTC 2021


On Thursday, 22 July 2021 at 03:21:06 UTC, Dukc wrote:
> On Tuesday, 20 July 2021 at 15:50:49 UTC, russhy wrote:
>> So what do you think? yay? nay? why not?
>
> As mentioned by others, `enumVar = .memberName` is ambiguous 
> with the module scope operator. If you want to pursue this, 
> might I recommend `enumVar = "memberName"` instead? You still 
> need no new syntax, and it could be implemented with value 
> range propagation mechanics. This way:
>
> If a `string`, `wstring` or `dstring` `str` that is known at 
> compile time, is assigned to value of enumerated type `ET`, it 
> is interpreted as assigning `mixin("ET." ~ str)` to the 
> assignee value.

```d
enum E : string { x = "y", y = "x" }

E e = "y"; // what happens here?
```


More information about the Digitalmars-d mailing list