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

Function sample2

sample/Extra-Conditionals-with-Match-Guards.cpp:34–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34void sample2()
35{
36 auto const x = std::make_optional(5);
37 auto const y = 10;
38
39 Id<int32_t> n;
40 match(x)(
41 // clang-format off
42 pattern | some(50) = [&]{ std::cout << "Got 50" << std::endl; },
43 // In `match(it)`, you can use variable inside patterns, just like literals.
44 pattern | some(y) = [&]{ std::cout << "Matched, n = " << *n << std::endl; },
45 pattern | _ = [&]{ std::cout << "Default case, x = " << x << std::endl; }
46 // clang-format on
47 );
48
49 std::cout << "at the end: x = " << x << ", y = " << y << std::endl;
50}
51
52void sample3()
53{

Callers 1

mainFunction · 0.70

Calls 1

matchFunction · 0.50

Tested by

no test coverage detected