mirror of
https://github.com/boostorg/integer.git
synced 2025-06-26 20:41:33 +02:00
Compare commits
33 Commits
svn-branch
...
boost-1.21
Author | SHA1 | Date | |
---|---|---|---|
610abfad44 | |||
b519841b7f | |||
d1781f09d2 | |||
c1c099c845 | |||
f4c38bdf51 | |||
53005cadc8 | |||
ea4963031a | |||
873879d5ac | |||
d39c7cd327 | |||
37eb749c49 | |||
8084359fda | |||
f544a58f58 | |||
d2c2e49154 | |||
50bd08d542 | |||
b5b41c73db | |||
a22a9a3d80 | |||
21ee723419 | |||
202890e032 | |||
4b2fcb5c36 | |||
35dbbde437 | |||
3f58452fa9 | |||
017c095cad | |||
c3d2838f55 | |||
6425892b75 | |||
99eff7e1bb | |||
d0b9d43e9b | |||
79accb0546 | |||
0b55c0ecfd | |||
76fcc1f65e | |||
70edfde847 | |||
34f4037317 | |||
a7bd4493ce | |||
6a093cf955 |
@ -12,11 +12,10 @@
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
|
||||
boost/cstdint.hpp </h1>
|
||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||
places the contents of the header <code><a href="../../boost/stdint.h"><boost/stdint.h></a></code>
|
||||
in namespace boost. That header consists entirely of typedef's useful for
|
||||
writing portable code that requires certain integer widths.</p>
|
||||
provides the typedef's useful for
|
||||
writing portable code that requires certain integer widths. All typedef's are in namespace boost.</p>
|
||||
<p>The specifications are based on the ISO/IEC 9899:1999 C Language standard
|
||||
header stdint.h. The 64-bit types required by the C standard are not
|
||||
header <stdint.h>. The 64-bit types required by the C standard are not
|
||||
required in the boost header, and may not be supplied in all implementations,
|
||||
because <code>long long</code> is not [yet] included in the C++ standard.</p>
|
||||
<p>See <a href="cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
@ -70,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 -->29 Jun 2000<!--webbot bot="Timestamp" endspan i-checksum="15060" -->
|
||||
<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>
|
||||
|
||||
|
227
cstdint_test.cpp
227
cstdint_test.cpp
@ -9,66 +9,219 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||
// 28 Jun 00 Initial version
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <boost/cstdint.hpp>
|
||||
//
|
||||
// macros should not be defined by default:
|
||||
//
|
||||
#ifdef INT8_C
|
||||
#error header incorrectly implemented
|
||||
#endif
|
||||
//
|
||||
// now define the macros:
|
||||
//
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
// the following class is designed to verify
|
||||
// that the various INTXX_C macros can be used
|
||||
// in integral constant expressions:
|
||||
//
|
||||
struct integral_constant_checker
|
||||
{
|
||||
static const boost::int8_t int8 = INT8_C(-127);
|
||||
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
static const boost::int16_t int16 = INT16_C(-32767);
|
||||
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
static void check();
|
||||
};
|
||||
|
||||
void integral_constant_checker::check()
|
||||
{
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
}
|
||||
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
//
|
||||
// the following function simply verifies that the type
|
||||
// of an integral constant is correctly defined:
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option -w-8008
|
||||
#pragma option -w-8066
|
||||
#endif
|
||||
template <class T1, class T2>
|
||||
void integral_constant_type_check(T1, T2)
|
||||
{
|
||||
//
|
||||
// the types T1 and T2 may not be exactly
|
||||
// the same type, but they should be the
|
||||
// same size and signedness. We could use
|
||||
// numeric_limits to verify this, but
|
||||
// numeric_limits implementations currently
|
||||
// vary too much, or are incomplete or missing.
|
||||
//
|
||||
assert(sizeof(T1) == sizeof(T2));
|
||||
T1 t1 = -1;
|
||||
T2 t2 = -1;
|
||||
assert(t1 == t2);
|
||||
if(t1 >= 0)
|
||||
assert(t2 >= 0);
|
||||
else
|
||||
assert(t2 < 0);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int8_t int8 = -127;
|
||||
boost::int_least8_t int_least8 = -127;
|
||||
boost::int_fast8_t int_fast8 = -127;
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
integral_constant_checker::check();
|
||||
#endif
|
||||
//
|
||||
// verify the types of the integral constants:
|
||||
//
|
||||
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||
#endif
|
||||
//
|
||||
boost::int8_t int8 = INT8_C(-127);
|
||||
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
boost::uint8_t uint8 = 255;
|
||||
boost::uint_least8_t uint_least8 = 255;
|
||||
boost::uint_fast8_t uint_fast8 = 255;
|
||||
|
||||
boost::int16_t int16 = -32767;
|
||||
boost::int_least16_t int_least16 = -32767;
|
||||
boost::int_fast16_t int_fast16 = -32767;
|
||||
|
||||
boost::uint16_t uint16 = 65535;
|
||||
boost::uint_least16_t uint_least16 = 65535;
|
||||
boost::uint_fast16_t uint_fast16 = 65535;
|
||||
|
||||
boost::int32_t int32 = -2147483647;
|
||||
boost::int_least32_t int_least32 = -2147483647;
|
||||
boost::int_fast32_t int_fast32 = -2147483647;
|
||||
|
||||
boost::uint32_t uint32 = 4294967295;
|
||||
boost::uint_least32_t uint_least32 = 4294967295;
|
||||
boost::uint_fast32_t uint_fast32 = 4294967295;
|
||||
boost::uint8_t uint8 = UINT8_C(255);
|
||||
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
boost::intmax_t intmax = -2147483647;
|
||||
boost::uintmax_t uintmax = 4294967295;
|
||||
boost::int16_t int16 = INT16_C(-32767);
|
||||
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
boost::uint16_t uint16 = UINT16_C(65535);
|
||||
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
boost::int32_t int32 = INT32_C(-2147483647);
|
||||
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||
|
||||
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||
|
||||
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||
#else
|
||||
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||
#endif
|
||||
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255 );
|
||||
assert( uint_least8 == 255 );
|
||||
assert( uint_fast8 == 255 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535 );
|
||||
assert( uint_least16 == 65535 );
|
||||
assert( uint_fast16 == 65535 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295 );
|
||||
assert( uint_least32 == 4294967295 );
|
||||
assert( uint_fast32 == 4294967295 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
assert( int64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_least64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_fast64 == INT64_C(-9223372036854775807) );
|
||||
assert( uint64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_least64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||
assert( intmax == INT64_C(-9223372036854775807) );
|
||||
assert( uintmax == UINT64_C(18446744073709551615) );
|
||||
#else
|
||||
assert( intmax == -2147483647 );
|
||||
assert( uintmax == 4294967295 );
|
||||
assert( uintmax == 4294967295u );
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// now verify that constant macros get undef'ed correctly:
|
||||
//
|
||||
#undef __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef INT8_C
|
||||
#error boost/cstdint.hpp not correctly defined
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
// boost cstdint.hpp header file -------------------------------------------//
|
||||
// boost cstdint.hpp header file ------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
@ -9,15 +9,24 @@
|
||||
// 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).
|
||||
// 22 Sep 00 Better 64-bit support (John Maddock)
|
||||
// 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
|
||||
// 8 Aug 99 Initial version
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
|
||||
|
||||
#ifndef BOOST_CSTDINT_HPP
|
||||
#define BOOST_CSTDINT_HPP
|
||||
|
||||
#include <limits.h> // implementation artifact; not part of interface
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/stdint.h>
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
# include <stdint.h> // implementation artifact; not part of interface
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -43,7 +52,7 @@ namespace boost
|
||||
using ::uint_least32_t;
|
||||
using ::uint_fast32_t;
|
||||
|
||||
# ifdef ULLONG_MAX
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
using ::int64_t;
|
||||
using ::int_least64_t;
|
||||
@ -59,5 +68,234 @@ namespace boost
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#else // BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
typedef signed char int8_t;
|
||||
typedef signed char int_least8_t;
|
||||
typedef signed char int_fast8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
|
||||
# if ULONG_MAX == 0xffffffff
|
||||
typedef long int32_t;
|
||||
typedef long int_least32_t;
|
||||
typedef long int_fast32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# elif UINT_MAX == 0xffffffff
|
||||
typedef int int32_t;
|
||||
typedef int int_least32_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if 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;
|
||||
typedef long long int64_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
typedef long int64_t;
|
||||
typedef long int_least64_t;
|
||||
typedef long int_fast64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
# define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Define various INTXX_C macros only if
|
||||
__STDC_CONSTANT_MACROS is defined.
|
||||
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
# if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
# define INT8_C(value) value##i8
|
||||
# define INT16_C(value) value##i16
|
||||
# define INT32_C(value) value##i32
|
||||
# define INT64_C(value) value##i64
|
||||
# ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type a signed char
|
||||
# define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
# else
|
||||
# define UINT8_C(value) value##ui8
|
||||
# endif
|
||||
# define UINT16_C(value) value##ui16
|
||||
# define UINT32_C(value) value##ui32
|
||||
# define UINT64_C(value) value##ui64
|
||||
# define INTMAX_C(value) value##i64
|
||||
# define UINTMAX_C(value) value##ui64
|
||||
|
||||
# else
|
||||
// do it the old fashioned way:
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
# define INT8_C(value) static_cast<boost::int8_t>(value)
|
||||
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
# define INT16_C(value) static_cast<boost::int16_t>(value)
|
||||
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
# define INT32_C(value) value
|
||||
# define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
# define INT32_C(value) value##L
|
||||
# define UINT32_C(value) value##uL
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if 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)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
# define INT64_C(value) value##L
|
||||
# define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_NO_INT64_T
|
||||
# define INTMAX_C(value) INT32_C(value)
|
||||
# define UINTMAX_C(value) UINT32_C(value)
|
||||
# else
|
||||
# define INTMAX_C(value) INT64_C(value)
|
||||
# define UINTMAX_C(value) UINT64_C(value)
|
||||
# endif
|
||||
|
||||
# endif // Borland/Microsoft specific width suffixes
|
||||
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
# undef INT8_C
|
||||
# undef INT16_C
|
||||
# undef INT32_C
|
||||
# undef INT64_C
|
||||
# undef UINT8_C
|
||||
# undef UINT16_C
|
||||
# undef UINT32_C
|
||||
# undef UINT64_C
|
||||
# undef INTMAX_C
|
||||
# undef UINTMAX_C
|
||||
|
||||
#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
|
||||
{
|
||||
@ -23,6 +24,7 @@ namespace boost
|
||||
// Helper templates ------------------------------------------------------//
|
||||
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
|
||||
|
||||
@ -31,6 +33,7 @@ namespace boost
|
||||
|
||||
// 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; };
|
||||
@ -53,7 +56,7 @@ namespace boost
|
||||
(Bits-1 <= std::numeric_limits<short>::digits) +
|
||||
(Bits-1 <= std::numeric_limits<signed char>::digits)
|
||||
>::least least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
@ -68,7 +71,8 @@ namespace boost
|
||||
(Bits <= std::numeric_limits<unsigned short>::digits) +
|
||||
(Bits <= std::numeric_limits<unsigned char>::digits)
|
||||
>::least least;
|
||||
typedef 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.
|
||||
};
|
||||
|
||||
// The same dispatching technique can be used to select types based on
|
||||
|
@ -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,8 +18,8 @@
|
||||
#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
|
||||
#include <limits.h>
|
||||
@ -140,6 +140,17 @@ 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)
|
||||
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
|
||||
|
@ -1,4 +1,4 @@
|
||||
// boost stdint.h header file ---------------------------------------------//
|
||||
// boost stdint.h header file ---------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
@ -8,11 +8,32 @@
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// NOTE WELL: C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// NOTE WELL: This is an implementation of the ISO C Standard (1999) stdint.h
|
||||
// header. C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// this header.
|
||||
|
||||
// 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
|
||||
// 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
|
||||
// particular if a partly conformant <stdint.h> header is available
|
||||
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
|
||||
//
|
||||
// In order to avoid incompatibilities with ISO C99, this header
|
||||
// should not be used at all, and it may be deleted in the future.
|
||||
// C++ programs which require ISO C99 <stdint.h> functionality are
|
||||
// strongly advised to use <boost/cstdint.hpp> instead, which
|
||||
// provides <stdint.h> names in namespace boost, e.g. boost::int8_t.
|
||||
|
||||
|
||||
// Revision History
|
||||
// 8 Aug 99 Initial version
|
||||
// 12 Nov 00 obsoleted (Jens Maurer)
|
||||
// 23 Sep 00 INTXX_C support added (John Maddock)
|
||||
// 22 Sep 00 64-bit support for Borland & Microsoft compilers (John Maddock)
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
|
||||
#ifndef BOOST_STDINT_H
|
||||
#define BOOST_STDINT_H
|
||||
@ -24,16 +45,15 @@
|
||||
|
||||
#else
|
||||
|
||||
// This is not a complete implementation of the 1999 C Standard stdint.h
|
||||
// header; it doesn't supply various macros which are not advisable for use in
|
||||
// C++ programs.
|
||||
|
||||
#include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation.
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
@ -45,7 +65,7 @@
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
@ -58,7 +78,7 @@
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
@ -78,13 +98,15 @@
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# ifdef ULLONG_MAX
|
||||
# if ULLONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
@ -94,7 +116,7 @@
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
@ -108,12 +130,143 @@
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
#define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Define various INTXX_C macros only if
|
||||
__STDC_CONSTANT_MACROS is defined.
|
||||
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
#define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
#define INT8_C(value) value##i8
|
||||
#define INT16_C(value) value##i16
|
||||
#define INT32_C(value) value##i32
|
||||
#define INT64_C(value) value##i64
|
||||
#ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type
|
||||
// a signed char!!!!
|
||||
#define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
#else
|
||||
#define UINT8_C(value) value##ui8
|
||||
#endif
|
||||
#define UINT16_C(value) value##ui16
|
||||
#define UINT32_C(value) value##ui32
|
||||
#define UINT64_C(value) value##ui64
|
||||
#define INTMAX_C(value) value##i64
|
||||
#define UINTMAX_C(value) value##ui64
|
||||
|
||||
#else
|
||||
// do it the old fashioned way:
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
#define INT8_C(value) static_cast<int8_t>(value)
|
||||
#define UINT8_C(value) static_cast<uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
#define INT16_C(value) static_cast<int16_t>(value)
|
||||
#define UINT16_C(value) static_cast<uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
#define INT32_C(value) value
|
||||
#define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
#define INT32_C(value) value##L
|
||||
#define UINT32_C(value) value##uL
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
#define INT64_C(value) value##LL
|
||||
#define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
#define INT64_C(value) value##L
|
||||
#define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
#define INT64_C(value) value##i64
|
||||
#define UINT64_C(value) value##ui64
|
||||
# endif
|
||||
|
||||
#ifdef BOOST_NO_INT64_T
|
||||
#define INTMAX_C(value) INT32_C(value)
|
||||
#define UINTMAX_C(value) UINT32_C(value)
|
||||
#else
|
||||
#define INTMAX_C(value) INT64_C(value)
|
||||
#define UINTMAX_C(value) UINT64_C(value)
|
||||
#endif
|
||||
|
||||
#endif // Borland/MS specific
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
#undef INT8_C
|
||||
#undef INT16_C
|
||||
#undef INT32_C
|
||||
#undef INT64_C
|
||||
#undef UINT8_C
|
||||
#undef UINT16_C
|
||||
#undef UINT32_C
|
||||
#undef UINT64_C
|
||||
#undef INTMAX_C
|
||||
#undef UINTMAX_C
|
||||
|
||||
#endif // constant macros
|
||||
|
||||
|
||||
|
42
index.htm
42
index.htm
@ -14,8 +14,8 @@
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home </big></font></a></td>
|
||||
<td><a href="../../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ </big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More </big></font></a></td>
|
||||
</tr>
|
||||
@ -34,19 +34,12 @@
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Contents of <code><boost/stdint.h></code> wrapped in namespace boost.</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code> or<code> <boost/stdint.h></code>
|
||||
because the names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/stdint.h"><boost/stdint.h></a></code></td>
|
||||
<td valign="top">Typedefs as defined in the C99 standard header <<code>stdint.h></code>.
|
||||
This implementation #includes the compiler
|
||||
supplied <<code>stdint.h></code>, if present.</td>
|
||||
<td valign="top"> Supplied
|
||||
for use in the implementation of <boost/cstdint.hpp> and to ease transition to the C99 standard.
|
||||
Other uses are not recommended because this header places its names in the global namespace. </td>
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
@ -70,17 +63,16 @@
|
||||
|
||||
<h2>Rationale</h2>
|
||||
<p>The organization of boost integer headers and classes is designed to take
|
||||
advantage of <code><stdint.h></code> types from in the 1999 C standard
|
||||
advantage of <code><stdint.h></code> types from the 1999 C standard
|
||||
without resorting to undefined behavior in terms of
|
||||
the 1998 C++ standard. The header <code><boost/cstdint.hpp></code>
|
||||
makes the standard integer types safely available in namespace boost without placing any names in the
|
||||
global namespace or namespace std. As always, the intension is to complement rather than
|
||||
makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/stdint.h></code> and <code><boost/cstdint.hpp></code>
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/cstdint.hpp></code>
|
||||
will continue to function, but will become redundant and may be safely deprecated.</p>
|
||||
<p>Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions. An
|
||||
exception is <code><boost/stdint.h> </code>which uses a <b> .h</b> extension to indicate its C rather than C++ heritage.</p>
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
|
||||
<h2>Caveat emptor</h2>
|
||||
<p>As an
|
||||
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
@ -88,9 +80,17 @@ visible to users of <boost/cstdint.hpp>. Don't use these macros; the
|
||||
any Boost specified interface.
|
||||
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||
|
||||
<p>
|
||||
As another implementation artifact, certain C
|
||||
<code><stdint.h></code> typedef names may possibly be visible in the
|
||||
global namespace to users of <code><boost/cstdint.hpp></code>.
|
||||
Don't use these names, they are not part of any Boost specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->05 Mar 2000<!--webbot bot="Timestamp" endspan i-checksum="14882" -->
|
||||
<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>
|
||||
|
@ -34,6 +34,7 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
|
||||
<pre>namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||
|
||||
@ -51,6 +52,7 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
};
|
||||
} // namespace boost
|
||||
</pre>
|
||||
|
157
integer_test.cpp
157
integer_test.cpp
@ -9,15 +9,14 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||
// 31 Aug 99 Initial version
|
||||
|
||||
// This program is misnamed in that it is really a demonstration rather than
|
||||
// a test. It doesn't detect failure, so isn't worthy of the name "test".
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
using namespace boost; // not the best practice, but useful for testing
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -37,8 +36,12 @@ namespace boost
|
||||
template<> struct int_fast_t<short> { typedef long fast; };
|
||||
}
|
||||
|
||||
int main()
|
||||
int test_main(int,char**)
|
||||
{
|
||||
using boost::int_t;
|
||||
using boost::uint_t;
|
||||
|
||||
#ifdef BOOST_SHOW_TYPES
|
||||
std::cout << 32 << ' '; test( int_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::least() );
|
||||
@ -170,7 +173,145 @@ int main()
|
||||
std::cout << 3 << ' '; test( uint_t<3>::fast() );
|
||||
std::cout << 2 << ' '; test( uint_t<2>::fast() );
|
||||
std::cout << 1 << ' '; test( uint_t<1>::fast() );
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
#endif
|
||||
|
||||
long v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::least(v) == v );
|
||||
v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::fast(v) == v );
|
||||
unsigned long u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::least(u) == u );
|
||||
u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::fast(u) == u );
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,13 @@
|
||||
#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
|
||||
|
||||
// enable if you have "long long" and the proper macros in <limits.h>
|
||||
#undef HAVE_LONG_LONG
|
||||
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
@ -71,13 +70,15 @@ int main()
|
||||
runtest("long", long());
|
||||
typedef unsigned long unsigned_long;
|
||||
runtest("unsigned long", unsigned_long());
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef long long long_long;
|
||||
runtest("long long", long_long());
|
||||
typedef unsigned long long unsigned_long_long;
|
||||
runtest("unsigned long long", unsigned_long_long());
|
||||
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__) && !defined(__BEOS__)
|
||||
//
|
||||
// MS/Borland compilers can't support 64-bit member constants
|
||||
// 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());
|
||||
#endif
|
||||
// Some compilers don't pay attention to std:3.6.1/5 and issue a
|
||||
// warning here if "return 0;" is omitted.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user