Improvements to switch
Nick Treleaven
nick at geany.org
Wed Apr 17 11:24:16 UTC 2024
On Tuesday, 16 April 2024 at 18:25:45 UTC, Meta wrote:
> - branch guards
> - pattern match on arrays, slices:
Some other things, based on section 3.3 of this C++ proposal:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2392r2.pdf
- Multiple alternatives that have the same result: ||
E.g.
```d
case :9 || :15 -> "not prime";
```
- Multiple constraints required for a result: &&
E.g.
```d
switch (variant) {
case int _ && :42 -> "int and 42";
```
- Grouping common names and constraints: { }
E.g.
```d
switch (variant) {
case int i {
case if (i < 0) -> "negative int";
default -> "some other int";
}
```
More information about the dip.ideas
mailing list