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

Function main

sample/Conditional-if-let-Expressions.cpp:10–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8Result<uint8_t, std::exception> parse(std::string_view) { return uint8_t{34U}; }
9
10int32_t main()
11{
12 auto const favorite_color = std::optional<std::string>{};
13 auto const is_tuesday = false;
14
15 Result<uint8_t, std::exception> const age = parse("34");
16
17 using namespace matchit;
18 Id<std::string> color;
19 match(favorite_color)(
20 pattern | some(color) =
21 [&]
22 {
23 return "Using your favorite color, " + *color +
24 ", as the background";
25 },
26 pattern | _ | when(expr(is_tuesday)) = expr("Tuesday is green day!"),
27 pattern | _ =
28 [&]
29 {
30 Id<uint8_t> age_;
31 return match(age)(pattern | as<uint8_t>(age_) | when(age_ > 30) =
32 expr("Using purple as the background color"),
33 pattern | as<uint8_t>(age_) =
34 expr("Using orange as the background color"),
35 pattern | _ =
36 expr("Using blue as the background color"));
37 });
38
39 return 0;
40}

Callers

nothing calls this directly

Calls 4

parseFunction · 0.85
whenFunction · 0.85
matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected