Another option to destructure your struct / class.
| 52 | |
| 53 | // Another option to destructure your struct / class. |
| 54 | constexpr auto dsByMember(DummyStruct const &v) |
| 55 | { |
| 56 | using namespace matchit; |
| 57 | // compose patterns for destructuring struct DummyStruct. |
| 58 | constexpr auto dsA = dsVia(&DummyStruct::size, &DummyStruct::name); |
| 59 | Id<char const *> i; |
| 60 | return match(v)( |
| 61 | // clang-format off |
| 62 | pattern | dsA(2, i) = expr(i), |
| 63 | pattern | _ = expr("not matched") |
| 64 | // clang-format on |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | static_assert(dsByMember(DummyStruct{1, "123"}) == |
| 69 | std::string_view{"not matched"}); |
no test coverage detected