forked from boostorg/integer
initial checkin
[SVN r11972]
This commit is contained in:
211
doc/integer_mask.html
Normal file
211
doc/integer_mask.html
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Integer Bit Mask Templates</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
||||||
|
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
||||||
|
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
||||||
|
|
||||||
|
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp"><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>
|
122
doc/static_log2.html
Normal file
122
doc/static_log2.html
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<!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>.</p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<p>Revised October 1, 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>
|
121
doc/static_min_max.html
Normal file
121
doc/static_min_max.html
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Compile-Time Extrema Templates</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
||||||
|
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
||||||
|
align="middle" width="277" height="86">Compile-Time Extrema
|
||||||
|
Templates</h1>
|
||||||
|
|
||||||
|
<p>The class templates in <cite><a
|
||||||
|
href="../../../boost/integer/static_min_max.hpp"><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>
|
112
test/integer_mask_test.cpp
Normal file
112
test/integer_mask_test.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// boost integer_mask.hpp test program -------------------------------------//
|
||||||
|
|
||||||
|
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
||||||
|
// and distribute this software is granted provided this copyright
|
||||||
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
|
// any purpose.
|
||||||
|
|
||||||
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 23 Sep 2001 Initial version (Daryle Walker)
|
||||||
|
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp> // for main
|
||||||
|
|
||||||
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
|
#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc.
|
||||||
|
|
||||||
|
#include <iostream> // for std::cout (std::endl indirectly)
|
||||||
|
|
||||||
|
|
||||||
|
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
||||||
|
(v) >::high_bit == (1ul << (v)) );
|
||||||
|
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
||||||
|
(v) >::high_bit_fast == (1ul << (v)) );
|
||||||
|
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
|
||||||
|
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
|
||||||
|
|
||||||
|
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
||||||
|
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
||||||
|
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
||||||
|
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
|
||||||
|
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
|
||||||
|
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
|
||||||
|
|
||||||
|
|
||||||
|
int test_main( int, char*[] )
|
||||||
|
{
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
cout << "Doing high_bit_mask_t tests." << endl;
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 31 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 30 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 29 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 28 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 27 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 26 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 25 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 24 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 23 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 22 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 21 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 20 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 19 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 18 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 17 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 16 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 15 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 14 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 13 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 12 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 11 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 10 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 9 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 8 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 7 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 6 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 5 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 4 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 3 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 2 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 1 );
|
||||||
|
PRIVATE_HIGH_BIT_TEST( 0 );
|
||||||
|
|
||||||
|
cout << "Doing low_bits_mask_t tests." << endl;
|
||||||
|
PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops!
|
||||||
|
PRIVATE_LOW_BITS_TEST( 31 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 30 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 29 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 28 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 27 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 26 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 25 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 24 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 23 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 22 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 21 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 20 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 19 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 18 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 17 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 16 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 15 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 14 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 13 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 12 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 11 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 10 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 9 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 8 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 7 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 6 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 5 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 4 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 3 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 2 );
|
||||||
|
PRIVATE_LOW_BITS_TEST( 1 );
|
||||||
|
|
||||||
|
return boost::exit_success;
|
||||||
|
}
|
151
test/static_log2_test.cpp
Normal file
151
test/static_log2_test.cpp
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// Boost static_log2.hpp test program --------------------------------------//
|
||||||
|
|
||||||
|
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
||||||
|
// and distribute this software is granted provided this copyright
|
||||||
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
|
// any purpose.
|
||||||
|
|
||||||
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 01 Oct 2001 Initial version (Daryle Walker)
|
||||||
|
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp> // for main
|
||||||
|
|
||||||
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
|
#include <boost/integer/static_log2.hpp> // for boost::static_log2
|
||||||
|
|
||||||
|
#include <iostream> // for std::cout (std::endl indirectly)
|
||||||
|
|
||||||
|
|
||||||
|
// Macros to compact code
|
||||||
|
#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
|
||||||
|
|
||||||
|
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
|
||||||
|
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
|
||||||
|
|
||||||
|
// Control to check for a compile-time error
|
||||||
|
#ifndef CONTROL_LB_0_TEST
|
||||||
|
#define PRIVATE_LB_0_TEST
|
||||||
|
#else
|
||||||
|
#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Main testing function
|
||||||
|
int
|
||||||
|
test_main
|
||||||
|
(
|
||||||
|
int , // "argc" is unused
|
||||||
|
char * [] // "argv" is unused
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::cout << "Doing tests on static_log2." << std::endl;
|
||||||
|
|
||||||
|
PRIVATE_LB_0_TEST;
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 1, 0 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 2, 1 );
|
||||||
|
PRIVATE_LB_TEST( 3, 1 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 4, 2 );
|
||||||
|
PRIVATE_LB_TEST( 5, 2 );
|
||||||
|
PRIVATE_LB_TEST( 6, 2 );
|
||||||
|
PRIVATE_LB_TEST( 7, 2 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 8, 3 );
|
||||||
|
PRIVATE_LB_TEST( 9, 3 );
|
||||||
|
PRIVATE_LB_TEST( 10, 3 );
|
||||||
|
PRIVATE_LB_TEST( 11, 3 );
|
||||||
|
PRIVATE_LB_TEST( 12, 3 );
|
||||||
|
PRIVATE_LB_TEST( 13, 3 );
|
||||||
|
PRIVATE_LB_TEST( 14, 3 );
|
||||||
|
PRIVATE_LB_TEST( 15, 3 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 16, 4 );
|
||||||
|
PRIVATE_LB_TEST( 17, 4 );
|
||||||
|
PRIVATE_LB_TEST( 18, 4 );
|
||||||
|
PRIVATE_LB_TEST( 19, 4 );
|
||||||
|
PRIVATE_LB_TEST( 20, 4 );
|
||||||
|
PRIVATE_LB_TEST( 21, 4 );
|
||||||
|
PRIVATE_LB_TEST( 22, 4 );
|
||||||
|
PRIVATE_LB_TEST( 23, 4 );
|
||||||
|
PRIVATE_LB_TEST( 24, 4 );
|
||||||
|
PRIVATE_LB_TEST( 25, 4 );
|
||||||
|
PRIVATE_LB_TEST( 26, 4 );
|
||||||
|
PRIVATE_LB_TEST( 27, 4 );
|
||||||
|
PRIVATE_LB_TEST( 28, 4 );
|
||||||
|
PRIVATE_LB_TEST( 29, 4 );
|
||||||
|
PRIVATE_LB_TEST( 30, 4 );
|
||||||
|
PRIVATE_LB_TEST( 31, 4 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 32, 5 );
|
||||||
|
PRIVATE_LB_TEST( 33, 5 );
|
||||||
|
PRIVATE_LB_TEST( 34, 5 );
|
||||||
|
PRIVATE_LB_TEST( 35, 5 );
|
||||||
|
PRIVATE_LB_TEST( 36, 5 );
|
||||||
|
PRIVATE_LB_TEST( 37, 5 );
|
||||||
|
PRIVATE_LB_TEST( 38, 5 );
|
||||||
|
PRIVATE_LB_TEST( 39, 5 );
|
||||||
|
PRIVATE_LB_TEST( 40, 5 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 63, 5 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 64, 6 );
|
||||||
|
PRIVATE_LB_TEST( 65, 6 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 127, 6 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 128, 7 );
|
||||||
|
PRIVATE_LB_TEST( 129, 7 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 255, 7 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 256, 8 );
|
||||||
|
PRIVATE_LB_TEST( 257, 8 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 511, 8 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 512, 9 );
|
||||||
|
PRIVATE_LB_TEST( 513, 9 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 1023, 9 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 1024, 10 );
|
||||||
|
PRIVATE_LB_TEST( 1025, 10 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 2047, 10 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 2048, 11 );
|
||||||
|
PRIVATE_LB_TEST( 2049, 11 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 4095, 11 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 4096, 12 );
|
||||||
|
PRIVATE_LB_TEST( 4097, 12 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 8191, 12 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 8192, 13 );
|
||||||
|
PRIVATE_LB_TEST( 8193, 13 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 16383, 13 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 16384, 14 );
|
||||||
|
PRIVATE_LB_TEST( 16385, 14 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 32767, 14 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 32768, 15 );
|
||||||
|
PRIVATE_LB_TEST( 32769, 15 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 65535, 15 );
|
||||||
|
|
||||||
|
PRIVATE_LB_TEST( 65536, 16 );
|
||||||
|
PRIVATE_LB_TEST( 65537, 16 );
|
||||||
|
|
||||||
|
return boost::exit_success;
|
||||||
|
}
|
94
test/static_min_max_test.cpp
Normal file
94
test/static_min_max_test.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// Boost static_min_max.hpp test program -----------------------------------//
|
||||||
|
|
||||||
|
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
||||||
|
// and distribute this software is granted provided this copyright
|
||||||
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
|
// any purpose.
|
||||||
|
|
||||||
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 23 Sep 2001 Initial version (Daryle Walker)
|
||||||
|
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
|
||||||
|
|
||||||
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
|
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
|
||||||
|
|
||||||
|
#include <iostream> // for std::cout (std::endl indirectly)
|
||||||
|
|
||||||
|
|
||||||
|
// Main testing function
|
||||||
|
int
|
||||||
|
test_main
|
||||||
|
(
|
||||||
|
int , // "argc" is unused
|
||||||
|
char * [] // "argv" is unused
|
||||||
|
)
|
||||||
|
{
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using boost::static_signed_min;
|
||||||
|
using boost::static_signed_max;
|
||||||
|
using boost::static_unsigned_min;
|
||||||
|
using boost::static_unsigned_max;
|
||||||
|
|
||||||
|
// Two positives
|
||||||
|
cout << "Doing tests with two positive values." << endl;
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
|
||||||
|
BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
|
||||||
|
BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
|
||||||
|
|
||||||
|
BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
|
||||||
|
BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
|
||||||
|
BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
|
||||||
|
|
||||||
|
// Two negatives
|
||||||
|
cout << "Doing tests with two negative values." << endl;
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
|
||||||
|
BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
|
||||||
|
BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
|
||||||
|
BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
|
||||||
|
|
||||||
|
// With zero
|
||||||
|
cout << "Doing tests with zero and a positive or negative value." << endl;
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
|
||||||
|
|
||||||
|
BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
|
||||||
|
BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
|
||||||
|
BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
|
||||||
|
|
||||||
|
// With identical
|
||||||
|
cout << "Doing tests with two identical values." << endl;
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
|
||||||
|
BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
|
||||||
|
BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
|
||||||
|
|
||||||
|
BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
|
||||||
|
BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
|
||||||
|
|
||||||
|
return boost::exit_success;
|
||||||
|
}
|
Reference in New Issue
Block a user