mirror of
https://github.com/boostorg/integer.git
synced 2025-06-26 12:31:40 +02:00
Compare commits
1 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
f4d0cf99ad |
79
cstdint.htm
Normal file
79
cstdint.htm
Normal file
@ -0,0 +1,79 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Header boost/cstdint.hpp</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<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>
|
||||
<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
|
||||
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>
|
||||
<h2>Exact-width integer types</h2>
|
||||
<p>The typedef <code>int#_t</code>, with # replaced by the width, designates a
|
||||
signed integer type of exactly # bits; <code>int8_t</code> denotes an 8-bit
|
||||
signed integer type. Similarly, the typedef <code>uint#_t</code>
|
||||
designates and unsigned integer type of exactly # bits.</p>
|
||||
<p>These types are optional. However, if an implementation provides integer
|
||||
types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding
|
||||
typedef names.</p>
|
||||
<h2>Minimum-width integer types</h2>
|
||||
<p>The typedef <code>int_least#_t</code>, with # replaced by the width,
|
||||
designates a signed integer type with a width of at least # bits, such that no
|
||||
signed integer type with lesser size has at least the specified width. Thus, <code>int_least32_t</code>
|
||||
denotes a signed integer type with a width of at least 32 bits. Similarly, the
|
||||
typedef name <code>uint_least#_t</code> designates an unsigned integer type with
|
||||
a width of at least # bits, such that no unsigned integer type with lesser size
|
||||
has at least the specified width.</p>
|
||||
<p>Required minimum-width integer types:</p>
|
||||
<ul>
|
||||
<li><code>int_least8_t</code></li>
|
||||
<li><code>int_least16_t</code></li>
|
||||
<li><code>int_least32_t</code></li>
|
||||
<li><code>uint_least8_t</code></li>
|
||||
<li><code>uint_least16_t</code></li>
|
||||
<li><code>uint_least32_t</code></li>
|
||||
</ul>
|
||||
<p>All other minimum-width integer types are optional.</p>
|
||||
<h2>Fastest minimum-width integer types</h2>
|
||||
<p>The typedef <code>int_fast#_t</code>, with # replaced by the width,
|
||||
designates the fastest signed integer type with a width of at least # bits.
|
||||
Similarly, the typedef name <code>uint_fast#_t</code> designates the fastest
|
||||
unsigned integer type with a width of at least # bits.</p>
|
||||
<p>There is no guarantee that these types are fastest for all purposes. In
|
||||
any case, however, they satisfy the signedness and width requirements.</p>
|
||||
<p>Required fastest minimum-width integer types:</p>
|
||||
<ul>
|
||||
<li><code>int_fast8_t</code></li>
|
||||
<li><code>int_fast16_t</code></li>
|
||||
<li><code>int_fast32_t</code></li>
|
||||
<li><code>uint_fast8_t</code></li>
|
||||
<li><code>uint_fast16_t</code></li>
|
||||
<li><code>uint_fast32_t</code></li>
|
||||
</ul>
|
||||
<p>All other fastest minimum-width integer types are optional.</p>
|
||||
<h2>Greatest-width integer types</h2>
|
||||
<p>The typedef <code>intmax_t </code>designates a signed integer type capable of
|
||||
representing any value of any signed integer type.</p>
|
||||
<p>The typedef <code>uintmax_t</code> designates an unsigned integer type
|
||||
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>
|
||||
<p> </p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
74
cstdint_test.cpp
Normal file
74
cstdint_test.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 2000. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 28 Jun 00 Initial version
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int8_t int8 = -127;
|
||||
boost::int_least8_t int_least8 = -127;
|
||||
boost::int_fast8_t int_fast8 = -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::intmax_t intmax = -2147483647;
|
||||
boost::uintmax_t uintmax = 4294967295;
|
||||
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255 );
|
||||
assert( uint_least8 == 255 );
|
||||
assert( uint_fast8 == 255 );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535 );
|
||||
assert( uint_least16 == 65535 );
|
||||
assert( uint_fast16 == 65535 );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295 );
|
||||
assert( uint_least32 == 4294967295 );
|
||||
assert( uint_fast32 == 4294967295 );
|
||||
assert( intmax == -2147483647 );
|
||||
assert( uintmax == 4294967295 );
|
||||
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
@ -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
|
||||
@ -6,40 +6,18 @@
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
|
||||
// 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 vaguely nice <stdint.h> in a non-standard location
|
||||
# include <inttypes.h>
|
||||
# ifdef __STDC_32_MODE__
|
||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||
# define BOOST_NO_INT64_T
|
||||
# endif
|
||||
# elif defined(__FreeBSD__) || defined(__IBMCPP__)
|
||||
# include <inttypes.h>
|
||||
# else
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#include <boost/stdint.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -65,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;
|
||||
@ -81,324 +59,5 @@ namespace boost
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
|
||||
// FreeBSD has an <inttypes.h> that contains much of what we need
|
||||
# include <inttypes.h>
|
||||
|
||||
namespace boost {
|
||||
|
||||
using ::int8_t;
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int8_t int_fast8_t;
|
||||
using ::uint8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
|
||||
using ::int16_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
using ::uint16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
|
||||
using ::int32_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
using ::uint32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
using ::int64_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
using ::uint64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
# else
|
||||
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
# include <boost/limits.hpp> // 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
|
||||
# if defined(__crayx1)
|
||||
// The Cray X1 has a 16-bit short, however it is not recommend
|
||||
// for use in performance critical code.
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
# else
|
||||
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;
|
||||
# endif
|
||||
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
|
||||
// no 16-bit types on Cray:
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_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_HAS_LONG_LONG) && \
|
||||
!defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
|
||||
(!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
|
||||
// 2**64 - 1
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
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;
|
||||
|
||||
# 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(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
|
||||
__extension__ typedef long long intmax_t;
|
||||
__extension__ typedef unsigned long long uintmax_t;
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef long long int_least64_t;
|
||||
__extension__ typedef long long int_fast64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
__extension__ typedef unsigned long long uint_least64_t;
|
||||
__extension__ typedef unsigned long long uint_fast64_t;
|
||||
# elif defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// we have Borland/Intel/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 2000 (John Maddock).
|
||||
Modified 11th September 2001 to be excluded when
|
||||
BOOST_HAS_STDINT_H is defined (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
|
||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
# if defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// Borland/Intel/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(BOOST_HAS_LONG_LONG) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# 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) && !defined(BOOST_HAS_STDINT_H)
|
||||
//
|
||||
// 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
|
||||
|
@ -1,23 +1,21 @@
|
||||
// boost integer.hpp header file -------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 1999.
|
||||
// See accompanying license for terms and conditions of use.
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||
// 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/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <limits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -25,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
|
||||
|
||||
@ -34,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; };
|
||||
@ -57,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
|
||||
@ -72,55 +68,14 @@ 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;
|
||||
};
|
||||
|
||||
// integer templates specifying extreme value ----------------------------//
|
||||
|
||||
// signed
|
||||
template< long MaxValue > // maximum value to require support
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
(MaxValue <= integer_traits<long>::const_max) +
|
||||
(MaxValue <= integer_traits<int>::const_max) +
|
||||
(MaxValue <= integer_traits<short>::const_max) +
|
||||
(MaxValue <= integer_traits<signed char>::const_max)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< long MinValue > // minimum value to require support
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
(MinValue >= integer_traits<long>::const_min) +
|
||||
(MinValue >= integer_traits<int>::const_min) +
|
||||
(MinValue >= integer_traits<short>::const_min) +
|
||||
(MinValue >= integer_traits<signed char>::const_min)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< unsigned long Value > // maximum value to require support
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
5 +
|
||||
(Value <= integer_traits<unsigned long>::const_max) +
|
||||
(Value <= integer_traits<unsigned int>::const_max) +
|
||||
(Value <= integer_traits<unsigned short>::const_max) +
|
||||
(Value <= integer_traits<unsigned char>::const_max)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
// The same dispatching technique can be used to select types based on
|
||||
// values. That will be added once boost::integer_traits is available.
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INTEGER_HPP
|
||||
|
||||
|
@ -1,93 +0,0 @@
|
||||
// Boost integer/integer_mask.hpp header file ------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or
|
||||
// implied warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
#define BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
#include <boost/integer.hpp> // for boost::uint_t
|
||||
|
||||
#include <climits> // for UCHAR_MAX, etc.
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// Specified single-bit mask class declaration -----------------------------//
|
||||
// (Lowest bit starts counting at 0.)
|
||||
|
||||
template < std::size_t Bit >
|
||||
struct high_bit_mask_t
|
||||
{
|
||||
typedef typename uint_t<(Bit + 1)>::least least;
|
||||
typedef typename uint_t<(Bit + 1)>::fast fast;
|
||||
|
||||
BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
|
||||
BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
|
||||
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
|
||||
|
||||
}; // boost::high_bit_mask_t
|
||||
|
||||
|
||||
// Specified bit-block mask class declaration ------------------------------//
|
||||
// Makes masks for the lowest N bits
|
||||
// (Specializations are needed when N fills up a type.)
|
||||
|
||||
template < std::size_t Bits >
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
typedef typename uint_t<Bits>::least least;
|
||||
typedef typename uint_t<Bits>::fast fast;
|
||||
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
|
||||
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
|
||||
|
||||
}; // boost::low_bits_mask_t
|
||||
|
||||
|
||||
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
|
||||
template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
|
||||
typedef std::numeric_limits<Type> limits_type; \
|
||||
typedef uint_t<limits_type::digits>::least least; \
|
||||
typedef uint_t<limits_type::digits>::fast fast; \
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
|
||||
}
|
||||
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
|
||||
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
|
||||
#endif
|
||||
|
||||
#undef BOOST_LOW_BITS_MASK_SPECIALIZE
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_INTEGER_MASK_HPP
|
@ -1,132 +0,0 @@
|
||||
// -------------- Boost static_log2.hpp header file ----------------------- //
|
||||
//
|
||||
// Copyright (C) 2001 Daryle Walker.
|
||||
// Copyright (C) 2003 Vesa Karvonen.
|
||||
// Copyright (C) 2003 Gennaro Prota.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// ---------------------------------------------------
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
|
||||
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace static_log2_impl {
|
||||
|
||||
// choose_initial_n<>
|
||||
//
|
||||
// Recursively doubles its integer argument, until it
|
||||
// becomes >= of the "width" (C99, 6.2.6.2p4) of
|
||||
// static_log2_argument_type.
|
||||
//
|
||||
// Used to get the maximum power of two less then the width.
|
||||
//
|
||||
// Example: if on your platform argument_type has 48 value
|
||||
// bits it yields n=32.
|
||||
//
|
||||
// It's easy to prove that, starting from such a value
|
||||
// of n, the core algorithm works correctly for any width
|
||||
// of static_log2_argument_type and that recursion always
|
||||
// terminates with x = 1 and n = 0 (see the algorithm's
|
||||
// invariant).
|
||||
|
||||
typedef unsigned long argument_type;
|
||||
typedef int result_type;
|
||||
|
||||
|
||||
template <result_type n>
|
||||
struct choose_initial_n {
|
||||
|
||||
enum { c = (argument_type(1) << n << n) != 0 };
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = !c*n + choose_initial_n<2*c*n>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct choose_initial_n<0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// start computing from n_zero - must be a power of two
|
||||
const result_type n_zero = 16;
|
||||
const result_type initial_n = choose_initial_n<n_zero>::value;
|
||||
|
||||
// static_log2_impl<>
|
||||
//
|
||||
// * Invariant:
|
||||
// 2n
|
||||
// 1 <= x && x < 2 at the start of each recursion
|
||||
// (see also choose_initial_n<>)
|
||||
//
|
||||
// * Type requirements:
|
||||
//
|
||||
// argument_type maybe any unsigned type with at least n_zero + 1
|
||||
// value bits. (Note: If larger types will be standardized -e.g
|
||||
// . unsigned long long- then the argument_type typedef can be
|
||||
// changed without affecting the rest of the code.)
|
||||
//
|
||||
|
||||
template <argument_type x, result_type n = initial_n>
|
||||
struct static_log2_impl {
|
||||
|
||||
enum { c = (x >> n) > 0 }; // x >= 2**n ?
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct static_log2_impl<1, 0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
}
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
// --------------------------------------
|
||||
// static_log2<x>
|
||||
// ----------------------------------------
|
||||
|
||||
typedef detail::static_log2_impl::argument_type static_log2_argument_type;
|
||||
typedef detail::static_log2_impl::result_type static_log2_result_type;
|
||||
|
||||
|
||||
template <static_log2_argument_type x>
|
||||
struct static_log2 {
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
static_log2_result_type,
|
||||
value = detail::static_log2_impl::static_log2_impl<x>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct static_log2<0> { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // include guard
|
@ -1,56 +0,0 @@
|
||||
// Boost integer/static_min_max.hpp header file ----------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright notice
|
||||
// appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability
|
||||
// for any purpose.
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
#define BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// Compile-time extrema class declarations ---------------------------------//
|
||||
// Get the minimum or maximum of two values, signed or unsigned.
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
= (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
= (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
@ -1,154 +0,0 @@
|
||||
// Boost integer_fwd.hpp header file ---------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 2001. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
#ifndef BOOST_INTEGER_FWD_HPP
|
||||
#define BOOST_INTEGER_FWD_HPP
|
||||
|
||||
#include <climits> // for UCHAR_MAX, etc.
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// From <boost/cstdint.hpp> ------------------------------------------------//
|
||||
|
||||
// Only has typedefs or using statements, with #conditionals
|
||||
|
||||
|
||||
// From <boost/integer_traits.hpp> -----------------------------------------//
|
||||
|
||||
template < class T >
|
||||
class integer_traits;
|
||||
|
||||
template < >
|
||||
class integer_traits< bool >;
|
||||
|
||||
template < >
|
||||
class integer_traits< char >;
|
||||
|
||||
template < >
|
||||
class integer_traits< signed char >;
|
||||
|
||||
template < >
|
||||
class integer_traits< unsigned char >;
|
||||
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template < >
|
||||
class integer_traits< wchar_t >;
|
||||
#endif
|
||||
|
||||
template < >
|
||||
class integer_traits< short >;
|
||||
|
||||
template < >
|
||||
class integer_traits< unsigned short >;
|
||||
|
||||
template < >
|
||||
class integer_traits< int >;
|
||||
|
||||
template < >
|
||||
class integer_traits< unsigned int >;
|
||||
|
||||
template < >
|
||||
class integer_traits< long >;
|
||||
|
||||
template < >
|
||||
class integer_traits< unsigned long >;
|
||||
|
||||
#ifdef ULLONG_MAX
|
||||
template < >
|
||||
class integer_traits< long long >;
|
||||
|
||||
template < >
|
||||
class integer_traits< unsigned long long >;
|
||||
#endif
|
||||
|
||||
|
||||
// From <boost/integer.hpp> ------------------------------------------------//
|
||||
|
||||
template < typename LeastInt >
|
||||
struct int_fast_t;
|
||||
|
||||
template< int Bits >
|
||||
struct int_t;
|
||||
|
||||
template< int Bits >
|
||||
struct uint_t;
|
||||
|
||||
template< long MaxValue >
|
||||
struct int_max_value_t;
|
||||
|
||||
template< long MinValue >
|
||||
struct int_min_value_t;
|
||||
|
||||
template< unsigned long Value >
|
||||
struct uint_value_t;
|
||||
|
||||
|
||||
// From <boost/integer/integer_mask.hpp> -----------------------------------//
|
||||
|
||||
template < std::size_t Bit >
|
||||
struct high_bit_mask_t;
|
||||
|
||||
template < std::size_t Bits >
|
||||
struct low_bits_mask_t;
|
||||
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned char>::digits >;
|
||||
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned short>::digits >;
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned int>::digits >;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned long>::digits >;
|
||||
#endif
|
||||
|
||||
|
||||
// From <boost/integer/static_log2.hpp> ------------------------------------//
|
||||
|
||||
template < unsigned long Value >
|
||||
struct static_log2;
|
||||
|
||||
template < >
|
||||
struct static_log2< 0ul >;
|
||||
|
||||
|
||||
// From <boost/integer/static_min_max.hpp> ---------------------------------//
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min;
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max;
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_FWD_HPP
|
@ -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,
|
||||
*
|
||||
@ -15,20 +15,14 @@
|
||||
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
||||
*/
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
|
||||
#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>
|
||||
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
@ -36,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 {
|
||||
@ -44,23 +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
|
||||
// A definition is required even for integral static constants
|
||||
template<class T, T min_val, T max_val>
|
||||
const bool integer_traits_base<T, min_val, max_val>::is_integral;
|
||||
|
||||
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<>
|
||||
@ -87,37 +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(WCHAR_MIN) && defined(WCHAR_MAX)
|
||||
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
||||
#elif 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))\
|
||||
|| (defined __APPLE__)\
|
||||
|| (defined(__OpenBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__NetBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__FreeBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
||||
// - SGI MIPSpro with native library
|
||||
// - gcc 3.x on HP-UX
|
||||
// - Mac OS X with native library
|
||||
// - gcc on FreeBSD, OpenBSD and NetBSD
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
||||
// - gcc 2.95.x on HP-UX
|
||||
// (also, std::numeric_limits<wchar_t> appears to return the wrong values).
|
||||
public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
|
||||
#else
|
||||
#error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
|
||||
#endif
|
||||
{ };
|
||||
#endif // BOOST_NO_INTRINSIC_WCHAR_T
|
||||
// What about wchar_t ?
|
||||
|
||||
template<>
|
||||
class integer_traits<short>
|
||||
@ -155,65 +118,30 @@ class integer_traits<unsigned long>
|
||||
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
||||
{ };
|
||||
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
|
||||
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
#ifdef ULLONG_MAX
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
#elif defined(ULONG_LONG_MAX)
|
||||
template<>
|
||||
class integer_traits<long long> : public std::numeric_limits<long long>, public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>{ };
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>
|
||||
{ };
|
||||
template<>
|
||||
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_HAS_LONG_LONG)
|
||||
|
||||
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>
|
||||
{ };
|
||||
|
||||
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, -_LLONG_MAX - _C2, _LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, _ULLONG_MAX>
|
||||
{ };
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
||||
|
||||
|
119
include/boost/stdint.h
Normal file
119
include/boost/stdint.h
Normal file
@ -0,0 +1,119 @@
|
||||
// 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
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// NOTE WELL: C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// this header.
|
||||
|
||||
// Revision History
|
||||
// 8 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_STDINT_H
|
||||
#define BOOST_STDINT_H
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#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.
|
||||
|
||||
// 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/stdint.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/stdint.hpp
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
|
||||
# if 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;
|
||||
# elif 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;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# 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;
|
||||
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/stdint.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/stdint.hpp
|
||||
# endif
|
||||
# else // assume no 64-bit integers
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
98
index.htm
Normal file
98
index.htm
Normal file
@ -0,0 +1,98 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Boost Integer Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||
<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="../../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>
|
||||
</table>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<td align="center"><b><i>Header / Docs</i></b></td>
|
||||
<td align="center"><b><i>Contents</i></b></td>
|
||||
<td align="center"><b><i>Use</i></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||
</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">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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<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
|
||||
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
|
||||
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>
|
||||
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>
|
||||
<h2>Caveat emptor</h2>
|
||||
<p>As an
|
||||
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
visible to users of <boost/cstdint.hpp>. Don't use these macros; they are not part of
|
||||
any Boost specified interface.
|
||||
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||
|
||||
<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>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
110
integer.htm
Normal file
110
integer.htm
Normal file
@ -0,0 +1,110 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Integer Type Selection Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Integer
|
||||
Type Selection Templates</h1>
|
||||
<p>The <code><a href="../../boost/integer.hpp"><boost/integer.hpp></a></code>
|
||||
type selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility is
|
||||
particularly useful for solving generic programming problems.</p>
|
||||
|
||||
<p>The templates <b>int_t<></b> and <b>uint_t<></b> supply typedefs <b>least</b>
|
||||
and <b>fast</b>. The <b>least</b> type be the smallest type which holds at
|
||||
least the number of bits (including sign) specified. The <b>fast</b> type will
|
||||
be at least as large as the <b>least</b> type, but may possible be larger.
|
||||
There is no guarantee that the <b>fast</b> type will actually be faster than
|
||||
other possible types.</p>
|
||||
|
||||
<h2>Alternative</h2>
|
||||
|
||||
<p>If the number of bits required is known beforehand, it may be more
|
||||
appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>.</p>
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
|
||||
<blockquote>
|
||||
<pre>namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||
|
||||
// signed
|
||||
template< int Bits > // bits (including sign) required, 0-32 valid
|
||||
struct int_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // bits required, 0-32 valid
|
||||
struct uint_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
} // namespace boost
|
||||
</pre>
|
||||
|
||||
</blockquote>
|
||||
<p>[Templates to select type based on maximum value are under development.]
|
||||
</p>
|
||||
|
||||
<h2>Example</h2>
|
||||
|
||||
<blockquote>
|
||||
<pre>#include <boost/integer.hpp>
|
||||
using boost::int_t;
|
||||
|
||||
...
|
||||
int_t<24>::least my_var; </pre>
|
||||
|
||||
</blockquote>
|
||||
<h2>Demonstration Program</h2>
|
||||
|
||||
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a not very
|
||||
smart demonstration of the results from instantiating various <b>int_t<></b>
|
||||
and <b>uint_t<></b> examples.</p>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
|
||||
<p>The rationale for the design of the templates in this header includes:</p>
|
||||
|
||||
<ul>
|
||||
<li>Avoid recursion because of concern about C++'s limited guaranteed
|
||||
recursion depth (17).</li>
|
||||
<li>Avoid macros on general principles.</li>
|
||||
<li>Try to keep the design as simple as possible.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Credits</h2>
|
||||
|
||||
<p>The author of the Boost integer type choosing templates is <a href="../../people/beman_dawes.html">Beman
|
||||
Dawes</a>. He thanks to <a href="../../people/valentin_bonnard.htm"> Valentin Bonnard</a> and
|
||||
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing their designs for similar templates.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised August 31, 1999</p>
|
||||
|
||||
<p><EFBFBD> Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
and distribute this document is granted provided this copyright notice appears in all
|
||||
copies. This document is provided "as is" without express or implied warranty,
|
||||
and with no claim as to its suitability for any purpose.</p>
|
||||
|
||||
<p></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
176
integer_test.cpp
Normal file
176
integer_test.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
// boost integer.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 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
|
||||
|
||||
namespace
|
||||
{
|
||||
void test( long ) { std::cout << "long\n"; }
|
||||
void test( int ) { std::cout << "int\n"; }
|
||||
void test( short ) { std::cout << "short\n"; }
|
||||
void test( signed char ) { std::cout << "signed char\n"; }
|
||||
void test( unsigned long ) { std::cout << "unsigned long\n"; }
|
||||
void test( unsigned int ) { std::cout << "unsigned int\n"; }
|
||||
void test( unsigned short ) { std::cout << "unsigned short\n"; }
|
||||
void test( unsigned char ) { std::cout << "unsigned char\n"; }
|
||||
} // unnamed namespace
|
||||
|
||||
// just to prove it works, specialize int_fast_t<short> to yield long
|
||||
namespace boost
|
||||
{
|
||||
template<> struct int_fast_t<short> { typedef long fast; };
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << 32 << ' '; test( int_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::least() );
|
||||
std::cout << 29 << ' '; test( int_t<29>::least() );
|
||||
std::cout << 28 << ' '; test( int_t<28>::least() );
|
||||
std::cout << 27 << ' '; test( int_t<27>::least() );
|
||||
std::cout << 26 << ' '; test( int_t<26>::least() );
|
||||
std::cout << 25 << ' '; test( int_t<25>::least() );
|
||||
std::cout << 24 << ' '; test( int_t<24>::least() );
|
||||
std::cout << 23 << ' '; test( int_t<23>::least() );
|
||||
std::cout << 22 << ' '; test( int_t<22>::least() );
|
||||
std::cout << 21 << ' '; test( int_t<21>::least() );
|
||||
std::cout << 20 << ' '; test( int_t<20>::least() );
|
||||
std::cout << 19 << ' '; test( int_t<19>::least() );
|
||||
std::cout << 18 << ' '; test( int_t<18>::least() );
|
||||
std::cout << 17 << ' '; test( int_t<17>::least() );
|
||||
std::cout << 16 << ' '; test( int_t<16>::least() );
|
||||
std::cout << 15 << ' '; test( int_t<15>::least() );
|
||||
std::cout << 14 << ' '; test( int_t<14>::least() );
|
||||
std::cout << 13 << ' '; test( int_t<13>::least() );
|
||||
std::cout << 12 << ' '; test( int_t<12>::least() );
|
||||
std::cout << 11 << ' '; test( int_t<11>::least() );
|
||||
std::cout << 10 << ' '; test( int_t<10>::least() );
|
||||
std::cout << 9 << ' '; test( int_t<9>::least() );
|
||||
std::cout << 8 << ' '; test( int_t<8>::least() );
|
||||
std::cout << 7 << ' '; test( int_t<7>::least() );
|
||||
std::cout << 6 << ' '; test( int_t<6>::least() );
|
||||
std::cout << 5 << ' '; test( int_t<5>::least() );
|
||||
std::cout << 4 << ' '; test( int_t<4>::least() );
|
||||
std::cout << 3 << ' '; test( int_t<3>::least() );
|
||||
std::cout << 2 << ' '; test( int_t<2>::least() );
|
||||
std::cout << 1 << ' '; test( int_t<1>::least() );
|
||||
std::cout << 0 << ' '; test( int_t<0>::least() );
|
||||
std::cout << 32 << ' '; test( int_t<32>::fast() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::fast() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::fast() );
|
||||
std::cout << 29 << ' '; test( int_t<29>::fast() );
|
||||
std::cout << 28 << ' '; test( int_t<28>::fast() );
|
||||
std::cout << 27 << ' '; test( int_t<27>::fast() );
|
||||
std::cout << 26 << ' '; test( int_t<26>::fast() );
|
||||
std::cout << 25 << ' '; test( int_t<25>::fast() );
|
||||
std::cout << 24 << ' '; test( int_t<24>::fast() );
|
||||
std::cout << 23 << ' '; test( int_t<23>::fast() );
|
||||
std::cout << 22 << ' '; test( int_t<22>::fast() );
|
||||
std::cout << 21 << ' '; test( int_t<21>::fast() );
|
||||
std::cout << 20 << ' '; test( int_t<20>::fast() );
|
||||
std::cout << 19 << ' '; test( int_t<19>::fast() );
|
||||
std::cout << 18 << ' '; test( int_t<18>::fast() );
|
||||
std::cout << 17 << ' '; test( int_t<17>::fast() );
|
||||
std::cout << 16 << ' '; test( int_t<16>::fast() );
|
||||
std::cout << 15 << ' '; test( int_t<15>::fast() );
|
||||
std::cout << 14 << ' '; test( int_t<14>::fast() );
|
||||
std::cout << 13 << ' '; test( int_t<13>::fast() );
|
||||
std::cout << 12 << ' '; test( int_t<12>::fast() );
|
||||
std::cout << 11 << ' '; test( int_t<11>::fast() );
|
||||
std::cout << 10 << ' '; test( int_t<10>::fast() );
|
||||
std::cout << 9 << ' '; test( int_t<9>::fast() );
|
||||
std::cout << 8 << ' '; test( int_t<8>::fast() );
|
||||
std::cout << 7 << ' '; test( int_t<7>::fast() );
|
||||
std::cout << 6 << ' '; test( int_t<6>::fast() );
|
||||
std::cout << 5 << ' '; test( int_t<5>::fast() );
|
||||
std::cout << 4 << ' '; test( int_t<4>::fast() );
|
||||
std::cout << 3 << ' '; test( int_t<3>::fast() );
|
||||
std::cout << 2 << ' '; test( int_t<2>::fast() );
|
||||
std::cout << 1 << ' '; test( int_t<1>::fast() );
|
||||
std::cout << 0 << ' '; test( int_t<0>::fast() );
|
||||
std::cout << 32 << ' '; test( uint_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( uint_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( uint_t<30>::least() );
|
||||
std::cout << 29 << ' '; test( uint_t<29>::least() );
|
||||
std::cout << 28 << ' '; test( uint_t<28>::least() );
|
||||
std::cout << 27 << ' '; test( uint_t<27>::least() );
|
||||
std::cout << 26 << ' '; test( uint_t<26>::least() );
|
||||
std::cout << 25 << ' '; test( uint_t<25>::least() );
|
||||
std::cout << 24 << ' '; test( uint_t<24>::least() );
|
||||
std::cout << 23 << ' '; test( uint_t<23>::least() );
|
||||
std::cout << 22 << ' '; test( uint_t<22>::least() );
|
||||
std::cout << 21 << ' '; test( uint_t<21>::least() );
|
||||
std::cout << 20 << ' '; test( uint_t<20>::least() );
|
||||
std::cout << 19 << ' '; test( uint_t<19>::least() );
|
||||
std::cout << 18 << ' '; test( uint_t<18>::least() );
|
||||
std::cout << 17 << ' '; test( uint_t<17>::least() );
|
||||
std::cout << 16 << ' '; test( uint_t<16>::least() );
|
||||
std::cout << 15 << ' '; test( uint_t<15>::least() );
|
||||
std::cout << 14 << ' '; test( uint_t<14>::least() );
|
||||
std::cout << 13 << ' '; test( uint_t<13>::least() );
|
||||
std::cout << 12 << ' '; test( uint_t<12>::least() );
|
||||
std::cout << 11 << ' '; test( uint_t<11>::least() );
|
||||
std::cout << 10 << ' '; test( uint_t<10>::least() );
|
||||
std::cout << 9 << ' '; test( uint_t<9>::least() );
|
||||
std::cout << 8 << ' '; test( uint_t<8>::least() );
|
||||
std::cout << 7 << ' '; test( uint_t<7>::least() );
|
||||
std::cout << 6 << ' '; test( uint_t<6>::least() );
|
||||
std::cout << 5 << ' '; test( uint_t<5>::least() );
|
||||
std::cout << 4 << ' '; test( uint_t<4>::least() );
|
||||
std::cout << 3 << ' '; test( uint_t<3>::least() );
|
||||
std::cout << 2 << ' '; test( uint_t<2>::least() );
|
||||
std::cout << 1 << ' '; test( uint_t<1>::least() );
|
||||
std::cout << 0 << ' '; test( uint_t<0>::least() );
|
||||
std::cout << 32 << ' '; test( uint_t<32>::fast() );
|
||||
std::cout << 31 << ' '; test( uint_t<31>::fast() );
|
||||
std::cout << 30 << ' '; test( uint_t<30>::fast() );
|
||||
std::cout << 29 << ' '; test( uint_t<29>::fast() );
|
||||
std::cout << 28 << ' '; test( uint_t<28>::fast() );
|
||||
std::cout << 27 << ' '; test( uint_t<27>::fast() );
|
||||
std::cout << 26 << ' '; test( uint_t<26>::fast() );
|
||||
std::cout << 25 << ' '; test( uint_t<25>::fast() );
|
||||
std::cout << 24 << ' '; test( uint_t<24>::fast() );
|
||||
std::cout << 23 << ' '; test( uint_t<23>::fast() );
|
||||
std::cout << 22 << ' '; test( uint_t<22>::fast() );
|
||||
std::cout << 21 << ' '; test( uint_t<21>::fast() );
|
||||
std::cout << 20 << ' '; test( uint_t<20>::fast() );
|
||||
std::cout << 19 << ' '; test( uint_t<19>::fast() );
|
||||
std::cout << 18 << ' '; test( uint_t<18>::fast() );
|
||||
std::cout << 17 << ' '; test( uint_t<17>::fast() );
|
||||
std::cout << 16 << ' '; test( uint_t<16>::fast() );
|
||||
std::cout << 15 << ' '; test( uint_t<15>::fast() );
|
||||
std::cout << 14 << ' '; test( uint_t<14>::fast() );
|
||||
std::cout << 13 << ' '; test( uint_t<13>::fast() );
|
||||
std::cout << 12 << ' '; test( uint_t<12>::fast() );
|
||||
std::cout << 11 << ' '; test( uint_t<11>::fast() );
|
||||
std::cout << 10 << ' '; test( uint_t<10>::fast() );
|
||||
std::cout << 9 << ' '; test( uint_t<9>::fast() );
|
||||
std::cout << 8 << ' '; test( uint_t<8>::fast() );
|
||||
std::cout << 7 << ' '; test( uint_t<7>::fast() );
|
||||
std::cout << 6 << ' '; test( uint_t<6>::fast() );
|
||||
std::cout << 5 << ' '; test( uint_t<5>::fast() );
|
||||
std::cout << 4 << ' '; test( uint_t<4>::fast() );
|
||||
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() );
|
||||
|
||||
return 0;
|
||||
}
|
89
integer_traits.html
Normal file
89
integer_traits.html
Normal file
@ -0,0 +1,89 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<title>integer_traits: Compile-Time Limits for Integral Types</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
Type Limits</h1>
|
||||
|
||||
<p>
|
||||
The C++ Standard Library <limits> header supplies a class template
|
||||
numeric_limits<> with specializations for each fundamental
|
||||
type.</p>
|
||||
<p>
|
||||
For integer types, the interesting members of std::numeric_limits<> are:
|
||||
<pre> static const bool is_specialized; // will be true for integers
|
||||
static T min() throw();
|
||||
static T max() throw();
|
||||
static const int digits; // for integers, # value bits
|
||||
static const int digits10;
|
||||
static const bool is_signed;
|
||||
static const bool is_integer; // will be true for integers</pre>
|
||||
For many uses, these are sufficient. But min() and max() are problematical because they are not constant expressions
|
||||
(std::5.19), yet some usages require constant expressions.
|
||||
<p>
|
||||
The template class <code>integer_traits</code> addresses this
|
||||
problem.
|
||||
|
||||
|
||||
<h2>Header <code><a href="../../boost/integer_traits.hpp">integer_traits.hpp</a></code> Synopsis</h2>
|
||||
|
||||
<pre>namespace boost {
|
||||
template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
static const bool is_integral = false;
|
||||
};
|
||||
|
||||
// specializations for all integral types
|
||||
}</pre>
|
||||
|
||||
|
||||
<h2>Description</h2>
|
||||
|
||||
Template class <code>integer_traits</code> is derived from
|
||||
<code>std::numeric_limits</code>. In general, it adds the single
|
||||
<code>bool</code> member <code>is_integral</code> with the
|
||||
compile-time constant value <code>false</code>. However, for all
|
||||
integral types <code>T</code> (std::3.9.1/7 [basic.fundamental]),
|
||||
there are specializations provided with the following compile-time
|
||||
constants defined:
|
||||
<p>
|
||||
<table border=1>
|
||||
<tr><th>member</th><th>type</th><th>value</th></tr>
|
||||
<tr><td><code>is_integral</code></td><td>bool</td><td><code>true</code></td></tr>
|
||||
<tr><td><code>const_min</code></td><td><code>T</code></td><td>equivalent
|
||||
to <code>std::numeric_limits<T>::min()</code></td></tr>
|
||||
<tr><td><code>const_max</code></td><td><code>T</code></td><td>equivalent
|
||||
to <code>std::numeric_limits<T>::max()</code></td></tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
|
||||
<em>Note:</em> A flag <code>is_integral</code> is provided, because a
|
||||
user-defined integer class should specialize
|
||||
<code>std::numeric_limits<>::is_integer = true</code>,
|
||||
nonetheless compile-time constants <code>const_min</code> and
|
||||
<code>const_max</code> cannot be provided for that user-defined class.
|
||||
|
||||
<h2>
|
||||
|
||||
Test Program</h2>
|
||||
|
||||
<p>
|
||||
|
||||
The program <code><a href="integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
exercises the <code>integer_traits</code> class.
|
||||
|
||||
<h2>Acknowledgements</h2>
|
||||
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||
traits idea on the boost mailing list in August 1999.
|
||||
<hr>
|
||||
<a href="../../people/jens_maurer.htm">
|
||||
Jens Maurer</a>, 2000-02-20
|
83
integer_traits_test.cpp
Normal file
83
integer_traits_test.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/* boost integer_traits.hpp tests
|
||||
*
|
||||
* 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
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
* Jens Maurer makes no representations about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Revision history
|
||||
* 2000-02-22 Small improvements by Beman Dawes
|
||||
* 2000-06-27 Rework for better MSVC and BCC co-operation
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/integer_traits.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:
|
||||
* MSVC mis-compiles explicit function template instantiations.
|
||||
* For example, f<A>() and f<B>() are both compiled to call f<A>().
|
||||
* BCC is unable to implicitly convert a "const char *" to a std::string
|
||||
* when using explicit function template instantiations.
|
||||
*
|
||||
* Therefore, avoid explicit function template instantiations.
|
||||
*/
|
||||
|
||||
template<class T>
|
||||
void runtest(const char * type, T)
|
||||
{
|
||||
typedef boost::integer_traits<T> traits;
|
||||
std::cout << "Checking " << type
|
||||
<< "; min is " << traits::min()
|
||||
<< ", max is " << traits::max()
|
||||
<< std::endl;
|
||||
assert(traits::is_specialized);
|
||||
assert(traits::is_integer);
|
||||
assert(traits::is_integral);
|
||||
assert(traits::const_min == traits::min());
|
||||
assert(traits::const_max == traits::max());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
runtest("bool", bool());
|
||||
runtest("char", char());
|
||||
typedef signed char signed_char;
|
||||
runtest("signed char", signed_char());
|
||||
typedef unsigned char unsigned_char;
|
||||
runtest("unsigned char", unsigned_char());
|
||||
runtest("short", short());
|
||||
typedef unsigned short unsigned_short;
|
||||
runtest("unsigned short", unsigned_short());
|
||||
runtest("int", int());
|
||||
typedef unsigned int unsigned_int;
|
||||
runtest("unsigned int", unsigned_int());
|
||||
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());
|
||||
#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