1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| template <int i>
struct metafunc_log2
{
enum { value=1+metafunc_log2< (i>>1) >::value };
};
template <>
struct metafunc_log2<1>
{
enum { value=0 };
};
template<typename UI>
struct serializable_type
{
enum { bytes=sizeof(UI), bits=bytes*8, log2=metafunc_log2<bytes>::value };
};
int main(int argc, char* argv[])
{
int log2=serializable_type<unsigned short>::log2;
int bytes=serializable_type<unsigned short>::bytes;
int bits=serializable_type<unsigned short>::bits;
return 0;
} |