123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
- # define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
- # include <boost/config.hpp>
- # include <boost/cstdint.hpp>
- # include <boost/static_assert.hpp>
- # include <boost/type_traits.hpp>
- # include <boost/detail/select_type.hpp>
- # include <boost/limits.hpp>
- namespace boost { namespace detail {
-
-
-
-
- template <class Number>
- struct is_signed
- {
- #if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_MSVC) && BOOST_MSVC <= 1300
- BOOST_STATIC_CONSTANT(bool, value = (Number(-1) < Number(0)));
- #else
- BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<Number>::is_signed);
- #endif
- };
- # ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
-
-
-
- template <bool is_specialized> struct digit_traits_select;
-
- template <> struct digit_traits_select<true>
- {
- template <class T> struct traits
- {
- BOOST_STATIC_CONSTANT(int, digits = std::numeric_limits<T>::digits);
- };
- };
-
- template <> struct digit_traits_select<false>
- {
- template <class T> struct traits
- {
- BOOST_STATIC_CONSTANT(int, digits = (
- sizeof(T) * std::numeric_limits<unsigned char>::digits
- - (is_signed<T>::value ? 1 : 0))
- );
- };
- };
-
- template <class T> struct digit_traits
- {
- typedef digit_traits_select<
- ::std::numeric_limits<T>::is_specialized> selector;
- typedef typename selector::template traits<T> traits;
- BOOST_STATIC_CONSTANT(int, digits = traits::digits);
- };
- #endif
-
-
-
- template <class Integer>
- struct integer_traits
- {
- # ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- private:
- typedef Integer integer_type;
- typedef std::numeric_limits<integer_type> x;
- # if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
-
-
- BOOST_STATIC_CONSTANT(bool, is_integer = x::is_integer);
- BOOST_STATIC_CONSTANT(bool, is_specialized = x::is_specialized);
-
- BOOST_STATIC_ASSERT(is_integer);
- BOOST_STATIC_ASSERT(is_specialized);
- # endif
- public:
- typedef typename
- if_true<(int(x::is_signed)
- && (!int(x::is_bounded)
- // digits is the number of no-sign bits
- || (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits)))>::template then<
- Integer,
-
- typename if_true<(int(x::digits) + 1 < digit_traits<signed int>::digits)>::template then<
- signed int,
- typename if_true<(int(x::digits) + 1 < digit_traits<signed long>::digits)>::template then<
- signed long,
- // else
- intmax_t
- >::type>::type>::type difference_type;
- #else
- BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
- typedef typename
- if_true<(sizeof(Integer) >= sizeof(intmax_t))>::template then<
-
- typename if_true<(is_signed<Integer>::value)>::template then<
- Integer,
- intmax_t
- >::type,
- typename if_true<(sizeof(Integer) < sizeof(std::ptrdiff_t))>::template then<
- std::ptrdiff_t,
- intmax_t
- >::type
- >::type difference_type;
- # endif
- };
-
- template <class Number>
- struct numeric_traits
- {
- typedef typename integer_traits<Number>::difference_type difference_type;
- };
- template <class Number>
- typename numeric_traits<Number>::difference_type numeric_distance(Number x, Number y)
- {
- typedef typename numeric_traits<Number>::difference_type difference_type;
- return difference_type(y) - difference_type(x);
- }
- }}
- #endif
|