|
|
|
|
|
by quietbritishjim
652 days ago
|
|
But there are two variables being defined by the destructuring. I believe OP's question was whether there's a rule for which gets chosen for the condition, rather than about contextual conversion to bool in general (which happens even when there's no initialisation in the if statement at all). Your comment seems to imply the condition is evaluated before initialising the variable(s) at all; is that what you meant? If so, this beast would work (even though it's undefined behaviour to construct a std::string from nullptr, and std::string is not convertible to bool): const char* foo() // may return nullptr
if (std::string s = foo())
|
|
But I could be wrong, the paper for the feature is linked but I didn't read it (!).