Date: Sat, 12 Sep 2026 00:26:37 -0700
On Sat, Sep 12, 2026 at 12:20 AM Jefferson Carpenter <
jeffersoncarpenter2_at_[hidden]> wrote:
> On Sat, Sep 12, 2026 at 2:03 AM Michael Park <mcypark_at_[hidden]> wrote:
> >
> > The problem with switch is that the syntax for switch is not structured
> at all.
> > The syntax for switch is essentially:
> >
> > switch (value) statement
> >
> > The statement there makes it such that any arbitrary sequence of
> statements can
> > be written with cases written somewhere sometimes.
> >
> > It also has too much baggage around fall-through and requiring break,
> etc.
>
> I agree with this point. I'd prefer the value in a new feature to
> "look" more like a lambda body anyway, complete with a return
> statement (or instead of a full lambda body, just a single expression
> that gives the value). I may have more detailed ideas later.
>
I feel like this example might be pretty close to what you're saying?
#include <variant>
struct MyClass { int num; };
int f(std::variant<MyClass, int> x) {
int result = match (x) {
case { MyClass myclass } => myclass.num;
case { int n } => n;
};
}
The match expression here produces an int with the expression on the rhs of
=>.
>
> > The committee has been pretty firm on "leave switch alone".
>
> Interesting! I'm not surprised, but I wouldn't mind making little
> improvements to this statement over adding a new language feature.
>
jeffersoncarpenter2_at_[hidden]> wrote:
> On Sat, Sep 12, 2026 at 2:03 AM Michael Park <mcypark_at_[hidden]> wrote:
> >
> > The problem with switch is that the syntax for switch is not structured
> at all.
> > The syntax for switch is essentially:
> >
> > switch (value) statement
> >
> > The statement there makes it such that any arbitrary sequence of
> statements can
> > be written with cases written somewhere sometimes.
> >
> > It also has too much baggage around fall-through and requiring break,
> etc.
>
> I agree with this point. I'd prefer the value in a new feature to
> "look" more like a lambda body anyway, complete with a return
> statement (or instead of a full lambda body, just a single expression
> that gives the value). I may have more detailed ideas later.
>
I feel like this example might be pretty close to what you're saying?
#include <variant>
struct MyClass { int num; };
int f(std::variant<MyClass, int> x) {
int result = match (x) {
case { MyClass myclass } => myclass.num;
case { int n } => n;
};
}
The match expression here produces an int with the expression on the rhs of
=>.
>
> > The committee has been pretty firm on "leave switch alone".
>
> Interesting! I'm not surprised, but I wouldn't mind making little
> improvements to this statement over adding a new language feature.
>
Received on 2026-09-12 07:27:15
