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

Function fib

test/matchit/constexpr.cpp:4–14  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace matchit;
3
4constexpr int32_t fib(int32_t n)
5{
6 assert(n >= 1);
7 return match(n)(
8 // clang-format off
9 pattern | 1 = expr(1),
10 pattern | 2 = expr(1),
11 pattern | _ = [n] { return fib(n - 1) + fib(n - 2); }
12 // clang-format on
13 );
14}
15
16static_assert(fib(1) == 1);
17static_assert(fib(2) == 1);

Callers 1

constexpr.cppFile · 0.70

Calls 2

matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected