| 4 | |
| 5 | template <typename T> |
| 6 | constexpr auto square(std::optional<T> const &t) |
| 7 | { |
| 8 | using namespace matchit; |
| 9 | Id<T> id; |
| 10 | return match(t)( |
| 11 | // clang-format off |
| 12 | pattern | some(id) = id * id, |
| 13 | pattern | none = expr(0) |
| 14 | // clang-format on |
| 15 | ); |
| 16 | } |
| 17 | constexpr auto x = std::make_optional(5); |
| 18 | static_assert(square(x) == 25); |
| 19 |
no test coverage detected