| 14 | } |
| 15 | |
| 16 | void 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 | |
| 51 | int32_t main() |
| 52 | { |