Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
00059 # define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
00060
00061 # include <boost/config.hpp>
00062 # include <boost/cstdint.hpp>
00063 # include <boost/static_assert.hpp>
00064 # include <boost/type_traits.hpp>
00065 # include <boost/detail/select_type.hpp>
00066 # include <boost/limits.hpp>
00067
00068 namespace boost { namespace detail {
00069
00070
00071
00072
00073
00074 template <class Number>
00075 struct is_signed
00076 {
00077 #if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_MSVC) && BOOST_MSVC <= 1300
00078 BOOST_STATIC_CONSTANT(bool, value = (Number(-1) < Number(0)));
00079 #else
00080 BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<Number>::is_signed);
00081 #endif
00082 };
00083
00084 # ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
00085
00086
00087
00088 template <bool is_specialized> struct digit_traits_select;
00089
00090
00091 template <> struct digit_traits_select<true>
00092 {
00093 template <class T> struct traits
00094 {
00095 BOOST_STATIC_CONSTANT(int, digits = std::numeric_limits<T>::digits);
00096 };
00097 };
00098
00099
00100 template <> struct digit_traits_select<false>
00101 {
00102 template <class T> struct traits
00103 {
00104 BOOST_STATIC_CONSTANT(int, digits = (
00105 sizeof(T) * std::numeric_limits<unsigned char>::digits
00106 - (is_signed<T>::value ? 1 : 0))
00107 );
00108 };
00109 };
00110
00111
00112 template <class T> struct digit_traits
00113 {
00114 typedef digit_traits_select<
00115 ::std::numeric_limits<T>::is_specialized> selector;
00116 typedef typename selector::template traits<T> traits;
00117 BOOST_STATIC_CONSTANT(int, digits = traits::digits);
00118 };
00119 #endif
00120
00121
00122
00123
00124 template <class Integer>
00125 struct integer_traits
00126 {
00127 # ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
00128 private:
00129 typedef Integer integer_type;
00130 typedef std::numeric_limits<integer_type> x;
00131 # if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
00132
00133
00134 BOOST_STATIC_CONSTANT(bool, is_integer = x::is_integer);
00135 BOOST_STATIC_CONSTANT(bool, is_specialized = x::is_specialized);
00136
00137 BOOST_STATIC_ASSERT(is_integer);
00138 BOOST_STATIC_ASSERT(is_specialized);
00139 # endif
00140 public:
00141 typedef typename
00142 if_true<(int(x::is_signed)
00143 && (!int(x::is_bounded)
00144
00145 || (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits)))>::template then<
00146 Integer,
00147
00148 typename if_true<(int(x::digits) + 1 < digit_traits<signed int>::digits)>::template then<
00149 signed int,
00150
00151 typename if_true<(int(x::digits) + 1 < digit_traits<signed long>::digits)>::template then<
00152 signed long,
00153
00154
00155 intmax_t
00156 >::type>::type>::type difference_type;
00157 #else
00158 BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
00159
00160 typedef typename
00161 if_true<(sizeof(Integer) >= sizeof(intmax_t))>::template then<
00162
00163 typename if_true<(is_signed<Integer>::value)>::template then<
00164 Integer,
00165 intmax_t
00166 >::type,
00167
00168 typename if_true<(sizeof(Integer) < sizeof(std::ptrdiff_t))>::template then<
00169 std::ptrdiff_t,
00170 intmax_t
00171 >::type
00172 >::type difference_type;
00173 # endif
00174 };
00175
00176
00177 template <class Number>
00178 struct numeric_traits
00179 {
00180 typedef typename integer_traits<Number>::difference_type difference_type;
00181 };
00182
00183 template <class Number>
00184 typename numeric_traits<Number>::difference_type numeric_distance(Number x, Number y)
00185 {
00186 typedef typename numeric_traits<Number>::difference_type difference_type;
00187 return difference_type(y) - difference_type(x);
00188 }
00189 }}
00190
00191 #endif // BOOST_NUMERIC_TRAITS_HPP_DWA20001901