File indexing completed on 2025-01-18 09:30:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 #ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
0059 #define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
0060
0061 #include <cstddef>
0062 #include <boost/config.hpp>
0063 #include <boost/limits.hpp>
0064 #include <boost/cstdint.hpp>
0065 #include <boost/type_traits/is_signed.hpp>
0066 #include <boost/type_traits/conditional.hpp>
0067 #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
0068 #include <boost/static_assert.hpp>
0069 #include <boost/type_traits/is_integral.hpp>
0070 #endif
0071
0072 namespace boost { namespace detail {
0073
0074 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
0075
0076
0077
0078 template <class T, bool IsSpecialized = std::numeric_limits<T>::is_specialized>
0079 struct digit_traits
0080 {
0081 BOOST_STATIC_CONSTANT(int, digits = std::numeric_limits<T>::digits);
0082 };
0083
0084
0085 template <class T>
0086 struct digit_traits<T, false>
0087 {
0088 BOOST_STATIC_CONSTANT(int, digits = (
0089 sizeof(T) * std::numeric_limits<unsigned char>::digits
0090 - (boost::is_signed<T>::value ? 1 : 0))
0091 );
0092 };
0093 #endif
0094
0095
0096
0097
0098 template <class Integer>
0099 struct integer_traits
0100 {
0101 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
0102 private:
0103 typedef Integer integer_type;
0104 typedef std::numeric_limits<integer_type> x;
0105 public:
0106 typedef typename boost::conditional<
0107 (int(x::is_signed)
0108 && (!int(x::is_bounded)
0109
0110 || (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits))),
0111 Integer,
0112
0113 typename boost::conditional<
0114 (int(x::digits) + 1 < digit_traits<signed int>::digits),
0115 signed int,
0116
0117 typename boost::conditional<
0118 (int(x::digits) + 1 < digit_traits<signed long>::digits),
0119 signed long,
0120 boost::intmax_t
0121 >::type
0122 >::type
0123 >::type difference_type;
0124 #else
0125 BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
0126
0127 typedef typename boost::conditional<
0128 (sizeof(Integer) >= sizeof(intmax_t)),
0129
0130 boost::conditional<
0131 (boost::is_signed<Integer>::value),
0132 Integer,
0133 boost::intmax_t
0134 >,
0135
0136 boost::conditional<
0137 (sizeof(Integer) < sizeof(std::ptrdiff_t)),
0138 std::ptrdiff_t,
0139 boost::intmax_t
0140 >
0141 >::type::type difference_type;
0142 #endif
0143 };
0144
0145
0146 template <class Number>
0147 struct numeric_traits
0148 {
0149 typedef typename integer_traits<Number>::difference_type difference_type;
0150 };
0151
0152 template <class Number>
0153 inline BOOST_CONSTEXPR typename numeric_traits<Number>::difference_type numeric_distance(Number x, Number y)
0154 {
0155 typedef typename numeric_traits<Number>::difference_type difference_type;
0156 return difference_type(y) - difference_type(x);
0157 }
0158 }}
0159
0160 #endif