<sigh> C++ used to be a simple, elegant language…

On Wed, 14 May 2025 at 08:44, Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> wrote:

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 
```cpp
int 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 improve 
 
Tymi.
-- 
 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