Created
November 8, 2011 20:56
-
-
Save aztek/1349185 to your computer and use it in GitHub Desktop.
Compile-time factorial in C++
This file contains hidden or 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> | |
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