Advertisement
Guest User

MetaFactorial

a guest
Feb 28th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <assert.h>
  3.  
  4. using namespace std;
  5. //Example own practice.
  6.  
  7. template<int n>
  8. class MetaFactorial {
  9.   public:
  10.     enum{value = n * MetaFactorial<n-1>::value};
  11. };
  12.  
  13. template<>
  14. class MetaFactorial<0> {
  15.   public:
  16.     enum{ value = 1 };
  17. };
  18.  
  19. int main() {
  20.  
  21.   cout<<MetaFactorial<5>::value<<endl;
  22.  
  23.   return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement