Scott McMurray (me22) wrote:
Given the fact that
is part of Boost already, it would make sense to me to allow easy access to its integer types by means of a templated struct like int_exact. Agreed.
Thanks :-)
I suppose there might be value in making them meta-functions, with just ::type
Okay, so instead we could have a templated struct int_exact<Bits>,
containing just one type, taken from
I'm wondering about a special thing like this: template
struct stdint_t { typedef U type; } template <typename U = void> struct stdint_t<32,U> { typedef int32_t type; } // and etc
Not completely clear to me...
Suppose that we just went and used the cstdint.hpp method. Would we then just using uint_t<N> = uint_exact_t< ((N-1)|7)+1 >; Since all the types we know about would be multiples of 8 bits?
Hmmm... I don't really understand this formula either: (((N-1)|7)+1)
int_exact
BTW: CHAR_BIT or integer_traits<unsigned char>::digits, not 8 :P
Oops! You're absolutely right! I was very very bad ;-)
/usr/include/boost/xpressive/traits/cpp_regex_traits.hpp has "define an unsigned integral typedef of the same size as std::ctype_base::mask" So this does seem like a good suggestion.
Easy to implement, too: template <typename T> struct unsigned_ { BOOST_STATIC_ASSERT(integer_traits<T>::is_specialized); // and maybe BOOST_STATIC_ASSERT(integer_traits<T>::is_signed); typedef uint_exact_t
::type type; }; template <typename T> unsigned_<T> make_unsigned(T x) { return unsigned_<T>(x); }
I'm afraid I will lose the value of my argument (x), when passing it to make_unsigned, because it returns a struct that doesn't have any data! But at least it will get me the right unsigned type :-)
Or maybe a new metafunction, int_size_as<T> = int_exact_t
;
That's possible... BTW, I think we might drop the "_t", and call the struct "int_exact", instead of "int_exact_t", when the typedef is simply called "type". Because IMO int_exact<32>::type is clear enough. :-) So... any suggestions on how to get those simple structs like int_exact and uint_exact into the Boost Integer Library? Kind regards, Niels