Advertisement
hxrussia

Factorial calculation at compile-time

Jul 14th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. typedef long long ll;
  4.  
  5. template< ll n >
  6. struct Factorial {
  7.     const static ll value = Factorial< n - 1 >::value * n;
  8. };
  9.  
  10. template<>
  11. struct Factorial< 1 > {
  12.     const static ll value = 1;
  13. };
  14.  
  15. int main() {
  16.     printf("%lld\n", Factorial< 10 >::value);
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement