3 ms·
It's consistent with for (init; condition;) {} and solves a problem like: if (std::vector<int> v = f(); !v.empty()) { // Use v } without requiring an extra
by BudVVeezer 9y ago
It's consistent with for (init; condition;) {} and solves a problem like:
if (std::vector<int> v = f(); !v.empty()) {
// Use v
}
without requiring an extra compound statement to limit the scope and lifetime of v.
- tcbawo 9y agoI agree that it's consistent, I find it easier to read when the branching condition is front and center. In 99% of cases I've encountered, the scope of the branching condition variable doesn't matter. When it does, an extra set of {} defines a scope clearly.
- leni536 9y agoAn extra set of {} seems to be clutter to me.
- lomnakkus 9y agoThat plus extra indentation. It also obscures the intent since it's not necessarily unambiguous why those braces are there? Is it just to group logically related code (without putting it in a separate method/function) or is it because you're relying on RAII -- it's only possible to tell by searching for destructors on all the classes you're instantiating.