logoalt Hacker News

Panzerschrektoday at 6:36 AM2 repliesview on HN

> 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.


Replies

daemintoday at 7:06 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.

addaontoday at 6:44 AM

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