1 #ifndef STATIC_COUNTER_H_INCLUDED     2 #define STATIC_COUNTER_H_INCLUDED    42 template <
class T, 
class U>
    44  : 
public CStaticCounter<IntToType<T::value - 1>, U>
    48 class CStaticCounter<IntToType<0>, U> \
    49 { 
unsigned char space; };
    51 #define DEF_STATIC_COUNTER_EX(type, line)           \    52   class CStaticCounterType_ ## type;\    54   class CStaticCounter<IntToType<line>, CStaticCounterType_ ## type> \    55   { unsigned char space; }    57 #define DEF_STATIC_COUNTER(type) \    58   DEF_STATIC_COUNTER_EX(type, __LINE__)    60 #define INC_STATIC_COUNTER_EX(type, line)           \    62   class CStaticCounter<IntToType<line>, CStaticCounterType_ ## type> \    63   { unsigned char space[GET_STATIC_COUNTER(type) + 2]; }    65 #define INC_STATIC_COUNTER(type)           \    66   INC_STATIC_COUNTER_EX(type, __LINE__)    68 #define ADD_STATIC_COUNTER_EX(type, val, line)      \    70   class CStaticCounter<IntToType<line>, CStaticCounterType_ ## type> \    71   { unsigned char space[GET_STATIC_COUNTER(type) + 1 + (val)]; }    73 #define ADD_STATIC_COUNTER(type, val)      \    74    ADD_STATIC_COUNTER_EX(type, val, __LINE__)    76 #define SET_STATIC_COUNTER_EX(type, val, line)      \    78   class CStaticCounter<IntToType<line>, CStaticCounterType_ ## type> \    79   { unsigned char space[1 + (val)]; }    81 #define SET_STATIC_COUNTER(type, val)      \    82   SET_STATIC_COUNTER_EX(type, val, __LINE__)    84 #define GET_STATIC_COUNTER_EX(type, line)         \    85   (sizeof(CStaticCounter<IntToType<line - 1>, CStaticCounterType_ ## type>) - 1)    87 #define GET_STATIC_COUNTER(type) \    88   GET_STATIC_COUNTER_EX(type, __LINE__)    92 DEF_STATIC_COUNTER(test);
    93 static const int cnt0 = GET_STATIC_COUNTER(test); 
    94 INC_STATIC_COUNTER(test);
    95 static const int cnt1 = GET_STATIC_COUNTER(test); 
    96 INC_STATIC_COUNTER(test);
    97 INC_STATIC_COUNTER(test);
    98 static const int cnt2 = GET_STATIC_COUNTER(test); 
    99 ADD_STATIC_COUNTER(test, -1);
   100 static const int cnt3 = GET_STATIC_COUNTER(test); 
   101 SET_STATIC_COUNTER(test, 4);
   102 static const int cnt4 = GET_STATIC_COUNTER(test); 
 A part of TOC table compile-time generator.