| 5 | // lift a function from T -> U to std::optional<T> -> std::optional<U> |
| 6 | template <typename Func> |
| 7 | auto optionalLift(Func func) |
| 8 | { |
| 9 | using namespace matchit; |
| 10 | return [func](auto &&v) |
| 11 | { |
| 12 | Id<std::decay_t<decltype(*v)>> x; |
| 13 | using RetType = decltype(std::make_optional(func(*x))); |
| 14 | return match(v)( |
| 15 | // clang-format off |
| 16 | pattern | some(x) = [&] { return std::make_optional(func(*x)); }, |
| 17 | pattern | none = expr(RetType{}) |
| 18 | // clang-format on |
| 19 | ); |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | int32_t main() |
| 24 | { |