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

Function square

sample/someNone.cpp:6–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5template <typename T>
6constexpr 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}
17constexpr auto x = std::make_optional(5);
18static_assert(square(x) == 25);
19

Callers 2

someNone.cppFile · 0.85
mainFunction · 0.85

Calls 2

matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected