forked from boostorg/integer
Compare commits
23 Commits
boost-1.21
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
b3b5b039f7 | |||
0462a811f6 | |||
c6f3dce91a | |||
3e2b929118 | |||
645f809379 | |||
28ec7fa76c | |||
07505c76f8 | |||
fda46f9780 | |||
125bf3351f | |||
e3702f3abc | |||
c54da75efb | |||
2dd1bee693 | |||
949134726f | |||
b3f587b9f7 | |||
215b4d8ee7 | |||
976c5e6572 | |||
0424bb266e | |||
33abcf7250 | |||
b519841b7f | |||
d1781f09d2 | |||
c1c099c845 | |||
f4c38bdf51 | |||
53005cadc8 |
@ -69,7 +69,7 @@ representing any value of any signed integer type.</p>
|
||||
capable of representing any value of any unsigned integer type.</p>
|
||||
<p>These types are required.</p>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
||||
</p>
|
||||
<p> </p>
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
|
||||
// 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
|
||||
// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
|
||||
// 23 Sep 00 Added INTXX_C macro support (John Maddock).
|
||||
@ -23,9 +24,19 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
|
||||
# include <stdint.h> // implementation artifact; not part of interface
|
||||
// The following #include is an implementation artifact; not part of interface.
|
||||
# ifdef __hpux
|
||||
// HP-UX has a nice <stdint.h> in a non-standard location
|
||||
# include <sys/_inttypes.h>
|
||||
# ifdef __STDC_32_MODE__
|
||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||
# define BOOST_NO_INT64_T
|
||||
# endif
|
||||
# else
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -68,7 +79,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#else // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
@ -133,8 +144,10 @@ namespace boost
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U)
|
||||
# if !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
|
||||
(!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
# if (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
@ -182,7 +195,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#endif // BOOST_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
@ -252,9 +265,11 @@ Added 23rd September (John Maddock).
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
# if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# if (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONG_LONG_MAX) && (defined(__hpux) || ULONG_LONG_MAX == 18446744073709551615U)) || \
|
||||
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
@ -298,3 +313,4 @@ Added 23rd September (John Maddock).
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||
|
||||
|
||||
|
@ -9,13 +9,14 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 28 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_INTEGER_HPP
|
||||
#define BOOST_INTEGER_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
@ -18,11 +18,14 @@
|
||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||
#define BOOST_INTEGER_TRAITS_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
// This is an implementation detail and not part of the interface
|
||||
// These are an implementation detail and not part of the interface
|
||||
#include <limits.h>
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
@ -30,11 +33,7 @@ template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = false;
|
||||
#else
|
||||
enum { is_integral = false };
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = false);
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@ -42,18 +41,20 @@ template<class T, T min_val, T max_val>
|
||||
class integer_traits_base
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = true;
|
||||
static const T const_min = min_val;
|
||||
static const T const_max = max_val;
|
||||
#else
|
||||
enum {
|
||||
is_integral = true,
|
||||
const_min = min_val,
|
||||
const_max = max_val
|
||||
};
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = true);
|
||||
BOOST_STATIC_CONSTANT(T, const_min = min_val);
|
||||
BOOST_STATIC_CONSTANT(T, const_max = max_val);
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
// The definition is required even for integral static constants
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_min;
|
||||
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_max;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<>
|
||||
@ -80,7 +81,25 @@ class integer_traits<unsigned char>
|
||||
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
|
||||
{ };
|
||||
|
||||
// What about wchar_t ?
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template<>
|
||||
class integer_traits<wchar_t>
|
||||
: public std::numeric_limits<wchar_t>,
|
||||
#if defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
||||
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
||||
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
||||
#elif defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)
|
||||
// SGI MIPSpro with native library doesn't have them, either
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && !defined(__SGI_STL_PORT)
|
||||
// GCC 2.95.2 doesn't have them on HP-UX, either
|
||||
// (also, std::numeric_limits<wchar_t> appears to return the wrong values)
|
||||
public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
|
||||
#else
|
||||
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
||||
#endif
|
||||
{ };
|
||||
#endif // BOOST_NO_INTRINSIC_WCHAR_T
|
||||
|
||||
template<>
|
||||
class integer_traits<short>
|
||||
@ -140,8 +159,20 @@ class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
|
||||
{ };
|
||||
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
|
||||
{ };
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
|
||||
{ };
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
@ -14,11 +14,11 @@
|
||||
|
||||
// NOTE OF OBSOLESCENCE: In general, this header file cannot detect
|
||||
// whether the current translation unit somewhere includes ISO C99
|
||||
// <stdint.h> or not. For example, in case BOOST_SYSTEM_HAS_STDINT_H
|
||||
// <stdint.h> or not. For example, in case BOOST_HAS_STDINT_H
|
||||
// is not defined and ISO C99 <stdint.h> has been included before,
|
||||
// this file will re-define ISO C99 reserved file-scope identifiers
|
||||
// such as int8_t (see ISO C99 7.1.3 and 7.18). Defining the macro
|
||||
// BOOST_SYSTEM_HAS_STDINT_H is not sufficient in general, in
|
||||
// BOOST_HAS_STDINT_H is not sufficient in general, in
|
||||
// particular if a partly conformant <stdint.h> header is available
|
||||
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
|
||||
//
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
#include <stdint.h>
|
||||
|
||||
#else
|
||||
@ -150,7 +150,7 @@
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
||||
|
||||
/****************************************************
|
||||
|
@ -90,7 +90,7 @@ instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without free provided that the above copyright notice
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
@ -18,15 +18,12 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/integer_traits.hpp>
|
||||
// use int64_t instead of long long for better portability
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test relies on assert() and thus makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
@ -46,14 +43,14 @@ void runtest(const char * type, T)
|
||||
<< "; min is " << traits::min()
|
||||
<< ", max is " << traits::max()
|
||||
<< std::endl;
|
||||
assert(traits::is_specialized);
|
||||
assert(traits::is_integer);
|
||||
assert(traits::is_integral);
|
||||
assert(traits::const_min == traits::min());
|
||||
assert(traits::const_max == traits::max());
|
||||
BOOST_TEST(traits::is_specialized);
|
||||
BOOST_TEST(traits::is_integer);
|
||||
BOOST_TEST(traits::is_integral);
|
||||
BOOST_TEST(traits::const_min == traits::min());
|
||||
BOOST_TEST(traits::const_max == traits::max());
|
||||
}
|
||||
|
||||
int main()
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
runtest("bool", bool());
|
||||
runtest("char", char());
|
||||
@ -61,6 +58,7 @@ int main()
|
||||
runtest("signed char", signed_char());
|
||||
typedef unsigned char unsigned_char;
|
||||
runtest("unsigned char", unsigned_char());
|
||||
runtest("wchar_t", wchar_t());
|
||||
runtest("short", short());
|
||||
typedef unsigned short unsigned_short;
|
||||
runtest("unsigned short", unsigned_short());
|
||||
@ -76,6 +74,8 @@ int main()
|
||||
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
||||
runtest("int64_t (possibly long long)", boost::int64_t());
|
||||
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
|
||||
#else
|
||||
std::cout << "Skipped int64_t and uint64_t" << std::endl;
|
||||
#endif
|
||||
// Some compilers don't pay attention to std:3.6.1/5 and issue a
|
||||
// warning here if "return 0;" is omitted.
|
||||
|
Reference in New Issue
Block a user