aboutsummaryrefslogtreecommitdiff
path: root/templates/factorial.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--templates/factorial.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/templates/factorial.cpp b/templates/factorial.cpp
new file mode 100644
index 0000000..11e4789
--- /dev/null
+++ b/templates/factorial.cpp
@@ -0,0 +1,22 @@
1// Taken from https://en.wikipedia.org/wiki/Template_metaprogramming
2
3#include <iostream>
4
5template<long long N>
6class factorial {
7public:
8 static constexpr long long value = N * factorial<N-1>::value;
9};
10
11template<>
12class factorial<0> {
13public:
14 static constexpr long long value = 1;
15};
16
17int main() {
18 constexpr long long X = 12;
19 std::cout << factorial<X>::value << std::endl;
20
21 return 0;
22}

Generated with cgit - Back to sebastiano.tronto.net