r/cpp • u/danillissimo • Jul 19 '26
I've invented labeled loop breaks
And now I don't believe it wasn't invented before, but I can't find any info on it. How long ago was it invented? Why isn't it used widely or even mentioned anywhere? What are the downsides?
Here's the main idea:
// Keyword - for, while, or do
// Tag - custom loop name
// ... - loop body
#define loop_tag(keyword, tag, ...)\
keyword(__VA_ARGS__)\
if(false)\
{\
tag##_break: break;\
tag##_continue: continue;\
}\
else\
/*Here goes your loop body*/Here is the playground
0
Upvotes
View all comments
Show parent comment
1
u/danillissimo Jul 19 '26 edited Jul 19 '26
So, right now i have to write things like
And have to write them recursively. Just wow, thank you very much.
Functions won't actually fix it until the whole context gets packed in a giant struct making things inconvenient another way.
All of this gets even worse in presence of coroutines.
As for debugging - it doesn't break debugging, may be adds just a pair of excess step-overs, but nothing gets really broken.