Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
template madness: factorial
#include <iostream>
using std::cout;
using std::endl;
template <int N>
struct factorial {
constexpr static int value = N * factorial<N-1>::value;
template <>
struct factorial<0> {
constexpr static int value = 1;
main() {
std::cout << "5! = " << (factorial<5>::value) << std::endl;
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.