| 2 | #include <iostream> |
| 3 | |
| 4 | constexpr int32_t gcd(int32_t a, int32_t b) |
| 5 | { |
| 6 | using namespace matchit; |
| 7 | return match(a, b)( |
| 8 | // clang-format off |
| 9 | pattern | ds(_, 0) = [&] { return a >= 0 ? a : -a; }, |
| 10 | pattern | _ = [&] { return gcd(b, a % b); } |
| 11 | // clang-format on |
| 12 | ); |
| 13 | } |
| 14 | |
| 15 | static_assert(gcd(12, 6) == 6); |
| 16 |