fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <int N>
  5. struct pow2
  6. {
  7. enum { value = 2 * pow2<N - 1>::value };
  8. };
  9.  
  10. template <>
  11. struct pow2<0>
  12. {
  13. enum { value = 1 };
  14. };
  15.  
  16. int main()
  17. {
  18. const int x = pow2<4>::value; // == 16
  19. const int y = pow2<0>::value; // == 1
  20. char arr[x]; // Because x is constant
  21. cout << "Array size is " << sizeof arr << endl;
  22. }
  23.  
  24.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Array size is 16