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

Function sample

sample/Struct-pattern.cpp:13–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11{ return app(get<I>, pat); };
12
13void sample()
14{
15 struct Point
16 {
17 uint32_t x;
18 uint32_t y;
19 };
20 constexpr auto s = Point{1U, 1U};
21
22 match(s)(
23 // clang-format off
24 pattern | and_(app(&Point::x, 10U), app(&Point::y, 20U)) = []{},
25 pattern | and_(app(&Point::y, 10U), app(&Point::x, 20U)) = []{}, // order doesn't matter
26 pattern | app(&Point::x, 10U) = []{},
27 pattern | _ = []{} // clang-format on
28 );
29
30 using PointTuple = std::tuple<uint32_t, uint32_t>;
31 constexpr auto t = PointTuple{1U, 2U};
32
33 match(t)(
34 // clang-format off
35 pattern | and_(appGet<0>(10U), appGet<1>(20U)) = []{},
36 pattern | and_(appGet<1>(10U), appGet<0>(20U)) = []{}, // order doesn't matter
37 pattern | appGet<0>(10U) = []{},
38 pattern | _ = []{} // clang-format on
39 );
40}
41
42int32_t main()
43{

Callers 1

mainFunction · 0.70

Calls 3

appFunction · 0.85
matchFunction · 0.50
and_Function · 0.50

Tested by

no test coverage detected