Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 586 Bytes

376.md

File metadata and controls

29 lines (21 loc) · 586 Bytes
Info

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));

https://godbolt.org/z/fEzevGsnh