-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
51 lines (38 loc) · 1.13 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <type_traits>
struct zero {};
template <typename N>
struct next {};
using one = next<zero>;
using two = next<one>;
using three = next<two>;
using four = next<three>;
using five = next<four>;
using six = next<five>;
template <typename A, typename B>
struct addition;
template <typename A, typename B>
struct addition<A, next<B>> {
using result = next<typename addition<A, B>::result>;
};
template <typename A>
struct addition<A, zero> {
using result = A;
};
template <typename A, typename B>
using sum = typename addition<A, B>::result;
template <typename A, typename B>
struct multiplication;
template <typename A, typename B>
struct multiplication<A, next<B>> {
using result = sum<typename multiplication<A, B>::result, A>;
};
template <typename A>
struct multiplication<A, zero> {
using result = zero;
};
template <typename A, typename B>
using product = typename multiplication<A, B>::result;
template <typename A, typename B>
using equals = std::is_same<A, B>;
static_assert(equals<sum<two, two>, four>::value, "two plus two equals four");
static_assert(equals<product<two, three>, six>::value, "two times three equals six");