aboutsummaryrefslogtreecommitdiff
path: root/templates/factorial.cpp
blob: 11e4789a87c41a88af7f04d4a09578b69a10bfa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Taken from https://en.wikipedia.org/wiki/Template_metaprogramming

#include <iostream>

template<long long N>
class factorial {
public:
	static constexpr long long value = N * factorial<N-1>::value;
};

template<>
class factorial<0> {
public:
	static constexpr long long value = 1;
};

int main() {
	constexpr long long X = 12;
	std::cout << factorial<X>::value << std::endl;

	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net