From ddb6a13f29da4d994fa0d078a2d5e29f2f16e560 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 18:51:33 +0000 Subject: [PATCH] Add support for long long throughout. Fixes #653. [SVN r57873] --- include/boost/integer.hpp | 70 ++++++++++++++++++++++++++++------- include/boost/integer_fwd.hpp | 18 +++++++-- test/integer_test.cpp | 2 +- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index dc57dff..b39e300 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -19,6 +19,7 @@ #include // for boost::integer_traits #include // for std::numeric_limits +#include // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T namespace boost { @@ -36,14 +37,20 @@ namespace boost // specializatons: 1=long, 2=int, 3=short, 4=signed char, // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char // no specializations for 0 and 5: requests for a type > long are in error - template<> struct int_least_helper<1> { typedef long least; }; - template<> struct int_least_helper<2> { typedef int least; }; - template<> struct int_least_helper<3> { typedef short least; }; - template<> struct int_least_helper<4> { typedef signed char least; }; - template<> struct int_least_helper<6> { typedef unsigned long least; }; - template<> struct int_least_helper<7> { typedef unsigned int least; }; - template<> struct int_least_helper<8> { typedef unsigned short least; }; - template<> struct int_least_helper<9> { typedef unsigned char least; }; +#ifdef BOOST_HAS_LONG_LONG + template<> struct int_least_helper<1> { typedef boost::long_long_type least; }; +#endif + template<> struct int_least_helper<2> { typedef long least; }; + template<> struct int_least_helper<3> { typedef int least; }; + template<> struct int_least_helper<4> { typedef short least; }; + template<> struct int_least_helper<5> { typedef signed char least; }; +#ifdef BOOST_HAS_LONG_LONG + template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; }; +#endif + template<> struct int_least_helper<7> { typedef unsigned long least; }; + template<> struct int_least_helper<8> { typedef unsigned int least; }; + template<> struct int_least_helper<9> { typedef unsigned short least; }; + template<> struct int_least_helper<10> { typedef unsigned char least; }; // integer templates specifying number of bits ---------------------------// @@ -53,6 +60,11 @@ namespace boost { typedef typename int_least_helper < +#ifdef BOOST_HAS_LONG_LONG + (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) + +#else + 1 + +#endif (Bits-1 <= std::numeric_limits::digits) + (Bits-1 <= std::numeric_limits::digits) + (Bits-1 <= std::numeric_limits::digits) + @@ -68,6 +80,11 @@ namespace boost typedef typename int_least_helper < 5 + +#ifdef BOOST_HAS_LONG_LONG + (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) + +#else + 1 + +#endif (Bits <= std::numeric_limits::digits) + (Bits <= std::numeric_limits::digits) + (Bits <= std::numeric_limits::digits) + @@ -80,11 +97,20 @@ namespace boost // integer templates specifying extreme value ----------------------------// // signed +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MaxValue > // maximum value to require support +#else template< long MaxValue > // maximum value to require support +#endif struct int_max_value_t { typedef typename int_least_helper < +#ifdef BOOST_HAS_LONG_LONG + (MaxValue <= integer_traits::const_max) + +#else + 1 + +#endif (MaxValue <= integer_traits::const_max) + (MaxValue <= integer_traits::const_max) + (MaxValue <= integer_traits::const_max) + @@ -93,11 +119,20 @@ namespace boost typedef typename int_fast_t::fast fast; }; +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MinValue > // minimum value to require support +#else template< long MinValue > // minimum value to require support +#endif struct int_min_value_t { typedef typename int_least_helper < +#ifdef BOOST_HAS_LONG_LONG + (MinValue >= integer_traits::const_min) + +#else + 1 + +#endif (MinValue >= integer_traits::const_min) + (MinValue >= integer_traits::const_min) + (MinValue >= integer_traits::const_min) + @@ -107,16 +142,25 @@ namespace boost }; // unsigned - template< unsigned long Value > // maximum value to require support +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::ulong_long_type MaxValue > // minimum value to require support +#else + template< long MaxValue > // minimum value to require support +#endif struct uint_value_t { typedef typename int_least_helper < 5 + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) +#ifdef BOOST_HAS_LONG_LONG + (MaxValue <= integer_traits::const_max) + +#else + 1 + +#endif + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) >::least least; typedef typename int_fast_t::fast fast; }; diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index ae3d0f1..cd213b6 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -85,13 +85,25 @@ template< int Bits > template< int Bits > struct uint_t; -template< long MaxValue > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MaxValue > // maximum value to require support +#else + template< long MaxValue > // maximum value to require support +#endif struct int_max_value_t; -template< long MinValue > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MinValue > // minimum value to require support +#else + template< long MinValue > // minimum value to require support +#endif struct int_min_value_t; -template< unsigned long Value > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::ulong_long_type MaxValue > // maximum value to require support +#else + template< long MaxValue > // maximum value to require support +#endif struct uint_value_t; diff --git a/test/integer_test.cpp b/test/integer_test.cpp index ba6a4bb..c6c3e8a 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -134,7 +134,7 @@ namespace boost // Test if a constant can fit within a certain type #define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value ) -#if ULONG_MAX > 0xFFFFFFFFL +#if (ULONG_MAX > 0xFFFFFFFFL) || !defined(BOOST_NO_INTEGRAL_INT64_T) #define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \ PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \