From 0b43d984905f07c59e3236d98d4e27409aba3cda Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 17 Jan 2025 16:23:24 +0100 Subject: More stuff with templates --- templates/factorial.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 templates/factorial.cpp (limited to 'templates/factorial.cpp') 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 @@ +// Taken from https://en.wikipedia.org/wiki/Template_metaprogramming + +#include + +template +class factorial { +public: + static constexpr long long value = N * factorial::value; +}; + +template<> +class factorial<0> { +public: + static constexpr long long value = 1; +}; + +int main() { + constexpr long long X = 12; + std::cout << factorial::value << std::endl; + + return 0; +} -- cgit v1.3