Skip to content

Instantly share code, notes, and snippets.

@cedricporter
Last active January 2, 2016 09:19
Show Gist options
  • Save cedricporter/8282484 to your computer and use it in GitHub Desktop.
Save cedricporter/8282484 to your computer and use it in GitHub Desktop.
#include <iostream>
template<unsigned long n>
struct Factorial {
enum {value = n * Factorial<n-1>::value};
};
template<>
struct Factorial<0> {
enum {value = 1};
};
int main() {
std::cout << Factorial<5>::value << std::endl;
std::cout << Factorial<10>::value << std::endl;
std::cout << Factorial<20>::value << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment