Does C++ support compile-time counters?
For the purpose of introspection, sometimes I've wanted to automatically assign serial numbers to types, or something similar. Unfortunately, template metaprogramming is essentially a functional language, and as such lacks global variables or modifiable state which would implement such a counter. Or is it? Example code by request: #include <iostream> int const a = counter_read; counter_inc; counter_inc; counter_inc; counter_inc; counter_inc; int const b = counter_read; int main() { std::cout << a << ' ' << b << '\n'; // print "0 5" counter_inc_t(); counter_inc_t(); counter_inc_t(); std::cout <