| 8 | Result<uint8_t, std::exception> parse(std::string_view) { return uint8_t{34U}; } |
| 9 | |
| 10 | int32_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 | } |