DIPX: Enum Literals / Implicit Selector Expression

Dave P. dave287091 at gmail.com
Fri Dec 3 02:38:18 UTC 2021


On Thursday, 2 December 2021 at 20:38:08 UTC, Paul Backus wrote:
> On Thursday, 2 December 2021 at 19:44:07 UTC, russhy wrote:
>> # DIPX: Enum Literals / Implicit Selector Expression
>>
> [...]
>>
>> [...]
>
> First impressions:
>
> ```d
> enum MyTag
> {
>     A, B, C
> }
> MyTag tag = .A;
> ```
>
> This looks like it can be made to work very easily, although I 
> am not convinced it is a huge improvement compared to just 
> using `auto`:
>
> ```d
> auto tag = MyTag.A;
> ```
>

Where this really shines are with bit flags. Enabling this would 
be quite nice:
```d
MyFlags flags = .A | .B | .C;
functionWithFlags(.Foo | .Bar, .Baz | .Qux);
```
vs.
```d
auto flags = MyFlags.A | MyFlags.B | MyFlags.C;
functionWithFlags(FuncOption.Foo | FuncOption.Bar, Second.Baz | 
Second.Qux);
```
It’s unfortunate that the module scope operator is prefix `.`




More information about the Digitalmars-d mailing list