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

Function factorial

sample/factorial.cpp:4–14  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

factorial.cppFile · 0.85
mainFunction · 0.85

Calls 1

matchFunction · 0.50

Tested by

no test coverage detected