mirror of
https://github.com/boostorg/integer.git
synced 2025-06-26 12:31:40 +02:00
Compare commits
1 Commits
svn-branch
...
boost-1.26
Author | SHA1 | Date | |
---|---|---|---|
75c55bbe81 |
@ -99,8 +99,8 @@ void integral_constant_type_check(T1, T2)
|
|||||||
// numeric_limits implementations currently
|
// numeric_limits implementations currently
|
||||||
// vary too much, or are incomplete or missing.
|
// vary too much, or are incomplete or missing.
|
||||||
//
|
//
|
||||||
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
|
T1 t1 = -1;
|
||||||
T2 t2 = static_cast<T2>(-1); // ditto
|
T2 t2 = -1;
|
||||||
#if defined(BOOST_HAS_STDINT_H)
|
#if defined(BOOST_HAS_STDINT_H)
|
||||||
// if we have a native stdint.h
|
// if we have a native stdint.h
|
||||||
// then the INTXX_C macros may define
|
// then the INTXX_C macros may define
|
||||||
@ -110,10 +110,10 @@ void integral_constant_type_check(T1, T2)
|
|||||||
assert(sizeof(T1) == sizeof(T2));
|
assert(sizeof(T1) == sizeof(T2));
|
||||||
assert(t1 == t2);
|
assert(t1 == t2);
|
||||||
#endif
|
#endif
|
||||||
if(t1 > 0)
|
if(t1 >= 0)
|
||||||
assert(t2 > 0);
|
assert(t2 >= 0);
|
||||||
else
|
else
|
||||||
assert(!(t2 > 0));
|
assert(t2 < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,211 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Integer Bit Mask Templates</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
|
||||||
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
|
||||||
|
|
||||||
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp"><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. 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>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,123 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Binary Logarithm Template</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body bgcolor="white" text="black">
|
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
|
||||||
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
|
||||||
|
|
||||||
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><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>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h2><a name="synopsis">Synopsis</a></h2>
|
|
||||||
|
|
||||||
<blockquote><pre>
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
template < unsigned long Value >
|
|
||||||
struct static_log2
|
|
||||||
{
|
|
||||||
static const int value = <em>implementation_defined</em>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template < >
|
|
||||||
struct static_log2< 0ul >
|
|
||||||
{
|
|
||||||
// The logarithm of zero is undefined.
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
</pre></blockquote>
|
|
||||||
|
|
||||||
<h2><a name="usage">Usage</a></h2>
|
|
||||||
|
|
||||||
<p>The <code>boost::static_log2</code> class template takes one template
|
|
||||||
parameter, a value of type <code>unsigned long</code>. The template
|
|
||||||
only defines one member, <code>value</code>, that returns the truncated
|
|
||||||
base-two logarithm of the template parameter.</p>
|
|
||||||
|
|
||||||
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
|
||||||
specialization of <code>static_log2</code> for a template parameter
|
|
||||||
of zero. This specialization has no members, so an attempt to use
|
|
||||||
the base-two logarithm of zero results in a compile-time error.</p>
|
|
||||||
|
|
||||||
<h2><a name="example">Example</a></h2>
|
|
||||||
|
|
||||||
<blockquote><pre>
|
|
||||||
#include <boost/integer/static_log2.hpp>
|
|
||||||
|
|
||||||
template < unsigned long 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="credits">Credits</a></h2>
|
|
||||||
|
|
||||||
<p>The author of the Boost binary logarithm class template is <a
|
|
||||||
href="../../../people/daryle_walker.html">Daryle Walker</a>. Giovanni Bajo
|
|
||||||
added support for compilers without partial template specialization.</p>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
|
|
||||||
<p>Revised May 14, 2002</p>
|
|
||||||
|
|
||||||
<p>© Copyright Daryle Walker 2001. Permission to copy, use,
|
|
||||||
modify, sell and distribute this document is granted provided this
|
|
||||||
copyright notice appears in all copies. This document is provided
|
|
||||||
"as is" without express or implied warranty, and with no claim
|
|
||||||
as to its suitability for any purpose.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,121 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Compile-Time Extrema Templates</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
|
||||||
align="middle" width="277" height="86">Compile-Time Extrema
|
|
||||||
Templates</h1>
|
|
||||||
|
|
||||||
<p>The class templates in <cite><a
|
|
||||||
href="../../../boost/integer/static_min_max.hpp"><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. 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>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -35,8 +35,6 @@
|
|||||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||||
# define BOOST_NO_INT64_T
|
# define BOOST_NO_INT64_T
|
||||||
# endif
|
# endif
|
||||||
# elif defined(__FreeBSD__)
|
|
||||||
# include <inttypes.h>
|
|
||||||
# else
|
# else
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# endif
|
# endif
|
||||||
@ -81,56 +79,10 @@ namespace boost
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
|
|
||||||
// FreeBSD has an <inttypes.h> that contains much of what we need
|
|
||||||
# include <inttypes.h>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
using ::int8_t;
|
|
||||||
typedef int8_t int_least8_t;
|
|
||||||
typedef int8_t int_fast8_t;
|
|
||||||
using ::uint8_t;
|
|
||||||
typedef uint8_t uint_least8_t;
|
|
||||||
typedef uint8_t uint_fast8_t;
|
|
||||||
|
|
||||||
using ::int16_t;
|
|
||||||
typedef int16_t int_least16_t;
|
|
||||||
typedef int16_t int_fast16_t;
|
|
||||||
using ::uint16_t;
|
|
||||||
typedef uint16_t uint_least16_t;
|
|
||||||
typedef uint16_t uint_fast16_t;
|
|
||||||
|
|
||||||
using ::int32_t;
|
|
||||||
typedef int32_t int_least32_t;
|
|
||||||
typedef int32_t int_fast32_t;
|
|
||||||
using ::uint32_t;
|
|
||||||
typedef uint32_t uint_least32_t;
|
|
||||||
typedef uint32_t uint_fast32_t;
|
|
||||||
|
|
||||||
# ifndef BOOST_NO_INT64_T
|
|
||||||
|
|
||||||
using ::int64_t;
|
|
||||||
typedef int64_t int_least64_t;
|
|
||||||
typedef int64_t int_fast64_t;
|
|
||||||
using ::uint64_t;
|
|
||||||
typedef uint64_t uint_least64_t;
|
|
||||||
typedef uint64_t uint_fast64_t;
|
|
||||||
|
|
||||||
typedef int64_t intmax_t;
|
|
||||||
typedef uint64_t uintmax_t;
|
|
||||||
|
|
||||||
# else
|
|
||||||
|
|
||||||
typedef int32_t intmax_t;
|
|
||||||
typedef uint32_t uintmax_t;
|
|
||||||
|
|
||||||
# endif
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#else // BOOST_HAS_STDINT_H
|
#else // BOOST_HAS_STDINT_H
|
||||||
|
|
||||||
|
|
||||||
# include <limits.h> // implementation artifact; not part of interface
|
# include <limits.h> // implementation artifact; not part of interface
|
||||||
|
|
||||||
|
|
||||||
@ -228,9 +180,9 @@ namespace boost
|
|||||||
# else
|
# else
|
||||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||||
# endif
|
# endif
|
||||||
# elif defined(BOOST_HAS_MS_INT64)
|
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||||
//
|
//
|
||||||
// we have Borland/Intel/Microsoft __int64:
|
// we have Borland/Microsoft __int64:
|
||||||
//
|
//
|
||||||
typedef __int64 intmax_t;
|
typedef __int64 intmax_t;
|
||||||
typedef unsigned __int64 uintmax_t;
|
typedef unsigned __int64 uintmax_t;
|
||||||
@ -272,9 +224,9 @@ BOOST_HAS_STDINT_H is defined (John Maddock).
|
|||||||
|
|
||||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
|
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
|
||||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||||
# if defined(BOOST_HAS_MS_INT64)
|
# if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||||
//
|
//
|
||||||
// Borland/Intel/Microsoft compilers have width specific suffixes:
|
// Borland/Microsoft compilers have width specific suffixes:
|
||||||
//
|
//
|
||||||
# define INT8_C(value) value##i8
|
# define INT8_C(value) value##i8
|
||||||
# define INT16_C(value) value##i16
|
# define INT16_C(value) value##i16
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
// Revision History
|
// 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)
|
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||||
// 28 Aug 99 Initial version
|
// 28 Aug 99 Initial version
|
||||||
@ -17,10 +16,7 @@
|
|||||||
#ifndef BOOST_INTEGER_HPP
|
#ifndef BOOST_INTEGER_HPP
|
||||||
#define BOOST_INTEGER_HPP
|
#define BOOST_INTEGER_HPP
|
||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
#include <boost/limits.hpp>
|
||||||
|
|
||||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@ -79,51 +75,11 @@ namespace boost
|
|||||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||||
};
|
};
|
||||||
|
|
||||||
// integer templates specifying extreme value ----------------------------//
|
// The same dispatching technique can be used to select types based on
|
||||||
|
// values. That will be added once boost::integer_traits is available.
|
||||||
// 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
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_HPP
|
#endif // BOOST_INTEGER_HPP
|
||||||
|
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
// Boost integer/integer_mask.hpp header file ------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and
|
|
||||||
// distribute this software is granted provided this copyright notice appears
|
|
||||||
// in all copies. This software is provided "as is" without express or
|
|
||||||
// implied warranty, and with no claim as to its suitability for any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
|
|
||||||
#define BOOST_INTEGER_INTEGER_MASK_HPP
|
|
||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
|
||||||
#include <boost/integer.hpp> // for boost::uint_t
|
|
||||||
|
|
||||||
#include <climits> // for UCHAR_MAX, etc.
|
|
||||||
#include <cstddef> // for std::size_t
|
|
||||||
|
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
// Specified single-bit mask class declaration -----------------------------//
|
|
||||||
// (Lowest bit starts counting at 0.)
|
|
||||||
|
|
||||||
template < std::size_t Bit >
|
|
||||||
struct high_bit_mask_t
|
|
||||||
{
|
|
||||||
typedef typename uint_t<(Bit + 1)>::least least;
|
|
||||||
typedef typename uint_t<(Bit + 1)>::fast fast;
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
|
|
||||||
BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
|
|
||||||
|
|
||||||
}; // boost::high_bit_mask_t
|
|
||||||
|
|
||||||
|
|
||||||
// Specified bit-block mask class declaration ------------------------------//
|
|
||||||
// Makes masks for the lowest N bits
|
|
||||||
// (Specializations are needed when N fills up a type.)
|
|
||||||
|
|
||||||
template < std::size_t Bits >
|
|
||||||
struct low_bits_mask_t
|
|
||||||
{
|
|
||||||
typedef typename uint_t<Bits>::least least;
|
|
||||||
typedef typename uint_t<Bits>::fast fast;
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
|
|
||||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
|
|
||||||
|
|
||||||
}; // boost::low_bits_mask_t
|
|
||||||
|
|
||||||
|
|
||||||
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
|
|
||||||
template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
|
|
||||||
typedef std::numeric_limits<Type> limits_type; \
|
|
||||||
typedef uint_t<limits_type::digits>::least least; \
|
|
||||||
typedef uint_t<limits_type::digits>::fast fast; \
|
|
||||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
|
|
||||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
|
|
||||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
|
|
||||||
|
|
||||||
#if USHRT_MAX > UCHAR_MAX
|
|
||||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if UINT_MAX > USHRT_MAX
|
|
||||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ULONG_MAX > UINT_MAX
|
|
||||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef BOOST_LOW_BITS_MASK_SPECIALIZE
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_INTEGER_MASK_HPP
|
|
@ -1,141 +0,0 @@
|
|||||||
// Boost integer/static_log2.hpp header file -------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and
|
|
||||||
// distribute this software is granted provided this copyright notice appears
|
|
||||||
// in all copies. This software is provided "as is" without express or
|
|
||||||
// implied warranty, and with no claim as to its suitability for any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
|
||||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
|
||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
|
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
|
||||||
|
|
||||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
#include <boost/pending/ct_if.hpp> // for boost::ct_if<>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
// Implementation details --------------------------------------------------//
|
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template < unsigned long Val, int Place = 0, int Index
|
|
||||||
= std::numeric_limits<unsigned long>::digits >
|
|
||||||
struct static_log2_helper_t;
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place >
|
|
||||||
struct static_log2_helper_t< Val, Place, 1 >;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
template < int Place >
|
|
||||||
struct static_log2_helper_final_step;
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place = 0, int Index
|
|
||||||
= std::numeric_limits<unsigned long>::digits >
|
|
||||||
struct static_log2_helper_nopts_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Recursively build the logarithm by examining the upper bits
|
|
||||||
template < unsigned long Val, int Place, int Index >
|
|
||||||
struct static_log2_helper_t
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
BOOST_STATIC_CONSTANT( int, half_place = Index / 2 );
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, lower_mask = (1ul << half_place)
|
|
||||||
- 1ul );
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, upper_mask = ~lower_mask );
|
|
||||||
BOOST_STATIC_CONSTANT( bool, do_shift = (Val & upper_mask) != 0ul );
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, new_val = do_shift ? (Val
|
|
||||||
>> half_place) : Val );
|
|
||||||
BOOST_STATIC_CONSTANT( int, new_place = do_shift ? (Place + half_place)
|
|
||||||
: Place );
|
|
||||||
BOOST_STATIC_CONSTANT( int, new_index = Index - half_place );
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
typedef static_log2_helper_t<new_val, new_place, new_index> next_step_type;
|
|
||||||
#else
|
|
||||||
typedef static_log2_helper_nopts_t<new_val, new_place, new_index> next_step_type;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_t
|
|
||||||
|
|
||||||
// Non-recursive case
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place >
|
|
||||||
struct static_log2_helper_t< Val, Place, 1 >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = Place );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_t
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
template < int Place >
|
|
||||||
struct static_log2_helper_final_step
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = Place );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_final_step
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place, int Index >
|
|
||||||
struct static_log2_helper_nopts_t
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
typedef static_log2_helper_t<Val, Place, Index> recursive_step_type;
|
|
||||||
typedef static_log2_helper_final_step<Place> final_step_type;
|
|
||||||
|
|
||||||
typedef typename ct_if<( Index != 1 ), recursive_step_type,
|
|
||||||
final_step_type>::type next_step_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_nopts_t
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
|
|
||||||
// Compile-time log-base-2 evaluator class declaration ---------------------//
|
|
||||||
|
|
||||||
template < unsigned long Value >
|
|
||||||
struct static_log2
|
|
||||||
{
|
|
||||||
BOOST_STATIC_CONSTANT( int, value
|
|
||||||
= detail::static_log2_helper_t<Value>::value );
|
|
||||||
};
|
|
||||||
|
|
||||||
template < >
|
|
||||||
struct static_log2< 0ul >
|
|
||||||
{
|
|
||||||
// The logarithm of zero is undefined.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_STATIC_LOG2_HPP
|
|
@ -1,56 +0,0 @@
|
|||||||
// Boost integer/static_min_max.hpp header file ----------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
|
||||||
// and distribute this software is granted provided this copyright notice
|
|
||||||
// appears in all copies. This software is provided "as is" without
|
|
||||||
// express or implied warranty, and with no claim as to its suitability
|
|
||||||
// for any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
|
||||||
#define BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
|
||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
// Compile-time extrema class declarations ---------------------------------//
|
|
||||||
// Get the minimum or maximum of two values, signed or unsigned.
|
|
||||||
|
|
||||||
template < long Value1, long Value2 >
|
|
||||||
struct static_signed_min
|
|
||||||
{
|
|
||||||
BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 );
|
|
||||||
};
|
|
||||||
|
|
||||||
template < long Value1, long Value2 >
|
|
||||||
struct static_signed_max
|
|
||||||
{
|
|
||||||
BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 );
|
|
||||||
};
|
|
||||||
|
|
||||||
template < unsigned long Value1, unsigned long Value2 >
|
|
||||||
struct static_unsigned_min
|
|
||||||
{
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
|
||||||
= (Value1 > Value2) ? Value2 : Value1 );
|
|
||||||
};
|
|
||||||
|
|
||||||
template < unsigned long Value1, unsigned long Value2 >
|
|
||||||
struct static_unsigned_max
|
|
||||||
{
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
|
||||||
= (Value1 < Value2) ? Value2 : Value1 );
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
|
@ -1,154 +0,0 @@
|
|||||||
// Boost integer_fwd.hpp header file ---------------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright boost.org 2001. Permission to copy, use, modify, sell
|
|
||||||
// and distribute this software is granted provided this copyright
|
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_FWD_HPP
|
|
||||||
#define BOOST_INTEGER_FWD_HPP
|
|
||||||
|
|
||||||
#include <climits> // for UCHAR_MAX, etc.
|
|
||||||
#include <cstddef> // for std::size_t
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T
|
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/cstdint.hpp> ------------------------------------------------//
|
|
||||||
|
|
||||||
// Only has typedefs or using statements, with #conditionals
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/integer_traits.hpp> -----------------------------------------//
|
|
||||||
|
|
||||||
template < class T >
|
|
||||||
class integer_traits;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< bool >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< char >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< signed char >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< unsigned char >;
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
|
||||||
template < >
|
|
||||||
class integer_traits< wchar_t >;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< short >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< unsigned short >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< int >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< unsigned int >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< long >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< unsigned long >;
|
|
||||||
|
|
||||||
#ifdef ULLONG_MAX
|
|
||||||
template < >
|
|
||||||
class integer_traits< long long >;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
class integer_traits< unsigned long long >;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/integer.hpp> ------------------------------------------------//
|
|
||||||
|
|
||||||
template < typename LeastInt >
|
|
||||||
struct int_fast_t;
|
|
||||||
|
|
||||||
template< int Bits >
|
|
||||||
struct int_t;
|
|
||||||
|
|
||||||
template< int Bits >
|
|
||||||
struct uint_t;
|
|
||||||
|
|
||||||
template< long MaxValue >
|
|
||||||
struct int_max_value_t;
|
|
||||||
|
|
||||||
template< long MinValue >
|
|
||||||
struct int_min_value_t;
|
|
||||||
|
|
||||||
template< unsigned long Value >
|
|
||||||
struct uint_value_t;
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/integer/integer_mask.hpp> -----------------------------------//
|
|
||||||
|
|
||||||
template < std::size_t Bit >
|
|
||||||
struct high_bit_mask_t;
|
|
||||||
|
|
||||||
template < std::size_t Bits >
|
|
||||||
struct low_bits_mask_t;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned char>::digits >;
|
|
||||||
|
|
||||||
#if USHRT_MAX > UCHAR_MAX
|
|
||||||
template < >
|
|
||||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned short>::digits >;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if UINT_MAX > USHRT_MAX
|
|
||||||
template < >
|
|
||||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned int>::digits >;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ULONG_MAX > UINT_MAX
|
|
||||||
template < >
|
|
||||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned long>::digits >;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/integer/static_log2.hpp> ------------------------------------//
|
|
||||||
|
|
||||||
template < unsigned long Value >
|
|
||||||
struct static_log2;
|
|
||||||
|
|
||||||
template < >
|
|
||||||
struct static_log2< 0ul >;
|
|
||||||
|
|
||||||
|
|
||||||
// From <boost/integer/static_min_max.hpp> ---------------------------------//
|
|
||||||
|
|
||||||
template < long Value1, long Value2 >
|
|
||||||
struct static_signed_min;
|
|
||||||
|
|
||||||
template < long Value1, long Value2 >
|
|
||||||
struct static_signed_max;
|
|
||||||
|
|
||||||
template < unsigned long Value1, unsigned long Value2 >
|
|
||||||
struct static_unsigned_min;
|
|
||||||
|
|
||||||
template < unsigned long Value1, unsigned long Value2 >
|
|
||||||
struct static_unsigned_max;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_FWD_HPP
|
|
@ -93,12 +93,11 @@ class integer_traits<wchar_t>
|
|||||||
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
||||||
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
||||||
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
||||||
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) || (defined __APPLE__) || (defined(__FreeBSD__) && defined(__GNUC__)) || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) || (defined __APPLE__) || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
||||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
||||||
// - SGI MIPSpro with native library
|
// - SGI MIPSpro with native library
|
||||||
// - gcc 3.x on HP-UX
|
// - gcc 3.x on HP-UX
|
||||||
// - Mac OS X with native library
|
// - Mac OS X with native library
|
||||||
// - gcc on FreeBSD
|
|
||||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||||
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
#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.
|
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
||||||
|
150
index.htm
150
index.htm
@ -1,128 +1,98 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<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>
|
<title>Boost Integer Library</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body bgcolor="white" text="black">
|
<body bgcolor="#FFFFFF" text="#000000">
|
||||||
<table border="1" bgcolor="teal" cellpadding="2">
|
|
||||||
<tr>
|
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||||
<td bgcolor="white"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
<tr>
|
||||||
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
|
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||||
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
|
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home </big></font></a></td>
|
||||||
<td><a href="../../people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
|
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||||
<td><a href="../../more/faq.htm"><font face="Arial" color="white"><big>FAQ</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/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
|
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ </big></font></a></td>
|
||||||
</tr>
|
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More </big></font></a></td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h1>Boost Integer Library</h1>
|
<h1>Boost Integer Library</h1>
|
||||||
|
|
||||||
<table border="1" cellpadding="5">
|
<table border="1" cellpadding="5">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Header / Docs</th>
|
<td align="center"><b><i>Header / Docs</i></b></td>
|
||||||
<th>Contents</th>
|
<td align="center"><b><i>Contents</i></b></td>
|
||||||
<th>Use</th>
|
<td align="center"><b><i>Use</i></b></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><cite><a href="../../boost/integer_fwd.hpp"><boost/integer_fwd.hpp></a></cite></td>
|
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||||
<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>
|
</a></code><a href="cstdint.htm"><br>
|
||||||
documentation</a>
|
documentation</a>
|
||||||
</td>
|
</td>
|
||||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
<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
|
This implementation may #include the compiler
|
||||||
supplied <<code>stdint.h></code>, if present. </td>
|
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>.
|
<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>
|
Use in preference to <<code>stdint.h></code>
|
||||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||||
<br>
|
<br>
|
||||||
<a href="integer_traits.html">documentation</a>
|
<a href="integer_traits.html">documentation</a>
|
||||||
</td>
|
</td>
|
||||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
<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>
|
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>
|
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||||
<br>
|
<br>
|
||||||
</code><a href="integer.htm">documentation</a></td>
|
</code><a href="integer.htm">documentation</a></td>
|
||||||
<td valign="top">Templates for integer type selection based on properties such as
|
<td valign="top">Templates for integer type selection based on properties such as
|
||||||
maximum value or number of bits.</td>
|
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.
|
<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>
|
Useful for generic programming. </td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
|
|
||||||
<h2>Rationale</h2>
|
<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.
|
||||||
|
|
||||||
<p>The organization of boost integer headers and classes is designed to
|
<h2>Caveat emptor</h2>
|
||||||
take advantage of <cite><stdint.h></cite> types from the 1999 C
|
<p>As an
|
||||||
standard without resorting to undefined behavior in terms of the 1998
|
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||||
C++ standard. The header <cite><boost/cstdint.hpp></cite> makes
|
visible to users of <boost/cstdint.hpp>. Don't use these macros; they are not part of
|
||||||
the standard integer types safely available in namespace
|
any Boost specified interface.
|
||||||
<code>boost</code> without placing any names in namespace
|
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||||
<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
|
<p>
|
||||||
naming conventions rather than C++ Standard Library header naming
|
As another implementation artifact, certain C
|
||||||
conventions.</p>
|
<code><stdint.h></code> typedef names may possibly be visible in the
|
||||||
|
global namespace to users of <code><boost/cstdint.hpp></code>.
|
||||||
<h2><i>Caveat emptor</i></h2>
|
Don't use these names, they are not part of any Boost specified
|
||||||
|
|
||||||
<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>
|
interface. Use the respective names in namespace <code>boost</code>
|
||||||
instead.</p>
|
instead.
|
||||||
|
|
||||||
<hr>
|
<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>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>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
237
integer.htm
237
integer.htm
@ -1,213 +1,112 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<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>
|
<title>Integer Type Selection Templates</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body bgcolor="white" text="black">
|
<body bgcolor="#FFFFFF" text="#000000">
|
||||||
<h1>
|
|
||||||
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
|
||||||
align="middle" width="277" height="86">Integer Type Selection
|
|
||||||
Templates</h1>
|
|
||||||
|
|
||||||
<p>The <cite><a
|
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Integer
|
||||||
href="../../boost/integer.hpp"><boost/integer.hpp></a></cite> type
|
Type Selection Templates</h1>
|
||||||
selection templates allow integer types to be selected based on desired
|
<p>The <code><a href="../../boost/integer.hpp"><boost/integer.hpp></a></code>
|
||||||
characteristics such as number of bits or maximum value. This facility
|
type selection templates allow integer types to be selected based on desired
|
||||||
is particularly useful for solving generic programming problems.</p>
|
characteristics such as number of bits or maximum value. This facility is
|
||||||
|
particularly useful for solving generic programming problems.</p>
|
||||||
|
|
||||||
<h2><a name="contents">Contents</a></h2>
|
<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>
|
||||||
|
|
||||||
<ul>
|
<h2>Alternative</h2>
|
||||||
<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>
|
|
||||||
|
|
||||||
<h2><a name="synopsis">Synopsis</a></h2>
|
<p>If the number of bits required is known beforehand, it may be more
|
||||||
|
appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>.</p>
|
||||||
|
|
||||||
<blockquote><pre>namespace boost
|
<h2>Synopsis</h2>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<pre>namespace boost
|
||||||
{
|
{
|
||||||
// fast integers from least integers
|
// fast integers from least integers
|
||||||
template< typename LeastInt >
|
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||||
struct int_fast_t
|
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||||
{
|
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||||
typedef <em>implementation_supplied</em> fast;
|
|
||||||
};
|
|
||||||
|
|
||||||
// signed
|
// signed
|
||||||
template< int Bits >
|
template< int Bits > // bits (including sign) required, 0-32 valid
|
||||||
struct int_t
|
struct int_t
|
||||||
{
|
{
|
||||||
typedef <em>implementation_supplied</em> least;
|
typedef <i>implementation-supplied</i> least;
|
||||||
typedef int_fast_t<least>::fast fast;
|
typedef int_fast_t<least>::fast fast;
|
||||||
};
|
};
|
||||||
|
|
||||||
// unsigned
|
// unsigned
|
||||||
template< int Bits >
|
template< int Bits > // bits required, 0-32 valid
|
||||||
struct uint_t
|
struct uint_t
|
||||||
{
|
{
|
||||||
typedef <em>implementation_supplied</em> least;
|
typedef <i>implementation-supplied</i> 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;
|
typedef int_fast_t<least>::fast fast;
|
||||||
|
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||||
};
|
};
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
</pre></blockquote>
|
</pre>
|
||||||
|
|
||||||
<h2><a name="easy">Easiest-to-Manipulate Types</a></h2>
|
</blockquote>
|
||||||
|
<p>[Templates to select type based on maximum value are under development.]
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>The <code>int_fast_t</code> class template maps its input type to the
|
<h2>Example</h2>
|
||||||
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>
|
|
||||||
|
|
||||||
<p><strong>Implementation Notes</strong><br>
|
<blockquote>
|
||||||
By default, the output type is identical to the input type. Eventually,
|
<pre>#include <boost/integer.hpp>
|
||||||
this code's implementation should be conditionalized for each platform
|
using boost::int_t;
|
||||||
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>
|
|
||||||
|
|
||||||
<h2><a name="sized">Sized Types</a></h2>
|
...
|
||||||
|
int_t<24>::least my_var; </pre>
|
||||||
|
|
||||||
<p>The <code>int_t</code>, <code>uint_t</code>,
|
</blockquote>
|
||||||
<code>int_max_value_t</code>, <code>int_min_value_t</code>, and
|
<h2>Demonstration Program</h2>
|
||||||
<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>
|
|
||||||
|
|
||||||
<table border="1" cellpadding="5">
|
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a not very
|
||||||
<caption>Criteria for the Sized Type Class Templates</caption>
|
smart demonstration of the results from instantiating various <b>int_t<></b>
|
||||||
<tr>
|
and <b>uint_t<></b> examples.</p>
|
||||||
<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><a name="example">Example</a></h2>
|
<h2>Rationale</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>
|
<p>The rationale for the design of the templates in this header includes:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>Avoid recursion because of concern about C++'s limited
|
<li>Avoid recursion because of concern about C++'s limited guaranteed
|
||||||
guaranteed recursion depth (17).</li>
|
recursion depth (17).</li>
|
||||||
<li>Avoid macros on general principles.</li>
|
<li>Avoid macros on general principles.</li>
|
||||||
<li>Try to keep the design as simple as possible.</li>
|
<li>Try to keep the design as simple as possible.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h2><a name="alternative">Alternative</a></h2>
|
<h2>Credits</h2>
|
||||||
|
|
||||||
<p>If the number of bits required is known beforehand, it may be more
|
<p>The author of the Boost integer type choosing templates is <a href="../../people/beman_dawes.html">Beman
|
||||||
appropriate to use the types supplied in <cite><a
|
Dawes</a>. He thanks to <a href="../../people/valentin_bonnard.htm"> Valentin Bonnard</a> and
|
||||||
href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></cite>.</p>
|
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing their designs for similar templates.</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>
|
<hr>
|
||||||
|
|
||||||
<p>Revised May 20, 2001</p>
|
<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>© 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>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
||||||
|
518
integer_test.cpp
518
integer_test.cpp
@ -9,247 +9,313 @@
|
|||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
// Revision History
|
// 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)
|
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||||
// 31 Aug 99 Initial version
|
// 31 Aug 99 Initial version
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
#include <iostream>
|
||||||
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
|
#include <boost/integer.hpp>
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
|
#define BOOST_INCLUDE_MAIN
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
#include <boost/test/test_tools.hpp>
|
||||||
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t
|
|
||||||
|
|
||||||
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
|
namespace
|
||||||
#include <iostream> // for std::cout (std::endl indirectly)
|
{
|
||||||
#include <typeinfo> // for std::type_info
|
void test( long ) { std::cout << "long\n"; }
|
||||||
|
void test( int ) { std::cout << "int\n"; }
|
||||||
|
void test( short ) { std::cout << "short\n"; }
|
||||||
|
void test( signed char ) { std::cout << "signed char\n"; }
|
||||||
|
void test( unsigned long ) { std::cout << "unsigned long\n"; }
|
||||||
|
void test( unsigned int ) { std::cout << "unsigned int\n"; }
|
||||||
|
void test( unsigned short ) { std::cout << "unsigned short\n"; }
|
||||||
|
void test( unsigned char ) { std::cout << "unsigned char\n"; }
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
|
// just to prove it works, specialize int_fast_t<short> to yield long
|
||||||
// Control if the names of the types for each version
|
|
||||||
// of the integer templates will be printed.
|
|
||||||
#ifndef CONTROL_SHOW_TYPES
|
|
||||||
#define CONTROL_SHOW_TYPES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// If specializations have not already been done, then we can confirm
|
|
||||||
// the effects of the "fast" types by making a specialization.
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
template < >
|
template<> struct int_fast_t<short> { typedef long fast; };
|
||||||
struct int_fast_t< short >
|
|
||||||
{
|
|
||||||
typedef long fast;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_main(int,char**)
|
||||||
// Show the types of an integer template version
|
|
||||||
#if CONTROL_SHOW_TYPES
|
|
||||||
#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \
|
|
||||||
#Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \
|
|
||||||
Number > :: Type).name() << ".\"\n"
|
|
||||||
#else
|
|
||||||
#define SHOW_TYPE(Template, Number, Type)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SHOW_TYPES(Template, Type) SHOW_TYPE(Template, 32, Type); \
|
|
||||||
SHOW_TYPE(Template, 31, Type); SHOW_TYPE(Template, 30, Type); \
|
|
||||||
SHOW_TYPE(Template, 29, Type); SHOW_TYPE(Template, 28, Type); \
|
|
||||||
SHOW_TYPE(Template, 27, Type); SHOW_TYPE(Template, 26, Type); \
|
|
||||||
SHOW_TYPE(Template, 25, Type); SHOW_TYPE(Template, 24, Type); \
|
|
||||||
SHOW_TYPE(Template, 23, Type); SHOW_TYPE(Template, 22, Type); \
|
|
||||||
SHOW_TYPE(Template, 21, Type); SHOW_TYPE(Template, 20, Type); \
|
|
||||||
SHOW_TYPE(Template, 19, Type); SHOW_TYPE(Template, 18, Type); \
|
|
||||||
SHOW_TYPE(Template, 17, Type); SHOW_TYPE(Template, 16, Type); \
|
|
||||||
SHOW_TYPE(Template, 15, Type); SHOW_TYPE(Template, 14, Type); \
|
|
||||||
SHOW_TYPE(Template, 13, Type); SHOW_TYPE(Template, 12, Type); \
|
|
||||||
SHOW_TYPE(Template, 11, Type); SHOW_TYPE(Template, 10, Type); \
|
|
||||||
SHOW_TYPE(Template, 9, Type); SHOW_TYPE(Template, 8, Type); \
|
|
||||||
SHOW_TYPE(Template, 7, Type); SHOW_TYPE(Template, 6, Type); \
|
|
||||||
SHOW_TYPE(Template, 5, Type); SHOW_TYPE(Template, 4, Type); \
|
|
||||||
SHOW_TYPE(Template, 3, Type); SHOW_TYPE(Template, 2, Type); \
|
|
||||||
SHOW_TYPE(Template, 1, Type); SHOW_TYPE(Template, 0, Type)
|
|
||||||
|
|
||||||
#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type)
|
|
||||||
|
|
||||||
#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \
|
|
||||||
SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type)
|
|
||||||
|
|
||||||
#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type)
|
|
||||||
|
|
||||||
#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \
|
|
||||||
SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type)
|
|
||||||
|
|
||||||
#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type)
|
|
||||||
|
|
||||||
#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \
|
|
||||||
SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type)
|
|
||||||
|
|
||||||
|
|
||||||
// Test if a constant can fit within a certain type
|
|
||||||
#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < Number > :: Type ( Value ) == Value )
|
|
||||||
|
|
||||||
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
|
||||||
|
|
||||||
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (ULONG_MAX >> Number) > :: Type ( Value ) == Value )
|
|
||||||
|
|
||||||
#define PRIVATE_SHIFTED_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
|
||||||
|
|
||||||
#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MAX >> Number) > :: Type ( Value ) == Value )
|
|
||||||
|
|
||||||
#define PRIVATE_POS_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
|
||||||
|
|
||||||
#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value )
|
|
||||||
|
|
||||||
#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
|
||||||
|
|
||||||
|
|
||||||
// Test program
|
|
||||||
int
|
|
||||||
test_main
|
|
||||||
(
|
|
||||||
int,
|
|
||||||
char*[]
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
#ifndef BOOST_NO_USING_TEMPLATE
|
#ifndef BOOST_NO_USING_TEMPLATE
|
||||||
using boost::int_t;
|
using boost::int_t;
|
||||||
using boost::uint_t;
|
using boost::uint_t;
|
||||||
using boost::int_max_value_t;
|
|
||||||
using boost::int_min_value_t;
|
|
||||||
using boost::uint_value_t;
|
|
||||||
#else
|
#else
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SHOW_TYPES( int_t, least );
|
#ifdef BOOST_SHOW_TYPES
|
||||||
SHOW_TYPES( int_t, fast );
|
std::cout << 32 << ' '; test( int_t<32>::least() );
|
||||||
SHOW_TYPES( uint_t, least );
|
std::cout << 31 << ' '; test( int_t<31>::least() );
|
||||||
SHOW_TYPES( uint_t, fast );
|
std::cout << 30 << ' '; test( int_t<30>::least() );
|
||||||
SHOW_POS_SHIFTED_TYPES( int_max_value_t, least );
|
std::cout << 29 << ' '; test( int_t<29>::least() );
|
||||||
SHOW_POS_SHIFTED_TYPES( int_max_value_t, fast );
|
std::cout << 28 << ' '; test( int_t<28>::least() );
|
||||||
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, least );
|
std::cout << 27 << ' '; test( int_t<27>::least() );
|
||||||
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, fast );
|
std::cout << 26 << ' '; test( int_t<26>::least() );
|
||||||
SHOW_SHIFTED_TYPES( uint_value_t, least );
|
std::cout << 25 << ' '; test( int_t<25>::least() );
|
||||||
SHOW_SHIFTED_TYPES( uint_value_t, fast );
|
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() );
|
||||||
|
#endif
|
||||||
|
|
||||||
PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX );
|
long v = 0x7FFFFFFF;
|
||||||
PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX );
|
BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX );
|
BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX );
|
BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX );
|
BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX );
|
BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN );
|
BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN );
|
BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX );
|
BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1;
|
||||||
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX );
|
BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<0>::least(v) == v );
|
||||||
|
v = 0x7FFFFFFF;
|
||||||
|
BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1;
|
||||||
|
BOOST_TEST( int_t<0>::fast(v) == v );
|
||||||
|
unsigned long u = 0xFFFFFFFF;
|
||||||
|
BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<0>::least(u) == u );
|
||||||
|
u = 0xFFFFFFFF;
|
||||||
|
BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1;
|
||||||
|
BOOST_TEST( uint_t<0>::fast(u) == u );
|
||||||
|
|
||||||
return boost::exit_success;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -35,20 +35,10 @@
|
|||||||
* Therefore, avoid explicit function template instantiations.
|
* 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; }
|
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(char c) { return c; }
|
||||||
inline int make_char_numeric_for_streaming(signed 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; }
|
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
|
||||||
#endif
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void runtest(const char * type, T)
|
void runtest(const char * type, T)
|
||||||
@ -83,7 +73,7 @@ int test_main(int, char*[])
|
|||||||
runtest("long", long());
|
runtest("long", long());
|
||||||
typedef unsigned long unsigned_long;
|
typedef unsigned long unsigned_long;
|
||||||
runtest("unsigned long", unsigned_long());
|
runtest("unsigned long", unsigned_long());
|
||||||
#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
|
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__) && !defined(__BEOS__)
|
||||||
//
|
//
|
||||||
// MS/Borland compilers can't support 64-bit member constants
|
// MS/Borland compilers can't support 64-bit member constants
|
||||||
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
// boost integer_mask.hpp test program -------------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
|
||||||
// and distribute this software is granted provided this copyright
|
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
|
||||||
|
|
||||||
// Revision History
|
|
||||||
// 23 Sep 2001 Initial version (Daryle Walker)
|
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
|
||||||
#include <boost/test/test_tools.hpp> // for main
|
|
||||||
|
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
|
||||||
#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc.
|
|
||||||
|
|
||||||
#include <iostream> // for std::cout (std::endl indirectly)
|
|
||||||
|
|
||||||
|
|
||||||
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
|
||||||
(v) >::high_bit == (1ul << (v)) );
|
|
||||||
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
|
||||||
(v) >::high_bit_fast == (1ul << (v)) );
|
|
||||||
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
|
|
||||||
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
|
|
||||||
|
|
||||||
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
|
||||||
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
|
||||||
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
|
||||||
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
|
|
||||||
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
|
|
||||||
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
|
|
||||||
|
|
||||||
|
|
||||||
int test_main( int, char*[] )
|
|
||||||
{
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
cout << "Doing high_bit_mask_t tests." << endl;
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 31 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 30 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 29 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 28 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 27 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 26 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 25 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 24 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 23 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 22 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 21 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 20 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 19 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 18 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 17 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 16 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 15 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 14 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 13 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 12 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 11 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 10 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 9 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 8 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 7 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 6 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 5 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 4 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 3 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 2 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 1 );
|
|
||||||
PRIVATE_HIGH_BIT_TEST( 0 );
|
|
||||||
|
|
||||||
cout << "Doing low_bits_mask_t tests." << endl;
|
|
||||||
PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops!
|
|
||||||
PRIVATE_LOW_BITS_TEST( 31 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 30 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 29 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 28 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 27 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 26 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 25 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 24 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 23 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 22 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 21 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 20 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 19 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 18 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 17 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 16 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 15 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 14 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 13 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 12 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 11 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 10 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 9 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 8 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 7 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 6 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 5 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 4 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 3 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 2 );
|
|
||||||
PRIVATE_LOW_BITS_TEST( 1 );
|
|
||||||
|
|
||||||
return boost::exit_success;
|
|
||||||
}
|
|
@ -1,151 +0,0 @@
|
|||||||
// Boost static_log2.hpp test program --------------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
|
||||||
// and distribute this software is granted provided this copyright
|
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
|
||||||
|
|
||||||
// Revision History
|
|
||||||
// 01 Oct 2001 Initial version (Daryle Walker)
|
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
|
||||||
#include <boost/test/test_tools.hpp> // for main
|
|
||||||
|
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
|
||||||
#include <boost/integer/static_log2.hpp> // for boost::static_log2
|
|
||||||
|
|
||||||
#include <iostream> // for std::cout (std::endl indirectly)
|
|
||||||
|
|
||||||
|
|
||||||
// Macros to compact code
|
|
||||||
#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
|
|
||||||
|
|
||||||
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
|
|
||||||
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
|
|
||||||
|
|
||||||
// Control to check for a compile-time error
|
|
||||||
#ifndef CONTROL_LB_0_TEST
|
|
||||||
#define PRIVATE_LB_0_TEST
|
|
||||||
#else
|
|
||||||
#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Main testing function
|
|
||||||
int
|
|
||||||
test_main
|
|
||||||
(
|
|
||||||
int , // "argc" is unused
|
|
||||||
char * [] // "argv" is unused
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Doing tests on static_log2." << std::endl;
|
|
||||||
|
|
||||||
PRIVATE_LB_0_TEST;
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 1, 0 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 2, 1 );
|
|
||||||
PRIVATE_LB_TEST( 3, 1 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 4, 2 );
|
|
||||||
PRIVATE_LB_TEST( 5, 2 );
|
|
||||||
PRIVATE_LB_TEST( 6, 2 );
|
|
||||||
PRIVATE_LB_TEST( 7, 2 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 8, 3 );
|
|
||||||
PRIVATE_LB_TEST( 9, 3 );
|
|
||||||
PRIVATE_LB_TEST( 10, 3 );
|
|
||||||
PRIVATE_LB_TEST( 11, 3 );
|
|
||||||
PRIVATE_LB_TEST( 12, 3 );
|
|
||||||
PRIVATE_LB_TEST( 13, 3 );
|
|
||||||
PRIVATE_LB_TEST( 14, 3 );
|
|
||||||
PRIVATE_LB_TEST( 15, 3 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 16, 4 );
|
|
||||||
PRIVATE_LB_TEST( 17, 4 );
|
|
||||||
PRIVATE_LB_TEST( 18, 4 );
|
|
||||||
PRIVATE_LB_TEST( 19, 4 );
|
|
||||||
PRIVATE_LB_TEST( 20, 4 );
|
|
||||||
PRIVATE_LB_TEST( 21, 4 );
|
|
||||||
PRIVATE_LB_TEST( 22, 4 );
|
|
||||||
PRIVATE_LB_TEST( 23, 4 );
|
|
||||||
PRIVATE_LB_TEST( 24, 4 );
|
|
||||||
PRIVATE_LB_TEST( 25, 4 );
|
|
||||||
PRIVATE_LB_TEST( 26, 4 );
|
|
||||||
PRIVATE_LB_TEST( 27, 4 );
|
|
||||||
PRIVATE_LB_TEST( 28, 4 );
|
|
||||||
PRIVATE_LB_TEST( 29, 4 );
|
|
||||||
PRIVATE_LB_TEST( 30, 4 );
|
|
||||||
PRIVATE_LB_TEST( 31, 4 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 32, 5 );
|
|
||||||
PRIVATE_LB_TEST( 33, 5 );
|
|
||||||
PRIVATE_LB_TEST( 34, 5 );
|
|
||||||
PRIVATE_LB_TEST( 35, 5 );
|
|
||||||
PRIVATE_LB_TEST( 36, 5 );
|
|
||||||
PRIVATE_LB_TEST( 37, 5 );
|
|
||||||
PRIVATE_LB_TEST( 38, 5 );
|
|
||||||
PRIVATE_LB_TEST( 39, 5 );
|
|
||||||
PRIVATE_LB_TEST( 40, 5 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 63, 5 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 64, 6 );
|
|
||||||
PRIVATE_LB_TEST( 65, 6 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 127, 6 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 128, 7 );
|
|
||||||
PRIVATE_LB_TEST( 129, 7 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 255, 7 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 256, 8 );
|
|
||||||
PRIVATE_LB_TEST( 257, 8 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 511, 8 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 512, 9 );
|
|
||||||
PRIVATE_LB_TEST( 513, 9 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 1023, 9 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 1024, 10 );
|
|
||||||
PRIVATE_LB_TEST( 1025, 10 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 2047, 10 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 2048, 11 );
|
|
||||||
PRIVATE_LB_TEST( 2049, 11 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 4095, 11 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 4096, 12 );
|
|
||||||
PRIVATE_LB_TEST( 4097, 12 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 8191, 12 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 8192, 13 );
|
|
||||||
PRIVATE_LB_TEST( 8193, 13 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 16383, 13 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 16384, 14 );
|
|
||||||
PRIVATE_LB_TEST( 16385, 14 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 32767, 14 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 32768, 15 );
|
|
||||||
PRIVATE_LB_TEST( 32769, 15 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 65535, 15 );
|
|
||||||
|
|
||||||
PRIVATE_LB_TEST( 65536, 16 );
|
|
||||||
PRIVATE_LB_TEST( 65537, 16 );
|
|
||||||
|
|
||||||
return boost::exit_success;
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
// Boost static_min_max.hpp test program -----------------------------------//
|
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
|
||||||
// and distribute this software is granted provided this copyright
|
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
|
||||||
|
|
||||||
// Revision History
|
|
||||||
// 23 Sep 2001 Initial version (Daryle Walker)
|
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
|
||||||
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
|
|
||||||
|
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
|
||||||
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
|
|
||||||
|
|
||||||
#include <iostream> // for std::cout (std::endl indirectly)
|
|
||||||
|
|
||||||
|
|
||||||
// Main testing function
|
|
||||||
int
|
|
||||||
test_main
|
|
||||||
(
|
|
||||||
int , // "argc" is unused
|
|
||||||
char * [] // "argv" is unused
|
|
||||||
)
|
|
||||||
{
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using boost::static_signed_min;
|
|
||||||
using boost::static_signed_max;
|
|
||||||
using boost::static_unsigned_min;
|
|
||||||
using boost::static_unsigned_max;
|
|
||||||
|
|
||||||
// Two positives
|
|
||||||
cout << "Doing tests with two positive values." << endl;
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
|
|
||||||
BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
|
|
||||||
BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
|
|
||||||
|
|
||||||
BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
|
|
||||||
BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
|
|
||||||
BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
|
|
||||||
|
|
||||||
// Two negatives
|
|
||||||
cout << "Doing tests with two negative values." << endl;
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
|
|
||||||
BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
|
|
||||||
BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
|
|
||||||
BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
|
|
||||||
|
|
||||||
// With zero
|
|
||||||
cout << "Doing tests with zero and a positive or negative value." << endl;
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
|
|
||||||
|
|
||||||
BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
|
|
||||||
BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
|
|
||||||
BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
|
|
||||||
|
|
||||||
// With identical
|
|
||||||
cout << "Doing tests with two identical values." << endl;
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
|
|
||||||
BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
|
|
||||||
BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
|
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
|
|
||||||
BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
|
|
||||||
|
|
||||||
return boost::exit_success;
|
|
||||||
}
|
|
Reference in New Issue
Block a user