Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compile-time factorial in C++
#include <iostream>
using namespace std;
template <int N> struct Factorial {
enum { value = N * Factorial<N - 1>::value };
};
template <> struct Factorial<0> {
enum { value = 1 };
};
int main() {
cout << Factorial<10>::value;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.