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

Function gcd

sample/gcd.cpp:4–13  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <iostream>
3
4constexpr int32_t gcd(int32_t a, int32_t b)
5{
6 using namespace matchit;
7 return match(a, b)(
8 // clang-format off
9 pattern | ds(_, 0) = [&] { return a >= 0 ? a : -a; },
10 pattern | _ = [&] { return gcd(b, a % b); }
11 // clang-format on
12 );
13}
14
15static_assert(gcd(12, 6) == 6);
16

Callers 2

gcd.cppFile · 0.85
mainFunction · 0.85

Calls 2

matchFunction · 0.50
dsFunction · 0.50

Tested by

no test coverage detected