Skip to content

Instantly share code, notes, and snippets.

@aztek
Created November 8, 2011 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aztek/1349185 to your computer and use it in GitHub Desktop.
Save aztek/1349185 to your computer and use it in GitHub Desktop.
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