DIPX: Enum Literals / Implicit Selector Expression

Mike Parker aldacron at gmail.com
Thu Jun 30 11:53:16 UTC 2022


On Thursday, 30 June 2022 at 11:40:31 UTC, ryuukk_ wrote:

> It's like
>
> ```int myInt = int(42);```
>
>
> Why do i need to be repetitive here?

You don't. I'm not sure of the point you're making here. Integer 
literals don't have namespaces. Named enums do.

>
> Also the goal is not to remove the ability to do 
> ```Color.orange``` it is to leverage the type system to avoid 
> having to be repetitive when it is not needed, like in the 
> flags example
>
>
> ```MyFlags flags = .A | .B | .C | .D | .E | .F;```

Yes, I understand the goal.

I'd rather see an enhancement to `with` that would allow it in 
declarations. Just off the top of my head, something like:

```d
with(.MyFlags) flags = A | B | C;
```

That would not create a scope, and it would have to be usable in 
module-scope initializers. `with` already means "prefix this type 
to fields that fit". Here it just goes one step further and 
allows for the type of the declaration to be inferred.


More information about the Digitalmars-d mailing list