DIP1044---"Enum Type Inference"---Formal Assessment
max haughton
maxhaton at gmail.com
Tue Apr 25 18:38:14 UTC 2023
On Tuesday, 25 April 2023 at 04:54:43 UTC, Mike Parker wrote:
Firstly I think this is the correct decision, certainly for now,
probably forever.
> Regarding enums in switch statements, Walter suggested we could
> shorten the `with final switch` syntax such that the `with` is
> implicitly applied to the type of the switch variable:
>
> ```D
> auto myEnum = MyEnum.a;
> with final switch (myEnum) { }
> ```
>
> Alternatively, we could make the `with` implicit for case
> statements, but that would break existing code.
What we have at the moment with `with` is, I think perfectly fine.
The `switch(...) with(...)` pattern is used rather a lot in the
SDC codebase
for example and I think it's very readable.
On the topic of `with` I do think, and have even implemented ;),
with expressions do need to happen eventually. The with statement
is a little heavy handed for places where these kinds of
shorthands are needed locally.
More information about the Digitalmars-d-announce
mailing list