Info
-
Did you know that C++26 added structured binding declaration as a condition?
Example
struct foo {
int a{};
int b{};
constexpr operator bool() const { return a != b; } // implicit condition
};
auto test = [](auto... ts) {
if (auto [a, b] = foo{ts...}) { // structure binding as condition
return true;
}
return false;
};
static_assert(test(1, 2));
static_assert(not test(1, 1));