mirror of
https://github.com/boostorg/integer.git
synced 2025-07-30 20:57:13 +02:00
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
#include <boost/integer_fwd.hpp> // self include
|
||||||
|
|
||||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
#include <boost/::boost::integer_traits.hpp> // for boost::::boost::integer_traits
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
#include <boost/limits.hpp> // for ::std::numeric_limits
|
||||||
#include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
|
#include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@ -31,6 +31,8 @@ namespace boost
|
|||||||
template< typename LeastInt >
|
template< typename LeastInt >
|
||||||
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
|
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
|
||||||
|
|
||||||
|
namespace detail{
|
||||||
|
|
||||||
// convert category to type
|
// convert category to type
|
||||||
template< int Category > struct int_least_helper {}; // default is empty
|
template< int Category > struct int_least_helper {}; // default is empty
|
||||||
|
|
||||||
@ -52,23 +54,25 @@ namespace boost
|
|||||||
template<> struct int_least_helper<9> { typedef unsigned short least; };
|
template<> struct int_least_helper<9> { typedef unsigned short least; };
|
||||||
template<> struct int_least_helper<10> { typedef unsigned char least; };
|
template<> struct int_least_helper<10> { typedef unsigned char least; };
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
// integer templates specifying number of bits ---------------------------//
|
// integer templates specifying number of bits ---------------------------//
|
||||||
|
|
||||||
// signed
|
// signed
|
||||||
template< int Bits > // bits (including sign) required
|
template< int Bits > // bits (including sign) required
|
||||||
struct int_t
|
struct int_t
|
||||||
{
|
{
|
||||||
typedef typename int_least_helper
|
typedef typename detail::int_least_helper
|
||||||
<
|
<
|
||||||
#ifdef BOOST_HAS_LONG_LONG
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
(Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
(Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
||||||
#else
|
#else
|
||||||
1 +
|
1 +
|
||||||
#endif
|
#endif
|
||||||
(Bits-1 <= std::numeric_limits<long>::digits) +
|
(Bits-1 <= ::std::numeric_limits<long>::digits) +
|
||||||
(Bits-1 <= std::numeric_limits<int>::digits) +
|
(Bits-1 <= ::std::numeric_limits<int>::digits) +
|
||||||
(Bits-1 <= std::numeric_limits<short>::digits) +
|
(Bits-1 <= ::std::numeric_limits<short>::digits) +
|
||||||
(Bits-1 <= std::numeric_limits<signed char>::digits)
|
(Bits-1 <= ::std::numeric_limits<signed char>::digits)
|
||||||
>::least least;
|
>::least least;
|
||||||
typedef typename int_fast_t<least>::fast fast;
|
typedef typename int_fast_t<least>::fast fast;
|
||||||
};
|
};
|
||||||
@ -77,7 +81,7 @@ namespace boost
|
|||||||
template< int Bits > // bits required
|
template< int Bits > // bits required
|
||||||
struct uint_t
|
struct uint_t
|
||||||
{
|
{
|
||||||
typedef typename int_least_helper
|
typedef typename detail::int_least_helper
|
||||||
<
|
<
|
||||||
5 +
|
5 +
|
||||||
#ifdef BOOST_HAS_LONG_LONG
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
@ -85,10 +89,10 @@ namespace boost
|
|||||||
#else
|
#else
|
||||||
1 +
|
1 +
|
||||||
#endif
|
#endif
|
||||||
(Bits <= std::numeric_limits<unsigned long>::digits) +
|
(Bits <= ::std::numeric_limits<unsigned long>::digits) +
|
||||||
(Bits <= std::numeric_limits<unsigned int>::digits) +
|
(Bits <= ::std::numeric_limits<unsigned int>::digits) +
|
||||||
(Bits <= std::numeric_limits<unsigned short>::digits) +
|
(Bits <= ::std::numeric_limits<unsigned short>::digits) +
|
||||||
(Bits <= std::numeric_limits<unsigned char>::digits)
|
(Bits <= ::std::numeric_limits<unsigned char>::digits)
|
||||||
>::least least;
|
>::least least;
|
||||||
typedef typename int_fast_t<least>::fast fast;
|
typedef typename int_fast_t<least>::fast fast;
|
||||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||||
@ -104,17 +108,17 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
struct int_max_value_t
|
struct int_max_value_t
|
||||||
{
|
{
|
||||||
typedef typename int_least_helper
|
typedef typename detail::int_least_helper
|
||||||
<
|
<
|
||||||
#ifdef BOOST_HAS_LONG_LONG
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
(MaxValue <= integer_traits<boost::long_long_type>::const_max) +
|
(MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +
|
||||||
#else
|
#else
|
||||||
1 +
|
1 +
|
||||||
#endif
|
#endif
|
||||||
(MaxValue <= integer_traits<long>::const_max) +
|
(MaxValue <= ::boost::integer_traits<long>::const_max) +
|
||||||
(MaxValue <= integer_traits<int>::const_max) +
|
(MaxValue <= ::boost::integer_traits<int>::const_max) +
|
||||||
(MaxValue <= integer_traits<short>::const_max) +
|
(MaxValue <= ::boost::integer_traits<short>::const_max) +
|
||||||
(MaxValue <= integer_traits<signed char>::const_max)
|
(MaxValue <= ::boost::integer_traits<signed char>::const_max)
|
||||||
>::least least;
|
>::least least;
|
||||||
typedef typename int_fast_t<least>::fast fast;
|
typedef typename int_fast_t<least>::fast fast;
|
||||||
};
|
};
|
||||||
@ -126,17 +130,17 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
struct int_min_value_t
|
struct int_min_value_t
|
||||||
{
|
{
|
||||||
typedef typename int_least_helper
|
typedef typename detail::int_least_helper
|
||||||
<
|
<
|
||||||
#ifdef BOOST_HAS_LONG_LONG
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
(MinValue >= integer_traits<boost::long_long_type>::const_min) +
|
(MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +
|
||||||
#else
|
#else
|
||||||
1 +
|
1 +
|
||||||
#endif
|
#endif
|
||||||
(MinValue >= integer_traits<long>::const_min) +
|
(MinValue >= ::boost::integer_traits<long>::const_min) +
|
||||||
(MinValue >= integer_traits<int>::const_min) +
|
(MinValue >= ::boost::integer_traits<int>::const_min) +
|
||||||
(MinValue >= integer_traits<short>::const_min) +
|
(MinValue >= ::boost::integer_traits<short>::const_min) +
|
||||||
(MinValue >= integer_traits<signed char>::const_min)
|
(MinValue >= ::boost::integer_traits<signed char>::const_min)
|
||||||
>::least least;
|
>::least least;
|
||||||
typedef typename int_fast_t<least>::fast fast;
|
typedef typename int_fast_t<least>::fast fast;
|
||||||
};
|
};
|
||||||
@ -149,18 +153,18 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
struct uint_value_t
|
struct uint_value_t
|
||||||
{
|
{
|
||||||
typedef typename int_least_helper
|
typedef typename detail::int_least_helper
|
||||||
<
|
<
|
||||||
5 +
|
5 +
|
||||||
#ifdef BOOST_HAS_LONG_LONG
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
(MaxValue <= integer_traits<boost::ulong_long_type>::const_max) +
|
(MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
|
||||||
#else
|
#else
|
||||||
1 +
|
1 +
|
||||||
#endif
|
#endif
|
||||||
(MaxValue <= integer_traits<unsigned long>::const_max) +
|
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
|
||||||
(MaxValue <= integer_traits<unsigned int>::const_max) +
|
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
|
||||||
(MaxValue <= integer_traits<unsigned short>::const_max) +
|
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
|
||||||
(MaxValue <= integer_traits<unsigned char>::const_max)
|
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max)
|
||||||
>::least least;
|
>::least least;
|
||||||
typedef typename int_fast_t<least>::fast fast;
|
typedef typename int_fast_t<least>::fast fast;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user