I have a strong dislike for the enhanced conditionals. Like, the feature itself is fine... but there's just a certain subset of people who think any new C++ feature is the blessed "proper" way to accomplish any task and this feature is very abusable. It also doesn't provide very much benefit to actual practice in return.
For some additional context, this came up for me because some other team had snuck verbiage into our style guide that mandated things like this instead of traditional initializers:
void foo() {
if (auto [a, b, c] = std::make_tuple(x, y, z); true) { /* [...] */ }
}
Yeah you can still read this, but it's stupid to support constructs creating scope, doing control flow, and initializing arbitrarily many variables simultaneously (which may invoke constructors of their own). The relatively minor benefits to things like iterators are not outweighed by the burden of supporting this stupid code.
I think the original comment's point is exactly that. But people see the new expression type and want to apply it in this case.
I'm of two minds on this. I can see the impulse and why you'd reach for it: Block lexical scopes with no if/while/etc statement attached read a bit odd. Introducing an "unattached" block means as a reader/reviewer I want to know why the scope has been created. So in this new syntax I suppose makes it "clearer" (in some respects) that what is being done here is introducing a new lexical scope specifically for the given variables. Like I commented elsewhere, this is somewhat similar to the ML-languages "let <assignments> in <block>" syntax, which I have always found admirable, as it makes clear to the reader (and compiler) what scope and state are being dealt with.
On the other hand, this is so out of step with C/C++ style generally, and it seems so excessively "clever" that I think it's going to piss people off. And because it's bolted onto the conditional expr, you get the pointless ;true there.
Having a with ( ... ) syntax would have been nicer?
with (auto [a, b, c] = std::make_tuple(x, y, z)) {
}
I'm curious what Titus Winters and the Google C++ style guide is saying about this.
Different feature, I'm talking about the optional initialization section added to conditionals. It allows moving declarations to the point of use like for statements. I've also met people who think it's now the appropriate place to declare all block scope variables, which is horrifying.
Has shades of the OCaml/StandardML "let ... " scope:
StandardML:
let
val a = 1
val b = 2
in
a + b
end
It's nice for making it clear that the scope of the assignment is restricted to this lexical scope, though there are other ways to do this in C/C++.
I work in Rust these days so haven't had a chance to use much of this, but I wonder if this has some nice RAII type use patterns? I may now go explore.