-
July 10th, 2012, 07:17 PM
#1
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
-
July 11th, 2012, 01:30 AM
#2
Re: find a type based on value ?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
July 11th, 2012, 01:44 AM
#3
Re: find a type based on value ?
-
July 11th, 2012, 03:20 AM
#4
Re: find a type based on value ?
you can use the new cstdint to simplify this. Note that boost already did it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|