Compare commits

...

32 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
20 changed files with 1927 additions and 755 deletions

View File

@ -69,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 -->17 Aug 2001<!--webbot bot="Timestamp" endspan i-checksum="14763" -->
<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,21 +9,12 @@
// 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 <cassert>
#include <iostream>
#include <boost/cstdint.hpp>
//
// macros should not be defined by default:
//
#ifdef INT8_C
#error header incorrectly implemented
#endif
//
// now define the macros:
//
#define __STDC_CONSTANT_MACROS
#include <boost/cstdint.hpp>
@ -108,14 +99,21 @@ void integral_constant_type_check(T1, T2)
// 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));
T1 t1 = -1;
T2 t2 = -1;
assert(t1 == t2);
if(t1 >= 0)
assert(t2 >= 0);
#endif
if(t1 > 0)
assert(t2 > 0);
else
assert(t2 < 0);
assert(!(t2 > 0));
}
@ -216,12 +214,4 @@ int main()
return 0;
}
//
// now verify that constant macros get undef'ed correctly:
//
#undef __STDC_CONSTANT_MACROS
#include <boost/cstdint.hpp>
#ifdef INT8_C
#error boost/cstdint.hpp not correctly defined
#endif

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

@ -9,6 +9,7 @@
// 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)
@ -24,16 +25,18 @@
#include <boost/config.hpp>
#ifdef BOOST_SYSTEM_HAS_STDINT_H
#ifdef BOOST_HAS_STDINT_H
// The following #include is an implementation artifact; not part of interface.
# ifdef __hpux
// HP-UX has a nice <stdint.h> in a non-standard location
# include <sys/_inttypes.h>
// 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
@ -78,9 +81,55 @@ namespace boost
} // namespace boost
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
// FreeBSD has an <inttypes.h> that contains much of what we need
# include <inttypes.h>
#else // BOOST_SYSTEM_HAS_STDINT_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
@ -144,11 +193,18 @@ namespace boost
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
# if !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
# 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(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
# 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;
@ -157,9 +213,7 @@ namespace boost
typedef unsigned long long uint64_t;
typedef unsigned long long uint_least64_t;
typedef unsigned long long uint_fast64_t;
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# elif ULONG_MAX != 0xffffffff
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
@ -174,9 +228,9 @@ namespace boost
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
# elif defined(BOOST_HAS_MS_INT64)
//
// we have Borland/Microsoft __int64:
// we have Borland/Intel/Microsoft __int64:
//
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
@ -195,7 +249,7 @@ namespace boost
} // namespace boost
#endif // BOOST_SYSTEM_HAS_STDINT_H
#endif // BOOST_HAS_STDINT_H
#endif // BOOST_CSTDINT_HPP
@ -210,15 +264,17 @@ __STDC_CONSTANT_MACROS is defined.
Undefine the macros if __STDC_CONSTANT_MACROS is
not defined and the macros are (cf <cassert>).
Added 23rd September (John Maddock).
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)
#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_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
# if defined(BOOST_HAS_MS_INT64)
//
// Borland/Microsoft compilers have width specific suffixes:
// Borland/Intel/Microsoft compilers have width specific suffixes:
//
# define INT8_C(value) value##i8
# define INT16_C(value) value##i16
@ -265,16 +321,20 @@ Added 23rd September (John Maddock).
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
# if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)
# 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
# if (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
(defined(ULONG_LONG_MAX) && (defined(__hpux) || ULONG_LONG_MAX == 18446744073709551615U)) || \
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# elif ULONG_MAX != 0xffffffff
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
@ -296,7 +356,7 @@ Added 23rd September (John Maddock).
# endif // Borland/Microsoft specific width suffixes
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
//
// undef all the macros:
//

View File

@ -9,6 +9,7 @@
// 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
@ -16,7 +17,10 @@
#ifndef BOOST_INTEGER_HPP
#define BOOST_INTEGER_HPP
#include <boost/limits.hpp>
#include <boost/integer_fwd.hpp> // self include
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
namespace boost
{
@ -75,11 +79,51 @@ namespace boost
// 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

@ -23,7 +23,7 @@
// These are an implementation detail and not part of the interface
#include <limits.h>
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
#include <wchar.h>
#endif
@ -47,7 +47,10 @@ public:
};
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// The definition is required even for integral static constants
// 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;
@ -85,18 +88,25 @@ class integer_traits<unsigned char>
template<>
class integer_traits<wchar_t>
: public std::numeric_limits<wchar_t>,
#if defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
#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)
// SGI MIPSpro with native library doesn't have them, either
#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__) && !defined(__SGI_STL_PORT)
// GCC 2.95.2 doesn't have them on HP-UX, either
// (also, std::numeric_limits<wchar_t> appears to return the wrong values)
#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
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
#error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
#endif
{ };
#endif // BOOST_NO_INTRINSIC_WCHAR_T
@ -137,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>,

View File

@ -1,272 +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: This is an implementation of the ISO C Standard (1999) stdint.h
// header. C++ programs are advised to use <boost/cstdint.hpp> rather than
// this header.
// NOTE OF OBSOLESCENCE: In general, this header file cannot detect
// whether the current translation unit somewhere includes ISO C99
// <stdint.h> or not. For example, in case BOOST_SYSTEM_HAS_STDINT_H
// is not defined and ISO C99 <stdint.h> has been included before,
// this file will re-define ISO C99 reserved file-scope identifiers
// such as int8_t (see ISO C99 7.1.3 and 7.18). Defining the macro
// BOOST_SYSTEM_HAS_STDINT_H is not sufficient in general, in
// particular if a partly conformant <stdint.h> header is available
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
//
// In order to avoid incompatibilities with ISO C99, this header
// should not be used at all, and it may be deleted in the future.
// C++ programs which require ISO C99 <stdint.h> functionality are
// strongly advised to use <boost/cstdint.hpp> instead, which
// provides <stdint.h> names in namespace boost, e.g. boost::int8_t.
// Revision History
// 12 Nov 00 obsoleted (Jens Maurer)
// 23 Sep 00 INTXX_C support added (John Maddock)
// 22 Sep 00 64-bit support for Borland & Microsoft compilers (John Maddock)
// 8 Aug 99 Initial version (Beman Dawes)
#ifndef BOOST_STDINT_H
#define BOOST_STDINT_H
#include <boost/config.hpp>
#ifdef BOOST_SYSTEM_HAS_STDINT_H
#include <stdint.h>
#else
#include <limits.h> // implementation artifact; not part of interface
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
// platforms. For other systems, they will have to be hand tailored.
//
// Because the fast types are assumed to be the same as the undecorated types,
// it may be possible to hand tailor a more efficient implementation. Such
// an optimization may be illusionary; on the Intel x86-family 386 on, for
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
// 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.h
# 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.h
# 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.h
# endif
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
// 2**64 - 1
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.h
# 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.h
# endif
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
//
// we have Borland/Microsoft __int64:
//
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
typedef __int64 int64_t;
typedef __int64 int_least64_t;
typedef __int64 int_fast64_t;
typedef unsigned __int64 uint64_t;
typedef unsigned __int64 uint_least64_t;
typedef unsigned __int64 uint_fast64_t;
# else // assume no 64-bit integers
#define BOOST_NO_INT64_T
typedef int32_t intmax_t;
typedef uint32_t uintmax_t;
# endif
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
#endif // BOOST_STDINT_H
/****************************************************
Macro definition section:
Define various INTXX_C macros only if
__STDC_CONSTANT_MACROS is defined.
Undefine the macros if __STDC_CONSTANT_MACROS is
not defined and the macros are (cf <cassert>).
Added 23rd September (John Maddock).
******************************************************/
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
#define BOOST__STDC_CONSTANT_MACROS_DEFINED
#if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
//
// Borland/Microsoft compilers have width specific suffixes:
//
#define INT8_C(value) value##i8
#define INT16_C(value) value##i16
#define INT32_C(value) value##i32
#define INT64_C(value) value##i64
#ifdef __BORLANDC__
// Borland bug: appending ui8 makes the type
// a signed char!!!!
#define UINT8_C(value) static_cast<unsigned char>(value##u)
#else
#define UINT8_C(value) value##ui8
#endif
#define UINT16_C(value) value##ui16
#define UINT32_C(value) value##ui32
#define UINT64_C(value) value##ui64
#define INTMAX_C(value) value##i64
#define UINTMAX_C(value) value##ui64
#else
// do it the old fashioned way:
// 8-bit types -------------------------------------------------------------//
# if UCHAR_MAX == 0xff
#define INT8_C(value) static_cast<int8_t>(value)
#define UINT8_C(value) static_cast<uint8_t>(value##u)
# endif
// 16-bit types ------------------------------------------------------------//
# if USHRT_MAX == 0xffff
#define INT16_C(value) static_cast<int16_t>(value)
#define UINT16_C(value) static_cast<uint16_t>(value##u)
# endif
// 32-bit types ------------------------------------------------------------//
# if UINT_MAX == 0xffffffff
#define INT32_C(value) value
#define UINT32_C(value) value##u
# elif ULONG_MAX == 0xffffffff
#define INT32_C(value) value##L
#define UINT32_C(value) value##uL
# endif
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
#define INT64_C(value) value##LL
#define UINT64_C(value) value##uLL
# else
# error defaults not correct; you must hand modify boost/stdint.h
# endif
# elif ULONG_MAX != 0xffffffff
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
#define INT64_C(value) value##L
#define UINT64_C(value) value##uL
# else
# error defaults not correct; you must hand modify boost/stdint.h
# endif
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
//
// we have Borland/Microsoft __int64:
//
#define INT64_C(value) value##i64
#define UINT64_C(value) value##ui64
# endif
#ifdef BOOST_NO_INT64_T
#define INTMAX_C(value) INT32_C(value)
#define UINTMAX_C(value) UINT32_C(value)
#else
#define INTMAX_C(value) INT64_C(value)
#define UINTMAX_C(value) UINT64_C(value)
#endif
#endif // Borland/MS specific
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
//
// undef all the macros:
//
#undef INT8_C
#undef INT16_C
#undef INT32_C
#undef INT64_C
#undef UINT8_C
#undef UINT16_C
#undef UINT32_C
#undef UINT64_C
#undef INTMAX_C
#undef UINTMAX_C
#endif // constant macros

112
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/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,9 +20,14 @@
<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>
@ -59,40 +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 the 1999 C standard
without resorting to undefined behavior in terms of
the 1998 C++ standard.&nbsp; The header <code>&lt;boost/cstdint.hpp&gt;</code>
makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than
compete with the C++ Standard Library.&nbsp; Should some future C++ standard
include <code>&lt;stdint.h&gt;</code> and <code>&lt;cstdint&gt;</code>, then <code>&lt;boost/cstdint.hpp&gt;</code>
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.
<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>
As another implementation artifact, certain C
<code>&lt;stdint.h&gt;</code> typedef names may possibly be visible in the
global namespace to users of <code>&lt;boost/cstdint.hpp&gt;</code>.
Don't use these names, they are not part of any Boost specified
<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.
instead.</p>
<hr>
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->17 Aug 2001<!--webbot bot="Timestamp" endspan i-checksum="14763" -->
<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,112 +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
// int_fast_t&lt;&gt; works correctly for unsigned too, in spite of the name.
template&lt; typename LeastInt &gt; // Required: LeastInt is integral type, not bool
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
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;
// int_fast_t&lt;&gt; works correctly for unsigned too, in spite of the name.
};
} // 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,309 +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
#include <iostream>
#include <boost/integer.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
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
#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
// just to prove it works, specialize int_fast_t<short> to yield long
namespace boost
{
template<> struct int_fast_t<short> { typedef long fast; };
}
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
#include <iostream> // for std::cout (std::endl indirectly)
#include <typeinfo> // for std::type_info
int test_main(int,char**)
{
using boost::int_t;
using boost::uint_t;
#ifdef BOOST_SHOW_TYPES
std::cout << 32 << ' '; test( int_t<32>::least() );
std::cout << 31 << ' '; test( int_t<31>::least() );
std::cout << 30 << ' '; test( int_t<30>::least() );
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() );
// 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
long v = 0x7FFFFFFF;
BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1;
BOOST_TEST( int_t<0>::least(v) == v );
v = 0x7FFFFFFF;
BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1;
BOOST_TEST( int_t<0>::fast(v) == v );
unsigned long u = 0xFFFFFFFF;
BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1;
BOOST_TEST( uint_t<0>::least(u) == u );
u = 0xFFFFFFFF;
BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1;
BOOST_TEST( uint_t<0>::fast(u) == u );
return 0;
// 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;
};
}
// 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*[]
)
{
#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
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

@ -35,13 +35,28 @@
* 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;
BOOST_TEST(traits::is_specialized);
BOOST_TEST(traits::is_integer);
@ -68,7 +83,7 @@ int test_main(int, char*[])
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_long());
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__) && !defined(__BEOS__)
#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.

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;
}