123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
- #define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
- #include <cstddef>
- #include <boost/config.hpp>
- #include <boost/limits.hpp>
- #include <boost/cstdint.hpp>
- #include <boost/type_traits/is_signed.hpp>
- #include <boost/type_traits/conditional.hpp>
- #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
- #include <boost/static_assert.hpp>
- #include <boost/type_traits/is_integral.hpp>
- #endif
- namespace boost { namespace detail {
- #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
-
-
-
- template <class T, bool IsSpecialized = std::numeric_limits<T>::is_specialized>
- struct digit_traits
- {
- BOOST_STATIC_CONSTANT(int, digits = std::numeric_limits<T>::digits);
- };
-
- template <class T>
- struct digit_traits<T, false>
- {
- BOOST_STATIC_CONSTANT(int, digits = (
- sizeof(T) * std::numeric_limits<unsigned char>::digits
- - (boost::is_signed<T>::value ? 1 : 0))
- );
- };
- #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;
- public:
- typedef typename boost::conditional<
- (int(x::is_signed)
- && (!int(x::is_bounded)
-
- || (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits))),
- Integer,
- typename boost::conditional<
- (int(x::digits) + 1 < digit_traits<signed int>::digits),
- signed int,
- typename boost::conditional<
- (int(x::digits) + 1 < digit_traits<signed long>::digits),
- signed long,
- boost::intmax_t
- >::type
- >::type
- >::type difference_type;
- #else
- BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
- typedef typename boost::conditional<
- (sizeof(Integer) >= sizeof(intmax_t)),
- boost::conditional<
- (boost::is_signed<Integer>::value),
- Integer,
- boost::intmax_t
- >,
- boost::conditional<
- (sizeof(Integer) < sizeof(std::ptrdiff_t)),
- std::ptrdiff_t,
- boost::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>
- inline BOOST_CONSTEXPR 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
|