Also have a look at do-expressions:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2806r3.html
int purr = do {switch(meow){case 5: do_return 123;case 123: do_return 321;default: throw nullptr;};
};
They can (if accepted) also be combined with pattern-matching:
int purr = meow match {
5 => do { do_return 123; };
123 => do { do_return 321; };
_ => do { throw nullptr; };
};
-----Ursprüngliche Nachricht-----
Von: Tymi via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mi 14.05.2025 07:05
Betreff: [std-proposals] switch expression/matching switch expression
An: std-proposals@lists.isocpp.org;
CC: Tymi <tymi.cpp@gmail.com>;
A matching switch expression could be useful and could get optimised into a jump table```cppint meow = 5;int purr = switch(meow){case 5: 123;case 123: 321;default: throw nullptr;};```Whatever the syntax would be, this is just an example and it can definitely improveTymi.---- Std-Proposals mailing list Std-Proposals@lists.isocpp.org https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals