mirror of
https://github.com/boostorg/integer.git
synced 2025-06-25 20:11:41 +02:00
Compare commits
72 Commits
boost-1.24
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
26f7ec0bd8 | |||
a1cc143de7 | |||
cd99f24a87 | |||
93612e6c0b | |||
d9f5b1bbf9 | |||
37d7590f2f | |||
cb9a7792cc | |||
291bb8c525 | |||
8602a17a10 | |||
29275d71aa | |||
9df9a90217 | |||
65607e3b82 | |||
39399de102 | |||
27aae3b3cb | |||
21fe6251ab | |||
07019a8801 | |||
3892592661 | |||
0935f20c69 | |||
7197caf500 | |||
92a46aac83 | |||
c32a045fa4 | |||
0c31aa03f0 | |||
bfc384a435 | |||
198530a48d | |||
91f511cab4 | |||
0f84fe35da | |||
fa5aba353f | |||
170a352574 | |||
4862574bb1 | |||
f2d22d091f | |||
1e6ab2dc10 | |||
a656e7744f | |||
46fdbba4b8 | |||
f2ea03679b | |||
890e28ab67 | |||
1252426554 | |||
19fb03cefe | |||
a9b35df2f8 | |||
49a8d69fe3 | |||
9cc587a7f2 | |||
2de1422682 | |||
344fe9f30a | |||
8ad3bbafbc | |||
cc1183d347 | |||
a9703fa803 | |||
5e26f47535 | |||
57e7ccd494 | |||
c56e4674f8 | |||
41620a14f9 | |||
a42ede713e | |||
92de2f44a0 | |||
59779dec2c | |||
3bb567ad9d | |||
c50993d5d4 | |||
5477a9641c | |||
162c6aefa1 | |||
24e6bfbfaa | |||
ccabb522d0 | |||
0995d0a6fb | |||
5ec8116c34 | |||
4a094c4bcb | |||
a7d2da8d1c | |||
4d2a921dbf | |||
0c758855e4 | |||
3399df597e | |||
a066e242b0 | |||
a635f753a4 | |||
08f30ea46c | |||
292eeb5c90 | |||
8a105dab3f | |||
5b0d514aa4 | |||
eee6dfa4d9 |
@ -9,7 +9,7 @@
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Header
|
||||
boost/cstdint.hpp </h1>
|
||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for
|
||||
@ -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> </p>
|
||||
|
||||
|
@ -1,35 +1,29 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 2000. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// See http://www.boost.org/libs/integer for 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
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <boost/cstdint.hpp>
|
||||
//
|
||||
// macros should not be defined by default:
|
||||
//
|
||||
#ifdef INT8_C
|
||||
#error header incorrectly implemented
|
||||
#endif
|
||||
//
|
||||
// now define the macros:
|
||||
//
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test makes no sense with NDEBUG defined
|
||||
#endif
|
||||
int main()
|
||||
{
|
||||
std::cout << "This test makes no sense with NDEBUG defined.\n";
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
@ -108,14 +102,35 @@ 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 defined(BOOST_HAS_STDINT_H)
|
||||
// native headers are permitted to promote small
|
||||
// unsigned types to type int:
|
||||
if(sizeof(T1) >= sizeof(int))
|
||||
{
|
||||
if(t1 > 0)
|
||||
assert(t2 > 0);
|
||||
else
|
||||
assert(!(t2 > 0));
|
||||
}
|
||||
else if(t1 < 0)
|
||||
assert(!(t2 > 0));
|
||||
#else
|
||||
if(t1 > 0)
|
||||
assert(t2 > 0);
|
||||
else
|
||||
assert(t2 < 0);
|
||||
assert(!(t2 > 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -215,13 +230,4 @@ int main()
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// now verify that constant macros get undef'ed correctly:
|
||||
//
|
||||
#undef __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef INT8_C
|
||||
#error boost/cstdint.hpp not correctly defined
|
||||
#endif
|
||||
|
210
doc/integer_mask.html
Normal file
210
doc/integer_mask.html
Normal file
@ -0,0 +1,210 @@
|
||||
<!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="../../../boost.png" alt="boost.png (6897 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"><boost/integer/integer_mask.hpp></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 <cstddef> <i>// for std::size_t</i>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template < std::size_t Bit >
|
||||
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 < std::size_t Bits >
|
||||
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 <boost/integer/integer_mask.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::high_bit_mask_t<29> mask1_type;
|
||||
typedef boost::low_bits_mask_t<15> mask2_type;
|
||||
|
||||
mask1_type::least my_var1;
|
||||
mask2_type::fast my_var2;
|
||||
//...
|
||||
|
||||
my_var1 |= mask1_type::high_bit;
|
||||
my_var2 &= 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>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
215
doc/static_log2.html
Normal file
215
doc/static_log2.html
Normal file
@ -0,0 +1,215 @@
|
||||
<!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="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
||||
|
||||
|
||||
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></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>
|
||||
|
||||
<li><a href="#whatsnew"><b>What's new</b></a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef <em>implementation-defined</em> static_log2_argument_type;
|
||||
typedef <em>implementation-defined</em> static_log2_result_type;
|
||||
|
||||
template < static_log2_argument_type arg >
|
||||
struct static_log2
|
||||
{
|
||||
static const static_log2_result_type value = <em>implementation-defined</em>;
|
||||
};
|
||||
|
||||
|
||||
template < >
|
||||
struct static_log2< 0 >
|
||||
{
|
||||
// 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>static_log2_argument_type</code>. The template
|
||||
only defines one member, <code>value</code>, which gives the truncated
|
||||
base-two logarithm of the template argument.</p>
|
||||
|
||||
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
||||
specialization of <code>static_log2</code> for a template argument
|
||||
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>
|
||||
|
||||
<p>Note: <ul>
|
||||
|
||||
<li><code>static_log2_argument_type</code> is an <i>unsigned integer
|
||||
type</i> (C++ standard, 3.9.1p3).</li>
|
||||
|
||||
<li><code>static_log2_result_type</code> is an <i>integer type</i>
|
||||
(C++ standard, 3.9.1p7).</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
#include "boost/integer/static_log2.hpp"
|
||||
|
||||
|
||||
template < boost::static_log2_argument_type value >
|
||||
bool is_it_what()
|
||||
{
|
||||
typedef boost::static_log2<value> lb_type;
|
||||
|
||||
int temp = lb_type::value;
|
||||
//...
|
||||
return (temp % 2) != 0;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
bool temp = is_it_what<2000>();
|
||||
//...
|
||||
# if 0
|
||||
temp = is_it_what<0>(); // would give an error
|
||||
# endif
|
||||
//...
|
||||
temp = is_it_what<24>();
|
||||
//...
|
||||
}
|
||||
|
||||
</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="whatsnew">Changes from previous versions:</a></h2>
|
||||
|
||||
|
||||
|
||||
<ul>
|
||||
<li><i>New in version 1.32.0:</i><br><br>
|
||||
|
||||
The argument type and the result type of <code>boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code>unsigned long</code>
|
||||
and <code>int</code> respectively. Please, use the provided typedefs in new
|
||||
code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The original version of the Boost binary logarithm class template was
|
||||
written by <a href="../../../people/daryle_walker.html">Daryle Walker</a>
|
||||
and then enhanced by Giovanni Bajo with support for compilers without
|
||||
partial template specialization. The current version was suggested,
|
||||
together with a reference implementation, by Vesa Karvonen. Gennaro Prota
|
||||
wrote the actual source file.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
|
||||
<p>Revised July 19, 2004</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001.<br>
|
||||
© Copyright Gennaro Prota 2004.</p>
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
120
doc/static_min_max.html
Normal file
120
doc/static_min_max.html
Normal file
@ -0,0 +1,120 @@
|
||||
<!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="../../../boost.png" alt="boost.png (6897 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"><boost/integer/static_min_max.hpp></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 < 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;
|
||||
|
||||
}
|
||||
</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 <boost/integer/static_min_max.hpp>
|
||||
|
||||
template < unsigned long AddendSize1, unsigned long AddendSize2 >
|
||||
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<AddendSize1, AddendSize2>::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 &a1, addend2_type const &a2, sum_type &s ) const;
|
||||
};
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
int const a1[] = { 0, 4, 3 }; // 340
|
||||
int const a2[] = { 9, 8 }; // 89
|
||||
int s[ 4 ];
|
||||
adder<3,2> 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>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +1,16 @@
|
||||
// boost cstdint.hpp header file ------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// 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.
|
||||
// (C) Copyright Beman Dawes 1999.
|
||||
// (C) Copyright Jens Mauer 2001
|
||||
// (C) Copyright John Maddock 2001
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/integer for 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,20 +26,62 @@
|
||||
#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__) || defined(__IBMCPP__)
|
||||
# include <inttypes.h>
|
||||
# else
|
||||
# include <stdint.h>
|
||||
|
||||
// There is a bug in Cygwin two _C macros
|
||||
# if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
|
||||
# undef INTMAX_C
|
||||
# undef UINTMAX_C
|
||||
# define INTMAX_C(c) c##LL
|
||||
# define UINTMAX_C(c) c##ULL
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#ifdef __QNX__
|
||||
|
||||
// QNX (Dinkumware stdlib) defines these as non-standard names.
|
||||
// Reflect to the standard names.
|
||||
|
||||
typedef ::intleast8_t int_least8_t;
|
||||
typedef ::intfast8_t int_fast8_t;
|
||||
typedef ::uintleast8_t uint_least8_t;
|
||||
typedef ::uintfast8_t uint_fast8_t;
|
||||
|
||||
typedef ::intleast16_t int_least16_t;
|
||||
typedef ::intfast16_t int_fast16_t;
|
||||
typedef ::uintleast16_t uint_least16_t;
|
||||
typedef ::uintfast16_t uint_fast16_t;
|
||||
|
||||
typedef ::intleast32_t int_least32_t;
|
||||
typedef ::intfast32_t int_fast32_t;
|
||||
typedef ::uintleast32_t uint_least32_t;
|
||||
typedef ::uintfast32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
typedef ::intleast64_t int_least64_t;
|
||||
typedef ::intfast64_t int_fast64_t;
|
||||
typedef ::uintleast64_t uint_least64_t;
|
||||
typedef ::uintfast64_t uint_fast64_t;
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@ -78,11 +122,58 @@ namespace boost
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__)
|
||||
// FreeBSD and Tru64 have 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
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
using ::int64_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
using ::uint64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
# else
|
||||
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
# include <boost/limits.hpp> // implementation artifact; not part of interface
|
||||
# include <limits.h> // needed for limits macros
|
||||
|
||||
|
||||
namespace boost
|
||||
@ -112,12 +203,29 @@ namespace boost
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
# if defined(__crayx1)
|
||||
// The Cray X1 has a 16-bit short, however it is not recommend
|
||||
// for use in performance critical code.
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
# else
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# endif
|
||||
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
|
||||
// no 16-bit types on Cray:
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
@ -144,22 +252,27 @@ 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
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
typedef ::boost::long_long_type intmax_t;
|
||||
typedef ::boost::ulong_long_type uintmax_t;
|
||||
typedef ::boost::long_long_type int64_t;
|
||||
typedef ::boost::long_long_type int_least64_t;
|
||||
typedef ::boost::long_long_type int_fast64_t;
|
||||
typedef ::boost::ulong_long_type uint64_t;
|
||||
typedef ::boost::ulong_long_type uint_least64_t;
|
||||
typedef ::boost::ulong_long_type uint_fast64_t;
|
||||
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
@ -174,9 +287,18 @@ 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(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
|
||||
__extension__ typedef long long intmax_t;
|
||||
__extension__ typedef unsigned long long uintmax_t;
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef long long int_least64_t;
|
||||
__extension__ typedef long long int_fast64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
__extension__ typedef unsigned long long uint_least64_t;
|
||||
__extension__ typedef unsigned long long uint_fast64_t;
|
||||
# elif defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
// we have Borland/Intel/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
@ -195,7 +317,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#endif // BOOST_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
@ -210,15 +332,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 +389,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 +424,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:
|
||||
//
|
||||
@ -314,3 +442,5 @@ Added 23rd September (John Maddock).
|
||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
// boost integer.hpp header file -------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// Copyright Beman Dawes and Daryle Walker 1999. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/integer for 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 +15,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 +77,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
|
||||
|
||||
|
93
include/boost/integer/integer_mask.hpp
Normal file
93
include/boost/integer/integer_mask.hpp
Normal file
@ -0,0 +1,93 @@
|
||||
// Boost integer/integer_mask.hpp header file ------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org 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
|
132
include/boost/integer/static_log2.hpp
Normal file
132
include/boost/integer/static_log2.hpp
Normal file
@ -0,0 +1,132 @@
|
||||
// -------------- Boost static_log2.hpp header file ----------------------- //
|
||||
//
|
||||
// Copyright (C) 2001 Daryle Walker.
|
||||
// Copyright (C) 2003 Vesa Karvonen.
|
||||
// Copyright (C) 2003 Gennaro Prota.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// ---------------------------------------------------
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
|
||||
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace static_log2_impl {
|
||||
|
||||
// choose_initial_n<>
|
||||
//
|
||||
// Recursively doubles its integer argument, until it
|
||||
// becomes >= of the "width" (C99, 6.2.6.2p4) of
|
||||
// static_log2_argument_type.
|
||||
//
|
||||
// Used to get the maximum power of two less then the width.
|
||||
//
|
||||
// Example: if on your platform argument_type has 48 value
|
||||
// bits it yields n=32.
|
||||
//
|
||||
// It's easy to prove that, starting from such a value
|
||||
// of n, the core algorithm works correctly for any width
|
||||
// of static_log2_argument_type and that recursion always
|
||||
// terminates with x = 1 and n = 0 (see the algorithm's
|
||||
// invariant).
|
||||
|
||||
typedef unsigned long argument_type;
|
||||
typedef int result_type;
|
||||
|
||||
|
||||
template <result_type n>
|
||||
struct choose_initial_n {
|
||||
|
||||
enum { c = (argument_type(1) << n << n) != 0 };
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = !c*n + choose_initial_n<2*c*n>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct choose_initial_n<0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// start computing from n_zero - must be a power of two
|
||||
const result_type n_zero = 16;
|
||||
const result_type initial_n = choose_initial_n<n_zero>::value;
|
||||
|
||||
// static_log2_impl<>
|
||||
//
|
||||
// * Invariant:
|
||||
// 2n
|
||||
// 1 <= x && x < 2 at the start of each recursion
|
||||
// (see also choose_initial_n<>)
|
||||
//
|
||||
// * Type requirements:
|
||||
//
|
||||
// argument_type maybe any unsigned type with at least n_zero + 1
|
||||
// value bits. (Note: If larger types will be standardized -e.g.
|
||||
// unsigned long long- then the argument_type typedef can be
|
||||
// changed without affecting the rest of the code.)
|
||||
//
|
||||
|
||||
template <argument_type x, result_type n = initial_n>
|
||||
struct static_log2_impl {
|
||||
|
||||
enum { c = (x >> n) > 0 }; // x >= 2**n ?
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct static_log2_impl<1, 0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
}
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
// --------------------------------------
|
||||
// static_log2<x>
|
||||
// ----------------------------------------
|
||||
|
||||
typedef detail::static_log2_impl::argument_type static_log2_argument_type;
|
||||
typedef detail::static_log2_impl::result_type static_log2_result_type;
|
||||
|
||||
|
||||
template <static_log2_argument_type x>
|
||||
struct static_log2 {
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
static_log2_result_type,
|
||||
value = detail::static_log2_impl::static_log2_impl<x>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct static_log2<0> { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // include guard
|
55
include/boost/integer/static_min_max.hpp
Normal file
55
include/boost/integer/static_min_max.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
// Boost integer/static_min_max.hpp header file ----------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org 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
|
152
include/boost/integer_fwd.hpp
Normal file
152
include/boost/integer_fwd.hpp
Normal file
@ -0,0 +1,152 @@
|
||||
// Boost integer_fwd.hpp header file ---------------------------------------//
|
||||
|
||||
// (C) Copyright Dave Abrahams and Daryle Walker 2001. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
#ifndef BOOST_INTEGER_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< ::boost::long_long_type>;
|
||||
|
||||
template < >
|
||||
class integer_traits< ::boost::ulong_long_type >;
|
||||
#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
|
@ -1,20 +1,18 @@
|
||||
/* boost integer_traits.hpp header file
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
* Jens Maurer makes no representations about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
||||
*/
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||
#define BOOST_INTEGER_TRAITS_HPP
|
||||
|
||||
@ -23,7 +21,9 @@
|
||||
|
||||
// These are an implementation detail and not part of the interface
|
||||
#include <limits.h>
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
// we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
|
||||
// and some may have <wchar.h> but not <cwchar> ...
|
||||
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__))
|
||||
#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,33 @@ 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__))
|
||||
// Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native
|
||||
// library: they are wrong!
|
||||
#if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
|
||||
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(__OpenBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__NetBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__FreeBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__DragonFly__) && defined(__GNUC__))\
|
||||
|| (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
||||
// - SGI MIPSpro with native library
|
||||
// - gcc 3.x on HP-UX
|
||||
// - Mac OS X with native library
|
||||
// - gcc on FreeBSD, OpenBSD and NetBSD
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && !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,42 +155,82 @@ class integer_traits<unsigned long>
|
||||
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
||||
{ };
|
||||
|
||||
#ifdef ULLONG_MAX
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
|
||||
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
|
||||
{ };
|
||||
#elif defined(ULONG_LONG_MAX)
|
||||
|
||||
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>
|
||||
{ };
|
||||
class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ };
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
|
||||
{ };
|
||||
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
|
||||
#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(BOOST_HAS_LONG_LONG)
|
||||
//
|
||||
// we have long long but no constants, this happens for example with gcc in -ansi mode,
|
||||
// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
|
||||
//
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
|
||||
{ };
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
98
index.htm
98
index.htm
@ -1,98 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Boost Integer Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home </big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ </big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More </big></font></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<td align="center"><b><i>Header / Docs</i></b></td>
|
||||
<td align="center"><b><i>Contents</i></b></td>
|
||||
<td align="center"><b><i>Use</i></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
<p>The organization of boost integer headers and classes is designed to take
|
||||
advantage of <code><stdint.h></code> types from the 1999 C standard
|
||||
without resorting to undefined behavior in terms of
|
||||
the 1998 C++ standard. The header <code><boost/cstdint.hpp></code>
|
||||
makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/cstdint.hpp></code>
|
||||
will continue to function, but will become redundant and may be safely deprecated.</p>
|
||||
<p>Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
|
||||
<h2>Caveat emptor</h2>
|
||||
<p>As an
|
||||
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
visible to users of <boost/cstdint.hpp>. Don't use these macros; they are not part of
|
||||
any Boost specified interface.
|
||||
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||
|
||||
<p>
|
||||
As another implementation artifact, certain C
|
||||
<code><stdint.h></code> typedef names may possibly be visible in the
|
||||
global namespace to users of <code><boost/cstdint.hpp></code>.
|
||||
Don't use these names, they are not part of any Boost specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->17 Aug 2001<!--webbot bot="Timestamp" endspan i-checksum="14763" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
128
index.html
Normal file
128
index.html
Normal file
@ -0,0 +1,128 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Boost Integer Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
<table border="1" bgcolor="teal" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="white"><img src="../../boost.png" alt="boost.png (6897 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>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th>Header / Docs</th>
|
||||
<th>Contents</th>
|
||||
<th>Use</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><cite><a href="../../boost/integer_fwd.hpp"><boost/integer_fwd.hpp></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"><boost/cstdint.hpp><br>
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></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"><boost/integer/static_log2.hpp></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"><boost/integer/static_min_max.hpp></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 <cite><stdint.h></cite> types from the 1999 C
|
||||
standard without resorting to undefined behavior in terms of the 1998
|
||||
C++ standard. The header <cite><boost/cstdint.hpp></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><stdint.h></cite> and <cite><cstdint></cite>,
|
||||
then <cite><boost/cstdint.hpp></cite> will continue to function,
|
||||
but will become redundant and may be safely deprecated.</p>
|
||||
|
||||
<p>Because these are boost headers, their names conform to boost header
|
||||
naming conventions rather than C++ Standard Library header naming
|
||||
conventions.</p>
|
||||
|
||||
<h2><i>Caveat emptor</i></h2>
|
||||
|
||||
<p>As an implementation artifact, certain C
|
||||
<cite><limits.h></cite> macro names may possibly be visible to
|
||||
users of <cite><boost/cstdint.hpp></cite>. Don't use these
|
||||
macros; they are not part of any Boost-specified interface. Use
|
||||
<code>boost::integer_traits<></code> or
|
||||
<code>std::numeric_limits<></code> instead.</p>
|
||||
|
||||
<p>As another implementation artifact, certain C
|
||||
<cite><stdint.h></cite> typedef names may possibly be visible in
|
||||
the global namespace to users of <cite><boost/cstdint.hpp></cite>.
|
||||
Don't use these names, they are not part of any Boost-specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->03 Oct 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
236
integer.htm
236
integer.htm
@ -1,112 +1,212 @@
|
||||
<!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="../../boost.png" alt="boost.png (6897 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"><boost/integer.hpp></a></code>
|
||||
type selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility is
|
||||
particularly useful for solving generic programming problems.</p>
|
||||
<p>The <cite><a
|
||||
href="../../boost/integer.hpp"><boost/integer.hpp></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<></b> and <b>uint_t<></b> supply typedefs <b>least</b>
|
||||
and <b>fast</b>. The <b>least</b> type be the smallest type which holds at
|
||||
least the number of bits (including sign) specified. The <b>fast</b> type will
|
||||
be at least as large as the <b>least</b> type, but may possible be larger.
|
||||
There is no guarantee that the <b>fast</b> type will actually be faster than
|
||||
other possible types.</p>
|
||||
<h2><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"><boost/cstdint.hpp></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<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< int Bits > // bits (including sign) required, 0-32 valid
|
||||
template< int Bits >
|
||||
struct int_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // bits required, 0-32 valid
|
||||
template< int Bits >
|
||||
struct uint_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< long MaxValue >
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< long MinValue >
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< unsigned long Value >
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> 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 <boost/integer.hpp>
|
||||
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<24>::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<></b>
|
||||
and <b>uint_t<></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 <boost/integer.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int_t<24>::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 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>
|
||||
<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>. 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"><boost/cstdint.hpp></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 August 31, 1999</p>
|
||||
|
||||
<p><EFBFBD> Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
and distribute this document is granted provided this copyright notice appears in all
|
||||
copies. This document is provided "as is" without express or implied warranty,
|
||||
and with no claim as to its suitability for any purpose.</p>
|
||||
|
||||
<p></p>
|
||||
|
||||
<p> </p>
|
||||
<p>Revised May 20, 2001</p>
|
||||
|
||||
<p>© Copyright Beman Dawes 1999. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
568
integer_test.cpp
568
integer_test.cpp
@ -1,317 +1,291 @@
|
||||
// boost integer.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// Copyright Beman Dawes 1999. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// See http://www.boost.org/libs/integer for 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>
|
||||
#include <boost/test/minimal.hpp> // for main, BOOST_CHECK
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t
|
||||
|
||||
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 <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
#include <typeinfo> // for std::type_info
|
||||
|
||||
// just to prove it works, specialize int_fast_t<short> to yield long
|
||||
|
||||
// Control if the names of the types for each version
|
||||
// of the integer templates will be printed.
|
||||
#ifndef CONTROL_SHOW_TYPES
|
||||
#define CONTROL_SHOW_TYPES 0
|
||||
#endif
|
||||
|
||||
|
||||
// If specializations have not already been done, then we can confirm
|
||||
// the effects of the "fast" types by making a specialization.
|
||||
namespace boost
|
||||
{
|
||||
template<> struct int_fast_t<short> { typedef long fast; };
|
||||
template < >
|
||||
struct int_fast_t< short >
|
||||
{
|
||||
typedef long fast;
|
||||
};
|
||||
}
|
||||
|
||||
int 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() );
|
||||
// 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_CHECK( Template < Number > :: Type ( Value ) == Value )
|
||||
|
||||
#if ULONG_MAX > 0xFFFFFFFFL
|
||||
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; 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 )
|
||||
#else
|
||||
#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 )
|
||||
#endif
|
||||
|
||||
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( 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_CHECK( 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_CHECK( 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 );
|
||||
|
||||
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 );
|
||||
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 0;
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
Type Limits</h1>
|
||||
|
||||
<p>
|
||||
|
@ -1,14 +1,9 @@
|
||||
/* boost integer_traits.hpp tests
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
* Jens Maurer makes no representations about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
@ -35,19 +30,42 @@
|
||||
* 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()
|
||||
<< std::endl;
|
||||
BOOST_TEST(traits::is_specialized);
|
||||
BOOST_TEST(traits::is_integer);
|
||||
BOOST_TEST(traits::is_integral);
|
||||
BOOST_TEST(traits::const_min == traits::min());
|
||||
BOOST_TEST(traits::const_max == traits::max());
|
||||
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
|
||||
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
|
||||
<< std::endl;
|
||||
BOOST_CHECK(traits::is_specialized);
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
|
||||
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
|
||||
// generates different symbol names with a very long common prefix:
|
||||
// the dummy "&& true" disambiguates between the symbols generated by this
|
||||
// BOOST_CHECK instantiation and the preceding one.
|
||||
BOOST_CHECK(traits::is_integer && true);
|
||||
#else
|
||||
BOOST_CHECK(traits::is_integer);
|
||||
#endif
|
||||
BOOST_CHECK(traits::is_integral == true);
|
||||
BOOST_CHECK(traits::const_min == (traits::min)());
|
||||
BOOST_CHECK(traits::const_max == (traits::max)());
|
||||
}
|
||||
|
||||
int test_main(int, char*[])
|
||||
@ -68,7 +86,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.
|
||||
|
111
test/integer_mask_test.cpp
Normal file
111
test/integer_mask_test.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
// boost integer_mask.hpp test program -------------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org 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_CHECK( ::boost::high_bit_mask_t< \
|
||||
(v) >::high_bit == (1ul << (v)) );
|
||||
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::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_CHECK( ::boost::low_bits_mask_t< \
|
||||
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
||||
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::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;
|
||||
}
|
150
test/static_log2_test.cpp
Normal file
150
test/static_log2_test.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
// Boost static_log2.hpp test program --------------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org 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_CHECK( ::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;
|
||||
}
|
93
test/static_min_max_test.cpp
Normal file
93
test/static_min_max_test.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
// Boost static_min_max.hpp test program -----------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org 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_CHECK
|
||||
|
||||
#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_CHECK( (static_signed_min< 9, 14>::value) == 9 );
|
||||
BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_min<14, 9>::value) == 9 );
|
||||
BOOST_CHECK( (static_signed_max<14, 9>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_unsigned_min< 9, 14>::value) == 9 );
|
||||
BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 9>::value) == 9 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 9>::value) == 14 );
|
||||
|
||||
// Two negatives
|
||||
cout << "Doing tests with two negative values." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min< -8, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< -8, -101>::value) == -8 );
|
||||
BOOST_CHECK( (static_signed_min<-101, -8>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max<-101, -8>::value) == -8 );
|
||||
|
||||
// With zero
|
||||
cout << "Doing tests with zero and a positive or negative value." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min< 0, 14>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_min<14, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max<14, 0>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_unsigned_min< 0, 14>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 0>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min< 0, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< 0, -101>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_min<-101, 0>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max<-101, 0>::value) == 0 );
|
||||
|
||||
// With identical
|
||||
cout << "Doing tests with two identical values." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 );
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
Reference in New Issue
Block a user