fork(1) download
  1. #include <iostream>
  2. template<unsigned int n> struct Count { bool data[n]; };
  3. template<int n> struct Counter : public Counter<n-1> {};
  4. template<> struct Counter<0> {};
  5. Count<1> GetCount(Counter<1>);
  6.  
  7. #define MAX_COUNTER_NUM 64
  8. #define COUNTER_VALUE (sizeof(GetCount(Counter<MAX_COUNTER_NUM + 1>())) / sizeof(bool))
  9. #define INC_COUNTER Count<COUNTER_VALUE + 1> GetCount(Counter<COUNTER_VALUE + 1>);
  10.  
  11. int main()
  12. {
  13. std::cout << "counter = " << COUNTER_VALUE << "\n";
  14. INC_COUNTER
  15. std::cout << "counter = " << COUNTER_VALUE << "\n";
  16. INC_COUNTER
  17. std::cout << "counter = " << COUNTER_VALUE << "\n";
  18. INC_COUNTER
  19. std::cout << "counter = " << COUNTER_VALUE << "\n";
  20. INC_COUNTER
  21. std::cout << "counter = " << COUNTER_VALUE << "\n";
  22. INC_COUNTER
  23. std::cout << "counter = " << COUNTER_VALUE << "\n";
  24. }
  25.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
counter = 1
counter = 2
counter = 3
counter = 4
counter = 5
counter = 6