#ifndef CL_COUNTER_HPP #define CL_COUNTER_HPP template struct _cc : _cc {}; template<> struct _cc<0> {}; typedef _cc<32> _cm; template struct _ct { static _ct f(); typedef T t; }; template struct _cs { char _[Size]; }; template _cs<1>& _cf(_ct&, _cc<0>&, _cc<0>&); template struct _cn { static const int b = N == 0 ? 0x1 : _cn::b + (N >> _cn::b); static const int l = N >> b/2; static const int r = N ^ (l << b/2); friend _cs& _cf(_ct&, _cc&, _cc&); static const int v = N-1; }; #define CL_COUNTER_NEXT(id) \ (::_cn(), ::_cm(), ::_cm()))>::v) #define CL_COUNTER_GET(id) \ (sizeof(::_cf(::_ct(), ::_cm(), ::_cm()))-1) #endif