fork download
  1. #include <iostream>
  2.  
  3. template <int N>
  4. struct Factorial {
  5. enum { value = N * Factorial<N - 1>::value };
  6. };
  7.  
  8. template <>
  9. struct Factorial<0> {
  10. enum { value = 1 };
  11. };
  12.  
  13. int main()
  14. {
  15. auto const f10 = Factorial<10>::value; // done at compile-time
  16. std::cout << f10 << "\n"; // prints 3628800
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
3628800