fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <int n> class SomeClass
  5. {
  6. public:
  7. void debug() {
  8. cout << "SomeClass<" << n << ">" << endl;
  9. }
  10. };
  11.  
  12. constexpr int n[5] = { 4, 8, 16, 32, 64 };
  13.  
  14. template <int i>
  15. struct loop
  16. {
  17. static void doit()
  18. {
  19. SomeClass<n[i]> C;
  20. C.debug();
  21. // other things depending on n[i]
  22. loop<i+1>::doit();
  23. }
  24. };
  25.  
  26. template <>
  27. struct loop<5>
  28. {
  29. static void doit()
  30. {
  31. }
  32. };
  33.  
  34. int main() {
  35. loop<0>::doit();
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
SomeClass<4>
SomeClass<8>
SomeClass<16>
SomeClass<32>
SomeClass<64>