MCPcopy Create free account
hub / github.com/BowenFu/matchit.cpp / optionalLift

Function optionalLift

sample/optionalLift.cpp:7–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5// lift a function from T -> U to std::optional<T> -> std::optional<U>
6template <typename Func>
7auto 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
23int32_t main()
24{

Callers 1

mainFunction · 0.85

Calls 2

matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected