find a type based on value ?
Another fun question...
Is it possible to make a type, based on a value ?
What I'm looking for is way to return the smallest (sizeof) unsigned integral type that will hold a certain value.
smallest_type<14>::type // unsigned char
smallest_type<127>::type // unsigned char
smallest_type<255>::type // unsigned char
smallest_type<256>::type // unsigned short
smallest_type<64000>::type // unsigned short
smallest_type<128000>::type // unsigned long
smallest_type<5000000000>::type // unsigned long long
Re: find a type based on value ?
Re: find a type based on value ?
Re: find a type based on value ?
you can use the new cstdint to simplify this. Note that boost already did it.