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


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Thu Jan 2 2014 11:38:41