Date: Wed, 21 May 2025 09:55:56 -0400
On Wed, May 21, 2025 at 3:34 AM Filip via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I agree, it seems like a better idea to have switch in non constexpr context available, to act like a nicer option acting like if else.
>
> Maybe I’m missing the key functionality of match, but it looks like a different syntax for something that we already have.
>
> I agree that assignment with match looks like a good idea, why wouldn’t we add that to the switch statement?
Because we're getting pattern matching anyway, which is a superset of
what switch can do. There's no point in improving a legacy feature
when it is simultaneously being rendered obsolete.
> string b = “hello”;
> auto var = switch(b){
> case “hi”: { return 42; }
> case “hello”: { return 43; }
> default: { return 0; } // probably should be mandatory
> };
```
b match {
"hi" => return 42;
"hello" => return 43;
_ => return 0;
}
```
<std-proposals_at_[hidden]> wrote:
>
> I agree, it seems like a better idea to have switch in non constexpr context available, to act like a nicer option acting like if else.
>
> Maybe I’m missing the key functionality of match, but it looks like a different syntax for something that we already have.
>
> I agree that assignment with match looks like a good idea, why wouldn’t we add that to the switch statement?
Because we're getting pattern matching anyway, which is a superset of
what switch can do. There's no point in improving a legacy feature
when it is simultaneously being rendered obsolete.
> string b = “hello”;
> auto var = switch(b){
> case “hi”: { return 42; }
> case “hello”: { return 43; }
> default: { return 0; } // probably should be mandatory
> };
```
b match {
"hi" => return 42;
"hello" => return 43;
_ => return 0;
}
```
Received on 2025-05-21 13:56:12