DIPX: Enum Literals / Implicit Selector Expression

The Zealot zod at zod.zod
Thu Jun 30 16:25:35 UTC 2022


On Thursday, 30 June 2022 at 15:42:05 UTC, ryuukk_ wrote:
> On Thursday, 30 June 2022 at 11:03:08 UTC, bauss wrote:
>> On Thursday, 30 June 2022 at 10:58:37 UTC, Mike Parker wrote:
>>> [...]
>>
>> What it seems like it's trying to solve is this:
>>
>> ```d
>> SomeEnum.a | SomeEnum.b | SomeEnum.c
>> ```
>>
>> So you could instead do:
>>
>> ```d
>> .a | .b | .c
>> ```
>>
>> But much like you I don't think that's at all clarified, maybe 
>> I would settle for something like this:
>>
>> SomeEnum(a | b | c) as that clearly tells you it's SomeEnum 
>> and then it's clear you're picking the values from that, so a, 
>> b and c will __always__ be from SomeEnum.
>>
>> But personally I don't really like that syntax either as it 
>> clashes too much with struct ctors and/or function calls.
>>
>> So I don't have an actual good solution, so I guess in the end 
>> I'm not for any changes.
>
>
>     SomeEnum flags = SomeEnum (a | b | c);
>
> Why do i have to be repetitive? the goal is to not be 
> repetitive and be cleaner
>
>     SomeEnum flags = .a | .b | .c;
>
> The brain no longer have to read 2x the same stuff, it goes 
> straight to the point, it is explicit and typechecked

and if you later see a line like
```
auto flags = .a | .b | .c;
```
imho it's just much harder to figure out whats going on.
i agree that a short syntax would be good. i'd prefer _with()_ 
because it makes it easier to understand later.


More information about the Digitalmars-d mailing list