Compare commits

...

82 Commits

Author SHA1 Message Date
fcd3688fcd This commit was manufactured by cvs2svn to create branch
'python-v2-dev'.

[SVN r14785]
2002-08-12 13:35:54 +00:00
344fe9f30a clear un/signed warnings
[SVN r14692]
2002-08-05 11:16:14 +00:00
8ad3bbafbc BOOST_HAS_MS_INT64 rather than specific compilers
[SVN r14668]
2002-08-05 00:02:10 +00:00
cc1183d347 Check for BOOST_HAS_MS_INT64 instead of specific compilers
[SVN r14664]
2002-08-04 01:27:24 +00:00
a9703fa803 Fix link
[SVN r14630]
2002-07-27 20:08:51 +00:00
5e26f47535 Fixed test case for VC7.0
[SVN r14627]
2002-07-27 11:47:04 +00:00
57e7ccd494 Fix unversioned VC++ checks
[SVN r14436]
2002-07-13 12:26:19 +00:00
c56e4674f8 Update from Daryle
[SVN r14187]
2002-06-19 20:11:17 +00:00
41620a14f9 Patched so that the code now compilers with VC6
[SVN r13669]
2002-05-05 11:00:28 +00:00
a42ede713e fix link
[SVN r12698]
2002-02-04 18:55:31 +00:00
92de2f44a0 cstdint.hpp:
- Handle FreeBSD's <inttypes.h>


[SVN r12601]
2002-01-31 12:58:35 +00:00
59779dec2c integer_traits.hpp:
- Handle wchar_t traits on FreeBSD


[SVN r12467]
2002-01-23 19:56:07 +00:00
3bb567ad9d initial checkin
[SVN r11972]
2001-12-07 13:19:38 +00:00
c50993d5d4 Added daryle's missing files
[SVN r11971]
2001-12-07 12:48:20 +00:00
5477a9641c initial checkin
[SVN r11898]
2001-12-03 23:55:35 +00:00
162c6aefa1 Integrated Daryle Walker's dlw_int.zip changes
[SVN r11866]
2001-12-03 03:29:57 +00:00
24e6bfbfaa add definition for integral constants initialized in-class
[SVN r11724]
2001-11-18 17:37:21 +00:00
ccabb522d0 Remove non-ASCII character that crept in.
[SVN r11570]
2001-11-04 21:53:21 +00:00
0995d0a6fb only use "long long" if there's a stdlib overload
[SVN r11516]
2001-11-01 21:52:08 +00:00
5ec8116c34 use BOOST_HAS_LONG_LONG
[SVN r11493]
2001-10-31 19:35:59 +00:00
4a094c4bcb fix wchar_t on HP-UX with gcc
[SVN r11472]
2001-10-30 20:55:18 +00:00
a7d2da8d1c 1.25.0 Final runup
[SVN r11315]
2001-10-01 15:54:23 +00:00
4d2a921dbf Write out limits as integers, even for char types.
[SVN r11301]
2001-09-28 17:38:10 +00:00
0c758855e4 Since it's obsolete, it should be removed.
[SVN r11300]
2001-09-28 17:37:25 +00:00
3399df597e Add case for Mac OS X to the WCHAR_MIN/WCHAR_MAX section.
[SVN r11242]
2001-09-24 23:45:49 +00:00
a066e242b0 always use WCHAR_MIN and WCHAR_MAX if defined
[SVN r11232]
2001-09-24 18:43:20 +00:00
a635f753a4 port cstdint.hpp to HP-UX
[SVN r11175]
2001-09-20 19:25:35 +00:00
08f30ea46c moved check, because different unsigned types may have different
representations for -1 (e.g. (unsigned char)-1 and (unsigned int)-1)


[SVN r11174]
2001-09-20 19:24:34 +00:00
292eeb5c90 Fixes for broken using declarations
[SVN r11164]
2001-09-20 11:44:34 +00:00
8a105dab3f Fixes for the case that platform has its own stdint.h (less stringent tests)
[SVN r11163]
2001-09-20 11:44:05 +00:00
5b0d514aa4 commit of split-config, including any changes required to existing libraries (mainly regex).
[SVN r11138]
2001-09-18 11:13:39 +00:00
eee6dfa4d9 avoid "long long" with SunCC (Gennadiy E. Rozental)
[SVN r11066]
2001-09-07 18:49:12 +00:00
3bd242ef49 Fix broken hyperlink
[SVN r10896]
2001-08-19 15:08:33 +00:00
3db9390efb Add LL suffix to line 150 for long longs at suggestion of Toon Knapen
[SVN r10854]
2001-08-13 17:02:48 +00:00
c6f3dce91a Fixed VC6+STLport-4.1b6 (changed preprocessor logic)
[SVN r10360]
2001-06-20 11:42:44 +00:00
3e2b929118 free -> fee
[SVN r10248]
2001-05-31 17:22:20 +00:00
645f809379 fix the "gcc 3.0 and long long" fix to check for the appropriate symbol
[SVN r10107]
2001-05-13 18:17:15 +00:00
28ec7fa76c Don't use "long long" with gcc 3.0's shipped library, because it does
not define operator<<(ostream&, long long) overloads.


[SVN r10095]
2001-05-11 17:04:56 +00:00
07505c76f8 Preprocessor fix for VC6 + STLPort 4.1b6
[SVN r10087]
2001-05-11 10:47:57 +00:00
fda46f9780 HP-UX needs special attention because ULONG_LONG_MAX is not fully usable
[SVN r10080]
2001-05-09 21:07:20 +00:00
125bf3351f gcc on HP-UX doesn't have WCHAR_MIN and WCHAR_MAX
[SVN r10068]
2001-05-08 18:15:32 +00:00
e3702f3abc int64_t may not be defined on HP-UX when using gcc
[SVN r10067]
2001-05-08 18:14:14 +00:00
c54da75efb Fixed more wchar_t problems
[SVN r10058]
2001-05-08 11:11:30 +00:00
2dd1bee693 add HP-UX workaround
[SVN r10051]
2001-05-07 21:21:13 +00:00
949134726f fix the fix for SGI MIPSpro with STLport
[SVN r10008]
2001-05-03 11:57:57 +00:00
b3f587b9f7 IRIX doesn't have WCHAR_MIN and WCHAR_MAX, either
[SVN r10005]
2001-05-02 16:18:08 +00:00
215b4d8ee7 compactify John Maddock's fix for Borland C++ / WCHAR_MIN, WCHAR_MAX
[SVN r10004]
2001-05-02 15:44:02 +00:00
976c5e6572 Fix for Borland C++ and wchar_t
[SVN r10001]
2001-05-02 10:58:30 +00:00
0424bb266e use Boost.Test
test wchar_t
output a message when int64_t is not available


[SVN r9998]
2001-04-30 13:38:23 +00:00
33abcf7250 use BOOST_STATIC_CONSTANT
define static member constants
add wchar_t specialization


[SVN r9997]
2001-04-30 13:36:05 +00:00
b519841b7f Change all eGroups references to YahooGroups
[SVN r9979]
2001-04-25 00:24:50 +00:00
d1781f09d2 allow for ULONGLONG_MAX as well
[SVN r9795]
2001-04-16 13:32:54 +00:00
c1c099c845 check for ULONGLONG_MAX as well
[SVN r9793]
2001-04-16 12:53:03 +00:00
f4c38bdf51 Added boost-wide <limits> woraround
[SVN r9688]
2001-04-01 11:59:18 +00:00
53005cadc8 added <limits> workaround
[SVN r9687]
2001-03-31 12:05:02 +00:00
ea4963031a Add comment: int_fast_t works for unsigned too.
[SVN r9545]
2001-03-12 14:01:34 +00:00
873879d5ac Use test_tools.hpp for error detection
[SVN r9540]
2001-03-11 13:31:00 +00:00
d39c7cd327 Correct spelling in Jens' licenses
[SVN r9372]
2001-03-01 18:54:36 +00:00
37eb749c49 Fix for BeOS <limits>
[SVN r9356]
2001-02-27 12:52:08 +00:00
8084359fda removed backslashes in macros
[SVN r9097]
2001-02-11 01:21:56 +00:00
f544a58f58 All final 1.20.2 changes, including fixing broken hyperlinks
[SVN r9071]
2001-02-10 14:42:14 +00:00
d2c2e49154 expanded int_least_helper comment on request of Daryle Walker
[SVN r8815]
2001-01-30 21:16:43 +00:00
50bd08d542 cstdint: cygwin fixes for long long support
[SVN r8754]
2001-01-24 12:18:30 +00:00
b5b41c73db for int32_t and intmax_t, prefer "long" over "int" if both are 32bit
[SVN r8743]
2001-01-23 19:45:00 +00:00
a22a9a3d80 Fixes so that long long is recognized for GCC.
[SVN r8706]
2001-01-22 05:06:37 +00:00
21ee723419 restricted Windows/gcc exclusion of int64_t to Cygwin, because
MingW seems to work


[SVN r8641]
2001-01-18 22:44:28 +00:00
202890e032 add typename to definition of (u)int_t::fast
[SVN r8560]
2001-01-12 18:07:34 +00:00
4b2fcb5c36 replace using-directive with using-declarations to avoid ambiguity on IRIX CC
[SVN r8557]
2001-01-11 23:00:32 +00:00
35dbbde437 1.19.0 runup
[SVN r8446]
2000-12-10 15:53:46 +00:00
3f58452fa9 added boost:: prefixes to all intXX_t references
[SVN r8176]
2000-11-12 18:38:17 +00:00
017c095cad removed boost/stdint.h from documentation
[SVN r8175]
2000-11-12 18:37:04 +00:00
c3d2838f55 Folded stdint.h into cstdint.hpp to avoid ISO C99 incompatibilities
[SVN r8174]
2000-11-12 18:35:33 +00:00
6425892b75 libraries.htm and people.htm moved to sub-directories to make root directory cleaner.
[SVN r8166]
2000-11-10 15:39:05 +00:00
99eff7e1bb check for ULONG_LONG_MAX as well (supports gcc)
[SVN r7862]
2000-09-27 21:43:54 +00:00
d0b9d43e9b Back out _fast optimization that wasn't. (Ken Hagan)
[SVN r7848]
2000-09-26 18:22:26 +00:00
79accb0546 More optimal choices for fast 8 and 16 types
[SVN r7816]
2000-09-25 11:58:38 +00:00
0b55c0ecfd Add newline at eof to quiet compiler warning
[SVN r7809]
2000-09-25 00:49:18 +00:00
76fcc1f65e addition of INTXX_C support to integer library
[SVN r7792]
2000-09-24 11:35:25 +00:00
70edfde847 use BOOST_NO_INT64_T to check wether "long long" traits should be tested.
[SVN r7783]
2000-09-23 16:35:19 +00:00
34f4037317 fix reversed BOOST_NO_INT64_T logic
[SVN r7780]
2000-09-23 16:29:01 +00:00
a7bd4493ce add support for gcc's long long
[SVN r7779]
2000-09-23 16:27:16 +00:00
6a093cf955 64-bit integer improvements from John Maddock
[SVN r7776]
2000-09-22 20:39:23 +00:00
20 changed files with 2415 additions and 506 deletions

View File

@ -12,11 +12,10 @@
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
boost/cstdint.hpp&nbsp;</h1>
<p>The header <code><a href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;</a></code>
places the contents of the header <code><a href="../../boost/stdint.h">&lt;boost/stdint.h&gt;</a></code>
in namespace boost.&nbsp; That header consists entirely of typedef's useful for
writing portable code that requires certain integer widths.</p>
provides the typedef's useful for
writing portable code that requires certain integer widths. All typedef's are in namespace boost.</p>
<p>The specifications are based on the ISO/IEC 9899:1999 C Language standard
header stdint.h.&nbsp; The 64-bit types required by the C standard are not
header &lt;stdint.h&gt;.&nbsp; The 64-bit types required by the C standard are not
required in the boost header, and may not be supplied in all implementations,
because <code>long long</code> is not [yet] included in the C++ standard.</p>
<p>See <a href="cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
@ -70,7 +69,7 @@ representing any value of any signed integer type.</p>
capable of representing any value of any unsigned integer type.</p>
<p>These types are required.</p>
<hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->29 Jun 2000<!--webbot bot="Timestamp" endspan i-checksum="15060" -->
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->19 Aug 2001<!--webbot bot="Timestamp" endspan i-checksum="14767" -->
</p>
<p>&nbsp;</p>

View File

@ -9,66 +9,209 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
// 28 Jun 00 Initial version
#include <boost/cstdint.hpp>
#include <cassert>
#include <iostream>
#define __STDC_CONSTANT_MACROS
#include <boost/cstdint.hpp>
#ifdef NDEBUG
#error This test makes no sense with NDEBUG defined
#endif
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following class is designed to verify
// that the various INTXX_C macros can be used
// in integral constant expressions:
//
struct integral_constant_checker
{
static const boost::int8_t int8 = INT8_C(-127);
static const boost::int_least8_t int_least8 = INT8_C(-127);
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
static const boost::uint8_t uint8 = UINT8_C(255);
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
static const boost::int16_t int16 = INT16_C(-32767);
static const boost::int_least16_t int_least16 = INT16_C(-32767);
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
static const boost::uint16_t uint16 = UINT16_C(65535);
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
static const boost::int32_t int32 = INT32_C(-2147483647);
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
static const boost::uint32_t uint32 = UINT32_C(4294967295);
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
static void check();
};
void integral_constant_checker::check()
{
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
}
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following function simply verifies that the type
// of an integral constant is correctly defined:
//
#ifdef __BORLANDC__
#pragma option -w-8008
#pragma option -w-8066
#endif
template <class T1, class T2>
void integral_constant_type_check(T1, T2)
{
//
// the types T1 and T2 may not be exactly
// the same type, but they should be the
// same size and signedness. We could use
// numeric_limits to verify this, but
// numeric_limits implementations currently
// vary too much, or are incomplete or missing.
//
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
T2 t2 = static_cast<T2>(-1); // ditto
#if defined(BOOST_HAS_STDINT_H)
// if we have a native stdint.h
// then the INTXX_C macros may define
// a type that's wider than required:
assert(sizeof(T1) <= sizeof(T2));
#else
assert(sizeof(T1) == sizeof(T2));
assert(t1 == t2);
#endif
if(t1 > 0)
assert(t2 > 0);
else
assert(!(t2 > 0));
}
int main()
{
boost::int8_t int8 = -127;
boost::int_least8_t int_least8 = -127;
boost::int_fast8_t int_fast8 = -127;
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
integral_constant_checker::check();
#endif
//
// verify the types of the integral constants:
//
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
#ifndef BOOST_NO_INT64_T
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
#endif
//
boost::int8_t int8 = INT8_C(-127);
boost::int_least8_t int_least8 = INT8_C(-127);
boost::int_fast8_t int_fast8 = INT8_C(-127);
boost::uint8_t uint8 = 255;
boost::uint_least8_t uint_least8 = 255;
boost::uint_fast8_t uint_fast8 = 255;
boost::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::int16_t int16 = -32767;
boost::int_least16_t int_least16 = -32767;
boost::int_fast16_t int_fast16 = -32767;
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 = 65535;
boost::uint_least16_t uint_least16 = 65535;
boost::uint_fast16_t uint_fast16 = 65535;
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 = -2147483647;
boost::int_least32_t int_least32 = -2147483647;
boost::int_fast32_t int_fast32 = -2147483647;
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 = 4294967295;
boost::uint_least32_t uint_least32 = 4294967295;
boost::uint_fast32_t uint_fast32 = 4294967295;
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);
boost::intmax_t intmax = -2147483647;
boost::uintmax_t uintmax = 4294967295;
#ifndef BOOST_NO_INT64_T
boost::int64_t int64 = INT64_C(-9223372036854775807);
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
#else
boost::intmax_t intmax = INTMAX_C(-2147483647);
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
#endif
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255 );
assert( uint_least8 == 255 );
assert( uint_fast8 == 255 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535 );
assert( uint_least16 == 65535 );
assert( uint_fast16 == 65535 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295 );
assert( uint_least32 == 4294967295 );
assert( uint_fast32 == 4294967295 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
#ifndef BOOST_NO_INT64_T
assert( int64 == INT64_C(-9223372036854775807) );
assert( int_least64 == INT64_C(-9223372036854775807) );
assert( int_fast64 == INT64_C(-9223372036854775807) );
assert( uint64 == UINT64_C(18446744073709551615) );
assert( uint_least64 == UINT64_C(18446744073709551615) );
assert( uint_fast64 == UINT64_C(18446744073709551615) );
assert( intmax == INT64_C(-9223372036854775807) );
assert( uintmax == UINT64_C(18446744073709551615) );
#else
assert( intmax == -2147483647 );
assert( uintmax == 4294967295 );
assert( uintmax == 4294967295u );
#endif
std::cout << "OK\n";
return 0;
}

211
doc/integer_mask.html Normal file
View File

@ -0,0 +1,211 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Integer Bit Mask Templates</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp">&lt;boost/integer/integer_mask.hpp&gt;</a></cite> provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. The types of the masking constants come from the <a href="../integer.htm">integer type selection templates</a> header.</p>
<h2><a name="contents">Contents</a></h2>
<ul>
<li><a href="#contents">Contents</a></li>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#single">Single Bit-Mask Class Template</a></li>
<li><a href="#group">Group Bit-Mask Class Template</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#demo">Demonstration Program</a></li>
<li><a href="#rationale">Rationale</a></li>
<li><a href="#credits">Credits</a></li>
</ul>
<h2><a name="synopsis">Synopsis</a></h2>
<blockquote><pre>
#include &lt;cstddef&gt; <i>// for std::size_t</i>
namespace boost
{
template &lt; std::size_t Bit &gt;
struct high_bit_mask_t
{
typedef <em>implementation_supplied</em> least;
typedef <em>implementation_supplied</em> fast;
static const least high_bit = <em>implementation_defined</em>;
static const fast high_bit_fast = <em>implementation_defined</em>;
static const std::size_t bit_position = Bit;
};
template &lt; std::size_t Bits &gt;
struct low_bits_mask_t
{
typedef <em>implementation_supplied</em> least;
typedef <em>implementation_supplied</em> fast;
static const least sig_bits = <em>implementation_defined</em>;
static const fast sig_bits_fast = <em>implementation_defined</em>;
static const std::size_t bit_count = Bits;
};
// Specializations for low_bits_mask_t exist for certain bit counts.
} // namespace boost
</pre></blockquote>
<h2><a name="single">Single Bit-Mask Class Template</a></h2>
<p>The <code>boost::high_bit_mask_t</code> class template provides
constants for bit masks representing the bit at a certain position. The
masks are equivalent to the value 2<sup><code>Bit</code></sup>, where
<code>Bit</code> is the template parameter. The bit position must be a
nonnegative number from zero to <i>Max</i>, where <dfn>Max</dfn> is one
less than the number of bits supported by the largest unsigned built-in
integral type. The following table describes the members of an
instantiation of <code>high_bit_mask_t</code>.</p>
<table border="1" cellpadding="5">
<caption>Members of the <code>boost::high_bit_mask_t</code> Class
Template</caption>
<tr>
<th>Member</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>least</code></td>
<td>The smallest unsigned built-in type that supports the given
bit position.</td>
</tr>
<tr>
<td><code>fast</code></td>
<td>The quick-to-manipulate analog of <code>least</code>.</td>
</tr>
<tr>
<td><code>high_bit</code></td>
<td>A <code>least</code> constant of the desired bit-masking
value.</td>
</tr>
<tr>
<td><code>high_bit_fast</code></td>
<td>A <code>fast</code> analog of <code>high_bit</code>.</td>
</tr>
<tr>
<td><code>bit_position</code></td>
<td>The value of the template parameter, in case its needed from
a renamed instantiation of the class template.</td>
</tr>
</table>
<h2><a name="group">Group Bit-Mask Class Template</a></h2>
<p>The <code>boost::low_bits_mask_t</code> class template provides
constants for bit masks representing the lowest bits of a certain
amount. The masks are equivalent to the value
(2<sup><code>Bits</code></sup> - 1), where <code>Bits</code> is the
template parameter. The bit amount must be a nonnegative number from
zero to <i>Max</i>, where <dfn>Max</dfn> is the number of bits supported
by the largest unsigned built-in integral type. The following table
describes the members of an instantiation of
<code>low_bits_mask_t</code>.</p>
<table border="1" cellpadding="5">
<caption>Members of the <code>boost::low_bits_mask_t</code> Class
Template</caption>
<tr>
<th>Member</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>least</code></td>
<td>The smallest unsigned built-in type that supports the given
bit count.</td>
</tr>
<tr>
<td><code>fast</code></td>
<td>The quick-to-manipulate analog of <code>least</code>.</td>
</tr>
<tr>
<td><code>sig_bits</code></td>
<td>A <code>least</code> constant of the desired bit-masking
value.</td>
</tr>
<tr>
<td><code>sig_bits_fast</code></td>
<td>A <code>fast</code> analog of <code>sig_bits</code>.</td>
</tr>
<tr>
<td><code>bit_count</code></td>
<td>The value of the template parameter, in case its needed from
a renamed instantiation of the class template.</td>
</tr>
</table>
<p><strong>Implementation Note</strong><br>
When <code>Bits</code> is the exact size of a built-in unsigned type,
the implementation has to change to prevent undefined behavior.
Therefore, there are specializations of <code>low_bits_mask_t</code> at
those bit counts.</p>
<h2><a name="example">Example</a></h2>
<blockquote><pre>
#include &lt;boost/integer/integer_mask.hpp&gt;
//...
int main()
{
typedef boost::high_bit_mask_t&lt;29&gt; mask1_type;
typedef boost::low_bits_mask_t&lt;15&gt; mask2_type;
mask1_type::least my_var1;
mask2_type::fast my_var2;
//...
my_var1 |= mask1_type::high_bit;
my_var2 &amp;= mask2_type::sig_bits_fast;
//...
}
</pre></blockquote>
<h2><a name="demo">Demonstration Program</a></h2>
<p>The program <a href="../test/integer_mask_test.cpp">integer_mask_test.cpp</a>
is a simplistic demonstration of the results from instantiating various
examples of the bit mask class templates.</p>
<h2><a name="rationale">Rationale</a></h2>
<p>The class templates in this header are an extension of the <a
href="../integer.htm">integer type selection class templates</a>. The new
class templates provide the same sized types, but also convienent masks
to use when extracting the highest or all the significant bits when the
containing built-in type contains more bits. This prevents
contaimination of values by the higher, unused bits.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of the Boost bit mask class templates is <a
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
<hr>
<p>Revised September 23, 2001</p>
<p>&copy; Copyright Daryle Walker 2001. Permission to copy, use,
modify, sell and distribute this document is granted provided this
copyright notice appears in all copies. This document is provided
&quot;as is&quot; without express or implied warranty, and with no claim
as to its suitability for any purpose.</p>
</body>
</html>

123
doc/static_log2.html Normal file
View File

@ -0,0 +1,123 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Binary Logarithm Template</title>
</head>
<body bgcolor="white" text="black">
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
align="middle" width="277" height="86">Binary Logarithm Template</h1>
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp">&lt;boost/integer/static_log2.hpp&gt;</a></cite> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.</p>
<h2><a name="contents">Contents</a></h2>
<ul>
<li><a href="#contents">Contents</a></li>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#demo">Demonstration Program</a></li>
<li><a href="#rationale">Rationale</a></li>
<li><a href="#credits">Credits</a></li>
</ul>
<h2><a name="synopsis">Synopsis</a></h2>
<blockquote><pre>
namespace boost
{
template &lt; unsigned long Value &gt;
struct static_log2
{
static const int value = <em>implementation_defined</em>;
};
template &lt; &gt;
struct static_log2&lt; 0ul &gt;
{
// The logarithm of zero is undefined.
};
} // namespace boost
</pre></blockquote>
<h2><a name="usage">Usage</a></h2>
<p>The <code>boost::static_log2</code> class template takes one template
parameter, a value of type <code>unsigned long</code>. The template
only defines one member, <code>value</code>, that returns the truncated
base-two logarithm of the template parameter.</p>
<p>Since the logarithm of zero, for any base, is undefined, there is a
specialization of <code>static_log2</code> for a template parameter
of zero. This specialization has no members, so an attempt to use
the base-two logarithm of zero results in a compile-time error.</p>
<h2><a name="example">Example</a></h2>
<blockquote><pre>
#include &lt;boost/integer/static_log2.hpp&gt;
template &lt; unsigned long Value &gt;
bool is_it_what()
{
typedef boost::static_log2&lt;Value&gt; lb_type;
int temp = lb_type::value;
//...
return (temp % 2) != 0;
}
//...
int main()
{
bool temp = is_it_what&lt;2000&gt;();
//...
#if 0
temp = is_it_what&lt;0&gt;(); // would give an error
#endif
//...
temp = is_it_what&lt;24&gt;();
//...
}
</pre></blockquote>
<h2><a name="demo">Demonstration Program</a></h2>
<p>The program <a href="../test/static_log2_test.cpp">static_log2_test.cpp</a>
is a simplistic demonstration of the results from instantiating various
examples of the binary logarithm class template.</p>
<h2><a name="rationale">Rationale</a></h2>
<p>The base-two (binary) logarithm, abbreviated <dfn>lb</dfn>, function
is occasionally used to give order-estimates of computer algorithms.
The truncated logarithm can be considered the highest power-of-two in a
value, which corresponds to the value's highest set bit (for binary
integers). Sometimes the highest-bit position could be used in generic
programming, which requires the position to be statically (<i>i.e.</i>
at compile-time) available.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of the Boost binary logarithm class template is <a
href="../../../people/daryle_walker.html">Daryle Walker</a>. Giovanni Bajo
added support for compilers without partial template specialization.</p>
<hr>
<p>Revised May 14, 2002</p>
<p>&copy; Copyright Daryle Walker 2001. Permission to copy, use,
modify, sell and distribute this document is granted provided this
copyright notice appears in all copies. This document is provided
&quot;as is&quot; without express or implied warranty, and with no claim
as to its suitability for any purpose.</p>
</body>
</html>

121
doc/static_min_max.html Normal file
View File

@ -0,0 +1,121 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Compile-Time Extrema Templates</title>
</head>
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
align="middle" width="277" height="86">Compile-Time Extrema
Templates</h1>
<p>The class templates in <cite><a
href="../../../boost/integer/static_min_max.hpp">&lt;boost/integer/static_min_max.hpp&gt;</a></cite>
provide a compile-time evaluation of the minimum or maximum of
two integers. These facilities are useful for generic programming problems.</p>
<h2><a name="contents">Contents</a></h2>
<ul>
<li><a href="#contents">Contents</a></li>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#demo">Demonstration Program</a></li>
<li><a href="#rationale">Rationale</a></li>
<li><a href="#credits">Credits</a></li>
</ul>
<h2><a name="synopsis">Synopsis</a></h2>
<blockquote><pre>
namespace boost
{
template &lt; long Value1, long Value2 &gt;
struct static_signed_min;
template &lt; long Value1, long Value2 &gt;
struct static_signed_max;
template &lt; unsigned long Value1, unsigned long Value2 &gt;
struct static_unsigned_min;
template &lt; unsigned long Value1, unsigned long Value2 &gt;
struct static_unsigned_max;
}
</pre></blockquote>
<h2><a name="usage">Usage</a></h2>
<p>The four class templates provide the combinations for finding the
minimum or maximum of two signed or <code>unsigned</code>
(<code>long</code>) parameters, <var>Value1</var> and <var>Value2</var>,
at compile-time. Each template has a single static data member,
<code>value</code>, which is set to the respective minimum or maximum
of the template's parameters.</p>
<h2><a name="example">Example</a></h2>
<blockquote><pre>
#include &lt;boost/integer/static_min_max.hpp&gt;
template &lt; unsigned long AddendSize1, unsigned long AddendSize2 &gt;
class adder
{
public:
static unsigned long const addend1_size = AddendSize1;
static unsigned long const addend2_size = AddendSize2;
static unsigned long const sum_size = boost::static_unsigned_max&lt;AddendSize1, AddendSize2&gt;::value + 1;
typedef int addend1_type[ addend1_size ];
typedef int addend2_type[ addend2_size ];
typedef int sum_type[ sum_size ];
void operator ()( addend1_type const &amp;a1, addend2_type const &amp;a2, sum_type &amp;s ) const;
};
//...
int main()
{
int const a1[] = { 0, 4, 3 }; // 340
int const a2[] = { 9, 8 }; // 89
int s[ 4 ];
adder&lt;3,2&gt; obj;
obj( a1, a2, s ); // 's' should be 429 or { 9, 2, 4, 0 }
//...
}
</pre></blockquote>
<h2><a name="demo">Demonstration Program</a></h2>
<p>The program <a
href="../test/static_min_max_test.cpp">static_min_max_test.cpp</a> is a
simplistic demonstration of various comparisons using the compile-time
extrema class templates.</p>
<h2><a name="rationale">Rationale</a></h2>
<p>Sometimes the minimum or maximum of several values needs to be found
for later compile-time processing, <i>e.g.</i> for a bound for another
class template.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of the Boost compile-time extrema class templates is <a
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
<hr>
<p>Revised October 12, 2001</p>
<p>&copy; Copyright Daryle Walker 2001. Permission to copy, use,
modify, sell and distribute this document is granted provided this
copyright notice appears in all copies. This document is provided
&quot;as is&quot; without express or implied warranty, and with no claim
as to its suitability for any purpose.</p>
</body>
</html>

View File

@ -1,4 +1,4 @@
// boost cstdint.hpp header file -------------------------------------------//
// boost cstdint.hpp header file ------------------------------------------//
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
// and distribute this software is granted provided this copyright
@ -9,15 +9,37 @@
// 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
// 8 Aug 99 Initial version (Beman Dawes)
#ifndef BOOST_CSTDINT_HPP
#define BOOST_CSTDINT_HPP
#include <limits.h> // implementation artifact; not part of interface
#include <boost/config.hpp>
#include <boost/stdint.h>
#ifdef BOOST_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__)
# include <inttypes.h>
# else
# include <stdint.h>
# endif
namespace boost
{
@ -43,7 +65,7 @@ namespace boost
using ::uint_least32_t;
using ::uint_fast32_t;
# ifdef ULLONG_MAX
# ifndef BOOST_NO_INT64_T
using ::int64_t;
using ::int_least64_t;
@ -59,5 +81,296 @@ namespace boost
} // namespace boost
#endif
#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 <limits.h> // implementation artifact; not part of interface
namespace boost
{
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
// platforms. For other systems, they will have to be hand tailored.
//
// Because the fast types are assumed to be the same as the undecorated types,
// it may be possible to hand tailor a more efficient implementation. Such
// an optimization may be illusionary; on the Intel x86-family 386 on, for
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
// 8-bit types ------------------------------------------------------------//
# if UCHAR_MAX == 0xff
typedef signed char int8_t;
typedef signed char int_least8_t;
typedef signed char int_fast8_t;
typedef unsigned char uint8_t;
typedef unsigned char uint_least8_t;
typedef unsigned char uint_fast8_t;
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
// 16-bit types -----------------------------------------------------------//
# if USHRT_MAX == 0xffff
typedef short int16_t;
typedef short int_least16_t;
typedef short int_fast16_t;
typedef unsigned short uint16_t;
typedef unsigned short uint_least16_t;
typedef unsigned short uint_fast16_t;
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
// 32-bit types -----------------------------------------------------------//
# if ULONG_MAX == 0xffffffff
typedef long int32_t;
typedef long int_least32_t;
typedef long int_fast32_t;
typedef unsigned long uint32_t;
typedef unsigned long uint_least32_t;
typedef unsigned long uint_fast32_t;
# elif UINT_MAX == 0xffffffff
typedef int int32_t;
typedef int int_least32_t;
typedef int int_fast32_t;
typedef unsigned int uint32_t;
typedef unsigned int uint_least32_t;
typedef unsigned int uint_fast32_t;
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
# if defined(BOOST_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(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.

View File

@ -9,13 +9,18 @@
// 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)
// 28 Aug 99 Initial version
#ifndef BOOST_INTEGER_HPP
#define BOOST_INTEGER_HPP
#include <limits>
#include <boost/integer_fwd.hpp> // self include
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
namespace boost
{
@ -23,6 +28,7 @@ namespace boost
// Helper templates ------------------------------------------------------//
// fast integers from least integers
// int_fast_t<> works correctly for unsigned too, in spite of the name.
template< typename LeastInt >
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
@ -31,6 +37,7 @@ namespace boost
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
// no specializations for 0 and 5: requests for a type > long are in error
template<> struct int_least_helper<1> { typedef long least; };
template<> struct int_least_helper<2> { typedef int least; };
template<> struct int_least_helper<3> { typedef short least; };
@ -53,7 +60,7 @@ namespace boost
(Bits-1 <= std::numeric_limits<short>::digits) +
(Bits-1 <= std::numeric_limits<signed char>::digits)
>::least least;
typedef int_fast_t<least>::fast fast;
typedef typename int_fast_t<least>::fast fast;
};
// unsigned
@ -68,14 +75,55 @@ namespace boost
(Bits <= std::numeric_limits<unsigned short>::digits) +
(Bits <= std::numeric_limits<unsigned char>::digits)
>::least least;
typedef int_fast_t<least>::fast fast;
typedef typename int_fast_t<least>::fast fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
};
// The same dispatching technique can be used to select types based on
// values. That will be added once boost::integer_traits is available.
// 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;
};
} // namespace boost
#endif // BOOST_INTEGER_HPP

View File

@ -0,0 +1,93 @@
// 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

View File

@ -0,0 +1,141 @@
// Boost integer/static_log2.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_LOG2_HPP
#define BOOST_INTEGER_STATIC_LOG2_HPP
#include <boost/integer_fwd.hpp> // self include
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
#include <boost/limits.hpp> // for std::numeric_limits
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#include <boost/pending/ct_if.hpp> // for boost::ct_if<>
#endif
namespace boost
{
// Implementation details --------------------------------------------------//
namespace detail
{
// Forward declarations
template < unsigned long Val, int Place = 0, int Index
= std::numeric_limits<unsigned long>::digits >
struct static_log2_helper_t;
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template < unsigned long Val, int Place >
struct static_log2_helper_t< Val, Place, 1 >;
#else
template < int Place >
struct static_log2_helper_final_step;
template < unsigned long Val, int Place = 0, int Index
= std::numeric_limits<unsigned long>::digits >
struct static_log2_helper_nopts_t;
#endif
// Recursively build the logarithm by examining the upper bits
template < unsigned long Val, int Place, int Index >
struct static_log2_helper_t
{
private:
BOOST_STATIC_CONSTANT( int, half_place = Index / 2 );
BOOST_STATIC_CONSTANT( unsigned long, lower_mask = (1ul << half_place)
- 1ul );
BOOST_STATIC_CONSTANT( unsigned long, upper_mask = ~lower_mask );
BOOST_STATIC_CONSTANT( bool, do_shift = (Val & upper_mask) != 0ul );
BOOST_STATIC_CONSTANT( unsigned long, new_val = do_shift ? (Val
>> half_place) : Val );
BOOST_STATIC_CONSTANT( int, new_place = do_shift ? (Place + half_place)
: Place );
BOOST_STATIC_CONSTANT( int, new_index = Index - half_place );
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
typedef static_log2_helper_t<new_val, new_place, new_index> next_step_type;
#else
typedef static_log2_helper_nopts_t<new_val, new_place, new_index> next_step_type;
#endif
public:
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
}; // boost::detail::static_log2_helper_t
// Non-recursive case
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template < unsigned long Val, int Place >
struct static_log2_helper_t< Val, Place, 1 >
{
public:
BOOST_STATIC_CONSTANT( int, value = Place );
}; // boost::detail::static_log2_helper_t
#else
template < int Place >
struct static_log2_helper_final_step
{
public:
BOOST_STATIC_CONSTANT( int, value = Place );
}; // boost::detail::static_log2_helper_final_step
template < unsigned long Val, int Place, int Index >
struct static_log2_helper_nopts_t
{
private:
typedef static_log2_helper_t<Val, Place, Index> recursive_step_type;
typedef static_log2_helper_final_step<Place> final_step_type;
typedef typename ct_if<( Index != 1 ), recursive_step_type,
final_step_type>::type next_step_type;
public:
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
}; // boost::detail::static_log2_helper_nopts_t
#endif
} // namespace detail
// Compile-time log-base-2 evaluator class declaration ---------------------//
template < unsigned long Value >
struct static_log2
{
BOOST_STATIC_CONSTANT( int, value
= detail::static_log2_helper_t<Value>::value );
};
template < >
struct static_log2< 0ul >
{
// The logarithm of zero is undefined.
};
} // namespace boost
#endif // BOOST_INTEGER_STATIC_LOG2_HPP

View File

@ -0,0 +1,56 @@
// 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

View File

@ -0,0 +1,154 @@
// 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 for most recent version including 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

View File

@ -2,7 +2,7 @@
*
* Copyright Jens Maurer 2000
* Permission to use, copy, modify, sell, and distribute this software
* is hereby granted without free provided that the above copyright notice
* is hereby granted without fee provided that the above copyright notice
* appears in all copies and that both that copyright notice and this
* permission notice appear in supporting documentation,
*
@ -18,11 +18,14 @@
#ifndef BOOST_INTEGER_TRAITS_HPP
#define BOOST_INTEGER_TRAITS_HPP
#include <limits>
#include <boost/config.hpp>
#include <boost/limits.hpp>
// This is an implementation detail and not part of the interface
// These are an implementation detail and not part of the interface
#include <limits.h>
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
#include <wchar.h>
#endif
namespace boost {
@ -30,11 +33,7 @@ template<class T>
class integer_traits : public std::numeric_limits<T>
{
public:
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
static const bool is_integral = false;
#else
enum { is_integral = false };
#endif
BOOST_STATIC_CONSTANT(bool, is_integral = false);
};
namespace detail {
@ -42,18 +41,23 @@ template<class T, T min_val, T max_val>
class integer_traits_base
{
public:
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
static const bool is_integral = true;
static const T const_min = min_val;
static const T const_max = max_val;
#else
enum {
is_integral = true,
const_min = min_val,
const_max = max_val
};
#endif
BOOST_STATIC_CONSTANT(bool, is_integral = true);
BOOST_STATIC_CONSTANT(T, const_min = min_val);
BOOST_STATIC_CONSTANT(T, const_max = max_val);
};
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// 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;
#endif
} // namespace detail
template<>
@ -80,7 +84,32 @@ class integer_traits<unsigned char>
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
{ };
// What about wchar_t ?
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<>
class integer_traits<wchar_t>
: public std::numeric_limits<wchar_t>,
#if defined(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(__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
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
template<>
class integer_traits<short>
@ -118,7 +147,7 @@ class integer_traits<unsigned long>
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
{ };
#ifdef ULLONG_MAX
#if defined(ULLONG_MAX) && !defined(__SUNPRO_CC)
template<>
class integer_traits<long long>
: public std::numeric_limits<long long>,
@ -140,8 +169,20 @@ class integer_traits<unsigned long long>
: public std::numeric_limits<unsigned long long>,
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
{ };
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
template<>
class integer_traits<long long>
: public std::numeric_limits<long long>,
public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
{ };
template<>
class integer_traits<unsigned long long>
: public std::numeric_limits<unsigned long long>,
public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
{ };
#endif
} // namespace boost
#endif /* BOOST_INTEGER_TRAITS_HPP */

View File

@ -1,119 +0,0 @@
// 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

128
index.htm
View File

@ -1,23 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<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">
<body bgcolor="white" text="black">
<table border="1" bgcolor="teal" 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>
<td bgcolor="white"><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="white"><big>Home</big></font></a></td>
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
<td><a href="../../people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
<td><a href="../../more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
</tr>
</table>
@ -25,28 +20,26 @@
<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>
<th>Header / Docs</th>
<th>Contents</th>
<th>Use</th>
</tr>
<tr>
<td align="center"><cite><a href="../../boost/integer_fwd.hpp">&lt;boost/integer_fwd.hpp&gt;</a></cite></td>
<td valign="top">Forward declarations of classes and class templates</td>
<td valign="top">When just the name of a class is needed</td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;<br>
</a></code><a href="cstdint.htm"><br>
documentation</a>
</td>
<td valign="top">Contents of <code>&lt;boost/stdint.h&gt;</code> wrapped in namespace boost.</td>
<td valign="top">Typedef's based on the 1999 C Standard header &lt;<code>stdint.h&gt;</code>, wrapped in namespace boost.
This implementation may #include the compiler
supplied &lt;<code>stdint.h&gt;</code>, if present. </td>
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
Use in preference to &lt;<code>stdint.h&gt;</code> or<code> &lt;boost/stdint.h&gt;</code>
because the names are safely placed in the boost namespace.</td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/stdint.h">&lt;boost/stdint.h&gt;</a></code></td>
<td valign="top">Typedefs as defined in the C99 standard header &lt;<code>stdint.h&gt;</code>.
This implementation #includes the compiler
supplied &lt;<code>stdint.h&gt;</code>, if present.</td>
<td valign="top"> Supplied
for use in the implementation of &lt;boost/cstdint.hpp&gt; and to ease transition to the C99 standard.
Other uses are not recommended because this header places its names in the global namespace.&nbsp;</td>
Use in preference to &lt;<code>stdint.h&gt;</code>
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/integer_traits.hpp">&lt;boost/integer_traits.hpp&gt;</a></code><br>
@ -66,33 +59,70 @@
<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>
<tr>
<td align="center"><code><a href="../../boost/integer/integer_mask.hpp">&lt;boost/integer/integer_mask.hpp&gt;</a><br>
<br>
</code><a href="doc/integer_mask.html">documentation</a></td>
<td valign="top">Templates for the selection of integer masks, single or lowest group, based on the number of bits.</td>
<td valign="top">Use to select a particular mask when the bit position(s) are based on a compile-time variable.
Useful for generic programming. </td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/integer/static_log2.hpp">&lt;boost/integer/static_log2.hpp&gt;</a><br>
<br>
</code><a href="doc/static_log2.html">documentation</a></td>
<td valign="top">Template for finding the highest power of two in a number.</td>
<td valign="top">Use to find the bit-size/range based on a maximum value.
Useful for generic programming. </td>
</tr>
<tr>
<td align="center"><code><a href="../../boost/integer/static_min_max.hpp">&lt;boost/integer/static_min_max.hpp&gt;</a><br>
<br>
</code><a href="doc/static_min_max.html">documentation</a></td>
<td valign="top">Templates for finding the extrema of two numbers.</td>
<td valign="top">Use to find a bound based on a minimum or maximum value.
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>&lt;stdint.h&gt;</code> types from in the 1999 C standard
without resorting to undefined behavior in terms of
the 1998 C++ standard.&nbsp; The header <code>&lt;boost/cstdint.hpp&gt;</code>
makes the standard integer types safely available in namespace boost without placing any names in the
global namespace or namespace std. As always, the intension is to complement rather than
compete with the C++ Standard Library.&nbsp; Should some future C++ standard
include <code>&lt;stdint.h&gt;</code> and <code>&lt;cstdint&gt;</code>, then <code>&lt;boost/stdint.h&gt;</code> and <code>&lt;boost/cstdint.hpp&gt;</code>
will continue to function, but will become redundant and may be safely deprecated.</p>
<p>Because these are boost headers, their names conform to boost header naming
conventions rather than C++ Standard Library header naming conventions.&nbsp; An
exception is <code>&lt;boost/stdint.h&gt; </code>which uses a <b> .h</b> extension to indicate its C rather than C++ heritage.</p>
<h2>Caveat emptor</h2>
<p>As an
implementation artifact, certain C &lt;limits.h&gt; macro names may possibly be
visible to users of &lt;boost/cstdint.hpp&gt;.&nbsp; Don't use these macros; they are not part of
any Boost specified interface.&nbsp;
Use boost:: integer_traits&lt;&gt; or std::numeric_limits&lt;&gt; instead.</p>
<p>The organization of boost integer headers and classes is designed to
take advantage of <cite>&lt;stdint.h&gt;</cite> types from the 1999 C
standard without resorting to undefined behavior in terms of the 1998
C++ standard. The header <cite>&lt;boost/cstdint.hpp&gt;</cite> makes
the standard integer types safely available in namespace
<code>boost</code> without placing any names in namespace
<code>std</code>. As always, the intension is to complement rather than
compete with the C++ Standard Library. Should some future C++ standard
include <cite>&lt;stdint.h&gt;</cite> and <cite>&lt;cstdint&gt;</cite>,
then <cite>&lt;boost/cstdint.hpp&gt;</cite> 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.</p>
<h2><i>Caveat emptor</i></h2>
<p>As an implementation artifact, certain C
<cite>&lt;limits.h&gt;</cite> macro names may possibly be visible to
users of <cite>&lt;boost/cstdint.hpp&gt;</cite>. Don't use these
macros; they are not part of any Boost-specified interface. Use
<code>boost::integer_traits&lt;&gt;</code> or
<code>std::numeric_limits&lt;&gt;</code> instead.</p>
<p>As another implementation artifact, certain C
<cite>&lt;stdint.h&gt;</cite> typedef names may possibly be visible in
the global namespace to users of <cite>&lt;boost/cstdint.hpp&gt;</cite>.
Don't use these names, they are not part of any Boost-specified
interface. Use the respective names in namespace <code>boost</code>
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>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->03 Oct 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
</p>
</body>
</html>

View File

@ -1,110 +1,213 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<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">
<body bgcolor="white" text="black">
<h1>
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
align="middle" width="277" height="86">Integer Type Selection
Templates</h1>
<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">&lt;boost/integer.hpp&gt;</a></code>
type selection templates allow integer types to be selected based on desired
characteristics such as number of bits or maximum value.&nbsp; This facility is
particularly useful for solving generic programming problems.</p>
<p>The <cite><a
href="../../boost/integer.hpp">&lt;boost/integer.hpp&gt;</a></cite> 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&lt;&gt;</b> and <b>uint_t&lt;&gt;</b> supply typedefs <b>least</b>
and <b>fast</b>.&nbsp; 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.&nbsp;
There is no guarantee that the <b>fast</b> type will actually be faster than
other possible types.</p>
<h2><a name="contents">Contents</a></h2>
<h2>Alternative</h2>
<ul>
<li><a href="#contents">Contents</a></li>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#easy">Easiest-to-Manipulate Types</a></li>
<li><a href="#sized">Sized Types</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#demo">Demonstration Program</a></li>
<li><a href="#rationale">Rationale</a></li>
<li><a href="#alternative">Alternative</a></li>
<li><a href="#credits">Credits</a></li>
</ul>
<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">&lt;boost/cstdint.hpp&gt;</a></code>.</p>
<h2><a name="synopsis">Synopsis</a></h2>
<h2>Synopsis</h2>
<blockquote>
<pre>namespace boost
<blockquote><pre>namespace boost
{
// fast integers from least integers
template&lt; typename LeastInt &gt; // Required: LeastInt is integral type, not bool
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
template&lt; typename LeastInt &gt;
struct int_fast_t
{
typedef <em>implementation_supplied</em> fast;
};
// signed
template&lt; int Bits &gt; // bits (including sign) required, 0-32 valid
template&lt; int Bits &gt;
struct int_t
{
typedef <i>implementation-supplied</i> least;
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
// unsigned
template&lt; int Bits &gt; // bits required, 0-32 valid
template&lt; int Bits &gt;
struct uint_t
{
typedef <i>implementation-supplied</i> least;
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
// signed
template&lt; long MaxValue &gt;
struct int_max_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; long MinValue &gt;
struct int_min_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
// unsigned
template&lt; unsigned long Value &gt;
struct uint_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
} // namespace boost
</pre>
</pre></blockquote>
</blockquote>
<p>[Templates to select type based on maximum value are under development.]
</p>
<h2><a name="easy">Easiest-to-Manipulate Types</a></h2>
<h2>Example</h2>
<p>The <code>int_fast_t</code> class template maps its input type to the
next-largest type that the processor can manipulate the easiest, or to
itself if the input type is already an easy-to-manipulate type. For
instance, processing a bunch of <code>char</code> objects may go faster
if they were converted to <code>int</code> objects before processing.
The input type, passed as the only template parameter, must be a
built-in integral type, except <code>bool</code>. Unsigned integral
types can be used, as well as signed integral types, despite the name.
The output type is given as the class member <code>fast</code>.</p>
<blockquote>
<pre>#include &lt;boost/integer.hpp&gt;
using boost::int_t;
<p><strong>Implementation Notes</strong><br>
By default, the output type is identical to the input type. Eventually,
this code's implementation should be conditionalized for each platform
to give accurate mappings between the built-in types and the
easiest-to-manipulate built-in types. Also, there is no guarantee that
the output type actually is easier to manipulate than the input
type.</p>
...
int_t&lt;24&gt;::least my_var; </pre>
<h2><a name="sized">Sized Types</a></h2>
</blockquote>
<h2>Demonstration Program</h2>
<p>The <code>int_t</code>, <code>uint_t</code>,
<code>int_max_value_t</code>, <code>int_min_value_t</code>, and
<code>uint_value_t</code> class templates find the most appropiate
built-in integral type for the given template parameter. This type is
given by the class member <code>least</code>. The easiest-to-manipulate
version of that type is given by the class member <code>fast</code>.
The following table describes each template's criteria.</p>
<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&lt;&gt;</b>
and <b>uint_t&lt;&gt;</b> examples.</p>
<table border="1" cellpadding="5">
<caption>Criteria for the Sized Type Class Templates</caption>
<tr>
<th>Class Template</th>
<th>Template Parameter Mapping</th>
</tr>
<tr>
<td><code>boost::int_t</code></td>
<td>The smallest built-in signed integral type with at least the
given number of bits, including the sign bit. The parameter
should be a positive number. A compile-time error results if
the parameter is larger than the number of bits in a
<code>long</code>.</td>
</tr>
<tr>
<td><code>boost::uint_t</code></td>
<td>The smallest built-in unsigned integral type with at least
the given number of bits. The parameter should be a positive
number. A compile-time error results if the parameter is
larger than the number of bits in an <code>unsigned
long</code>.</td>
</tr>
<tr>
<td><code>boost::int_max_value_t</code></td>
<td>The smallest built-in signed integral type that supports the
given value as a maximum. The parameter should be a
positive number.</td>
</tr>
<tr>
<td><code>boost::int_min_value_t</code></td>
<td>The smallest built-in signed integral type that supports the
given value as a minimum. The parameter should be a
negative number.</td>
</tr>
<tr>
<td><code>boost::uint_value_t</code></td>
<td>The smallest built-in unsigned integral type that supports
the given value as a maximum. The parameter should be a
positive number.</td>
</tr>
</table>
<h2>Rationale</h2>
<h2><a name="example">Example</a></h2>
<blockquote><pre>#include &lt;boost/integer.hpp&gt;
//...
int main()
{
boost::int_t&lt;24&gt;::least my_var;
//...
}
</pre></blockquote>
<h2><a name="demo">Demonstration Program</a></h2>
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a
simplistic demonstration of the results from instantiating various
examples of the sized type class templates.</p>
<h2><a name="rationale">Rationale</a></h2>
<p>The rationale for the design of the templates in this header includes:</p>
<ul>
<li>Avoid&nbsp; recursion because of concern about C++'s limited guaranteed
recursion depth (17).</li>
<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>
<h2><a name="alternative">Alternative</a></h2>
<p>The author of the Boost integer type choosing templates is <a href="../../people/beman_dawes.html">Beman
Dawes</a>.&nbsp; 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>
<p>If the number of bits required is known beforehand, it may be more
appropriate to use the types supplied in <cite><a
href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;</a></cite>.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of most of the Boost integer type choosing templates is <a
href="../../people/beman_dawes.html">Beman Dawes</a>. He gives thanks
to Valentin Bonnard and
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
their designs for similar templates. <a
href="../../people/daryle_walker.html">Daryle Walker</a> designed the
value-based sized templates.</p>
<hr>
<p>Revised&nbsp; 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 &quot;as is&quot; without express or implied warranty,
and with no claim as to its suitability for any purpose.</p>
<p></p>
<p>&nbsp;</p>
<p>Revised May 20, 2001</p>
<p>&copy; 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 &quot;as
is&quot; without express or implied warranty, and with no claim as to
its suitability for any purpose.</p>
</body>
</html>

View File

@ -9,168 +9,247 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
// 31 Aug 99 Initial version
// This program is misnamed in that it is really a demonstration rather than
// a test. It doesn't detect failure, so isn't worthy of the name "test".
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
#include <iostream>
#include <boost/integer.hpp>
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t
using namespace boost; // not the best practice, but useful for testing
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
#include <iostream> // for std::cout (std::endl indirectly)
#include <typeinfo> // for std::type_info
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
// Control if the names of the types for each version
// of the integer templates will be printed.
#ifndef CONTROL_SHOW_TYPES
#define CONTROL_SHOW_TYPES 0
#endif
// If specializations have not already been done, then we can confirm
// the effects of the "fast" types by making a specialization.
namespace boost
{
template<> struct int_fast_t<short> { typedef long fast; };
template < >
struct int_fast_t< short >
{
typedef long fast;
};
}
int main()
// Show the types of an integer template version
#if CONTROL_SHOW_TYPES
#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \
#Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \
Number > :: Type).name() << ".\"\n"
#else
#define SHOW_TYPE(Template, Number, Type)
#endif
#define SHOW_TYPES(Template, Type) SHOW_TYPE(Template, 32, Type); \
SHOW_TYPE(Template, 31, Type); SHOW_TYPE(Template, 30, Type); \
SHOW_TYPE(Template, 29, Type); SHOW_TYPE(Template, 28, Type); \
SHOW_TYPE(Template, 27, Type); SHOW_TYPE(Template, 26, Type); \
SHOW_TYPE(Template, 25, Type); SHOW_TYPE(Template, 24, Type); \
SHOW_TYPE(Template, 23, Type); SHOW_TYPE(Template, 22, Type); \
SHOW_TYPE(Template, 21, Type); SHOW_TYPE(Template, 20, Type); \
SHOW_TYPE(Template, 19, Type); SHOW_TYPE(Template, 18, Type); \
SHOW_TYPE(Template, 17, Type); SHOW_TYPE(Template, 16, Type); \
SHOW_TYPE(Template, 15, Type); SHOW_TYPE(Template, 14, Type); \
SHOW_TYPE(Template, 13, Type); SHOW_TYPE(Template, 12, Type); \
SHOW_TYPE(Template, 11, Type); SHOW_TYPE(Template, 10, Type); \
SHOW_TYPE(Template, 9, Type); SHOW_TYPE(Template, 8, Type); \
SHOW_TYPE(Template, 7, Type); SHOW_TYPE(Template, 6, Type); \
SHOW_TYPE(Template, 5, Type); SHOW_TYPE(Template, 4, Type); \
SHOW_TYPE(Template, 3, Type); SHOW_TYPE(Template, 2, Type); \
SHOW_TYPE(Template, 1, Type); SHOW_TYPE(Template, 0, Type)
#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type)
#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \
SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \
SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \
SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \
SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \
SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \
SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \
SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \
SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \
SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \
SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \
SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \
SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \
SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \
SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \
SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type)
#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type)
#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \
SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type)
#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type)
#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \
SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type)
// Test if a constant can fit within a certain type
#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < Number > :: Type ( Value ) == Value )
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (ULONG_MAX >> Number) > :: Type ( Value ) == Value )
#define PRIVATE_SHIFTED_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
PRIVATE_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
PRIVATE_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MAX >> Number) > :: Type ( Value ) == Value )
#define PRIVATE_POS_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value )
#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
// Test program
int
test_main
(
int,
char*[]
)
{
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() );
#ifndef BOOST_NO_USING_TEMPLATE
using boost::int_t;
using boost::uint_t;
using boost::int_max_value_t;
using boost::int_min_value_t;
using boost::uint_value_t;
#else
using namespace boost;
#endif
return 0;
SHOW_TYPES( int_t, least );
SHOW_TYPES( int_t, fast );
SHOW_TYPES( uint_t, least );
SHOW_TYPES( uint_t, fast );
SHOW_POS_SHIFTED_TYPES( int_max_value_t, least );
SHOW_POS_SHIFTED_TYPES( int_max_value_t, fast );
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, least );
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, fast );
SHOW_SHIFTED_TYPES( uint_value_t, least );
SHOW_SHIFTED_TYPES( uint_value_t, fast );
PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX );
PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX );
PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX );
PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX );
PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX );
PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX );
PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN );
PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN );
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX );
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX );
return boost::exit_success;
}

View File

@ -2,7 +2,7 @@
*
* Copyright Jens Maurer 2000
* Permission to use, copy, modify, sell, and distribute this software
* is hereby granted without free provided that the above copyright notice
* is hereby granted without fee provided that the above copyright notice
* appears in all copies and that both that copyright notice and this
* permission notice appear in supporting documentation,
*
@ -18,16 +18,12 @@
*/
#include <iostream>
#include <cassert>
#include <boost/integer_traits.hpp>
// use int64_t instead of long long for better portability
#include <boost/cstdint.hpp>
#ifdef NDEBUG
#error This test relies on assert() and thus makes no sense with NDEBUG defined
#endif
// enable if you have "long long" and the proper macros in <limits.h>
#undef HAVE_LONG_LONG
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
/*
* General portability note:
@ -39,22 +35,37 @@
* Therefore, avoid explicit function template instantiations.
*/
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
namespace fix{
inline int make_char_numeric_for_streaming(char c) { return c; }
inline int make_char_numeric_for_streaming(signed char c) { return c; }
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
}
using namespace fix;
#else
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
inline int make_char_numeric_for_streaming(char c) { return c; }
inline int make_char_numeric_for_streaming(signed char c) { return c; }
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
#endif
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()
<< "; min is " << make_char_numeric_for_streaming(traits::min())
<< ", max is " << make_char_numeric_for_streaming(traits::max())
<< std::endl;
assert(traits::is_specialized);
assert(traits::is_integer);
assert(traits::is_integral);
assert(traits::const_min == traits::min());
assert(traits::const_max == traits::max());
BOOST_TEST(traits::is_specialized);
BOOST_TEST(traits::is_integer);
BOOST_TEST(traits::is_integral);
BOOST_TEST(traits::const_min == traits::min());
BOOST_TEST(traits::const_max == traits::max());
}
int main()
int test_main(int, char*[])
{
runtest("bool", bool());
runtest("char", char());
@ -62,6 +73,7 @@ int main()
runtest("signed char", signed_char());
typedef unsigned char unsigned_char;
runtest("unsigned char", unsigned_char());
runtest("wchar_t", wchar_t());
runtest("short", short());
typedef unsigned short unsigned_short;
runtest("unsigned short", unsigned_short());
@ -71,13 +83,17 @@ int main()
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_long());
#ifdef HAVE_LONG_LONG
typedef long long long_long;
runtest("long long", long_long());
typedef unsigned long long unsigned_long_long;
runtest("unsigned long long", unsigned_long_long());
#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
//
// MS/Borland compilers can't support 64-bit member constants
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
runtest("int64_t (possibly long long)", boost::int64_t());
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
#else
std::cout << "Skipped int64_t and uint64_t" << std::endl;
#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;
}

112
test/integer_mask_test.cpp Normal file
View File

@ -0,0 +1,112 @@
// boost integer_mask.hpp test program -------------------------------------//
// (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 most recent version including documentation.
// Revision History
// 23 Sep 2001 Initial version (Daryle Walker)
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc.
#include <iostream> // for std::cout (std::endl indirectly)
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
(v) >::high_bit == (1ul << (v)) );
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
(v) >::high_bit_fast == (1ul << (v)) );
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
(v) >::sig_bits == ((1ul << (v)) - 1) );
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
int test_main( int, char*[] )
{
using std::cout;
using std::endl;
cout << "Doing high_bit_mask_t tests." << endl;
PRIVATE_HIGH_BIT_TEST( 31 );
PRIVATE_HIGH_BIT_TEST( 30 );
PRIVATE_HIGH_BIT_TEST( 29 );
PRIVATE_HIGH_BIT_TEST( 28 );
PRIVATE_HIGH_BIT_TEST( 27 );
PRIVATE_HIGH_BIT_TEST( 26 );
PRIVATE_HIGH_BIT_TEST( 25 );
PRIVATE_HIGH_BIT_TEST( 24 );
PRIVATE_HIGH_BIT_TEST( 23 );
PRIVATE_HIGH_BIT_TEST( 22 );
PRIVATE_HIGH_BIT_TEST( 21 );
PRIVATE_HIGH_BIT_TEST( 20 );
PRIVATE_HIGH_BIT_TEST( 19 );
PRIVATE_HIGH_BIT_TEST( 18 );
PRIVATE_HIGH_BIT_TEST( 17 );
PRIVATE_HIGH_BIT_TEST( 16 );
PRIVATE_HIGH_BIT_TEST( 15 );
PRIVATE_HIGH_BIT_TEST( 14 );
PRIVATE_HIGH_BIT_TEST( 13 );
PRIVATE_HIGH_BIT_TEST( 12 );
PRIVATE_HIGH_BIT_TEST( 11 );
PRIVATE_HIGH_BIT_TEST( 10 );
PRIVATE_HIGH_BIT_TEST( 9 );
PRIVATE_HIGH_BIT_TEST( 8 );
PRIVATE_HIGH_BIT_TEST( 7 );
PRIVATE_HIGH_BIT_TEST( 6 );
PRIVATE_HIGH_BIT_TEST( 5 );
PRIVATE_HIGH_BIT_TEST( 4 );
PRIVATE_HIGH_BIT_TEST( 3 );
PRIVATE_HIGH_BIT_TEST( 2 );
PRIVATE_HIGH_BIT_TEST( 1 );
PRIVATE_HIGH_BIT_TEST( 0 );
cout << "Doing low_bits_mask_t tests." << endl;
PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops!
PRIVATE_LOW_BITS_TEST( 31 );
PRIVATE_LOW_BITS_TEST( 30 );
PRIVATE_LOW_BITS_TEST( 29 );
PRIVATE_LOW_BITS_TEST( 28 );
PRIVATE_LOW_BITS_TEST( 27 );
PRIVATE_LOW_BITS_TEST( 26 );
PRIVATE_LOW_BITS_TEST( 25 );
PRIVATE_LOW_BITS_TEST( 24 );
PRIVATE_LOW_BITS_TEST( 23 );
PRIVATE_LOW_BITS_TEST( 22 );
PRIVATE_LOW_BITS_TEST( 21 );
PRIVATE_LOW_BITS_TEST( 20 );
PRIVATE_LOW_BITS_TEST( 19 );
PRIVATE_LOW_BITS_TEST( 18 );
PRIVATE_LOW_BITS_TEST( 17 );
PRIVATE_LOW_BITS_TEST( 16 );
PRIVATE_LOW_BITS_TEST( 15 );
PRIVATE_LOW_BITS_TEST( 14 );
PRIVATE_LOW_BITS_TEST( 13 );
PRIVATE_LOW_BITS_TEST( 12 );
PRIVATE_LOW_BITS_TEST( 11 );
PRIVATE_LOW_BITS_TEST( 10 );
PRIVATE_LOW_BITS_TEST( 9 );
PRIVATE_LOW_BITS_TEST( 8 );
PRIVATE_LOW_BITS_TEST( 7 );
PRIVATE_LOW_BITS_TEST( 6 );
PRIVATE_LOW_BITS_TEST( 5 );
PRIVATE_LOW_BITS_TEST( 4 );
PRIVATE_LOW_BITS_TEST( 3 );
PRIVATE_LOW_BITS_TEST( 2 );
PRIVATE_LOW_BITS_TEST( 1 );
return boost::exit_success;
}

151
test/static_log2_test.cpp Normal file
View File

@ -0,0 +1,151 @@
// Boost static_log2.hpp test program --------------------------------------//
// (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 most recent version including documentation.
// Revision History
// 01 Oct 2001 Initial version (Daryle Walker)
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/static_log2.hpp> // for boost::static_log2
#include <iostream> // for std::cout (std::endl indirectly)
// Macros to compact code
#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
// Control to check for a compile-time error
#ifndef CONTROL_LB_0_TEST
#define PRIVATE_LB_0_TEST
#else
#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 )
#endif
// Main testing function
int
test_main
(
int , // "argc" is unused
char * [] // "argv" is unused
)
{
std::cout << "Doing tests on static_log2." << std::endl;
PRIVATE_LB_0_TEST;
PRIVATE_LB_TEST( 1, 0 );
PRIVATE_LB_TEST( 2, 1 );
PRIVATE_LB_TEST( 3, 1 );
PRIVATE_LB_TEST( 4, 2 );
PRIVATE_LB_TEST( 5, 2 );
PRIVATE_LB_TEST( 6, 2 );
PRIVATE_LB_TEST( 7, 2 );
PRIVATE_LB_TEST( 8, 3 );
PRIVATE_LB_TEST( 9, 3 );
PRIVATE_LB_TEST( 10, 3 );
PRIVATE_LB_TEST( 11, 3 );
PRIVATE_LB_TEST( 12, 3 );
PRIVATE_LB_TEST( 13, 3 );
PRIVATE_LB_TEST( 14, 3 );
PRIVATE_LB_TEST( 15, 3 );
PRIVATE_LB_TEST( 16, 4 );
PRIVATE_LB_TEST( 17, 4 );
PRIVATE_LB_TEST( 18, 4 );
PRIVATE_LB_TEST( 19, 4 );
PRIVATE_LB_TEST( 20, 4 );
PRIVATE_LB_TEST( 21, 4 );
PRIVATE_LB_TEST( 22, 4 );
PRIVATE_LB_TEST( 23, 4 );
PRIVATE_LB_TEST( 24, 4 );
PRIVATE_LB_TEST( 25, 4 );
PRIVATE_LB_TEST( 26, 4 );
PRIVATE_LB_TEST( 27, 4 );
PRIVATE_LB_TEST( 28, 4 );
PRIVATE_LB_TEST( 29, 4 );
PRIVATE_LB_TEST( 30, 4 );
PRIVATE_LB_TEST( 31, 4 );
PRIVATE_LB_TEST( 32, 5 );
PRIVATE_LB_TEST( 33, 5 );
PRIVATE_LB_TEST( 34, 5 );
PRIVATE_LB_TEST( 35, 5 );
PRIVATE_LB_TEST( 36, 5 );
PRIVATE_LB_TEST( 37, 5 );
PRIVATE_LB_TEST( 38, 5 );
PRIVATE_LB_TEST( 39, 5 );
PRIVATE_LB_TEST( 40, 5 );
PRIVATE_LB_TEST( 63, 5 );
PRIVATE_LB_TEST( 64, 6 );
PRIVATE_LB_TEST( 65, 6 );
PRIVATE_LB_TEST( 127, 6 );
PRIVATE_LB_TEST( 128, 7 );
PRIVATE_LB_TEST( 129, 7 );
PRIVATE_LB_TEST( 255, 7 );
PRIVATE_LB_TEST( 256, 8 );
PRIVATE_LB_TEST( 257, 8 );
PRIVATE_LB_TEST( 511, 8 );
PRIVATE_LB_TEST( 512, 9 );
PRIVATE_LB_TEST( 513, 9 );
PRIVATE_LB_TEST( 1023, 9 );
PRIVATE_LB_TEST( 1024, 10 );
PRIVATE_LB_TEST( 1025, 10 );
PRIVATE_LB_TEST( 2047, 10 );
PRIVATE_LB_TEST( 2048, 11 );
PRIVATE_LB_TEST( 2049, 11 );
PRIVATE_LB_TEST( 4095, 11 );
PRIVATE_LB_TEST( 4096, 12 );
PRIVATE_LB_TEST( 4097, 12 );
PRIVATE_LB_TEST( 8191, 12 );
PRIVATE_LB_TEST( 8192, 13 );
PRIVATE_LB_TEST( 8193, 13 );
PRIVATE_LB_TEST( 16383, 13 );
PRIVATE_LB_TEST( 16384, 14 );
PRIVATE_LB_TEST( 16385, 14 );
PRIVATE_LB_TEST( 32767, 14 );
PRIVATE_LB_TEST( 32768, 15 );
PRIVATE_LB_TEST( 32769, 15 );
PRIVATE_LB_TEST( 65535, 15 );
PRIVATE_LB_TEST( 65536, 16 );
PRIVATE_LB_TEST( 65537, 16 );
return boost::exit_success;
}

View File

@ -0,0 +1,94 @@
// Boost static_min_max.hpp test program -----------------------------------//
// (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 most recent version including documentation.
// Revision History
// 23 Sep 2001 Initial version (Daryle Walker)
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
#include <iostream> // for std::cout (std::endl indirectly)
// Main testing function
int
test_main
(
int , // "argc" is unused
char * [] // "argv" is unused
)
{
using std::cout;
using std::endl;
using boost::static_signed_min;
using boost::static_signed_max;
using boost::static_unsigned_min;
using boost::static_unsigned_max;
// Two positives
cout << "Doing tests with two positive values." << endl;
BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
// Two negatives
cout << "Doing tests with two negative values." << endl;
BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
// With zero
cout << "Doing tests with zero and a positive or negative value." << endl;
BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
// With identical
cout << "Doing tests with two identical values." << endl;
BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
return boost::exit_success;
}