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
5 changed files with 66 additions and 355 deletions

View File

@ -9,216 +9,66 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 23 Sept 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
//
// 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(int8_t(0), INT8_C(0));
integral_constant_type_check(uint8_t(0), UINT8_C(0));
integral_constant_type_check(int16_t(0), INT16_C(0));
integral_constant_type_check(uint16_t(0), UINT16_C(0));
integral_constant_type_check(int32_t(0), INT32_C(0));
integral_constant_type_check(uint32_t(0), UINT32_C(0));
#ifndef BOOST_NO_INT64_T
integral_constant_type_check(int64_t(0), INT64_C(0));
integral_constant_type_check(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 stdint.h not correctly defined
#endif
}

View File

@ -9,20 +9,15 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 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)
//
// this has to go before the include guard (JM):
#include <boost/stdint.h>
// 8 Aug 99 Initial version
#ifndef BOOST_CSTDINT_HPP
#define BOOST_CSTDINT_HPP
#include <limits.h> // implementation artifact; not part of interface
#include <boost/stdint.h>
namespace boost
{
@ -48,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;
@ -57,7 +52,7 @@ namespace boost
using ::uint_least64_t;
using ::uint_fast64_t;
#endif
# endif
using ::intmax_t;
using ::uintmax_t;
@ -65,4 +60,4 @@ namespace boost
} // namespace boost
#endif

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,14 +8,11 @@
// 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.
// Revision History
// 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
@ -27,15 +24,16 @@
#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 -------------------------------------------------------------//
@ -47,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 ------------------------------------------------------------//
@ -60,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 ------------------------------------------------------------//
@ -80,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;
@ -98,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
@ -112,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_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

@ -173,4 +173,4 @@ int main()
std::cout << 0 << ' '; test( uint_t<0>::fast() );
return 0;
}
}

View File

@ -20,13 +20,14 @@
#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:
@ -70,11 +71,11 @@ int main()
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_long());
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
//
// MS/Borland compilers can't support 64-bit member constants
runtest("int64_t (possibly long long)", boost::int64_t());
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
#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.