DIPX: Enum Literals / Implicit Selector Expression
ShadoLight
ettienne.gilbert at gmail.com
Thu Jun 30 17:15:46 UTC 2022
On Thursday, 30 June 2022 at 11:32:42 UTC, ryuukk_ wrote:
> ```
> set_my_flag( MySuperLongName.MyFlagA | MySuperLongName.MyFlagB
> | MySuperLongName.MyFlagC | MySuperLongName.MyFlagD |
> MySuperLongName.MyFlagE | MySuperLongName.MyFlagF );
> ```
>
> vs
>
> ```
> set_my_flag( .MyFlagA | .MyFlagB | .MyFlagC | .MyFlagD |
> .MyFlagE | .MyFlagF );
> ```
>
> One could argue to use ``with``
>
> But what about places where it can't be used? and it is counter
> productive, if the goal is to remove repetition, why introduce
> more?
Where do you want to use it where it cannot be used?
This works today:
```
with(Color)
final switch(color) {
case red: writeln("red"); break;
case orange: writeln("orange");
}
```
```
with(MySuperLongName) set_my_flag( MyFlagA | MyFlagB |
MyFlagC | MyFlagD | MyFlagE | MyFlagF);
```
More clear at the cost of a few more characters to type. Quite
acceptable compromise in my view.
More information about the Digitalmars-d
mailing list