MCPcopy Create free account
hub / github.com/BowenFu/matchit.cpp / dsByMember

Function dsByMember

sample/customDs.cpp:54–66  ·  view source on GitHub ↗

Another option to destructure your struct / class.

Source from the content-addressed store, hash-verified

52
53// Another option to destructure your struct / class.
54constexpr 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
68static_assert(dsByMember(DummyStruct{1, "123"}) ==
69 std::string_view{"not matched"});

Callers 2

customDs.cppFile · 0.85
mainFunction · 0.85

Calls 2

matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected