r/ProgrammerHumor • • Oct 27 '26

Meme sameProblemSameSolution

Post image
1.5k Upvotes

79 comments sorted by

View all comments

Show parent comment

2

u/17HappyWombats Oct 27 '26 edited Oct 27 '26

Nope, that's not allowed. The previous standard let you say "if(auto foo = something)" and if foo could be interpreted as a boolean you had a valid if() statement. The new one lets you have two statements, the auto assign and the test.

The win here is the scoped auto variable, FWIW. If avoids the abominable pattern where you either alternate declaration/conditional, or a pile of declarations then a string of tests, mixing assignments in whatever way is least horrible. So you get a chain of declare-assign-test statements in a nice vertical line rather than a >