integer.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef BOOST_INTEGER_HPP
00016 #define BOOST_INTEGER_HPP
00017
00018 #include <boost/integer_fwd.hpp>
00019
00020 #include <boost/integer_traits.hpp>
00021 #include <boost/limits.hpp>
00022
00023 namespace boost
00024 {
00025
00026
00027
00028
00029
00030 template< typename LeastInt >
00031 struct int_fast_t { typedef LeastInt fast; };
00032
00033
00034 template< int Category > struct int_least_helper {};
00035
00036
00037
00038
00039 template<> struct int_least_helper<1> { typedef long least; };
00040 template<> struct int_least_helper<2> { typedef int least; };
00041 template<> struct int_least_helper<3> { typedef short least; };
00042 template<> struct int_least_helper<4> { typedef signed char least; };
00043 template<> struct int_least_helper<6> { typedef unsigned long least; };
00044 template<> struct int_least_helper<7> { typedef unsigned int least; };
00045 template<> struct int_least_helper<8> { typedef unsigned short least; };
00046 template<> struct int_least_helper<9> { typedef unsigned char least; };
00047
00048
00049
00050
00051 template< int Bits >
00052 struct int_t
00053 {
00054 typedef typename int_least_helper
00055 <
00056 (Bits-1 <= std::numeric_limits<long>::digits) +
00057 (Bits-1 <= std::numeric_limits<int>::digits) +
00058 (Bits-1 <= std::numeric_limits<short>::digits) +
00059 (Bits-1 <= std::numeric_limits<signed char>::digits)
00060 >::least least;
00061 typedef typename int_fast_t<least>::fast fast;
00062 };
00063
00064
00065 template< int Bits >
00066 struct uint_t
00067 {
00068 typedef typename int_least_helper
00069 <
00070 5 +
00071 (Bits <= std::numeric_limits<unsigned long>::digits) +
00072 (Bits <= std::numeric_limits<unsigned int>::digits) +
00073 (Bits <= std::numeric_limits<unsigned short>::digits) +
00074 (Bits <= std::numeric_limits<unsigned char>::digits)
00075 >::least least;
00076 typedef typename int_fast_t<least>::fast fast;
00077
00078 };
00079
00080
00081
00082
00083 template< long MaxValue >
00084 struct int_max_value_t
00085 {
00086 typedef typename int_least_helper
00087 <
00088 (MaxValue <= integer_traits<long>::const_max) +
00089 (MaxValue <= integer_traits<int>::const_max) +
00090 (MaxValue <= integer_traits<short>::const_max) +
00091 (MaxValue <= integer_traits<signed char>::const_max)
00092 >::least least;
00093 typedef typename int_fast_t<least>::fast fast;
00094 };
00095
00096 template< long MinValue >
00097 struct int_min_value_t
00098 {
00099 typedef typename int_least_helper
00100 <
00101 (MinValue >= integer_traits<long>::const_min) +
00102 (MinValue >= integer_traits<int>::const_min) +
00103 (MinValue >= integer_traits<short>::const_min) +
00104 (MinValue >= integer_traits<signed char>::const_min)
00105 >::least least;
00106 typedef typename int_fast_t<least>::fast fast;
00107 };
00108
00109
00110 template< unsigned long Value >
00111 struct uint_value_t
00112 {
00113 typedef typename int_least_helper
00114 <
00115 5 +
00116 (Value <= integer_traits<unsigned long>::const_max) +
00117 (Value <= integer_traits<unsigned int>::const_max) +
00118 (Value <= integer_traits<unsigned short>::const_max) +
00119 (Value <= integer_traits<unsigned char>::const_max)
00120 >::least least;
00121 typedef typename int_fast_t<least>::fast fast;
00122 };
00123
00124
00125 }
00126
00127 #endif // BOOST_INTEGER_HPP