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

Function matchGraph

sample/graph.cpp:24–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22*/
23
24bool matchGraph()
25{
26 using StrNode = Node<std::string>;
27 auto A = std::make_unique<StrNode>(StrNode{"A", {}});
28 auto B = std::make_unique<StrNode>(StrNode{"B", {A.get()}});
29 auto C = std::make_unique<StrNode>(StrNode{"C", {B.get()}});
30 auto D = std::make_unique<StrNode>(StrNode{"D", {B.get(), C.get()}});
31
32 using namespace matchit;
33 // FIXME, moving dsN into someDsN will cause segfault.
34 constexpr auto dsN = dsVia(&StrNode::value, &StrNode::parents);
35 constexpr auto someDsN = [dsN](auto... pats)
36 {
37 return some(dsN(pats...));
38 };
39 Id<StrNode *> b;
40 return match(D)(
41 pattern | someDsN("D",
42 ds(
43 b.at(
44 someDsN("B",
45 ds(someDsN("A", ds())))),
46 someDsN("C", ds(b)))) = []
47 {
48 std::cout << "Matched!" << std::endl;
49 return true;
50 });
51}
52
53int main()
54{

Callers 1

mainFunction · 0.85

Calls 3

matchFunction · 0.50
dsFunction · 0.50
atMethod · 0.45

Tested by

no test coverage detected