Last active
May 31, 2020 06:55
-
-
Save kjk/f5300f79d9c581e1a4ae2e727061e50d to your computer and use it in GitHub Desktop.
Essential C++ : Calculating Factorials https://www.programming-books.io/essential/cpp/calculating-factorials-317f96c51a284c9ab5e0bf64625f5d70 (made with https://codeeval.dev)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <type_traits> | |
template<long long n> | |
struct factorial : | |
std::integral_constant<long long, n * factorial<n - 1>::value> {}; | |
template<> | |
struct factorial<0> : | |
std::integral_constant<long long, 1> {}; | |
int main() | |
{ | |
std::cout << factorial<7>::value << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment