Compare commits

..

1 Commits

Author SHA1 Message Date
f4d0cf99ad This commit was manufactured by cvs2svn to create branch 'regex-sub'.
[SVN r7754]
2000-09-21 03:34:33 +00:00
10 changed files with 138 additions and 875 deletions

View File

@ -12,10 +12,11 @@
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
boost/cstdint.hpp&nbsp;</h1>
<p>The header <code><a href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;</a></code>
provides the typedef's useful for
writing portable code that requires certain integer widths. All typedef's are in namespace boost.</p>
places the contents of the header <code><a href="../../boost/stdint.h">&lt;boost/stdint.h&gt;</a></code>
in namespace boost.&nbsp; That header consists entirely of typedef's useful for
writing portable code that requires certain integer widths.</p>
<p>The specifications are based on the ISO/IEC 9899:1999 C Language standard
header &lt;stdint.h&gt;.&nbsp; The 64-bit types required by the C standard are not
header stdint.h.&nbsp; 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>
@ -69,7 +70,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 -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
<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>
<p>&nbsp;</p>

View File

@ -9,219 +9,66 @@
// 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()
{
#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::int8_t int8 = -127;
boost::int_least8_t int_least8 = -127;
boost::int_fast8_t int_fast8 = -127;
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::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::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
boost::intmax_t intmax = -2147483647;
boost::uintmax_t uintmax = 4294967295;
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( uint8 == 255 );
assert( uint_least8 == 255 );
assert( uint_fast8 == 255 );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( uint16 == 65535 );
assert( uint_least16 == 65535 );
assert( uint_fast16 == 65535 );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
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( uint32 == 4294967295 );
assert( uint_least32 == 4294967295 );
assert( uint_fast32 == 4294967295 );
assert( intmax == -2147483647 );
assert( uintmax == 4294967295u );
#endif
assert( uintmax == 4294967295 );
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
}

View File

@ -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,34 +9,15 @@
// 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 (Beman Dawes)
// 8 Aug 99 Initial version
#ifndef BOOST_CSTDINT_HPP
#define BOOST_CSTDINT_HPP
#include <boost/config.hpp>
#include <limits.h> // implementation artifact; not part of interface
#ifdef BOOST_HAS_STDINT_H
// 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
#include <boost/stdint.h>
namespace boost
{
@ -62,7 +43,7 @@ namespace boost
using ::uint_least32_t;
using ::uint_fast32_t;
# ifndef BOOST_NO_INT64_T
# ifdef ULLONG_MAX
using ::int64_t;
using ::int_least64_t;
@ -78,239 +59,5 @@ namespace boost
} // namespace boost
#else // BOOST_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(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;
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_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)
// 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
# 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.
#endif

View File

@ -9,14 +9,13 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
// 28 Aug 99 Initial version
#ifndef BOOST_INTEGER_HPP
#define BOOST_INTEGER_HPP
#include <boost/limits.hpp>
#include <limits>
namespace boost
{
@ -24,7 +23,6 @@ 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
@ -33,7 +31,6 @@ 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; };
@ -56,7 +53,7 @@ namespace boost
(Bits-1 <= std::numeric_limits<short>::digits) +
(Bits-1 <= std::numeric_limits<signed char>::digits)
>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef int_fast_t<least>::fast fast;
};
// unsigned
@ -71,8 +68,7 @@ namespace boost
(Bits <= std::numeric_limits<unsigned short>::digits) +
(Bits <= std::numeric_limits<unsigned char>::digits)
>::least least;
typedef typename int_fast_t<least>::fast fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
typedef int_fast_t<least>::fast fast;
};
// The same dispatching technique can be used to select types based on

View File

@ -2,7 +2,7 @@
*
* Copyright Jens Maurer 2000
* Permission to use, copy, modify, sell, and distribute this software
* is hereby granted without fee provided that the above copyright notice
* is hereby granted without free 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,14 +18,11 @@
#ifndef BOOST_INTEGER_TRAITS_HPP
#define BOOST_INTEGER_TRAITS_HPP
#include <limits>
#include <boost/config.hpp>
#include <boost/limits.hpp>
// These are an implementation detail and not part of the interface
// This is an implementation detail and not part of the interface
#include <limits.h>
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
#include <wchar.h>
#endif
namespace boost {
@ -33,7 +30,11 @@ template<class T>
class integer_traits : public std::numeric_limits<T>
{
public:
BOOST_STATIC_CONSTANT(bool, is_integral = false);
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
static const bool is_integral = false;
#else
enum { is_integral = false };
#endif
};
namespace detail {
@ -41,20 +42,18 @@ template<class T, T min_val, T max_val>
class integer_traits_base
{
public:
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;
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
};
} // namespace detail
template<>
@ -81,25 +80,7 @@ class integer_traits<unsigned char>
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
{ };
#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
// What about wchar_t ?
template<>
class integer_traits<short>
@ -159,20 +140,8 @@ 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 */

View File

@ -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,52 +8,32 @@
// See http://www.boost.org for most recent version including documentation.
// 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
// NOTE WELL: 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_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_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
// 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)
// 8 Aug 99 Initial version
#ifndef BOOST_STDINT_H
#define BOOST_STDINT_H
#include <boost/config.hpp>
#ifdef BOOST_HAS_STDINT_H
#ifdef BOOST_SYSTEM_HAS_STDINT_H
#include <stdint.h>
#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. 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.
// it may be possible to hand tailor a more efficient implementation.
// 8-bit types -------------------------------------------------------------//
@ -65,7 +45,7 @@
typedef unsigned char uint_least8_t;
typedef unsigned char uint_fast8_t;
# else
# error defaults not correct; you must hand modify boost/stdint.h
# error defaults not correct; you must hand modify boost/stdint.hpp
# endif
// 16-bit types ------------------------------------------------------------//
@ -78,7 +58,7 @@
typedef unsigned short uint_least16_t;
typedef unsigned short uint_fast16_t;
# else
# error defaults not correct; you must hand modify boost/stdint.h
# error defaults not correct; you must hand modify boost/stdint.hpp
# endif
// 32-bit types ------------------------------------------------------------//
@ -98,15 +78,13 @@
typedef unsigned long uint_least32_t;
typedef unsigned long uint_fast32_t;
# else
# error defaults not correct; you must hand modify boost/stdint.h
# error defaults not correct; you must hand modify boost/stdint.hpp
# 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)
// 2**64 - 1
# ifdef ULLONG_MAX
# if ULLONG_MAX == 18446744073709551615 // 2**64 - 1
typedef long long intmax_t;
typedef unsigned long long uintmax_t;
typedef long long int64_t;
@ -116,7 +94,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.h
# error defaults not correct; you must hand modify boost/stdint.hpp
# endif
# elif ULONG_MAX != 0xffffffff
@ -130,143 +108,12 @@
typedef unsigned long uint_least64_t;
typedef unsigned long uint_fast64_t;
# else
# error defaults not correct; you must hand modify boost/stdint.h
# error defaults not correct; you must hand modify boost/stdint.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
#endif // BOOST_HAS_STDINT_H not defined
#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

View File

@ -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/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.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,12 +34,19 @@
</a></code><a href="cstdint.htm"><br>
documentation</a>
</td>
<td valign="top">Typedef's based on the 1999 C Standard header &lt;<code>stdint.h&gt;</code>, wrapped in namespace boost.
This implementation may #include the compiler
supplied &lt;<code>stdint.h&gt;</code>, if present. </td>
<td valign="top">Contents of <code>&lt;boost/stdint.h&gt;</code> wrapped in namespace boost.</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 &lt;<code>stdint.h&gt;</code>
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
Use in preference to &lt;<code>stdint.h&gt;</code> or<code> &lt;boost/stdint.h&gt;</code>
because the names are safely placed in the boost namespace.</td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/stdint.h">&lt;boost/stdint.h&gt;</a></code></td>
<td valign="top">Typedefs as defined in the C99 standard header &lt;<code>stdint.h&gt;</code>.
This implementation #includes the compiler
supplied &lt;<code>stdint.h&gt;</code>, if present.</td>
<td valign="top"> Supplied
for use in the implementation of &lt;boost/cstdint.hpp&gt; and to ease transition to the C99 standard.
Other uses are not recommended because this header places its names in the global namespace.&nbsp;</td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/integer_traits.hpp">&lt;boost/integer_traits.hpp&gt;</a></code><br>
@ -63,16 +70,17 @@
<h2>Rationale</h2>
<p>The organization of boost integer headers and classes is designed to take
advantage of <code>&lt;stdint.h&gt;</code> types from the 1999 C standard
advantage of <code>&lt;stdint.h&gt;</code> types from in the 1999 C standard
without resorting to undefined behavior in terms of
the 1998 C++ standard.&nbsp; The header <code>&lt;boost/cstdint.hpp&gt;</code>
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
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
compete with the C++ Standard Library.&nbsp; Should some future C++ standard
include <code>&lt;stdint.h&gt;</code> and <code>&lt;cstdint&gt;</code>, then <code>&lt;boost/cstdint.hpp&gt;</code>
include <code>&lt;stdint.h&gt;</code> and <code>&lt;cstdint&gt;</code>, then <code>&lt;boost/stdint.h&gt;</code> and <code>&lt;boost/cstdint.hpp&gt;</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.
conventions rather than C++ Standard Library header naming conventions.&nbsp; An
exception is <code>&lt;boost/stdint.h&gt; </code>which uses a <b> .h</b> extension to indicate its C rather than C++ heritage.</p>
<h2>Caveat emptor</h2>
<p>As an
implementation artifact, certain C &lt;limits.h&gt; macro names may possibly be
@ -80,17 +88,9 @@ visible to users of &lt;boost/cstdint.hpp&gt;.&nbsp; Don't use these macros; the
any Boost specified interface.&nbsp;
Use boost:: integer_traits&lt;&gt; or std::numeric_limits&lt;&gt; instead.</p>
<p>
As another implementation artifact, certain C
<code>&lt;stdint.h&gt;</code> typedef names may possibly be visible in the
global namespace to users of <code>&lt;boost/cstdint.hpp&gt;</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 -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
<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>
</body>

View File

@ -34,7 +34,6 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
<pre>namespace boost
{
// fast integers from least integers
// int_fast_t&lt;&gt; works correctly for unsigned too, in spite of the name.
template&lt; typename LeastInt &gt; // Required: LeastInt is integral type, not bool
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
@ -52,7 +51,6 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
{
typedef <i>implementation-supplied</i> least;
typedef int_fast_t&lt;least&gt;::fast fast;
// int_fast_t&lt;&gt; works correctly for unsigned too, in spite of the name.
};
} // namespace boost
</pre>

View File

@ -9,14 +9,15 @@
// 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>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
using namespace boost; // not the best practice, but useful for testing
namespace
{
@ -36,12 +37,8 @@ namespace boost
template<> struct int_fast_t<short> { typedef long fast; };
}
int test_main(int,char**)
int main()
{
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() );
@ -173,145 +170,7 @@ int test_main(int,char**)
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() );
#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 );
std::cout << 0 << ' '; test( uint_t<0>::fast() );
return 0;
}
}

View File

@ -2,7 +2,7 @@
*
* Copyright Jens Maurer 2000
* Permission to use, copy, modify, sell, and distribute this software
* is hereby granted without fee provided that the above copyright notice
* is hereby granted without free 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,12 +18,16 @@
*/
#include <iostream>
#include <cassert>
#include <boost/integer_traits.hpp>
// use int64_t instead of long long for better portability
#include <boost/cstdint.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.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:
@ -43,14 +47,14 @@ void runtest(const char * type, T)
<< "; min is " << traits::min()
<< ", max is " << traits::max()
<< std::endl;
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());
assert(traits::is_specialized);
assert(traits::is_integer);
assert(traits::is_integral);
assert(traits::const_min == traits::min());
assert(traits::const_max == traits::max());
}
int test_main(int, char*[])
int main()
{
runtest("bool", bool());
runtest("char", char());
@ -58,7 +62,6 @@ int test_main(int, char*[])
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());
@ -68,17 +71,13 @@ int test_main(int, char*[])
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_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());
#else
std::cout << "Skipped int64_t and uint64_t" << std::endl;
#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());
#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;
}