C++ pattern matching is coming
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Oct 24 14:05:47 UTC 2022
On Sunday, 23 October 2022 at 23:40:21 UTC, Walter Bright wrote:
> The syntax of `switch` is old-fashioned, too.
Yes.
> A more modern one would be:
>
> match (x)
> {
> 0 => foo();
> 3 => bar();
> }
>
> Note the lack of need for `break`.
No. Java re-used the `swtich` keyword and IMO is correct in doing
so. The rest is great as in Java.
We could have both, C#’s and Java’s great version of switch, i.e.
the `expression switch { case pattern => …; }` *expression* and
the `switch (expression) { case value => statement; }` version.
Like with `mixin`, there can be a statement and an expression
form, and while the mixin stuff is confusing, here the syntax is
visually different.
More information about the Digitalmars-d
mailing list