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

Function sample2

sample/Wildcard-pattern.cpp:16–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16void sample2()
17{
18 // ignore a function/closure param
19 constexpr auto real_part = [](float a, float)
20 { return a; };
21 static_cast<void>(real_part);
22
23 // ignore a field from a struct
24 struct RGBA
25 {
26 float r;
27 float g;
28 float b;
29 float a;
30 };
31
32 constexpr auto color = RGBA{0.4f, 0.1f, 0.9f, 0.5f};
33
34 constexpr auto dsRGBA = dsVia(&RGBA::r, &RGBA::g, &RGBA::b, &RGBA::a);
35
36 Id<float> red, green, blue;
37 match(color)(pattern | dsRGBA(red, green, blue, _) = [&]
38 {
39 assert(color.r == *red);
40 assert(color.g == *green);
41 assert(color.b == *blue);
42 });
43
44 // accept any Some, with any value
45 constexpr auto x = std::make_optional(10);
46 match(x)(
47 // the x is always matched by _
48 pattern | some(_) = [] {});
49}
50
51int32_t main()
52{

Callers 1

mainFunction · 0.70

Calls 1

matchFunction · 0.50

Tested by

no test coverage detected