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

Function get_hint

sample/Structured-Binding-Pattern.cpp:12–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10};
11
12void get_hint(const Player &p)
13{
14 using namespace matchit;
15 using P = Player;
16 Id<std::string> n;
17 match(p)(
18 pattern | app(&P::hitpoints, 1) =
19 [&]
20 { std::cout << "You're almost destroyed. Give up!\n"; },
21 pattern | and_(app(&P::hitpoints, 10), app(&P::coins, 10)) =
22 [&]
23 { std::cout << "I need the hints from you!\n"; },
24 pattern |
25 app(&P::coins, 10) = [&]
26 { std::cout << "Get more hitpoints!\n"; },
27 pattern |
28 app(&P::hitpoints, 10) = [&]
29 { std::cout << "Get more ammo!\n"; },
30 pattern | app(&P::name, n) =
31 [&]
32 {
33 if (*n != "The Bruce Dickenson")
34 {
35 std::cout << "Get more hitpoints and ammo!\n";
36 }
37 else
38 {
39 std::cout << "More cowbell!\n";
40 }
41 });
42}
43
44int32_t main()
45{

Callers 1

mainFunction · 0.85

Calls 3

appFunction · 0.85
matchFunction · 0.50
and_Function · 0.50

Tested by

no test coverage detected