normalized_numerics.hh
Go to the documentation of this file.00001 #ifndef NORMALIZED_NUMERICS_HH
00002 #define NORMALIZED_NUMERICS_HH
00003
00004 namespace Typelib {
00005 namespace details {
00006 template<int Bits> class sint_t;
00007 template<> struct sint_t<7> { typedef int8_t type; };
00008 template<> struct sint_t<15> { typedef int16_t type; };
00009 template<> struct sint_t<31> { typedef int32_t type; };
00010 template<> struct sint_t<63> { typedef int64_t type; };
00011
00012 template<int Bits> class uint_t;
00013 template<> struct uint_t<8> { typedef uint8_t type; };
00014 template<> struct uint_t<16> { typedef uint16_t type; };
00015 template<> struct uint_t<32> { typedef uint32_t type; };
00016 template<> struct uint_t<64> { typedef uint64_t type; };
00017 }
00018
00021 template<typename T>
00022 struct normalized_numeric_type
00023 {
00024 typedef std::numeric_limits<T> limits;
00025 BOOST_STATIC_ASSERT(( limits::is_integer ));
00026
00027 typedef typename boost::mpl::if_
00028 < boost::mpl::bool_<std::numeric_limits<T>::is_signed>
00029 , details::sint_t< limits::digits >
00030 , details::uint_t< limits::digits >
00031 >::type getter;
00032 typedef typename getter::type type;
00033 };
00034
00035 template<> struct normalized_numeric_type<float> { typedef float type; };
00036 template<> struct normalized_numeric_type<double> { typedef double type; };
00037 }
00038
00039 #endif
00040
00041
00042