|
Boost : |
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2007-04-14 18:55:37
Dear All,
Searching the list archive reveals several previous discussions of
extending boost::int_t<N> to work with sizes up to 64 bits. These were
all several years ago when there may have been compiler issues that
made this complex. Would it be true to say that today int64_t is
sufficiently widely available that it could be used in integer.hpp?
I have hacked a local copy to work with int64_t. Patch follows. Any comments?
Phil.
--- /usr/include/boost/integer.hpp 2004-08-15 11:13:49.000000000 +0100
+++ integer.hpp 2007-04-14 11:06:11.000000000 +0100
@@ -6,6 +6,8 @@
// See http://www.boost.org/libs/integer for documentation.
+// Hacked by Phil Endecott to add 64 bits
+
// Revision History
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
@@ -15,10 +17,11 @@
#ifndef BOOST_INTEGER_HPP
#define BOOST_INTEGER_HPP
-#include <boost/integer_fwd.hpp> // self include
+#include "./integer_fwd.hpp" // self include
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
+#include <boost/cstdint.hpp>
namespace boost
{
@@ -33,17 +36,19 @@
// convert category to type
template< int Category > struct int_least_helper {}; // default is empty
- // specializatons: 1=long, 2=int, 3=short, 4=signed char,
- // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
- // 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; };
+ // specializatons: 1=int64_t 2=long, 3=int, 4=short, 5=signed char,
+ // 7=uint64_t 8=unsigned long, 9=unsigned int, 10=unsigned
short, 11=unsigned char
+ // no specializations for 0 and 6: requests for a type > 64 bits
are in error
+ template<> struct int_least_helper<1> { typedef int64_t least; };
+ 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; };
+ template<> struct int_least_helper<7> { typedef uint64_t least; };
+ template<> struct int_least_helper<8> { typedef unsigned long least; };
+ template<> struct int_least_helper<9> { typedef unsigned int least; };
+ template<> struct int_least_helper<10>{ typedef unsigned short
least; };
+ template<> struct int_least_helper<11>{ typedef unsigned char least; };
// integer templates specifying number of bits ---------------------------//
@@ -53,6 +58,7 @@
{
typedef typename int_least_helper
<
+ (Bits-1 <= std::numeric_limits<int64_t>::digits) +
(Bits-1 <= std::numeric_limits<long>::digits) +
(Bits-1 <= std::numeric_limits<int>::digits) +
(Bits-1 <= std::numeric_limits<short>::digits) +
@@ -67,8 +73,8 @@
{
typedef typename int_least_helper
<
- 5 +
- (Bits <= std::numeric_limits<unsigned long>::digits) +
+ 6 +
+ (Bits <= std::numeric_limits<uint64_t>::digits) +
(Bits <= std::numeric_limits<unsigned int>::digits) +
(Bits <= std::numeric_limits<unsigned short>::digits) +
(Bits <= std::numeric_limits<unsigned char>::digits)
@@ -80,11 +86,12 @@
// integer templates specifying extreme value ----------------------------//
// signed
- template< long MaxValue > // maximum value to require support
+ template< int64_t MaxValue > // maximum value to require support
struct int_max_value_t
{
typedef typename int_least_helper
<
+ (MaxValue <= integer_traits<int64_t>::const_max) +
(MaxValue <= integer_traits<long>::const_max) +
(MaxValue <= integer_traits<int>::const_max) +
(MaxValue <= integer_traits<short>::const_max) +
@@ -93,11 +100,12 @@
typedef typename int_fast_t<least>::fast fast;
};
- template< long MinValue > // minimum value to require support
+ template< int64_t MinValue > // minimum value to require support
struct int_min_value_t
{
typedef typename int_least_helper
<
+ (MinValue >= integer_traits<int64_t>::const_min) +
(MinValue >= integer_traits<long>::const_min) +
(MinValue >= integer_traits<int>::const_min) +
(MinValue >= integer_traits<short>::const_min) +
@@ -107,12 +115,13 @@
};
// unsigned
- template< unsigned long Value > // maximum value to require support
+ template< uint64_t Value > // maximum value to require support
struct uint_value_t
{
typedef typename int_least_helper
<
- 5 +
+ 6 +
+ (Value <= integer_traits<uint64_t>::const_max) +
(Value <= integer_traits<unsigned long>::const_max) +
(Value <= integer_traits<unsigned int>::const_max) +
(Value <= integer_traits<unsigned short>::const_max) +
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk