alt.hn

4/16/2026 at 3:06:04 AM

C++26: Structured Bindings in Conditions

https://www.sandordargo.com/blog/2026/04/15/cpp26-structured-bindings-condition

by jandeboevrie

4/16/2026 at 6:36:01 AM

> if (const auto& [is_successful, error_message] = foo(n))

I don't like it. It's hard to reason what exactly serves as condition variable.

by Panzerschrek

4/16/2026 at 7:06:11 AM

Should probably make it explicit in this case, something like: if (const auto& [is_successful, error_message] = foo(n); is_successful)

In a more normal scenario you'd expect to use std::expected here rather than a custom struct with an operator bool.

by daemin

4/16/2026 at 6:44:04 AM

The return value of foo(n), converted to bool, acts as the condition variable…

by addaon

4/16/2026 at 6:39:02 PM

Yeah I wouldn't like this in a code review. Add one more line of code so I don't have to investigate foo().

That's my fundamental gripe with C++

int i = 0;

function_0(i,...);

...

function_9(i,...);

which one changes i? It's not obvious in a code review due to default mutable references.

by porise