mirror of
https://github.com/boostorg/integer.git
synced 2025-06-25 12:01:34 +02:00
Compare commits
119 Commits
boost-1.21
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
f793dbeab8 | |||
2d259a4f3e | |||
2fd0675a21 | |||
f041dc0f0a | |||
188cef05a9 | |||
2ae867bcf8 | |||
2fcbc31b77 | |||
4af7660410 | |||
2b7ed6ebf7 | |||
203705fea6 | |||
ed80575830 | |||
f27ad7b337 | |||
55e1796c7a | |||
053be71261 | |||
10e5587b9e | |||
2f91e69629 | |||
422ef1ebe6 | |||
edfaeb6c0e | |||
3c7910fad3 | |||
600801670e | |||
4e2c8440b5 | |||
94ace80618 | |||
cd6a9565ff | |||
0d058f42cc | |||
7d8e93a6ac | |||
a1cc143de7 | |||
cd99f24a87 | |||
93612e6c0b | |||
d9f5b1bbf9 | |||
37d7590f2f | |||
cb9a7792cc | |||
291bb8c525 | |||
8602a17a10 | |||
29275d71aa | |||
9df9a90217 | |||
65607e3b82 | |||
39399de102 | |||
27aae3b3cb | |||
21fe6251ab | |||
07019a8801 | |||
3892592661 | |||
0935f20c69 | |||
7197caf500 | |||
92a46aac83 | |||
c32a045fa4 | |||
0c31aa03f0 | |||
bfc384a435 | |||
198530a48d | |||
91f511cab4 | |||
0f84fe35da | |||
fa5aba353f | |||
170a352574 | |||
4862574bb1 | |||
f2d22d091f | |||
1e6ab2dc10 | |||
a656e7744f | |||
46fdbba4b8 | |||
f2ea03679b | |||
890e28ab67 | |||
1252426554 | |||
19fb03cefe | |||
a9b35df2f8 | |||
49a8d69fe3 | |||
9cc587a7f2 | |||
2de1422682 | |||
344fe9f30a | |||
8ad3bbafbc | |||
cc1183d347 | |||
a9703fa803 | |||
5e26f47535 | |||
57e7ccd494 | |||
c56e4674f8 | |||
41620a14f9 | |||
a42ede713e | |||
92de2f44a0 | |||
59779dec2c | |||
3bb567ad9d | |||
c50993d5d4 | |||
5477a9641c | |||
162c6aefa1 | |||
24e6bfbfaa | |||
ccabb522d0 | |||
0995d0a6fb | |||
5ec8116c34 | |||
4a094c4bcb | |||
a7d2da8d1c | |||
4d2a921dbf | |||
0c758855e4 | |||
3399df597e | |||
a066e242b0 | |||
a635f753a4 | |||
08f30ea46c | |||
292eeb5c90 | |||
8a105dab3f | |||
5b0d514aa4 | |||
eee6dfa4d9 | |||
3bd242ef49 | |||
3db9390efb | |||
c6f3dce91a | |||
3e2b929118 | |||
645f809379 | |||
28ec7fa76c | |||
07505c76f8 | |||
fda46f9780 | |||
125bf3351f | |||
e3702f3abc | |||
c54da75efb | |||
2dd1bee693 | |||
949134726f | |||
b3f587b9f7 | |||
215b4d8ee7 | |||
976c5e6572 | |||
0424bb266e | |||
33abcf7250 | |||
b519841b7f | |||
d1781f09d2 | |||
c1c099c845 | |||
f4c38bdf51 | |||
53005cadc8 |
15
cstdint.htm
15
cstdint.htm
@ -2,14 +2,14 @@
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Header boost/cstdint.hpp</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Header
|
||||
boost/cstdint.hpp </h1>
|
||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for
|
||||
@ -18,7 +18,7 @@ writing portable code that requires certain integer widths. All typedef's are i
|
||||
header <stdint.h>. The 64-bit types required by the C standard are not
|
||||
required in the boost header, and may not be supplied in all implementations,
|
||||
because <code>long long</code> is not [yet] included in the C++ standard.</p>
|
||||
<p>See <a href="cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
<p>See <a href="test/cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
<h2>Exact-width integer types</h2>
|
||||
<p>The typedef <code>int#_t</code>, with # replaced by the width, designates a
|
||||
signed integer type of exactly # bits; <code>int8_t</code> denotes an 8-bit
|
||||
@ -69,10 +69,13 @@ representing any value of any signed integer type.</p>
|
||||
capable of representing any value of any unsigned integer type.</p>
|
||||
<p>These types are required.</p>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||
</p>
|
||||
<p> </p>
|
||||
<p><EFBFBD> Copyright Beman Dawes 2000</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
377
doc/integer_mask.html
Normal file
377
doc/integer_mask.html
Normal file
@ -0,0 +1,377 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Integer Bit Mask Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
||||
|
||||
<p>The class templates in <cite><a
|
||||
href="../../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a></cite>
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of a
|
||||
certain size. The types of the masking constants come from the <a
|
||||
href="../integer.htm">integer type selection templates</a> header.</p>
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#single">Single Bit-Mask Class Template</a></li>
|
||||
<li><a href="#group">Group Bit-Mask Class Template</a></li>
|
||||
<li><a href="#mpl">MPL-Compatible Variants</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 <<a href="../../../boost/integer_fwd.hpp">boost/integer_fwd.hpp</a>> <i>// forwarding header</i>
|
||||
#include <<a href="../../../boost/integer.hpp">boost/integer.hpp</a>> <i>// for boost::int_fast_t</i>
|
||||
#include <cstddef> <i>// for std::size_t</i>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// MPL-compatible
|
||||
template < int Offset >
|
||||
struct integer_hi_mask
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static int const bit_offset = Offset;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
typedef <em>implementation_supplied</em> value_type;
|
||||
static value_type const value = <em>implementation_supplied</em>;
|
||||
// There are other (optional) operations....
|
||||
};
|
||||
|
||||
template < int Length >
|
||||
struct integer_lo_mask
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static int const bit_count = Length;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
typedef <em>implementation_supplied</em> value_type;
|
||||
static value_type const value = <em>implementation_supplied</em>;
|
||||
// There are other (optional) operations....
|
||||
};
|
||||
|
||||
// single
|
||||
template < std::size_t Bit >
|
||||
class high_bit_mask_t
|
||||
{
|
||||
public:
|
||||
typedef typename integer_hi_mask<Bit>::value_type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
|
||||
static const least high_bit = integer_hi_mask<Bit>::value;
|
||||
static const fast high_bit_fast = high_bit;
|
||||
|
||||
static const std::size_t bit_position = Bit;
|
||||
|
||||
};
|
||||
|
||||
// group
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t
|
||||
{
|
||||
public:
|
||||
typedef typename integer_lo_mask<Bits>::value_type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
|
||||
static const least sig_bits = integer_lo_mask<Bits>::value;
|
||||
static const fast sig_bits_fast = sig_bits;
|
||||
|
||||
static const std::size_t bit_count = Bits;
|
||||
|
||||
};
|
||||
|
||||
} // 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>
|
||||
|
||||
<h2><a name="mpl">MPL-Compatible Variants</a></h2>
|
||||
|
||||
<p>The single and group bit-mask class templates have several drawbacks:</p>
|
||||
|
||||
<ul>
|
||||
<li>You must know the valid bit-lengths in advance.</li>
|
||||
<li>Using an inappropriate parameter value results in a compiler
|
||||
diagnostic.</li>
|
||||
<li>The type names used are inconsistent with other transformations in
|
||||
Boost, like in <a href="../../mpl/">MPL</a>.</li>
|
||||
<li>The above two facts make use of the regular bit-mask class templates
|
||||
incompatible with template meta-programming techniques.</li>
|
||||
</ul>
|
||||
|
||||
<p>The <code>integer_hi_mask</code> and <code>integer_lo_mask</code> class
|
||||
templates provide MPL-compatible alternatives. These alternatives have the
|
||||
form:</p>
|
||||
|
||||
<blockquote><pre>
|
||||
template< int <var>Size</var> >
|
||||
struct <var>name</var>
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static int const <var>switch_id</var> = <var>Size</var>;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
typedef <em>implementation_supplied</em> value_type;
|
||||
static value_type const value = <em>implementation_supplied</em>;
|
||||
// with other operations...
|
||||
};
|
||||
</pre></blockquote>
|
||||
|
||||
<p>Only some of the members are always present. The presence of other members
|
||||
and operations is flagged by the (always-present) <code>is_specialized</code>.</p>
|
||||
|
||||
<table border="2" cellpadding="5" align="center">
|
||||
<caption>Permanent Members of the MPL-Compatible Masking Class Template
|
||||
Types</caption>
|
||||
<tr>
|
||||
<th>Class Template Member</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>is_specialized</code></td>
|
||||
<td>Flag indicating when a particular template class instantiation is a
|
||||
valid meta-function (<code>true</code>) or not (<code>false</code>).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><var>switch_id</var></code> (Actual name is template-specific.)</td>
|
||||
<td>The value of the main control parameter, accessible even if the
|
||||
template class instantiation is aliased.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The optional members are based from inheriting from a <a
|
||||
href="../../mpl/doc/refmanual/integral-constant.html">MPL-style Integral
|
||||
Constant</a> type, but only if <code>is_specialized</code> is <code>true</code>.</p>
|
||||
|
||||
<table border="2" cellpadding="5" align="center">
|
||||
<caption>Optional Members of the MPL-Compatible Masking Types</caption>
|
||||
<tr>
|
||||
<th>Class Template Member</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>value</code></td>
|
||||
<td>The actual bit mask.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>value_type</code></td>
|
||||
<td>The type of the bit mask value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>type</code></td>
|
||||
<td>The Integral Constant</a> implementation type, which should be
|
||||
<code><a href="../../mpl/doc/refmanual/integral-c.html">boost::mpl::
|
||||
integral_c</a>< <var>value_type</var>, <var>value</var>
|
||||
></code>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The Integral Constant prototype also adds the following operations:</p>
|
||||
|
||||
<table border="2" cellpadding="5" align="center">
|
||||
<caption>Optional Operations of the MPL-Compatible Masking Types</caption>
|
||||
<tr>
|
||||
<th>Operation (with <var>n</var> as a masking type)</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::mpl::next< n >::type</code></td>
|
||||
<td><code>boost::mpl::next< n::type >::type</code>, i.e.
|
||||
<code>boost::mpl::integral_c< n::value_type, n::value + 1
|
||||
></code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::mpl::prior< n >::type</code></td>
|
||||
<td><code>boost::mpl::prior< n::type >::type</code>, i.e.
|
||||
<code>boost::mpl::integral_c< n::value_type, n::value - 1
|
||||
></code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>n::value_type const c = n();</code></td>
|
||||
<td><var>c</var> is set to <code>n::value</code>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The specifics for each masking class template are:</p>
|
||||
|
||||
<table border="2" cellpadding="5" align="center">
|
||||
<caption>Criteria for the MPL-Compatible Masking Types<br>
|
||||
(Everything besides the parameter ID is in name-space
|
||||
<code>boost</code> except where indicated.)</caption>
|
||||
<tr>
|
||||
<th>Class Template</th>
|
||||
<th>Parameter Member ID</th>
|
||||
<th>Classic Equivalent</th>
|
||||
<th>Value Type</th>
|
||||
<th>Value</th>
|
||||
<th>Valid Range</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>integer_hi_mask</code></td>
|
||||
<td><code>bit_offset</code></td>
|
||||
<td><code>high_bit_mask_t</code></td>
|
||||
<td><code>sized_integral < bit_offset + 1, unsigned ></code></td>
|
||||
<td>2<sup><code>bit_offset</code></sup></td>
|
||||
<td><code>0 <= bit_offset < std::numeric_limits< uintmax_t >::digits</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>integer_lo_mask</code></td>
|
||||
<td><code>bit_count</code></td>
|
||||
<td><code>low_bits_mask_t</code></td>
|
||||
<td><code>sized_integral < bit_count, unsigned ></code></td>
|
||||
<td>2<sup><code>bit_offset</code></sup> - 1</td>
|
||||
<td><code>0 <= bit_count <= std::numeric_limits< uintmax_t >::digits</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <<a href="../../../boost/integer/integer_mask.hpp">boost/integer/integer_mask.hpp</a>>
|
||||
|
||||
//...
|
||||
|
||||
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="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised July 29, 2008</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
215
doc/static_log2.html
Normal file
215
doc/static_log2.html
Normal file
@ -0,0 +1,215 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<title>Binary Logarithm Template</title>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
||||
|
||||
|
||||
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a></cite> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
|
||||
<li><a href="#usage">Usage</a></li>
|
||||
|
||||
<li><a href="#example">Example</a></li>
|
||||
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
|
||||
<li><a href="#whatsnew"><b>What's new</b></a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef <em>implementation-defined</em> static_log2_argument_type;
|
||||
typedef <em>implementation-defined</em> static_log2_result_type;
|
||||
|
||||
template < static_log2_argument_type arg >
|
||||
struct static_log2
|
||||
{
|
||||
static const static_log2_result_type value = <em>implementation-defined</em>;
|
||||
};
|
||||
|
||||
|
||||
template < >
|
||||
struct static_log2< 0 >
|
||||
{
|
||||
// The logarithm of zero is undefined.
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
</pre></blockquote>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2><a name="usage">Usage</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The <code>boost::static_log2</code> class template takes one template
|
||||
parameter, a value of type <code>static_log2_argument_type</code>. The template
|
||||
only defines one member, <code>value</code>, which gives the truncated
|
||||
base-two logarithm of the template argument.</p>
|
||||
|
||||
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
||||
specialization of <code>static_log2</code> for a template argument
|
||||
of zero. This specialization has no members, so an attempt to use
|
||||
the base-two logarithm of zero results in a compile-time error.</p>
|
||||
|
||||
<p>Note: <ul>
|
||||
|
||||
<li><code>static_log2_argument_type</code> is an <i>unsigned integer
|
||||
type</i> (C++ standard, 3.9.1p3).</li>
|
||||
|
||||
<li><code>static_log2_result_type</code> is an <i>integer type</i>
|
||||
(C++ standard, 3.9.1p7).</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
#include "boost/integer/static_log2.hpp"
|
||||
|
||||
|
||||
template < boost::static_log2_argument_type value >
|
||||
bool is_it_what()
|
||||
{
|
||||
typedef boost::static_log2<value> lb_type;
|
||||
|
||||
int temp = lb_type::value;
|
||||
//...
|
||||
return (temp % 2) != 0;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
bool temp = is_it_what<2000>();
|
||||
//...
|
||||
# if 0
|
||||
temp = is_it_what<0>(); // would give an error
|
||||
# endif
|
||||
//...
|
||||
temp = is_it_what<24>();
|
||||
//...
|
||||
}
|
||||
|
||||
</pre></blockquote>
|
||||
|
||||
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The program <a href="../test/static_log2_test.cpp">static_log2_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various
|
||||
examples of the binary logarithm class template.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The base-two (binary) logarithm, abbreviated <dfn>lb</dfn>, function
|
||||
is occasionally used to give order-estimates of computer algorithms.
|
||||
The truncated logarithm can be considered the highest power-of-two in a
|
||||
value, which corresponds to the value's highest set bit (for binary
|
||||
integers). Sometimes the highest-bit position could be used in generic
|
||||
programming, which requires the position to be statically (<i>i.e.</i>
|
||||
at compile-time) available.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="whatsnew">Changes from previous versions:</a></h2>
|
||||
|
||||
|
||||
|
||||
<ul>
|
||||
<li><i>New in version 1.32.0:</i><br><br>
|
||||
|
||||
The argument type and the result type of <code>boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code>unsigned long</code>
|
||||
and <code>int</code> respectively. Please, use the provided typedefs in new
|
||||
code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The original version of the Boost binary logarithm class template was
|
||||
written by <a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>
|
||||
and then enhanced by Giovanni Bajo with support for compilers without
|
||||
partial template specialization. The current version was suggested,
|
||||
together with a reference implementation, by Vesa Karvonen. Gennaro Prota
|
||||
wrote the actual source file.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
|
||||
<p>Revised July 19, 2004</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001.<br>
|
||||
© Copyright Gennaro Prota 2004.</p>
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
120
doc/static_min_max.html
Normal file
120
doc/static_min_max.html
Normal file
@ -0,0 +1,120 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Compile-Time Extrema Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Compile-Time Extrema
|
||||
Templates</h1>
|
||||
|
||||
<p>The class templates in <cite><a
|
||||
href="../../../boost/integer/static_min_max.hpp"><boost/integer/static_min_max.hpp></a></cite>
|
||||
provide a compile-time evaluation of the minimum or maximum of
|
||||
two integers. These facilities are useful for generic programming problems.</p>
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#usage">Usage</a></li>
|
||||
<li><a href="#example">Example</a></li>
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min;
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max;
|
||||
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="usage">Usage</a></h2>
|
||||
|
||||
<p>The four class templates provide the combinations for finding the
|
||||
minimum or maximum of two signed or <code>unsigned</code>
|
||||
(<code>long</code>) parameters, <var>Value1</var> and <var>Value2</var>,
|
||||
at compile-time. Each template has a single static data member,
|
||||
<code>value</code>, which is set to the respective minimum or maximum
|
||||
of the template's parameters.</p>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <boost/integer/static_min_max.hpp>
|
||||
|
||||
template < unsigned long AddendSize1, unsigned long AddendSize2 >
|
||||
class adder
|
||||
{
|
||||
public:
|
||||
static unsigned long const addend1_size = AddendSize1;
|
||||
static unsigned long const addend2_size = AddendSize2;
|
||||
static unsigned long const sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
|
||||
|
||||
typedef int addend1_type[ addend1_size ];
|
||||
typedef int addend2_type[ addend2_size ];
|
||||
typedef int sum_type[ sum_size ];
|
||||
|
||||
void operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const;
|
||||
};
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
int const a1[] = { 0, 4, 3 }; // 340
|
||||
int const a2[] = { 9, 8 }; // 89
|
||||
int s[ 4 ];
|
||||
adder<3,2> obj;
|
||||
|
||||
obj( a1, a2, s ); // 's' should be 429 or { 9, 2, 4, 0 }
|
||||
//...
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
<p>The program <a
|
||||
href="../test/static_min_max_test.cpp">static_min_max_test.cpp</a> is a
|
||||
simplistic demonstration of various comparisons using the compile-time
|
||||
extrema class templates.</p>
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
<p>Sometimes the minimum or maximum of several values needs to be found
|
||||
for later compile-time processing, <i>e.g.</i> for a bound for another
|
||||
class template.</p>
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
<p>The author of the Boost compile-time extrema class templates is <a
|
||||
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised October 12, 2001</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +1,17 @@
|
||||
// boost cstdint.hpp header file ------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// (C) Copyright Beman Dawes 1999.
|
||||
// (C) Copyright Jens Mauer 2001
|
||||
// (C) Copyright John Maddock 2001
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
|
||||
// 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
|
||||
// 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
|
||||
// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
|
||||
// 23 Sep 00 Added INTXX_C macro support (John Maddock).
|
||||
@ -23,9 +26,61 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
|
||||
# include <stdint.h> // implementation artifact; not part of interface
|
||||
// The following #include is an implementation artifact; not part of interface.
|
||||
# ifdef __hpux
|
||||
// HP-UX has a vaguely nice <stdint.h> in a non-standard location
|
||||
# include <inttypes.h>
|
||||
# ifdef __STDC_32_MODE__
|
||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||
# define BOOST_NO_INT64_T
|
||||
# endif
|
||||
# elif defined(__FreeBSD__) || defined(__IBMCPP__)
|
||||
# include <inttypes.h>
|
||||
# else
|
||||
# include <stdint.h>
|
||||
|
||||
// There is a bug in Cygwin two _C macros
|
||||
# if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
|
||||
# undef INTMAX_C
|
||||
# undef UINTMAX_C
|
||||
# define INTMAX_C(c) c##LL
|
||||
# define UINTMAX_C(c) c##ULL
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#ifdef __QNX__
|
||||
|
||||
// QNX (Dinkumware stdlib) defines these as non-standard names.
|
||||
// Reflect to the standard names.
|
||||
|
||||
typedef ::intleast8_t int_least8_t;
|
||||
typedef ::intfast8_t int_fast8_t;
|
||||
typedef ::uintleast8_t uint_least8_t;
|
||||
typedef ::uintfast8_t uint_fast8_t;
|
||||
|
||||
typedef ::intleast16_t int_least16_t;
|
||||
typedef ::intfast16_t int_fast16_t;
|
||||
typedef ::uintleast16_t uint_least16_t;
|
||||
typedef ::uintfast16_t uint_fast16_t;
|
||||
|
||||
typedef ::intleast32_t int_least32_t;
|
||||
typedef ::intfast32_t int_fast32_t;
|
||||
typedef ::uintleast32_t uint_least32_t;
|
||||
typedef ::uintfast32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
typedef ::intleast64_t int_least64_t;
|
||||
typedef ::intfast64_t int_fast64_t;
|
||||
typedef ::uintleast64_t uint_least64_t;
|
||||
typedef ::uintfast64_t uint_fast64_t;
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -67,11 +122,58 @@ namespace boost
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__)
|
||||
// FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
|
||||
# include <inttypes.h>
|
||||
|
||||
#else // BOOST_SYSTEM_HAS_STDINT_H
|
||||
namespace boost {
|
||||
|
||||
using ::int8_t;
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int8_t int_fast8_t;
|
||||
using ::uint8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
|
||||
using ::int16_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
using ::uint16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
|
||||
using ::int32_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
using ::uint32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
using ::int64_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
using ::uint64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
# else
|
||||
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
# include <boost/limits.hpp> // implementation artifact; not part of interface
|
||||
# include <limits.h> // needed for limits macros
|
||||
|
||||
|
||||
namespace boost
|
||||
@ -101,12 +203,29 @@ namespace boost
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
# if defined(__crayx1)
|
||||
// The Cray X1 has a 16-bit short, however it is not recommend
|
||||
// for use in performance critical code.
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
# else
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# endif
|
||||
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
|
||||
// no 16-bit types on Cray:
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
@ -133,20 +252,27 @@ namespace boost
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U)
|
||||
# if defined(BOOST_HAS_LONG_LONG) && \
|
||||
!defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
|
||||
(!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
typedef ::boost::long_long_type intmax_t;
|
||||
typedef ::boost::ulong_long_type uintmax_t;
|
||||
typedef ::boost::long_long_type int64_t;
|
||||
typedef ::boost::long_long_type int_least64_t;
|
||||
typedef ::boost::long_long_type int_fast64_t;
|
||||
typedef ::boost::ulong_long_type uint64_t;
|
||||
typedef ::boost::ulong_long_type uint_least64_t;
|
||||
typedef ::boost::ulong_long_type uint_fast64_t;
|
||||
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
@ -161,9 +287,18 @@ namespace boost
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
# elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
|
||||
__extension__ typedef long long intmax_t;
|
||||
__extension__ typedef unsigned long long uintmax_t;
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef long long int_least64_t;
|
||||
__extension__ typedef long long int_fast64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
__extension__ typedef unsigned long long uint_least64_t;
|
||||
__extension__ typedef unsigned long long uint_fast64_t;
|
||||
# elif defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
// we have Borland/Intel/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
@ -182,7 +317,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#endif // BOOST_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
@ -197,15 +332,17 @@ __STDC_CONSTANT_MACROS is defined.
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
Added 23rd September 2000 (John Maddock).
|
||||
Modified 11th September 2001 to be excluded when
|
||||
BOOST_HAS_STDINT_H is defined (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
|
||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
# if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
# if defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
// Borland/Intel/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
# define INT8_C(value) value##i8
|
||||
# define INT16_C(value) value##i16
|
||||
@ -252,14 +389,20 @@ Added 23rd September (John Maddock).
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# if defined(BOOST_HAS_LONG_LONG) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
@ -281,7 +424,7 @@ Added 23rd September (John Maddock).
|
||||
# endif // Borland/Microsoft specific width suffixes
|
||||
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
@ -298,3 +441,6 @@ Added 23rd September (John Maddock).
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||
|
||||
|
||||
|
||||
|
||||
|
177
include/boost/detail/extended_integer.hpp
Normal file
177
include/boost/detail/extended_integer.hpp
Normal file
@ -0,0 +1,177 @@
|
||||
// Boost detail/extended_integer.hpp header file ----------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2008. Distributed under the Boost Software
|
||||
// License, Version 1.0. (See the accompanying file LICENSE_1_0.txt or a copy
|
||||
// at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
// Encapsulates the double-long and __int64 type families as a single family,
|
||||
// as they are mutually exclusive.
|
||||
|
||||
/** \file
|
||||
\brief Common definition of extended integer types.
|
||||
|
||||
Instead of other Boost headers making separate \#defines for the double-long
|
||||
and __int64 type families, since they're mutually exclusive, make a single
|
||||
set of types and macros for the family that exists (if either).
|
||||
*/
|
||||
|
||||
#ifndef BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
||||
#define BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64
|
||||
|
||||
#include <climits> // for CHAR_BIT, etc.
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
// Extended integer type macro and alias definitions -----------------------//
|
||||
|
||||
// (Unsigned) long long family
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
|
||||
// Existence
|
||||
#define BOOST_HAS_XINT 1
|
||||
|
||||
// Extents
|
||||
#ifdef ULLONG_MAX
|
||||
#define BOOST_XINT_MAX LLONG_MAX
|
||||
#define BOOST_XINT_MIN LLONG_MIN
|
||||
#define BOOST_UXINT_MAX ULLONG_MAX
|
||||
#elif defined(ULONG_LONG_MAX)
|
||||
#define BOOST_XINT_MAX LONG_LONG_MAX
|
||||
#define BOOST_XINT_MIN LONG_LONG_MIN
|
||||
#define BOOST_UXINT_MAX ULONG_LONG_MAX
|
||||
#elif defined(ULONGLONG_MAX)
|
||||
#define BOOST_XINT_MAX LONGLONG_MAX
|
||||
#define BOOST_XINT_MIN LONGLONG_MIN
|
||||
#define BOOST_UXINT_MAX ULONGLONG_MAX
|
||||
#elif defined(_LLONG_MAX) && defined(_C2)
|
||||
#define BOOST_XINT_MAX _LLONG_MAX
|
||||
#define BOOST_XINT_MIN (-_LLONG_MAX - _C2)
|
||||
#define BOOST_UXINT_MAX _ULLONG_MAX
|
||||
#else // guess
|
||||
// Sometimes we get the double-long types without the corresponding constants,
|
||||
// e.g. GCC in "-ansi" mode. In this case, we'll just have to work out the
|
||||
// values ourselves. (Here we assume a two's complement representation.)
|
||||
#define BOOST_XINT_MIN (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))
|
||||
#define BOOST_XINT_MAX (~ BOOST_XINT_MIN)
|
||||
#define BOOST_UXINT_MAX (~ 0uLL)
|
||||
#endif
|
||||
|
||||
// Types
|
||||
typedef ::boost:: long_long_type xint_t;
|
||||
typedef ::boost::ulong_long_type uxint_t;
|
||||
|
||||
// (Unsigned) __int64 family
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
|
||||
// Existence
|
||||
#define BOOST_HAS_XINT 1
|
||||
|
||||
// Extents
|
||||
#ifdef _UI64_MAX
|
||||
#define BOOST_XINT_MAX _I64_MAX
|
||||
#define BOOST_XINT_MIN _I64_MIN
|
||||
#define BOOST_UXINT_MAX _UI64_MAX
|
||||
#else // guess
|
||||
// The types are exactly 2's-compl. 64-bit, so we'll enter the values directly.
|
||||
#define BOOST_XINT_MAX 0x7FFFFFFFFFFFFFFFi64
|
||||
#define BOOST_XINT_MIN 0x8000000000000000i64
|
||||
#define BOOST_UXINT_MAX 0xFFFFFFFFFFFFFFFFui64
|
||||
#endif
|
||||
|
||||
// Types
|
||||
typedef __int64 xint_t;
|
||||
typedef unsigned __int64 uxint_t;
|
||||
|
||||
// Neither
|
||||
#else
|
||||
|
||||
// Non-existence
|
||||
#define BOOST_HAS_XINT 0
|
||||
|
||||
// Dummy extents
|
||||
#define BOOST_XINT_MAX LONG_MAX
|
||||
#define BOOST_XINT_MIN LONG_MIN
|
||||
#define BOOST_UXINT_MAX ULONG_MAX
|
||||
|
||||
// Dummy types
|
||||
typedef signed long xint_t;
|
||||
typedef unsigned long uxint_t;
|
||||
|
||||
#endif // defined(BOOST_HAS_LONG_LONG)/defined(BOOST_HAS_MS_INT64)/else
|
||||
|
||||
/** \def BOOST_HAS_XINT
|
||||
|
||||
\brief Flag for extended integer types.
|
||||
|
||||
Indicates the presence of one of the two common extended integer type
|
||||
families, either (<code>unsigned</code>) <code>long long</code> or
|
||||
(<code>unsigned</code>) <code>__int64</code>. \c BOOST_HAS_XINT is \c 1 if
|
||||
either type family is defined, and \c 0 if neither is.
|
||||
*/
|
||||
|
||||
/** \def BOOST_XINT_MAX
|
||||
|
||||
\brief Maximum value for the signed extended integer type.
|
||||
|
||||
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||
|
||||
Macro constant representing the largest value the signed extended integer
|
||||
type supports. Its composition may be another macro, an expression, or a
|
||||
literal. Defaulted to \c LONG_MAX if \c BOOST_HAS_XINT is zero.
|
||||
*/
|
||||
/** \def BOOST_XINT_MIN
|
||||
|
||||
\brief Minimum value for the signed extended integer type.
|
||||
|
||||
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||
|
||||
Macro constant representing the smallest value the signed extended integer
|
||||
type supports. Its composition may be another macro, an expression, or a
|
||||
literal. Defaulted to \c LONG_MIN if \c BOOST_HAS_XINT is zero.
|
||||
*/
|
||||
/** \def BOOST_UXINT_MAX
|
||||
|
||||
\brief Maximum value for the unsigned extended integer type.
|
||||
|
||||
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||
|
||||
Macro constant representing the largest value the unsigned extended integer
|
||||
type supports. Its composition may be another macro, an expression, or a
|
||||
literal. Defaulted to \c ULONG_MAX if \c BOOST_HAS_XINT is zero. (Use
|
||||
\c 0u for the type's minimum value.)
|
||||
*/
|
||||
|
||||
/** \typedef signed long boost::detail::xint_t
|
||||
|
||||
\brief Alias for the signed extended integer type.
|
||||
|
||||
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||
|
||||
Alias representing the signed extended integer type, no matter which type
|
||||
family it came from. Defaulted to <code>signed long</code> if
|
||||
\c BOOST_HAS_XINT is zero.
|
||||
*/
|
||||
/** \typedef unsigned long ::boost::detail::uxint_t
|
||||
|
||||
\brief Alias for the signed extended integer type.
|
||||
|
||||
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||
|
||||
Alias representing the unsigned extended integer type, no matter which type
|
||||
family it came from. Defaulted to <code>unsigned long</code> if
|
||||
\c BOOST_HAS_XINT is zero.
|
||||
*/
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
@ -1,84 +1,382 @@
|
||||
// boost integer.hpp header file -------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// Copyright Beman Dawes and Daryle Walker 1999. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
|
||||
// based integer templates. (Daryle Walker)
|
||||
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
|
||||
// processor-optimized integer template. (Daryle Walker)
|
||||
// 14 Jul 08 Added extended-integer support. (Daryle Walker)
|
||||
// 13 Jul 08 Redid implmentation. (Daryle Walker)
|
||||
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 28 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_INTEGER_HPP
|
||||
#define BOOST_INTEGER_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
|
||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/utility/enable_if.hpp> // for boost::enable_if_c
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
|
||||
|
||||
#include <climits> // for UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, etc.
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// Helper templates ------------------------------------------------------//
|
||||
// integer template mapping a type to its processor-optimized analog -----//
|
||||
|
||||
// Some types can be handled better by the processor than others. This
|
||||
// template metafunction should map various built-in integral types to
|
||||
// the processor's perferred type for the given type's value range
|
||||
template < typename BaseInt >
|
||||
struct fast_integral
|
||||
{
|
||||
typedef BaseInt type;
|
||||
};
|
||||
|
||||
// Platform-specific specializations should go here.
|
||||
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
|
||||
struct int_fast_t { typedef typename fast_integral<LeastInt>::type fast; };
|
||||
|
||||
// convert category to type
|
||||
template< int Category > struct int_least_helper {}; // default is empty
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
|
||||
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
|
||||
// no specializations for 0 and 5: requests for a type > long are in error
|
||||
template<> struct int_least_helper<1> { typedef long least; };
|
||||
template<> struct int_least_helper<2> { typedef int least; };
|
||||
template<> struct int_least_helper<3> { typedef short least; };
|
||||
template<> struct int_least_helper<4> { typedef signed char least; };
|
||||
template<> struct int_least_helper<6> { typedef unsigned long least; };
|
||||
template<> struct int_least_helper<7> { typedef unsigned int least; };
|
||||
template<> struct int_least_helper<8> { typedef unsigned short least; };
|
||||
template<> struct int_least_helper<9> { typedef unsigned char least; };
|
||||
// Helper templates ------------------------------------------------------//
|
||||
|
||||
// convert integer category to type ; default is empty
|
||||
template< int Rank, typename Signedness > struct int_least_helper {};
|
||||
|
||||
// specializatons: 1=(unsigned) __int64/long long, 2=(unsigned) long,
|
||||
// 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char
|
||||
// no specializations for 0: requests for a type > (unsigned) (long) long are
|
||||
// in error
|
||||
#if BOOST_HAS_XINT
|
||||
template<> struct int_least_helper<1, signed> { typedef xint_t least; };
|
||||
template<> struct int_least_helper<1, unsigned> { typedef uxint_t least; };
|
||||
#endif
|
||||
template<> struct int_least_helper<2, signed> { typedef long least; };
|
||||
template<> struct int_least_helper<2, unsigned>
|
||||
{ typedef unsigned long least; };
|
||||
template<> struct int_least_helper<3, signed> { typedef int least; };
|
||||
template<> struct int_least_helper<3, unsigned>
|
||||
{ typedef unsigned int least; };
|
||||
template<> struct int_least_helper<4, signed> { typedef short least; };
|
||||
template<> struct int_least_helper<4, unsigned>
|
||||
{ typedef unsigned short least; };
|
||||
template<> struct int_least_helper<5, signed> { typedef signed char least; };
|
||||
template<> struct int_least_helper<5, unsigned>
|
||||
{ typedef unsigned char least; };
|
||||
|
||||
// category bounds
|
||||
enum
|
||||
{
|
||||
#if BOOST_HAS_XINT
|
||||
lowest_integral_rank = 1,
|
||||
#else
|
||||
lowest_integral_rank = 2,
|
||||
#endif
|
||||
highest_integral_rank = 5
|
||||
};
|
||||
|
||||
// map a bit count to a category
|
||||
template < int BitsIncludingSign >
|
||||
struct int_rank_helper
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 );
|
||||
#if BOOST_HAS_XINT
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits<
|
||||
xint_t >::digits) );
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * (extended_ +
|
||||
(mantissa <= std::numeric_limits< long >::digits) +
|
||||
(mantissa <= std::numeric_limits< int >::digits) +
|
||||
(mantissa <= std::numeric_limits< short >::digits) +
|
||||
(mantissa <= std::numeric_limits< signed char >::digits)) );
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct uint_rank_helper
|
||||
{
|
||||
#if BOOST_HAS_XINT
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits<
|
||||
uxint_t >::digits) );
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * (extended_ +
|
||||
(Bits <= std::numeric_limits< unsigned long >::digits) +
|
||||
(Bits <= std::numeric_limits< unsigned int >::digits) +
|
||||
(Bits <= std::numeric_limits< unsigned short >::digits) +
|
||||
(Bits <= std::numeric_limits< unsigned char >::digits)) );
|
||||
};
|
||||
|
||||
template < int BitsIncludingSign >
|
||||
struct int_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
|
||||
template < int Bits >
|
||||
struct uint_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
|
||||
|
||||
#define BOOST_PRIVATE_INT_EXACT_BUILDER(Type, Rank) \
|
||||
template < > \
|
||||
struct int_exact_rank_helper<std::numeric_limits< Type >::digits + 1> \
|
||||
{ BOOST_STATIC_CONSTANT( int, rank = Rank ); }
|
||||
#define BOOST_PRIVATE_UINT_EXACT_BUILDER(Type, Rank) \
|
||||
template < > \
|
||||
struct uint_exact_rank_helper<std::numeric_limits< Type >::digits> \
|
||||
{ BOOST_STATIC_CONSTANT( int, rank = Rank ); }
|
||||
|
||||
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
|
||||
BOOST_PRIVATE_INT_EXACT_BUILDER( xint_t, 1 );
|
||||
BOOST_PRIVATE_UINT_EXACT_BUILDER( uxint_t, 1 );
|
||||
#endif
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
BOOST_PRIVATE_INT_EXACT_BUILDER( long, 2 );
|
||||
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned long, 2 );
|
||||
#endif
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
BOOST_PRIVATE_INT_EXACT_BUILDER( int, 3 );
|
||||
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned, 3 );
|
||||
#endif
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
BOOST_PRIVATE_INT_EXACT_BUILDER( short, 4 );
|
||||
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned short, 4 );
|
||||
#endif
|
||||
BOOST_PRIVATE_INT_EXACT_BUILDER( signed char, 5 );
|
||||
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned char, 5 );
|
||||
|
||||
#undef BOOST_PRIVATE_INT_EXACT_BUILDER
|
||||
#undef BOOST_PRIVATE_UINT_EXACT_BUILDER
|
||||
|
||||
// map an extreme value to a category
|
||||
template < intmax_t MaxValue >
|
||||
struct int_max_rank_helper
|
||||
{
|
||||
#if BOOST_HAS_XINT
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <=
|
||||
boost::integer_traits< xint_t >::const_max) );
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ +
|
||||
(MaxValue <= boost::integer_traits< long >::const_max) +
|
||||
(MaxValue <= boost::integer_traits< int >::const_max) +
|
||||
(MaxValue <= boost::integer_traits< short >::const_max) +
|
||||
(MaxValue <= boost::integer_traits< signed char >::const_max)) );
|
||||
};
|
||||
|
||||
template < intmax_t MinValue >
|
||||
struct int_min_rank_helper
|
||||
{
|
||||
#if BOOST_HAS_XINT
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >=
|
||||
boost::integer_traits< xint_t >::const_min) );
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ +
|
||||
(MinValue >= boost::integer_traits< long >::const_min) +
|
||||
(MinValue >= boost::integer_traits< int >::const_min) +
|
||||
(MinValue >= boost::integer_traits< short >::const_min) +
|
||||
(MinValue >= boost::integer_traits< signed char >::const_min)) );
|
||||
};
|
||||
|
||||
template < uintmax_t Value >
|
||||
struct uint_max_rank_helper
|
||||
{
|
||||
#if BOOST_HAS_XINT
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits<
|
||||
uxint_t >::const_max) );
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT( int, rank = extended_ +
|
||||
(Value <= boost::integer_traits< unsigned long >::const_max) +
|
||||
(Value <= boost::integer_traits< unsigned int >::const_max) +
|
||||
(Value <= boost::integer_traits< unsigned short >::const_max) +
|
||||
(Value <= boost::integer_traits< unsigned char >::const_max) );
|
||||
};
|
||||
|
||||
// convert rank to type, Boost.MPL-style
|
||||
template < int Rank, typename Signedness, class Enable = void >
|
||||
struct integral_rank_to_type
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
|
||||
// No "signed" nor "type" here
|
||||
};
|
||||
|
||||
template < int Rank >
|
||||
struct integral_rank_to_type< Rank, signed, typename
|
||||
enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
|
||||
highest_integral_rank)>::type >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
|
||||
BOOST_STATIC_CONSTANT( bool, is_signed = true );
|
||||
typedef typename int_least_helper< Rank, signed >::least type;
|
||||
};
|
||||
|
||||
template < int Rank >
|
||||
struct integral_rank_to_type< Rank, unsigned, typename
|
||||
enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
|
||||
highest_integral_rank)>::type >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
|
||||
BOOST_STATIC_CONSTANT( bool, is_signed = false );
|
||||
typedef typename int_least_helper< Rank, unsigned >::least type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// MPL-compatible integer-mapping class templates ------------------------//
|
||||
|
||||
// minimum number of bits
|
||||
template < int Bits, typename Signedness >
|
||||
struct sized_integral
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
|
||||
};
|
||||
|
||||
template < int BitsIncludingSign >
|
||||
struct sized_integral< BitsIncludingSign, signed >
|
||||
: detail::integral_rank_to_type<
|
||||
detail::int_rank_helper<BitsIncludingSign>::rank, signed >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign );
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct sized_integral< Bits, unsigned >
|
||||
: detail::integral_rank_to_type<
|
||||
detail::uint_rank_helper<Bits>::rank, unsigned >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
|
||||
};
|
||||
|
||||
// exact number of bits
|
||||
template < int Bits, typename Signedness >
|
||||
struct exact_integral
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
|
||||
};
|
||||
|
||||
template < int BitsIncludingSign >
|
||||
struct exact_integral< BitsIncludingSign, signed >
|
||||
: detail::integral_rank_to_type<
|
||||
detail::int_exact_rank_helper<BitsIncludingSign>::rank, signed >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign );
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct exact_integral< Bits, unsigned >
|
||||
: detail::integral_rank_to_type<
|
||||
detail::uint_exact_rank_helper<Bits>::rank, unsigned >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
|
||||
};
|
||||
|
||||
// maximum supported (positive) value, signed
|
||||
template < intmax_t MaxValue >
|
||||
struct maximum_signed_integral
|
||||
: detail::integral_rank_to_type<
|
||||
detail::int_max_rank_helper<MaxValue>::rank, signed >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( intmax_t, bound = MaxValue );
|
||||
};
|
||||
|
||||
// minimum supported (negative) value
|
||||
template < intmax_t MinValue >
|
||||
struct minimum_signed_integral
|
||||
: detail::integral_rank_to_type<
|
||||
detail::int_min_rank_helper<MinValue>::rank, signed >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( intmax_t, bound = MinValue );
|
||||
};
|
||||
|
||||
// maximum supported (nonnegative) value, unsigned
|
||||
template < uintmax_t Value >
|
||||
struct maximum_unsigned_integral
|
||||
: detail::integral_rank_to_type<
|
||||
detail::uint_max_rank_helper<Value>::rank, unsigned >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( uintmax_t, bound = Value );
|
||||
};
|
||||
|
||||
// integer templates specifying number of bits ---------------------------//
|
||||
|
||||
// signed
|
||||
template< int Bits > // bits (including sign) required
|
||||
template< int Bits > // minimum bits (including sign) required
|
||||
struct int_t
|
||||
{
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
(Bits-1 <= std::numeric_limits<long>::digits) +
|
||||
(Bits-1 <= std::numeric_limits<int>::digits) +
|
||||
(Bits-1 <= std::numeric_limits<short>::digits) +
|
||||
(Bits-1 <= std::numeric_limits<signed char>::digits)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
typedef typename sized_integral<Bits, signed>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< int Bits > // exact bits (including sign) desired
|
||||
struct int_exact_t
|
||||
{
|
||||
typedef typename exact_integral<Bits, signed>::type exact;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // bits required
|
||||
template< int Bits > // minimum bits required
|
||||
struct uint_t
|
||||
{
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
5 +
|
||||
(Bits <= std::numeric_limits<unsigned long>::digits) +
|
||||
(Bits <= std::numeric_limits<unsigned int>::digits) +
|
||||
(Bits <= std::numeric_limits<unsigned short>::digits) +
|
||||
(Bits <= std::numeric_limits<unsigned char>::digits)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
typedef typename sized_integral<Bits, unsigned>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
};
|
||||
|
||||
// The same dispatching technique can be used to select types based on
|
||||
// values. That will be added once boost::integer_traits is available.
|
||||
template< int Bits > // exact bits desired
|
||||
struct uint_exact_t
|
||||
{
|
||||
typedef typename exact_integral<Bits, unsigned>::type exact;
|
||||
};
|
||||
|
||||
// integer templates specifying extreme value ----------------------------//
|
||||
|
||||
// signed
|
||||
template< intmax_t MaxValue > // maximum value to require support
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef typename maximum_signed_integral<MaxValue>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< intmax_t MinValue > // minimum value to require support
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef typename minimum_signed_integral<MinValue>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< uintmax_t Value > // maximum value to require support
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef typename maximum_unsigned_integral<Value>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INTEGER_HPP
|
||||
|
||||
|
204
include/boost/integer/integer_mask.hpp
Normal file
204
include/boost/integer/integer_mask.hpp
Normal file
@ -0,0 +1,204 @@
|
||||
// Boost integer/integer_mask.hpp header file ------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
#define BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t
|
||||
#include <boost/integer.hpp> // for boost::sized_integral
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/mpl/and.hpp> // for boost::mpl::and_
|
||||
#include <boost/mpl/bitwise.hpp> // for boost::mpl::bitor_, shift_left
|
||||
#include <boost/mpl/bool.hpp> // for boost::mpl::true_
|
||||
#include <boost/mpl/comparison.hpp> // for boost::mpl::greater_equal, etc.
|
||||
#include <boost/mpl/empty_base.hpp> // for boost::mpl::empty_base
|
||||
#include <boost/mpl/if.hpp> // for boost::mpl::if_
|
||||
#include <boost/mpl/int.hpp> // for boost::mpl::int_
|
||||
#include <boost/mpl/integral_c.hpp> // for boost::integral_c
|
||||
#include <boost/mpl/next_prior.hpp> // for boost::mpl::next, prior
|
||||
#include <boost/utility/enable_if.hpp> // for boost::enable_if
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Helper templates --------------------------------------------------------//
|
||||
|
||||
template < int Bits >
|
||||
struct hi_integer_mask_builder1
|
||||
{
|
||||
typedef boost::mpl::int_<Bits> bit_count_type;
|
||||
|
||||
typedef typename boost::mpl::next<bit_count_type>::type
|
||||
mask_length_type;
|
||||
typedef boost::sized_integral<mask_length_type::value, unsigned>
|
||||
mask_type;
|
||||
|
||||
typedef boost::mpl::integral_c<typename mask_type::type, 1> one_type;
|
||||
typedef boost::mpl::shift_left<one_type, bit_count_type> result_type;
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct hi_integer_mask_builder2
|
||||
{
|
||||
typedef boost::mpl::int_<Bits> bit_count_type;
|
||||
|
||||
typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
|
||||
lo_bound_type;
|
||||
typedef boost::mpl::less< bit_count_type,
|
||||
boost::mpl::int_<std::numeric_limits<boost::uintmax_t>::digits> >
|
||||
hi_bound_type;
|
||||
typedef boost::mpl::and_<lo_bound_type, hi_bound_type> count_valid_type;
|
||||
};
|
||||
|
||||
template < int Bits, class Enable = void >
|
||||
struct hi_integer_mask_builder3
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct hi_integer_mask_builder3< Bits, typename boost::enable_if<typename
|
||||
hi_integer_mask_builder2<Bits>::count_valid_type>::type >
|
||||
: hi_integer_mask_builder1<Bits>::result_type
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct lo_integer_mask_builder1
|
||||
{
|
||||
typedef boost::mpl::int_<Bits> bit_count_type;
|
||||
|
||||
typedef typename boost::mpl::prior<bit_count_type>::type
|
||||
shift_length_type;
|
||||
typedef boost::sized_integral<bit_count_type::value, unsigned>
|
||||
mask_type;
|
||||
|
||||
typedef boost::mpl::integral_c<typename mask_type::type, 1> one_type;
|
||||
typedef boost::mpl::shift_left<one_type, shift_length_type>
|
||||
high_bit_type;
|
||||
typedef typename boost::mpl::prior<high_bit_type>::type low_bits_type;
|
||||
typedef boost::mpl::bitor_<high_bit_type, low_bits_type> result_type;
|
||||
};
|
||||
|
||||
template < >
|
||||
struct lo_integer_mask_builder1< 0 >
|
||||
{
|
||||
// Let's not deal with negative interim values....
|
||||
typedef boost::mpl::integral_c<unsigned char, 0u> result_type;
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct lo_integer_mask_builder2
|
||||
{
|
||||
typedef boost::mpl::int_<Bits> bit_count_type;
|
||||
|
||||
typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
|
||||
lo_bound_type;
|
||||
typedef boost::mpl::less_equal< bit_count_type,
|
||||
boost::mpl::int_<std::numeric_limits<boost::uintmax_t>::digits> >
|
||||
hi_bound_type;
|
||||
typedef boost::mpl::and_<lo_bound_type, hi_bound_type> count_valid_type;
|
||||
};
|
||||
|
||||
template < >
|
||||
struct lo_integer_mask_builder2< 0 >
|
||||
{
|
||||
typedef boost::mpl::true_ count_valid_type;
|
||||
};
|
||||
|
||||
template < int Bits, class Enable = void >
|
||||
struct lo_integer_mask_builder3
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
|
||||
// No MPL Integral Constant to inherit from
|
||||
};
|
||||
|
||||
template < int Bits >
|
||||
struct lo_integer_mask_builder3< Bits, typename enable_if<typename
|
||||
lo_integer_mask_builder2<Bits>::count_valid_type>::type >
|
||||
: lo_integer_mask_builder1<Bits>::result_type
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
// MPL-compatible integer mask class templates -----------------------------//
|
||||
|
||||
// Displaced single-bit mask, 1 << Offset, 0 <= Offset < BitLengthOf(uintmax_t)
|
||||
template < int Offset >
|
||||
struct integer_hi_mask
|
||||
: detail::hi_integer_mask_builder3<Offset>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_offset = Offset );
|
||||
};
|
||||
|
||||
// Lowest bit-group mask, 2**Length - 1, 0 <= Length <= BitLengthOf(uintmax_t)
|
||||
template < int Length >
|
||||
struct integer_lo_mask
|
||||
: detail::lo_integer_mask_builder3<Length>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( int, bit_count = Length );
|
||||
};
|
||||
|
||||
|
||||
// Specified single-bit mask class declaration -----------------------------//
|
||||
// (Lowest bit starts counting at 0.)
|
||||
|
||||
template < std::size_t Bit >
|
||||
class high_bit_mask_t
|
||||
{
|
||||
typedef integer_hi_mask<Bit> impl_type;
|
||||
|
||||
public:
|
||||
typedef typename impl_type::value_type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
|
||||
BOOST_STATIC_CONSTANT( least, high_bit = impl_type::value );
|
||||
BOOST_STATIC_CONSTANT( fast, high_bit_fast = impl_type::value );
|
||||
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_position = impl_type::bit_offset );
|
||||
|
||||
}; // boost::high_bit_mask_t
|
||||
|
||||
|
||||
// Specified bit-block mask class declaration ------------------------------//
|
||||
// Makes masks for the lowest N bits
|
||||
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t
|
||||
{
|
||||
typedef integer_lo_mask<Bits> impl_type;
|
||||
|
||||
public:
|
||||
typedef typename impl_type::value_type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = impl_type::value );
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = impl_type::value );
|
||||
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = impl_type::bit_count );
|
||||
|
||||
}; // boost::low_bits_mask_t
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_INTEGER_MASK_HPP
|
132
include/boost/integer/static_log2.hpp
Normal file
132
include/boost/integer/static_log2.hpp
Normal file
@ -0,0 +1,132 @@
|
||||
// -------------- Boost static_log2.hpp header file ----------------------- //
|
||||
//
|
||||
// Copyright (C) 2001 Daryle Walker.
|
||||
// Copyright (C) 2003 Vesa Karvonen.
|
||||
// Copyright (C) 2003 Gennaro Prota.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// ---------------------------------------------------
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
|
||||
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace static_log2_impl {
|
||||
|
||||
// choose_initial_n<>
|
||||
//
|
||||
// Recursively doubles its integer argument, until it
|
||||
// becomes >= of the "width" (C99, 6.2.6.2p4) of
|
||||
// static_log2_argument_type.
|
||||
//
|
||||
// Used to get the maximum power of two less then the width.
|
||||
//
|
||||
// Example: if on your platform argument_type has 48 value
|
||||
// bits it yields n=32.
|
||||
//
|
||||
// It's easy to prove that, starting from such a value
|
||||
// of n, the core algorithm works correctly for any width
|
||||
// of static_log2_argument_type and that recursion always
|
||||
// terminates with x = 1 and n = 0 (see the algorithm's
|
||||
// invariant).
|
||||
|
||||
typedef unsigned long argument_type;
|
||||
typedef int result_type;
|
||||
|
||||
|
||||
template <result_type n>
|
||||
struct choose_initial_n {
|
||||
|
||||
enum { c = (argument_type(1) << n << n) != 0 };
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = !c*n + choose_initial_n<2*c*n>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct choose_initial_n<0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// start computing from n_zero - must be a power of two
|
||||
const result_type n_zero = 16;
|
||||
const result_type initial_n = choose_initial_n<n_zero>::value;
|
||||
|
||||
// static_log2_impl<>
|
||||
//
|
||||
// * Invariant:
|
||||
// 2n
|
||||
// 1 <= x && x < 2 at the start of each recursion
|
||||
// (see also choose_initial_n<>)
|
||||
//
|
||||
// * Type requirements:
|
||||
//
|
||||
// argument_type maybe any unsigned type with at least n_zero + 1
|
||||
// value bits. (Note: If larger types will be standardized -e.g.
|
||||
// unsigned long long- then the argument_type typedef can be
|
||||
// changed without affecting the rest of the code.)
|
||||
//
|
||||
|
||||
template <argument_type x, result_type n = initial_n>
|
||||
struct static_log2_impl {
|
||||
|
||||
enum { c = (x >> n) > 0 }; // x >= 2**n ?
|
||||
BOOST_STATIC_CONSTANT(
|
||||
result_type,
|
||||
value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct static_log2_impl<1, 0> {
|
||||
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||
};
|
||||
|
||||
}
|
||||
} // detail
|
||||
|
||||
|
||||
|
||||
// --------------------------------------
|
||||
// static_log2<x>
|
||||
// ----------------------------------------
|
||||
|
||||
typedef detail::static_log2_impl::argument_type static_log2_argument_type;
|
||||
typedef detail::static_log2_impl::result_type static_log2_result_type;
|
||||
|
||||
|
||||
template <static_log2_argument_type x>
|
||||
struct static_log2 {
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
static_log2_result_type,
|
||||
value = detail::static_log2_impl::static_log2_impl<x>::value
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct static_log2<0> { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // include guard
|
55
include/boost/integer/static_min_max.hpp
Normal file
55
include/boost/integer/static_min_max.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
// Boost integer/static_min_max.hpp header file ----------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
#define BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// Compile-time extrema class declarations ---------------------------------//
|
||||
// Get the minimum or maximum of two values, signed or unsigned.
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
= (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
= (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
172
include/boost/integer_fwd.hpp
Normal file
172
include/boost/integer_fwd.hpp
Normal file
@ -0,0 +1,172 @@
|
||||
// Boost integer_fwd.hpp header file ---------------------------------------//
|
||||
|
||||
// (C) Copyright Dave Abrahams and Daryle Walker 2001. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
#ifndef BOOST_INTEGER_FWD_HPP
|
||||
#define BOOST_INTEGER_FWD_HPP
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T, etc.
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// From <boost/cstdint.hpp> ------------------------------------------------//
|
||||
|
||||
// Only has typedefs or using statements, with #conditionals
|
||||
|
||||
// ALERT: the forward declarations of items in <boost/integer.hpp> need items
|
||||
// from this header. That means that <boost/cstdint.hpp> cannot #include this
|
||||
// forwarding header, to avoid infinite recursion! One day, maybe
|
||||
// boost::uintmax_t and boost::intmax_t could be segregated into their own
|
||||
// header file (which can't #include this header), <boost/integer.hpp> will use
|
||||
// that header, and <boost/cstdint.hpp> could refer to <boost/integer.hpp>.
|
||||
|
||||
|
||||
// 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 >;
|
||||
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
|
||||
template < >
|
||||
class integer_traits< ::boost::detail::xint_t >;
|
||||
|
||||
template < >
|
||||
class integer_traits< ::boost::detail::uxint_t >;
|
||||
#endif
|
||||
|
||||
|
||||
// From <boost/integer.hpp> ------------------------------------------------//
|
||||
|
||||
template < typename BaseInt >
|
||||
struct fast_integral;
|
||||
|
||||
template < typename LeastInt >
|
||||
struct int_fast_t;
|
||||
|
||||
template < int Bits, typename Signedness >
|
||||
struct sized_integral;
|
||||
|
||||
template < int Bits, typename Signedness >
|
||||
struct exact_integral;
|
||||
|
||||
template < intmax_t MaxValue >
|
||||
struct maximum_signed_integral;
|
||||
|
||||
template < intmax_t MinValue >
|
||||
struct minimum_signed_integral;
|
||||
|
||||
template < uintmax_t Value >
|
||||
struct maximum_unsigned_integral;
|
||||
|
||||
template< int Bits >
|
||||
struct int_t;
|
||||
|
||||
template< int Bits >
|
||||
struct int_exact_t;
|
||||
|
||||
template< int Bits >
|
||||
struct uint_t;
|
||||
|
||||
template< int Bits >
|
||||
struct uint_exact_t;
|
||||
|
||||
template< intmax_t MaxValue >
|
||||
struct int_max_value_t;
|
||||
|
||||
template< intmax_t MinValue >
|
||||
struct int_min_value_t;
|
||||
|
||||
template< uintmax_t Value >
|
||||
struct uint_value_t;
|
||||
|
||||
|
||||
// From <boost/integer/integer_mask.hpp> -----------------------------------//
|
||||
|
||||
template < int Offset >
|
||||
struct integer_hi_mask;
|
||||
|
||||
template < int Length >
|
||||
struct integer_lo_mask;
|
||||
|
||||
template < std::size_t Bit >
|
||||
class high_bit_mask_t;
|
||||
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t;
|
||||
|
||||
|
||||
// From <boost/integer/static_log2.hpp> ------------------------------------//
|
||||
|
||||
template < unsigned long Value >
|
||||
struct static_log2;
|
||||
|
||||
template < >
|
||||
struct static_log2< 0ul >;
|
||||
|
||||
|
||||
// From <boost/integer/static_min_max.hpp> ---------------------------------//
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min;
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max;
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_FWD_HPP
|
@ -1,28 +1,33 @@
|
||||
/* boost integer_traits.hpp header file
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
* Jens Maurer makes no representations about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
||||
*/
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||
#define BOOST_INTEGER_TRAITS_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
// This is an implementation detail and not part of the interface
|
||||
// These are an implementation detail and not part of the interface
|
||||
#include <limits.h>
|
||||
// we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
|
||||
// and some may have <wchar.h> but not <cwchar> ...
|
||||
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__))
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
|
||||
|
||||
|
||||
namespace boost {
|
||||
@ -30,11 +35,7 @@ template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = false;
|
||||
#else
|
||||
enum { is_integral = false };
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = false);
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@ -42,18 +43,23 @@ template<class T, T min_val, T max_val>
|
||||
class integer_traits_base
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = true;
|
||||
static const T const_min = min_val;
|
||||
static const T const_max = max_val;
|
||||
#else
|
||||
enum {
|
||||
is_integral = true,
|
||||
const_min = min_val,
|
||||
const_max = max_val
|
||||
};
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = true);
|
||||
BOOST_STATIC_CONSTANT(T, const_min = min_val);
|
||||
BOOST_STATIC_CONSTANT(T, const_max = max_val);
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
// A definition is required even for integral static constants
|
||||
template<class T, T min_val, T max_val>
|
||||
const bool integer_traits_base<T, min_val, max_val>::is_integral;
|
||||
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_min;
|
||||
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_max;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<>
|
||||
@ -80,7 +86,40 @@ class integer_traits<unsigned char>
|
||||
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
|
||||
{ };
|
||||
|
||||
// What about wchar_t ?
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template<>
|
||||
class integer_traits<wchar_t>
|
||||
: public std::numeric_limits<wchar_t>,
|
||||
// Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native
|
||||
// library: they are wrong!
|
||||
#if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
|
||||
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
||||
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
||||
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
||||
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
||||
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\
|
||||
|| (defined __APPLE__)\
|
||||
|| (defined(__OpenBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__NetBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__FreeBSD__) && defined(__GNUC__))\
|
||||
|| (defined(__DragonFly__) && defined(__GNUC__))\
|
||||
|| (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
||||
// - SGI MIPSpro with native library
|
||||
// - gcc 3.x on HP-UX
|
||||
// - Mac OS X with native library
|
||||
// - gcc on FreeBSD, OpenBSD and NetBSD
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
||||
// - gcc 2.95.x on HP-UX
|
||||
// (also, std::numeric_limits<wchar_t> appears to return the wrong values).
|
||||
public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
|
||||
#else
|
||||
#error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
|
||||
#endif
|
||||
{ };
|
||||
#endif // BOOST_NO_INTRINSIC_WCHAR_T
|
||||
|
||||
template<>
|
||||
class integer_traits<short>
|
||||
@ -118,30 +157,23 @@ class integer_traits<unsigned long>
|
||||
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
||||
{ };
|
||||
|
||||
#ifdef ULLONG_MAX
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX>
|
||||
class integer_traits< detail::xint_t >
|
||||
: public std::numeric_limits< detail::xint_t >,
|
||||
public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX >
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX>
|
||||
{ };
|
||||
#elif defined(ULONG_LONG_MAX)
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>
|
||||
{ };
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
|
||||
class integer_traits< detail::uxint_t >
|
||||
: public std::numeric_limits< detail::uxint_t >,
|
||||
public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX >
|
||||
{ };
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
||||
|
||||
|
@ -1,272 +0,0 @@
|
||||
// boost stdint.h header file ---------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// NOTE WELL: This is an implementation of the ISO C Standard (1999) stdint.h
|
||||
// header. C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// this header.
|
||||
|
||||
// NOTE OF OBSOLESCENCE: In general, this header file cannot detect
|
||||
// whether the current translation unit somewhere includes ISO C99
|
||||
// <stdint.h> or not. For example, in case BOOST_SYSTEM_HAS_STDINT_H
|
||||
// is not defined and ISO C99 <stdint.h> has been included before,
|
||||
// this file will re-define ISO C99 reserved file-scope identifiers
|
||||
// such as int8_t (see ISO C99 7.1.3 and 7.18). Defining the macro
|
||||
// BOOST_SYSTEM_HAS_STDINT_H is not sufficient in general, in
|
||||
// particular if a partly conformant <stdint.h> header is available
|
||||
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
|
||||
//
|
||||
// In order to avoid incompatibilities with ISO C99, this header
|
||||
// should not be used at all, and it may be deleted in the future.
|
||||
// C++ programs which require ISO C99 <stdint.h> functionality are
|
||||
// strongly advised to use <boost/cstdint.hpp> instead, which
|
||||
// provides <stdint.h> names in namespace boost, e.g. boost::int8_t.
|
||||
|
||||
|
||||
// Revision History
|
||||
// 12 Nov 00 obsoleted (Jens Maurer)
|
||||
// 23 Sep 00 INTXX_C support added (John Maddock)
|
||||
// 22 Sep 00 64-bit support for Borland & Microsoft compilers (John Maddock)
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
|
||||
#ifndef BOOST_STDINT_H
|
||||
#define BOOST_STDINT_H
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#include <stdint.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
typedef signed char int8_t;
|
||||
typedef signed char int_least8_t;
|
||||
typedef signed char int_fast8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
typedef int int32_t;
|
||||
typedef int int_least32_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
typedef long int32_t;
|
||||
typedef long int_least32_t;
|
||||
typedef long int_fast32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
typedef long int64_t;
|
||||
typedef long int_least64_t;
|
||||
typedef long int_fast64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
#define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Define various INTXX_C macros only if
|
||||
__STDC_CONSTANT_MACROS is defined.
|
||||
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
#define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
#define INT8_C(value) value##i8
|
||||
#define INT16_C(value) value##i16
|
||||
#define INT32_C(value) value##i32
|
||||
#define INT64_C(value) value##i64
|
||||
#ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type
|
||||
// a signed char!!!!
|
||||
#define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
#else
|
||||
#define UINT8_C(value) value##ui8
|
||||
#endif
|
||||
#define UINT16_C(value) value##ui16
|
||||
#define UINT32_C(value) value##ui32
|
||||
#define UINT64_C(value) value##ui64
|
||||
#define INTMAX_C(value) value##i64
|
||||
#define UINTMAX_C(value) value##ui64
|
||||
|
||||
#else
|
||||
// do it the old fashioned way:
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
#define INT8_C(value) static_cast<int8_t>(value)
|
||||
#define UINT8_C(value) static_cast<uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
#define INT16_C(value) static_cast<int16_t>(value)
|
||||
#define UINT16_C(value) static_cast<uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
#define INT32_C(value) value
|
||||
#define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
#define INT32_C(value) value##L
|
||||
#define UINT32_C(value) value##uL
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
#define INT64_C(value) value##LL
|
||||
#define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
#define INT64_C(value) value##L
|
||||
#define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
#define INT64_C(value) value##i64
|
||||
#define UINT64_C(value) value##ui64
|
||||
# endif
|
||||
|
||||
#ifdef BOOST_NO_INT64_T
|
||||
#define INTMAX_C(value) INT32_C(value)
|
||||
#define UINTMAX_C(value) UINT32_C(value)
|
||||
#else
|
||||
#define INTMAX_C(value) INT64_C(value)
|
||||
#define UINTMAX_C(value) UINT64_C(value)
|
||||
#endif
|
||||
|
||||
#endif // Borland/MS specific
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
#undef INT8_C
|
||||
#undef INT16_C
|
||||
#undef INT32_C
|
||||
#undef INT64_C
|
||||
#undef UINT8_C
|
||||
#undef UINT16_C
|
||||
#undef UINT32_C
|
||||
#undef UINT64_C
|
||||
#undef INTMAX_C
|
||||
#undef UINTMAX_C
|
||||
|
||||
#endif // constant macros
|
||||
|
||||
|
98
index.htm
98
index.htm
@ -1,98 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Boost Integer Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home </big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ </big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More </big></font></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<td align="center"><b><i>Header / Docs</i></b></td>
|
||||
<td align="center"><b><i>Contents</i></b></td>
|
||||
<td align="center"><b><i>Use</i></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
<p>The organization of boost integer headers and classes is designed to take
|
||||
advantage of <code><stdint.h></code> types from the 1999 C standard
|
||||
without resorting to undefined behavior in terms of
|
||||
the 1998 C++ standard. The header <code><boost/cstdint.hpp></code>
|
||||
makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/cstdint.hpp></code>
|
||||
will continue to function, but will become redundant and may be safely deprecated.</p>
|
||||
<p>Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
|
||||
<h2>Caveat emptor</h2>
|
||||
<p>As an
|
||||
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
visible to users of <boost/cstdint.hpp>. Don't use these macros; they are not part of
|
||||
any Boost specified interface.
|
||||
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||
|
||||
<p>
|
||||
As another implementation artifact, certain C
|
||||
<code><stdint.h></code> typedef names may possibly be visible in the
|
||||
global namespace to users of <code><boost/cstdint.hpp></code>.
|
||||
Don't use these names, they are not part of any Boost specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
133
index.html
Normal file
133
index.html
Normal file
@ -0,0 +1,133 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Boost Integer Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
<table border="1" bgcolor="teal" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="white"><img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
|
||||
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
|
||||
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th>Header / Docs</th>
|
||||
<th>Contents</th>
|
||||
<th>Use</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><cite><a href="../../boost/integer_fwd.hpp"><boost/integer_fwd.hpp></a></cite></td>
|
||||
<td valign="top">Forward declarations of classes and class templates</td>
|
||||
<td valign="top">When just the name of a class is needed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/integer_mask.html">documentation</a></td>
|
||||
<td valign="top">Templates for the selection of integer masks, single or lowest group, based on the number of bits.</td>
|
||||
<td valign="top">Use to select a particular mask when the bit position(s) are based on a compile-time variable.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/static_log2.html">documentation</a></td>
|
||||
<td valign="top">Template for finding the highest power of two in a number.</td>
|
||||
<td valign="top">Use to find the bit-size/range based on a maximum value.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/static_min_max.hpp"><boost/integer/static_min_max.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/static_min_max.html">documentation</a></td>
|
||||
<td valign="top">Templates for finding the extrema of two numbers.</td>
|
||||
<td valign="top">Use to find a bound based on a minimum or maximum value.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
|
||||
<p>The organization of boost integer headers and classes is designed to
|
||||
take advantage of <cite><stdint.h></cite> types from the 1999 C
|
||||
standard without resorting to undefined behavior in terms of the 1998
|
||||
C++ standard. The header <cite><boost/cstdint.hpp></cite> makes
|
||||
the standard integer types safely available in namespace
|
||||
<code>boost</code> without placing any names in namespace
|
||||
<code>std</code>. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <cite><stdint.h></cite> and <cite><cstdint></cite>,
|
||||
then <cite><boost/cstdint.hpp></cite> will continue to function,
|
||||
but will become redundant and may be safely deprecated.</p>
|
||||
|
||||
<p>Because these are boost headers, their names conform to boost header
|
||||
naming conventions rather than C++ Standard Library header naming
|
||||
conventions.</p>
|
||||
|
||||
<h2><i>Caveat emptor</i></h2>
|
||||
|
||||
<p>As an implementation artifact, certain C
|
||||
<cite><limits.h></cite> macro names may possibly be visible to
|
||||
users of <cite><boost/cstdint.hpp></cite>. Don't use these
|
||||
macros; they are not part of any Boost-specified interface. Use
|
||||
<code>boost::integer_traits<></code> or
|
||||
<code>std::numeric_limits<></code> instead.</p>
|
||||
|
||||
<p>As another implementation artifact, certain C
|
||||
<cite><stdint.h></cite> typedef names may possibly be visible in
|
||||
the global namespace to users of <cite><boost/cstdint.hpp></cite>.
|
||||
Don't use these names, they are not part of any Boost-specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||
</p>
|
||||
|
||||
<p><EFBFBD> Copyright Beman Dawes 2003</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
529
integer.htm
529
integer.htm
@ -1,112 +1,505 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Integer Type Selection Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
<body bgcolor="white" text="black">
|
||||
<h1>
|
||||
<img src="../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Integer Type Selection
|
||||
Templates</h1>
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Integer
|
||||
Type Selection Templates</h1>
|
||||
<p>The <code><a href="../../boost/integer.hpp"><boost/integer.hpp></a></code>
|
||||
type selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility is
|
||||
particularly useful for solving generic programming problems.</p>
|
||||
<p>The <cite><a
|
||||
href="../../boost/integer.hpp"><boost/integer.hpp></a></cite> type
|
||||
selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility
|
||||
is particularly useful for solving generic programming problems.</p>
|
||||
|
||||
<p>The templates <b>int_t<></b> and <b>uint_t<></b> supply typedefs <b>least</b>
|
||||
and <b>fast</b>. The <b>least</b> type be the smallest type which holds at
|
||||
least the number of bits (including sign) specified. The <b>fast</b> type will
|
||||
be at least as large as the <b>least</b> type, but may possible be larger.
|
||||
There is no guarantee that the <b>fast</b> type will actually be faster than
|
||||
other possible types.</p>
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<h2>Alternative</h2>
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#easy">Processor-Optimized Types</a></li>
|
||||
<li><a href="#sized">Sized Types</a></li>
|
||||
<li><a href="#mpl">MPL-Compatible Variants</a></li>
|
||||
<li><a href="#example">Example</a></li>
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
<li><a href="#alternative">Alternative</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<p>If the number of bits required is known beforehand, it may be more
|
||||
appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
<blockquote><pre>
|
||||
#include <<a href="../../boost/integer_fwd.hpp">boost/integer_fwd.hpp</a>> // forwarding header
|
||||
#include <<a href="cstdint.htm">boost/cstdint.hpp</a>> // for boost::uintmax_t, intmax_t
|
||||
|
||||
<blockquote>
|
||||
<pre>namespace boost
|
||||
namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||
template< typename BaseInt >
|
||||
struct fast_integral
|
||||
{
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef typename fast_integral<LeastInt>::type fast;
|
||||
};
|
||||
|
||||
// MPL-compatible
|
||||
template< int Bits, typename Signedness >
|
||||
struct sized_integral
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = <em>implementation_supplied</em>;
|
||||
static int const bit_count = Bits;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
template< int Bits, typename Signedness >
|
||||
struct exact_integral
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = <em>implementation_supplied</em>;
|
||||
static int const bit_count = Bits;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
template< intmax_t MaxValue >
|
||||
struct maximum_signed_integral
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = true;
|
||||
static intmax_t const bound = MaxValue;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
template< intmax_t MinValue >
|
||||
struct minimum_signed_integral
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = true;
|
||||
static intmax_t const bound = MinValue;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
template< uintmax_t Value >
|
||||
struct maximum_unsigned_integral
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = false;
|
||||
static uintmax_t const bound = Value;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< int Bits > // bits (including sign) required, 0-32 valid
|
||||
template< int Bits >
|
||||
struct int_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef typename sized_integral<Bits, signed>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< int Bits >
|
||||
struct int_exact_t
|
||||
{
|
||||
typedef typename exact_integral<Bits, signed>::type exact;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // bits required, 0-32 valid
|
||||
template< int Bits >
|
||||
struct uint_t
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
typedef typename sized_integral<Bits, unsigned>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< int Bits >
|
||||
struct uint_exact_t
|
||||
{
|
||||
typedef typename exact_integral<Bits, unsigned>::type exact;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< intmax_t MaxValue >
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef typename maximum_signed_integral<MaxValue>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< intmax_t MinValue >
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef typename minimum_signed_integral<MinValue>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< uintmax_t Value >
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef typename maximum_unsigned_integral<Value>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
} // namespace boost
|
||||
</pre>
|
||||
</pre></blockquote>
|
||||
|
||||
</blockquote>
|
||||
<p>[Templates to select type based on maximum value are under development.]
|
||||
</p>
|
||||
<h2><a name="easy">Processor-Optimized Types</a></h2>
|
||||
|
||||
<h2>Example</h2>
|
||||
<p>The <code>fast_integral</code> class template maps its input type to the
|
||||
next-largest type that the processor can manipulate the easiest, or to
|
||||
itself if the input type is already an easy-to-manipulate type. For
|
||||
instance, processing a bunch of <code>char</code> objects may go faster
|
||||
if they were converted to <code>int</code> objects before processing.
|
||||
The input type, passed as the only template parameter, can be any built-in
|
||||
integral type besides <code>bool</code>. The output type is given as the class
|
||||
member <code>type</code>.</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>#include <boost/integer.hpp>
|
||||
using boost::int_t;
|
||||
<p>The <code>int_fast_t</code> class template is the classic meta-function for
|
||||
this operation. Despite the name, it works for unsigned integral types just
|
||||
like it works for the signed integral types. The output type is given as the
|
||||
class member <code>fast</code>, defined to be the same as the corresponding
|
||||
result from the <code>fast_integral</code> meta-function.</p>
|
||||
|
||||
...
|
||||
int_t<24>::least my_var; </pre>
|
||||
<p><strong>Implementation Notes</strong><br>
|
||||
By default, the output type is identical to the input type. Eventually,
|
||||
this code's implementation should be conditionalized for each platform
|
||||
to give accurate mappings between the built-in types and the
|
||||
easiest-to-manipulate built-in types. Also, there is no guarantee that
|
||||
the output type actually is easier to manipulate than the input
|
||||
type.</p>
|
||||
|
||||
</blockquote>
|
||||
<h2>Demonstration Program</h2>
|
||||
<h2><a name="sized">Sized Types</a></h2>
|
||||
|
||||
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a not very
|
||||
smart demonstration of the results from instantiating various <b>int_t<></b>
|
||||
and <b>uint_t<></b> examples.</p>
|
||||
<p>The <code>int_t</code>, <code>int_exact_t</code>, <code>uint_t</code>,
|
||||
<code>uint_exact_t</code>, <code>int_max_value_t</code>,
|
||||
<code>int_min_value_t</code>, and <code>uint_value_t</code> class templates find
|
||||
the most appropriate built-in integral type for the given template parameter.
|
||||
This type is given by the class member <code>least</code> or <code>exact</code>.
|
||||
For the non-exact class templates, 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>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
<table border="2" cellpadding="5">
|
||||
<caption>Criteria for the Sized Type Class Templates</caption>
|
||||
<tr>
|
||||
<th>Class Template (all in name-space <code>boost</code>)</th>
|
||||
<th>Template Parameter Mapping</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>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
|
||||
<em>must</em> be a positive number. A compile-time error results if
|
||||
the parameter is larger than the number of bits in a
|
||||
<code>boost::intmax_t</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>int_exact_t</code></td>
|
||||
<td>The smallest built-in signed integral type with exactly the
|
||||
given number of bits, including the sign bit. A compile-time error
|
||||
results if no qualifying type exists.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>uint_t</code></td>
|
||||
<td>The smallest built-in unsigned integral type with at least
|
||||
the given number of bits. The parameter <em>must</em> be a
|
||||
non-negative number. A compile-time error results if the parameter
|
||||
is larger than the number of bits in a
|
||||
<code>boost::uintmax_t</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>uint_exact_t</code></td>
|
||||
<td>The smallest built-in unsigned integral type with exactly the given
|
||||
number of bits. A compile-time error results if no qualifying type
|
||||
exists.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>int_max_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a maximum. The parameter <em>must</em> be a
|
||||
positive number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>int_min_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a minimum. The parameter <em>must</em> be a
|
||||
negative number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>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="mpl">MPL-Compatible Variants</a></h2>
|
||||
|
||||
<p>The bit-length sized-type class templates have several drawbacks:</p>
|
||||
|
||||
<ul>
|
||||
<li>You must know the valid bit-lengths in advance.</li>
|
||||
<li>There is no way to inspect the parameter used after a size-type template
|
||||
class is aliased.</li>
|
||||
<li>Using an inappropriate parameter value results in a compiler
|
||||
diagnostic.</li>
|
||||
<li>The type names used are inconsistent with other transformations in
|
||||
Boost, like in <a href="../mpl/">MPL</a>.</li>
|
||||
<li>The above two facts make use of the size-type class templates
|
||||
incompatible with template meta-programming techniques.</li>
|
||||
</ul>
|
||||
|
||||
<p>The <code>sized_integral</code>, <code>exact_integral</code>,
|
||||
<code>maximum_signed_integral</code>, <code>minimum_signed_integral</code>, and
|
||||
<code>maximum_unsigned_integral</code> class templates provide MPL-compatible
|
||||
alternatives. These alternatives generally have the form:</p>
|
||||
|
||||
<blockquote><pre>
|
||||
template< <var>SwitchType</var> <var>SwitchValue</var>, typename Signedness >
|
||||
struct <var>name</var>
|
||||
{
|
||||
static bool const is_specialized = <em>implementation_supplied</em>;
|
||||
static bool const is_signed = <em>implementation_supplied</em>;
|
||||
static <var>SwitchType</var> const <var>switch_id</var> = <var>SwitchValue</var>;
|
||||
|
||||
typedef <em>implementation_supplied</em> type;
|
||||
};
|
||||
</pre></blockquote>
|
||||
|
||||
<p>Each member, if present, is defined by:</p>
|
||||
|
||||
<table border="2" cellpadding="5">
|
||||
<caption>Members in MPL-Compatible Class Templates</caption>
|
||||
<tr>
|
||||
<th>Class Template Member</th>
|
||||
<th>When Defined</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>is_specialized</code></td>
|
||||
<td>Always</td>
|
||||
<td>Flag indicating when a particular template class instantiation is a
|
||||
valid meta-function (<code>true</code>) or not (<code>false</code>).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>is_signed</code></td>
|
||||
<td><code>is_specialized == true</code></td>
|
||||
<td>Flag indicating whether the signed-variant (<code>true</code>) or
|
||||
the unsigned-variant (<code>false</code>) of the meta-function is
|
||||
used. This is controlled by the <code>Signedness</code> template
|
||||
parameter:
|
||||
<table border="1" cellpadding="3" align="center">
|
||||
<caption>Effect of <code>Signedness</code> Setting</caption>
|
||||
<tr>
|
||||
<th><code>Signedness</code> Type</th>
|
||||
<th><code>is_signed</code></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>signed</code></td>
|
||||
<td><code>true</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>unsigned</code></td>
|
||||
<td><code>false</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>anything else</td>
|
||||
<td><em>not defined</em></td>
|
||||
</tr>
|
||||
</table>
|
||||
The type used is a programmer mnemonic; the compiler cannot prevent
|
||||
someone from using <code>int</code> or <code>signed int</code>
|
||||
instead of <code>signed</code>, or <code>unsigned int</code> instead
|
||||
of <code>unsigned</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><var>switch_id</var></code> (Actual name is template-specific.)</td>
|
||||
<td>Always</td>
|
||||
<td>The value of the main control parameter, accessible even if the
|
||||
template class instantiation is aliased.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>type</code></td>
|
||||
<td><code>is_specialized == true</code></td>
|
||||
<td>The meta-function's result. It appears only if the input parameters
|
||||
satisfy the template's requirements. Its presence, or lack thereof,
|
||||
enables "Substitution Failure Is Not An Error" (SFINAE)
|
||||
techniques, instead of a hard compiler diagnostic.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The exceptions are the extreme-value class templates
|
||||
(<code>maximum_signed_integral</code>, <code>minimum_signed_integral</code>, and
|
||||
<code>maximum_unsigned_integral</code>), which do not take a <var>Signedness</var>
|
||||
template parameter because the meta-functions already inherently have signedness.
|
||||
|
||||
<p>The following table describes each template's criteria. The classic signed
|
||||
and unsigned equivalents are the sized-type class templates that each
|
||||
MPL-compatible class template emulates. (The setting of <var>Signedness</var>
|
||||
controls the appropriate emulation.)</p>
|
||||
|
||||
<table border="2" cellpadding="5">
|
||||
<caption>Criteria for the MPL-Compatible Class Templates</caption>
|
||||
<tr>
|
||||
<th rowspan="2">Class Template (all in name-space <code>boost</code>)</th>
|
||||
<th rowspan="2">Parameter Type (in name-space <code>boost</code> as needed)</th>
|
||||
<th rowspan="2">Parameter Member ID</th>
|
||||
<th colspan="2">Classic Equivalent</th>
|
||||
<th rowspan="2" colspan="2">Template Parameter Mapping (when <code>type</code> is defined)</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Signed</th>
|
||||
<th>Unsigned</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sized_integral</code></td>
|
||||
<td><code>int</code></td>
|
||||
<td><code>bit_count</code></td>
|
||||
<td><code>int_t</code></td>
|
||||
<td><code>uint_t</code></td>
|
||||
<td colspan="2">The smallest built-in integral type with at least
|
||||
<code>bit_count</code> bits (including the sign bit when
|
||||
<var>Signedness</var> is <code>signed</code>). Not present if no
|
||||
type qualifies.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>exact_integral</code></td>
|
||||
<td><code>int</code></td>
|
||||
<td><code>bit_count</code></td>
|
||||
<td><code>int_exact_t</code></td>
|
||||
<td><code>uint_exact_t</code></td>
|
||||
<td colspan="2">The smallest built-in integral type with exactly
|
||||
<code>bit_count</code> bits (including the sign bit when
|
||||
<var>Signedness</var> is <code>signed</code>). Not present if no
|
||||
type qualifies.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>maximum_signed_integral</code></td>
|
||||
<td><code>intmax_t</code></td>
|
||||
<td><code>bound</code></td>
|
||||
<td colspan="2"><code>int_max_value_t</code></td>
|
||||
<td>The smallest built-in integral type that can perserve the value in
|
||||
<code>bound</code>. Not present if <code>bound</code> is non-positive.</td>
|
||||
<td rowspan="3">It is possible for a <code>type</code> to be absent if
|
||||
a platform supports really-extended integral types (beyond <code>long
|
||||
long</code> or <code>__int64</code>), support for those types goes
|
||||
into <<a href="../../boost/cstdint.hpp">boost/cstdint.hpp</a>>,
|
||||
but said support hadn't yet been added to <<a
|
||||
href="../../boost/integer.hpp">boost/integer.hpp</a>></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>minimum_signed_integral</code></td>
|
||||
<td><code>intmax_t</code></td>
|
||||
<td><code>bound</code></td>
|
||||
<td colspan="2"><code>int_min_value_t</code></td>
|
||||
<td>The smallest built-in integral type that can perserve the value in
|
||||
<code>bound</code>. Not present if <code>bound</code> is non-negative.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>maximum_unsigned_integral</code></td>
|
||||
<td><code>uintmax_t</code></td>
|
||||
<td><code>bound</code></td>
|
||||
<td colspan="2"><code>uint_value_t</code></td>
|
||||
<td>The smallest built-in integral type that can perserve the value in
|
||||
<code>bound</code>. Should always be present.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <<a href="../../boost/integer.hpp">boost/integer.hpp</a>>
|
||||
#include <<a href="../../boost/mpl/int.hpp">boost/mpl/int.hpp</a>>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
//...
|
||||
|
||||
template < int Bits >
|
||||
bool
|
||||
fit_exactly( boost::mpl::int_<Bits> const &x,
|
||||
typename boost::exact_integral<Bits, signed>::type *unused = 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
bool
|
||||
fit_exactly( T const &x )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::mpl::int_<24> twenty_four;
|
||||
|
||||
boost::int_t<twenty_four::value>::least my_var;
|
||||
|
||||
//...
|
||||
|
||||
std::cout << "my_var " << ( fit_exactly(twenty_four()) ? "does" :
|
||||
"does not" ) << " fit its type exactly." << std::endl;
|
||||
|
||||
//...
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
<p>The program <a href="test/integer_test.cpp">integer_test.cpp</a> is a
|
||||
simplistic demonstration of the results from instantiating various
|
||||
examples of the sized type class templates.</p>
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
<p>The rationale for the design of the templates in this header includes:</p>
|
||||
|
||||
<ul>
|
||||
<li>Avoid recursion because of concern about C++'s limited guaranteed
|
||||
recursion depth (17).</li>
|
||||
<li>Avoid macros on general principles.</li>
|
||||
<li>Try to keep the design as simple as possible.</li>
|
||||
<li>Avoid recursion because of concern about C++'s limited
|
||||
guaranteed recursion depth (17).</li>
|
||||
<li>Avoid macros on general principles.</li>
|
||||
<li>Try to keep the design as simple as possible.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Credits</h2>
|
||||
<h2><a name="alternative">Alternative</a></h2>
|
||||
|
||||
<p>The author of the Boost integer type choosing templates is <a href="../../people/beman_dawes.html">Beman
|
||||
Dawes</a>. He thanks to <a href="../../people/valentin_bonnard.htm"> Valentin Bonnard</a> and
|
||||
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing their designs for similar templates.</p>
|
||||
<p>If the number of bits required is known beforehand, it may be more
|
||||
appropriate to use the types supplied in <cite><a
|
||||
href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></cite>.</p>
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
<p>The author of most of the Boost integer type choosing templates is <a
|
||||
href="http://www.boost.org/people/beman_dawes.html">Beman Dawes</a>. He gives thanks
|
||||
to Valentin Bonnard and
|
||||
<a href="http://www.boost.org/people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
|
||||
their designs for similar templates. <a
|
||||
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a> designed the
|
||||
exact and value-based sized templates, and the MPL-compatible templates.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised August 31, 1999</p>
|
||||
|
||||
<p><EFBFBD> Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
and distribute this document is granted provided this copyright notice appears in all
|
||||
copies. This document is provided "as is" without express or implied warranty,
|
||||
and with no claim as to its suitability for any purpose.</p>
|
||||
|
||||
<p></p>
|
||||
|
||||
<p> </p>
|
||||
<p>Revised July 16, 2008</p>
|
||||
|
||||
<p>© Copyright Beman Dawes 1999. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
317
integer_test.cpp
317
integer_test.cpp
@ -1,317 +0,0 @@
|
||||
// boost integer.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||
// 31 Aug 99 Initial version
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void test( long ) { std::cout << "long\n"; }
|
||||
void test( int ) { std::cout << "int\n"; }
|
||||
void test( short ) { std::cout << "short\n"; }
|
||||
void test( signed char ) { std::cout << "signed char\n"; }
|
||||
void test( unsigned long ) { std::cout << "unsigned long\n"; }
|
||||
void test( unsigned int ) { std::cout << "unsigned int\n"; }
|
||||
void test( unsigned short ) { std::cout << "unsigned short\n"; }
|
||||
void test( unsigned char ) { std::cout << "unsigned char\n"; }
|
||||
} // unnamed namespace
|
||||
|
||||
// just to prove it works, specialize int_fast_t<short> to yield long
|
||||
namespace boost
|
||||
{
|
||||
template<> struct int_fast_t<short> { typedef long fast; };
|
||||
}
|
||||
|
||||
int test_main(int,char**)
|
||||
{
|
||||
using boost::int_t;
|
||||
using boost::uint_t;
|
||||
|
||||
#ifdef BOOST_SHOW_TYPES
|
||||
std::cout << 32 << ' '; test( int_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::least() );
|
||||
std::cout << 29 << ' '; test( int_t<29>::least() );
|
||||
std::cout << 28 << ' '; test( int_t<28>::least() );
|
||||
std::cout << 27 << ' '; test( int_t<27>::least() );
|
||||
std::cout << 26 << ' '; test( int_t<26>::least() );
|
||||
std::cout << 25 << ' '; test( int_t<25>::least() );
|
||||
std::cout << 24 << ' '; test( int_t<24>::least() );
|
||||
std::cout << 23 << ' '; test( int_t<23>::least() );
|
||||
std::cout << 22 << ' '; test( int_t<22>::least() );
|
||||
std::cout << 21 << ' '; test( int_t<21>::least() );
|
||||
std::cout << 20 << ' '; test( int_t<20>::least() );
|
||||
std::cout << 19 << ' '; test( int_t<19>::least() );
|
||||
std::cout << 18 << ' '; test( int_t<18>::least() );
|
||||
std::cout << 17 << ' '; test( int_t<17>::least() );
|
||||
std::cout << 16 << ' '; test( int_t<16>::least() );
|
||||
std::cout << 15 << ' '; test( int_t<15>::least() );
|
||||
std::cout << 14 << ' '; test( int_t<14>::least() );
|
||||
std::cout << 13 << ' '; test( int_t<13>::least() );
|
||||
std::cout << 12 << ' '; test( int_t<12>::least() );
|
||||
std::cout << 11 << ' '; test( int_t<11>::least() );
|
||||
std::cout << 10 << ' '; test( int_t<10>::least() );
|
||||
std::cout << 9 << ' '; test( int_t<9>::least() );
|
||||
std::cout << 8 << ' '; test( int_t<8>::least() );
|
||||
std::cout << 7 << ' '; test( int_t<7>::least() );
|
||||
std::cout << 6 << ' '; test( int_t<6>::least() );
|
||||
std::cout << 5 << ' '; test( int_t<5>::least() );
|
||||
std::cout << 4 << ' '; test( int_t<4>::least() );
|
||||
std::cout << 3 << ' '; test( int_t<3>::least() );
|
||||
std::cout << 2 << ' '; test( int_t<2>::least() );
|
||||
std::cout << 1 << ' '; test( int_t<1>::least() );
|
||||
std::cout << 0 << ' '; test( int_t<0>::least() );
|
||||
std::cout << 32 << ' '; test( int_t<32>::fast() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::fast() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::fast() );
|
||||
std::cout << 29 << ' '; test( int_t<29>::fast() );
|
||||
std::cout << 28 << ' '; test( int_t<28>::fast() );
|
||||
std::cout << 27 << ' '; test( int_t<27>::fast() );
|
||||
std::cout << 26 << ' '; test( int_t<26>::fast() );
|
||||
std::cout << 25 << ' '; test( int_t<25>::fast() );
|
||||
std::cout << 24 << ' '; test( int_t<24>::fast() );
|
||||
std::cout << 23 << ' '; test( int_t<23>::fast() );
|
||||
std::cout << 22 << ' '; test( int_t<22>::fast() );
|
||||
std::cout << 21 << ' '; test( int_t<21>::fast() );
|
||||
std::cout << 20 << ' '; test( int_t<20>::fast() );
|
||||
std::cout << 19 << ' '; test( int_t<19>::fast() );
|
||||
std::cout << 18 << ' '; test( int_t<18>::fast() );
|
||||
std::cout << 17 << ' '; test( int_t<17>::fast() );
|
||||
std::cout << 16 << ' '; test( int_t<16>::fast() );
|
||||
std::cout << 15 << ' '; test( int_t<15>::fast() );
|
||||
std::cout << 14 << ' '; test( int_t<14>::fast() );
|
||||
std::cout << 13 << ' '; test( int_t<13>::fast() );
|
||||
std::cout << 12 << ' '; test( int_t<12>::fast() );
|
||||
std::cout << 11 << ' '; test( int_t<11>::fast() );
|
||||
std::cout << 10 << ' '; test( int_t<10>::fast() );
|
||||
std::cout << 9 << ' '; test( int_t<9>::fast() );
|
||||
std::cout << 8 << ' '; test( int_t<8>::fast() );
|
||||
std::cout << 7 << ' '; test( int_t<7>::fast() );
|
||||
std::cout << 6 << ' '; test( int_t<6>::fast() );
|
||||
std::cout << 5 << ' '; test( int_t<5>::fast() );
|
||||
std::cout << 4 << ' '; test( int_t<4>::fast() );
|
||||
std::cout << 3 << ' '; test( int_t<3>::fast() );
|
||||
std::cout << 2 << ' '; test( int_t<2>::fast() );
|
||||
std::cout << 1 << ' '; test( int_t<1>::fast() );
|
||||
std::cout << 0 << ' '; test( int_t<0>::fast() );
|
||||
std::cout << 32 << ' '; test( uint_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( uint_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( uint_t<30>::least() );
|
||||
std::cout << 29 << ' '; test( uint_t<29>::least() );
|
||||
std::cout << 28 << ' '; test( uint_t<28>::least() );
|
||||
std::cout << 27 << ' '; test( uint_t<27>::least() );
|
||||
std::cout << 26 << ' '; test( uint_t<26>::least() );
|
||||
std::cout << 25 << ' '; test( uint_t<25>::least() );
|
||||
std::cout << 24 << ' '; test( uint_t<24>::least() );
|
||||
std::cout << 23 << ' '; test( uint_t<23>::least() );
|
||||
std::cout << 22 << ' '; test( uint_t<22>::least() );
|
||||
std::cout << 21 << ' '; test( uint_t<21>::least() );
|
||||
std::cout << 20 << ' '; test( uint_t<20>::least() );
|
||||
std::cout << 19 << ' '; test( uint_t<19>::least() );
|
||||
std::cout << 18 << ' '; test( uint_t<18>::least() );
|
||||
std::cout << 17 << ' '; test( uint_t<17>::least() );
|
||||
std::cout << 16 << ' '; test( uint_t<16>::least() );
|
||||
std::cout << 15 << ' '; test( uint_t<15>::least() );
|
||||
std::cout << 14 << ' '; test( uint_t<14>::least() );
|
||||
std::cout << 13 << ' '; test( uint_t<13>::least() );
|
||||
std::cout << 12 << ' '; test( uint_t<12>::least() );
|
||||
std::cout << 11 << ' '; test( uint_t<11>::least() );
|
||||
std::cout << 10 << ' '; test( uint_t<10>::least() );
|
||||
std::cout << 9 << ' '; test( uint_t<9>::least() );
|
||||
std::cout << 8 << ' '; test( uint_t<8>::least() );
|
||||
std::cout << 7 << ' '; test( uint_t<7>::least() );
|
||||
std::cout << 6 << ' '; test( uint_t<6>::least() );
|
||||
std::cout << 5 << ' '; test( uint_t<5>::least() );
|
||||
std::cout << 4 << ' '; test( uint_t<4>::least() );
|
||||
std::cout << 3 << ' '; test( uint_t<3>::least() );
|
||||
std::cout << 2 << ' '; test( uint_t<2>::least() );
|
||||
std::cout << 1 << ' '; test( uint_t<1>::least() );
|
||||
std::cout << 0 << ' '; test( uint_t<0>::least() );
|
||||
std::cout << 32 << ' '; test( uint_t<32>::fast() );
|
||||
std::cout << 31 << ' '; test( uint_t<31>::fast() );
|
||||
std::cout << 30 << ' '; test( uint_t<30>::fast() );
|
||||
std::cout << 29 << ' '; test( uint_t<29>::fast() );
|
||||
std::cout << 28 << ' '; test( uint_t<28>::fast() );
|
||||
std::cout << 27 << ' '; test( uint_t<27>::fast() );
|
||||
std::cout << 26 << ' '; test( uint_t<26>::fast() );
|
||||
std::cout << 25 << ' '; test( uint_t<25>::fast() );
|
||||
std::cout << 24 << ' '; test( uint_t<24>::fast() );
|
||||
std::cout << 23 << ' '; test( uint_t<23>::fast() );
|
||||
std::cout << 22 << ' '; test( uint_t<22>::fast() );
|
||||
std::cout << 21 << ' '; test( uint_t<21>::fast() );
|
||||
std::cout << 20 << ' '; test( uint_t<20>::fast() );
|
||||
std::cout << 19 << ' '; test( uint_t<19>::fast() );
|
||||
std::cout << 18 << ' '; test( uint_t<18>::fast() );
|
||||
std::cout << 17 << ' '; test( uint_t<17>::fast() );
|
||||
std::cout << 16 << ' '; test( uint_t<16>::fast() );
|
||||
std::cout << 15 << ' '; test( uint_t<15>::fast() );
|
||||
std::cout << 14 << ' '; test( uint_t<14>::fast() );
|
||||
std::cout << 13 << ' '; test( uint_t<13>::fast() );
|
||||
std::cout << 12 << ' '; test( uint_t<12>::fast() );
|
||||
std::cout << 11 << ' '; test( uint_t<11>::fast() );
|
||||
std::cout << 10 << ' '; test( uint_t<10>::fast() );
|
||||
std::cout << 9 << ' '; test( uint_t<9>::fast() );
|
||||
std::cout << 8 << ' '; test( uint_t<8>::fast() );
|
||||
std::cout << 7 << ' '; test( uint_t<7>::fast() );
|
||||
std::cout << 6 << ' '; test( uint_t<6>::fast() );
|
||||
std::cout << 5 << ' '; test( uint_t<5>::fast() );
|
||||
std::cout << 4 << ' '; test( uint_t<4>::fast() );
|
||||
std::cout << 3 << ' '; test( uint_t<3>::fast() );
|
||||
std::cout << 2 << ' '; test( uint_t<2>::fast() );
|
||||
std::cout << 1 << ' '; test( uint_t<1>::fast() );
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
#endif
|
||||
|
||||
long v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::least(v) == v );
|
||||
v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::fast(v) == v );
|
||||
unsigned long u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::least(u) == u );
|
||||
u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::fast(u) == u );
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
Type Limits</h1>
|
||||
|
||||
<p>
|
||||
@ -77,7 +77,7 @@ Test Program</h2>
|
||||
|
||||
<p>
|
||||
|
||||
The program <code><a href="integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
The program <code><a href="test/integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
exercises the <code>integer_traits</code> class.
|
||||
|
||||
<h2>Acknowledgements</h2>
|
||||
@ -85,5 +85,10 @@ exercises the <code>integer_traits</code> class.
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||
traits idea on the boost mailing list in August 1999.
|
||||
<hr>
|
||||
<a href="../../people/jens_maurer.htm">
|
||||
Jens Maurer</a>, 2000-02-20
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->06 November 2007<!--webbot bot="Timestamp" endspan i-checksum="40336" --></p>
|
||||
<p><EFBFBD> Copyright Beman Dawes 2000</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
|
@ -1,84 +0,0 @@
|
||||
/* boost integer_traits.hpp tests
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without free provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
* Jens Maurer makes no representations about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Revision history
|
||||
* 2000-02-22 Small improvements by Beman Dawes
|
||||
* 2000-06-27 Rework for better MSVC and BCC co-operation
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/integer_traits.hpp>
|
||||
// use int64_t instead of long long for better portability
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test relies on assert() and thus makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
* MSVC mis-compiles explicit function template instantiations.
|
||||
* For example, f<A>() and f<B>() are both compiled to call f<A>().
|
||||
* BCC is unable to implicitly convert a "const char *" to a std::string
|
||||
* when using explicit function template instantiations.
|
||||
*
|
||||
* Therefore, avoid explicit function template instantiations.
|
||||
*/
|
||||
|
||||
template<class T>
|
||||
void runtest(const char * type, T)
|
||||
{
|
||||
typedef boost::integer_traits<T> traits;
|
||||
std::cout << "Checking " << type
|
||||
<< "; min is " << traits::min()
|
||||
<< ", max is " << traits::max()
|
||||
<< std::endl;
|
||||
assert(traits::is_specialized);
|
||||
assert(traits::is_integer);
|
||||
assert(traits::is_integral);
|
||||
assert(traits::const_min == traits::min());
|
||||
assert(traits::const_max == traits::max());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
runtest("bool", bool());
|
||||
runtest("char", char());
|
||||
typedef signed char signed_char;
|
||||
runtest("signed char", signed_char());
|
||||
typedef unsigned char unsigned_char;
|
||||
runtest("unsigned char", unsigned_char());
|
||||
runtest("short", short());
|
||||
typedef unsigned short unsigned_short;
|
||||
runtest("unsigned short", unsigned_short());
|
||||
runtest("int", int());
|
||||
typedef unsigned int unsigned_int;
|
||||
runtest("unsigned int", unsigned_int());
|
||||
runtest("long", long());
|
||||
typedef unsigned long unsigned_long;
|
||||
runtest("unsigned long", unsigned_long());
|
||||
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__) && !defined(__BEOS__)
|
||||
//
|
||||
// MS/Borland compilers can't support 64-bit member constants
|
||||
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
||||
runtest("int64_t (possibly long long)", boost::int64_t());
|
||||
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
|
||||
#endif
|
||||
// Some compilers don't pay attention to std:3.6.1/5 and issue a
|
||||
// warning here if "return 0;" is omitted.
|
||||
return 0;
|
||||
}
|
||||
|
20
test/Jamfile.v2
Normal file
20
test/Jamfile.v2
Normal file
@ -0,0 +1,20 @@
|
||||
#~ Copyright Rene Rivera 2008
|
||||
#~ Distributed under the Boost Software License, Version 1.0.
|
||||
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import testing ;
|
||||
|
||||
test-suite integer
|
||||
: [ run cstdint_test.cpp ]
|
||||
[ run integer_test.cpp
|
||||
/boost/test//boost_unit_test_framework ]
|
||||
[ run integer_traits_test.cpp
|
||||
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||
[ run integer_mask_test.cpp
|
||||
/boost/test//boost_unit_test_framework ]
|
||||
[ run static_log2_test.cpp
|
||||
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||
[ run static_min_max_test.cpp
|
||||
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||
[ compile issue_2134.cpp ]
|
||||
;
|
@ -1,35 +1,29 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 2000. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability for
|
||||
// any purpose.
|
||||
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||
// 28 Jun 00 Initial version
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <boost/cstdint.hpp>
|
||||
//
|
||||
// macros should not be defined by default:
|
||||
//
|
||||
#ifdef INT8_C
|
||||
#error header incorrectly implemented
|
||||
#endif
|
||||
//
|
||||
// now define the macros:
|
||||
//
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test makes no sense with NDEBUG defined
|
||||
#endif
|
||||
int main()
|
||||
{
|
||||
std::cout << "This test makes no sense with NDEBUG defined.\n";
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
@ -108,14 +102,35 @@ void integral_constant_type_check(T1, T2)
|
||||
// numeric_limits implementations currently
|
||||
// vary too much, or are incomplete or missing.
|
||||
//
|
||||
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
|
||||
T2 t2 = static_cast<T2>(-1); // ditto
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// if we have a native stdint.h
|
||||
// then the INTXX_C macros may define
|
||||
// a type that's wider than required:
|
||||
assert(sizeof(T1) <= sizeof(T2));
|
||||
#else
|
||||
assert(sizeof(T1) == sizeof(T2));
|
||||
T1 t1 = -1;
|
||||
T2 t2 = -1;
|
||||
assert(t1 == t2);
|
||||
if(t1 >= 0)
|
||||
assert(t2 >= 0);
|
||||
#endif
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// native headers are permitted to promote small
|
||||
// unsigned types to type int:
|
||||
if(sizeof(T1) >= sizeof(int))
|
||||
{
|
||||
if(t1 > 0)
|
||||
assert(t2 > 0);
|
||||
else
|
||||
assert(!(t2 > 0));
|
||||
}
|
||||
else if(t1 < 0)
|
||||
assert(!(t2 > 0));
|
||||
#else
|
||||
if(t1 > 0)
|
||||
assert(t2 > 0);
|
||||
else
|
||||
assert(t2 < 0);
|
||||
assert(!(t2 > 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -215,13 +230,4 @@ int main()
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// now verify that constant macros get undef'ed correctly:
|
||||
//
|
||||
#undef __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef INT8_C
|
||||
#error boost/cstdint.hpp not correctly defined
|
||||
#endif
|
171
test/integer_mask_test.cpp
Normal file
171
test/integer_mask_test.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
// boost integer_mask.hpp test program -------------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 29 Jul 2008 Added MPL-compatible variants of the integer-mask templates.
|
||||
// (Daryle Walker)
|
||||
// 27 Jul 2008 Changed tests to use the unit-test system; added
|
||||
// extended-integer support. (Daryle Walker)
|
||||
// 23 Sep 2001 Initial version (Daryle Walker)
|
||||
|
||||
#define BOOST_TEST_MODULE "Integer mask tests"
|
||||
#include <boost/test/unit_test.hpp> // unit testing framework
|
||||
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t
|
||||
#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc.
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION,etc.
|
||||
#include <boost/mpl/bool.hpp> // for boost::mpl::bool_
|
||||
#include <boost/mpl/bitwise.hpp> // for boost::mpl::bitor_, shift_left
|
||||
#include <boost/mpl/equal_to.hpp> // for boost::mpl::equal_to
|
||||
#include <boost/mpl/int.hpp> // for boost::mpl::int_
|
||||
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
|
||||
#include <boost/mpl/next_prior.hpp> // for boost::mpl::prior
|
||||
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <ios> // for std::hex
|
||||
#include <iostream> // for std::cout
|
||||
#include <ostream> // for std::endl
|
||||
|
||||
|
||||
// Control if events will be printed conventionally, or just logged.
|
||||
#ifndef CONTROL_SHOW_TYPES
|
||||
#define CONTROL_SHOW_TYPES 0
|
||||
#endif
|
||||
|
||||
// Logging
|
||||
#if CONTROL_SHOW_TYPES
|
||||
#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
|
||||
#else
|
||||
#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
|
||||
#endif
|
||||
|
||||
|
||||
// Custom types/templates, helper functions, and objects
|
||||
namespace
|
||||
{
|
||||
|
||||
// List the ranges of template parameters tests (ranges are half-open)
|
||||
int const max_offset = std::numeric_limits<boost::uintmax_t>::digits;
|
||||
|
||||
typedef boost::mpl::range_c<int, 0, max_offset> high_bit_offsets;
|
||||
typedef boost::mpl::range_c<int, 0, max_offset + 1> low_bit_lengths;
|
||||
typedef boost::mpl::range_c<int, 1, max_offset + 1> special_low_bit_lengths;
|
||||
|
||||
// List a range with out-of-service values
|
||||
typedef boost::mpl::range_c<int, -10, max_offset + 11> wild_bit_lengths;
|
||||
|
||||
// Use SFINAE to check if a particular parameter is supported
|
||||
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
|
||||
bool
|
||||
print_out_template( Tmpl<Value> const &, ValueT setting, char const
|
||||
*template_name, typename Tmpl<Value>::type *unused = 0 )
|
||||
{
|
||||
// Too bad the type-id expression couldn't use the compact form "*unused",
|
||||
// but type-ids of dereferenced null pointers throw by order of C++ 2003,
|
||||
// sect. 5.2.8, para. 2 (although the result is not conceptually needed).
|
||||
PRIVATE_SHOW_MESSAGE( "There is an " << template_name << "<" << setting <<
|
||||
"> specialization with type '" << typeid(typename
|
||||
Tmpl<Value>::value_type).name() << "' and value '" << std::hex <<
|
||||
Tmpl<Value>::value << "'." );
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename ValueT, typename T >
|
||||
bool
|
||||
print_out_template( T const &, ValueT setting, char const *template_name )
|
||||
{
|
||||
PRIVATE_SHOW_MESSAGE( "There is no " << template_name << "<" << setting <<
|
||||
"> specialization." );
|
||||
return false;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
// Check the various integer-valued bit-masks
|
||||
BOOST_AUTO_TEST_SUITE( integer_mask_tests )
|
||||
|
||||
// Check the bit-masks of one offset bit
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets )
|
||||
{
|
||||
typedef boost::mpl::integral_c<typename
|
||||
boost::high_bit_mask_t<T::value>::least, 1u> one_type;
|
||||
typedef boost::mpl::shift_left<one_type, T> result_type;
|
||||
|
||||
BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t<T::value>::high_bit, ==,
|
||||
result_type::value );
|
||||
BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t<T::value>::high_bit_fast,
|
||||
==, result_type::value );
|
||||
}
|
||||
|
||||
// Check the bit-masks of a block of low-valued bits, non-zero block-lengths
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, special_low_bit_lengths )
|
||||
{
|
||||
// One can express (2^x - 1) in two ways
|
||||
// 1. (1 << x) - 1
|
||||
// 2. (1 << (x-1)) | ((1 << (x-1)) - 1)
|
||||
// Since unsigneds have modulo arithmetic, [1] gives the right answer even
|
||||
// when x is the number of bits in the register. However, that last case
|
||||
// gives warnings about the sole bit flowing past the register. Applying
|
||||
// distributive property backwards gives [2], which works without overflow.
|
||||
typedef typename boost::mpl::prior<T>::type shift_type;
|
||||
typedef boost::mpl::integral_c<typename
|
||||
boost::low_bits_mask_t<T::value>::least, 1u> one_type;
|
||||
typedef boost::mpl::shift_left<one_type, shift_type> high_bit_type;
|
||||
typedef typename boost::mpl::prior<high_bit_type>::type low_bits_type;
|
||||
typedef boost::mpl::bitor_<high_bit_type, low_bits_type> result_type;
|
||||
|
||||
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<T::value>::sig_bits, ==,
|
||||
result_type::value );
|
||||
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<T::value>::sig_bits_fast,
|
||||
==, result_type::value );
|
||||
}
|
||||
|
||||
// Check the bit-masks of a block of low-valued bits, zero block-length
|
||||
BOOST_AUTO_TEST_CASE( special_low_bits_mask_test )
|
||||
{
|
||||
// Just like "low_bits_mask_test" above, except that the shifts are negative
|
||||
// when the bit-count is zero. That causes a lot of warnings and errors, so
|
||||
// special-case that bit-count.
|
||||
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<0u>::sig_bits, ==, 0 );
|
||||
BOOST_MPL_ASSERT_RELATION(boost::low_bits_mask_t<0u>::sig_bits_fast, ==, 0);
|
||||
}
|
||||
|
||||
// Check the specialization type status of given bit-offsets/lengths
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( confirm_bounds_test, T, wild_bit_lengths )
|
||||
{
|
||||
typedef boost::integer_hi_mask<T::value> hi_type;
|
||||
typedef boost::mpl::int_<hi_type::bit_offset> hi_offset_type;
|
||||
typedef boost::mpl::bool_<hi_type::is_specialized> special_hi_type;
|
||||
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal_to< hi_offset_type, T >) );
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_hi_type,
|
||||
boost::mpl::bool_<(T::value >= 0) && (T::value < max_offset)> >) );
|
||||
BOOST_CHECK_EQUAL( print_out_template(hi_type(), hi_offset_type::value,
|
||||
"integer_hi_mask"), special_hi_type::value );
|
||||
|
||||
typedef boost::integer_lo_mask<T::value> lo_type;
|
||||
typedef boost::mpl::int_<lo_type::bit_count> lo_length_type;
|
||||
typedef boost::mpl::bool_<lo_type::is_specialized> special_lo_type;
|
||||
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal_to< lo_length_type, T >) );
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_lo_type,
|
||||
boost::mpl::bool_<(T::value >= 0) && (T::value <= max_offset)> >) );
|
||||
BOOST_CHECK_EQUAL( print_out_template(lo_type(), lo_length_type::value,
|
||||
"integer_lo_mask"), special_lo_type::value );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
// Verification of bugs and their fixes
|
||||
BOOST_AUTO_TEST_SUITE( bug_fix_tests )
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
685
test/integer_test.cpp
Normal file
685
test/integer_test.cpp
Normal file
@ -0,0 +1,685 @@
|
||||
// boost integer.hpp test program ------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 1999. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
|
||||
// based integer templates. (Daryle Walker)
|
||||
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
|
||||
// processor-optimized integer template. (Daryle Walker)
|
||||
// 14 Jul 08 Improved testing of processor-optimized integer template; added
|
||||
// extended-integer support. (Daryle Walker)
|
||||
// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker)
|
||||
// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker)
|
||||
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
|
||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||
// 31 Aug 99 Initial version
|
||||
|
||||
#define BOOST_TEST_MODULE "Integer size-selection tests"
|
||||
|
||||
#include <boost/test/unit_test.hpp> // unit testing framework
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_SFINAE
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
|
||||
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t, etc.
|
||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // BOOST_HAS_XINT, BOOST_UXINT_MAX
|
||||
|
||||
#include <boost/mpl/arithmetic.hpp> // for boost::mpl::plus, divides
|
||||
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION, etc.
|
||||
#include <boost/mpl/back.hpp> // for boost::mpl::back
|
||||
#include <boost/mpl/copy.hpp> // for boost::mpl::copy
|
||||
#include <boost/mpl/equal.hpp> // for boost::mpl::equal
|
||||
#include <boost/mpl/front_inserter.hpp> // for boost::mpl::front_inserter
|
||||
#include <boost/mpl/int.hpp> // for boost::mpl::int_
|
||||
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
|
||||
#include <boost/mpl/joint_view.hpp> // for boost::mpl::joint_view
|
||||
#include <boost/mpl/pop_back.hpp> // for boost::mpl::pop_back
|
||||
#include <boost/mpl/push_back.hpp> // for boost::mpl::push_back
|
||||
#include <boost/mpl/push_front.hpp> // for boost::mpl::push_front
|
||||
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
|
||||
#include <boost/mpl/shift_right.hpp> // for boost::mpl::shift_right
|
||||
#include <boost/mpl/sort.hpp> // for boost::mpl::sort
|
||||
#include <boost/mpl/transform.hpp> // for boost::mpl::transform
|
||||
#include <boost/mpl/transform_view.hpp> // for boost::mpl::transform_view
|
||||
#include <boost/mpl/unpack_args.hpp> // for boost::mpl::unpack_args
|
||||
#include <boost/mpl/vector.hpp> // for boost::mpl::vector
|
||||
#include <boost/mpl/zip_view.hpp> // for boost::mpl::zip_view
|
||||
|
||||
#include <boost/type_traits/is_same.hpp> // for boost::is_same
|
||||
#include <boost/type_traits/make_signed.hpp> // for boost::make_signed
|
||||
|
||||
#include <algorithm> // for std::binary_search
|
||||
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN, etc.
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <iostream> // for std::cout
|
||||
#include <ostream> // for std::endl
|
||||
#include <typeinfo> // for std::type_info
|
||||
|
||||
|
||||
// Control what the "fast" specialization of "short" is
|
||||
#ifndef CONTROL_FAST_SHORT
|
||||
#define CONTROL_FAST_SHORT long
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
// Control if every potential bit-count is used, or only a selection
|
||||
// For me, full counts increase compile time from 90 seconds to 20 minutes!
|
||||
#ifndef CONTROL_FULL_COUNTS
|
||||
#define CONTROL_FULL_COUNTS 1
|
||||
#endif
|
||||
|
||||
|
||||
// If specializations have not already been done, then we can confirm
|
||||
// the effects of the fast types by making a specialization. If there
|
||||
// is a specialization for "short," make sure that CONTROL_FAST_SHORT
|
||||
// is set to a type distinct from "short" and the default implementation.
|
||||
namespace boost
|
||||
{
|
||||
template < >
|
||||
struct fast_integral< short >
|
||||
{
|
||||
typedef CONTROL_FAST_SHORT type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Logging
|
||||
#if CONTROL_SHOW_TYPES
|
||||
#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
|
||||
#else
|
||||
#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
|
||||
#endif
|
||||
|
||||
|
||||
// Custom types/templates, helper functions, and objects
|
||||
namespace
|
||||
{
|
||||
|
||||
// List the built-in integral types, excluding the ones that are strong-typedefs
|
||||
// of a lower type.
|
||||
typedef boost::mpl::vector<
|
||||
unsigned char
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
, unsigned short
|
||||
#endif
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
, unsigned int
|
||||
#endif
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
, unsigned long
|
||||
#endif
|
||||
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
|
||||
, boost::detail::uxint_t
|
||||
#endif
|
||||
> distinct_unsigned_types;
|
||||
|
||||
typedef boost::mpl::transform<
|
||||
distinct_unsigned_types,
|
||||
boost::make_signed< boost::mpl::_1 >
|
||||
>::type distinct_signed_types;
|
||||
|
||||
// List the digit counts for each integral type
|
||||
template < typename T >
|
||||
struct digits_of
|
||||
: boost::mpl::int_< std::numeric_limits<T>::digits >
|
||||
{
|
||||
};
|
||||
|
||||
typedef boost::mpl::transform<
|
||||
distinct_unsigned_types,
|
||||
digits_of< boost::mpl::_1 >
|
||||
>::type distinct_integral_bit_counts;
|
||||
|
||||
// Make list of bit counts between each offical point, plus CHAR_BIT/2
|
||||
typedef boost::mpl::transform_view<
|
||||
boost::mpl::zip_view<
|
||||
boost::mpl::vector<
|
||||
boost::mpl::push_front<
|
||||
boost::mpl::pop_back< distinct_integral_bit_counts >::type,
|
||||
boost::mpl::integral_c< int, 0 >
|
||||
>::type,
|
||||
distinct_integral_bit_counts
|
||||
>
|
||||
>,
|
||||
boost::mpl::unpack_args<
|
||||
boost::mpl::divides<
|
||||
boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >,
|
||||
boost::mpl::integral_c< int, 2 >
|
||||
>
|
||||
>
|
||||
> median_bit_counts;
|
||||
|
||||
// Maximum number of bits allowed
|
||||
typedef std::numeric_limits<boost:: intmax_t> intmax_limits;
|
||||
typedef std::numeric_limits<boost::uintmax_t> uintmax_limits;
|
||||
|
||||
int const intmax_bits = intmax_limits::digits + 1;
|
||||
int const uintmax_bits = uintmax_limits::digits;
|
||||
|
||||
// Make master lists including an outlier beyond all valid bit counts
|
||||
#if CONTROL_FULL_COUNTS
|
||||
typedef boost::mpl::range_c<int, 0, uintmax_bits + 2> bits_list;
|
||||
#else
|
||||
typedef boost::mpl::sort<
|
||||
boost::mpl::copy<
|
||||
boost::mpl::joint_view<
|
||||
distinct_integral_bit_counts,
|
||||
median_bit_counts
|
||||
>,
|
||||
boost::mpl::front_inserter<
|
||||
boost::mpl::vector<
|
||||
boost::mpl::integral_c<int, uintmax_bits + 1>
|
||||
>
|
||||
>
|
||||
>::type
|
||||
>::type bits_list;
|
||||
#endif
|
||||
|
||||
// Remove the outlier when all bits counts must be valid
|
||||
#if CONTROL_FULL_COUNTS
|
||||
typedef boost::mpl::range_c<int, 0, uintmax_bits + 1> valid_bits_list;
|
||||
#else
|
||||
typedef boost::mpl::pop_back<bits_list>::type valid_bits_list;
|
||||
#endif
|
||||
|
||||
// Replace the minimum bit count with one more, so right-shifting by a stored
|
||||
// value doesn't give an invalid result
|
||||
#if CONTROL_FULL_COUNTS
|
||||
typedef boost::mpl::range_c<int, 1, uintmax_bits + 1>
|
||||
valid_to_decrease_bits_list;
|
||||
#else
|
||||
typedef valid_bits_list valid_to_decrease_bits_list;
|
||||
#endif
|
||||
|
||||
// Replace the maximum bit count with one less, so left-shifting by a stored
|
||||
// value doesn't give an invalid result
|
||||
#if CONTROL_FULL_COUNTS
|
||||
typedef boost::mpl::range_c<int, 0, uintmax_bits> valid_to_increase_ubits_list;
|
||||
#else
|
||||
typedef boost::mpl::push_back<
|
||||
boost::mpl::pop_back< valid_bits_list >::type,
|
||||
boost::mpl::integral_c< int, uintmax_bits - 1 >
|
||||
>::type valid_to_increase_ubits_list;
|
||||
#endif
|
||||
|
||||
// Do it again for signed types since they have one-less bit to use for the
|
||||
// mantissa (don't want to shift into the sign bit)
|
||||
#if CONTROL_FULL_COUNTS
|
||||
typedef boost::mpl::range_c<int, 0, intmax_bits - 2>
|
||||
valid_to_increase_sbits_list;
|
||||
#else
|
||||
typedef boost::mpl::push_back<
|
||||
boost::mpl::pop_back< valid_bits_list >::type,
|
||||
boost::mpl::integral_c< int, intmax_bits - 3 >
|
||||
>::type valid_to_increase_sbits_list;
|
||||
#endif
|
||||
|
||||
// List the digit counts for each integral type, this time as an object, an
|
||||
// array working as a sorted list
|
||||
int const integral_bit_lengths[] = {
|
||||
std::numeric_limits< unsigned char >::digits
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
, std::numeric_limits< unsigned short >::digits
|
||||
#endif
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
, std::numeric_limits< unsigned int >::digits
|
||||
#endif
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
, std::numeric_limits< unsigned long >::digits
|
||||
#endif
|
||||
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
|
||||
, std::numeric_limits< boost::detail::uxint_t >::digits
|
||||
#endif
|
||||
};
|
||||
|
||||
std::size_t const integral_type_count = sizeof(integral_bit_lengths) /
|
||||
sizeof(integral_bit_lengths[0]);
|
||||
|
||||
// "Template-typedefs" to reduce two-argument templates to single-argument.
|
||||
// This way, all the MPL-compatible templates have the same form, for below.
|
||||
template < int Bits >
|
||||
struct signed_sized_integral : boost::sized_integral<Bits, signed> {};
|
||||
|
||||
template < int Bits >
|
||||
struct unsigned_sized_integral : boost::sized_integral<Bits, unsigned> {};
|
||||
|
||||
template < int Bits >
|
||||
struct signed_exact_integral : boost::exact_integral<Bits, signed> {};
|
||||
|
||||
template < int Bits >
|
||||
struct unsigned_exact_integral : boost::exact_integral<Bits, unsigned> {};
|
||||
|
||||
// Use SFINAE to check if a particular parameter is supported
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
|
||||
bool
|
||||
print_out_template( Tmpl<Value> const &, ValueT setting, char const
|
||||
*template_pre_name, char const *template_post_name, typename Tmpl<Value>::type
|
||||
*unused = 0 )
|
||||
{
|
||||
// Too bad the type-id expression couldn't use the compact form "*unused",
|
||||
// but type-ids of dereferenced null pointers throw by order of C++ 2003,
|
||||
// sect. 5.2.8, para. 2 (although the result is not conceptually needed).
|
||||
PRIVATE_SHOW_MESSAGE( "This is " << template_pre_name << setting
|
||||
<< template_post_name << " specialization, with type '" << typeid(typename
|
||||
Tmpl<Value>::type).name() << "'." );
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename ValueT, typename T >
|
||||
bool
|
||||
print_out_template( T const &, ValueT setting, char const *template_pre_name,
|
||||
char const *template_post_name )
|
||||
{
|
||||
PRIVATE_SHOW_MESSAGE( "Looking for " << template_pre_name << setting
|
||||
<< template_post_name << " specialization? It doesn't exist." );
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error"
|
||||
#endif
|
||||
|
||||
// Get the extreme values for each integral type
|
||||
template < typename T >
|
||||
struct minimum_of
|
||||
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_min >
|
||||
{
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct maximum_of
|
||||
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_max >
|
||||
{
|
||||
};
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
// Check the processor-optimzed type system
|
||||
BOOST_AUTO_TEST_SUITE( optimized_type_tests )
|
||||
|
||||
// Check the optimzed type override of a given type
|
||||
BOOST_AUTO_TEST_CASE( fast_type_test )
|
||||
{
|
||||
typedef short least_type;
|
||||
typedef boost::int_fast_t<least_type>::fast fast_type;
|
||||
typedef std::numeric_limits<least_type> least_limits;
|
||||
typedef std::numeric_limits<fast_type> fast_limits;
|
||||
|
||||
typedef boost::fast_integral<least_type>::type real_fast_type;
|
||||
|
||||
BOOST_MPL_ASSERT_RELATION( (boost::is_same<least_type, fast_type>::value),
|
||||
==, false );
|
||||
BOOST_MPL_ASSERT_RELATION( (boost::is_same<fast_type,
|
||||
real_fast_type>::value), ==, true );
|
||||
BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true );
|
||||
BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed &&
|
||||
fast_limits::is_bounded, ==, true );
|
||||
BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 );
|
||||
BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
// Check if given types can support given size parameters
|
||||
BOOST_AUTO_TEST_SUITE( show_type_tests )
|
||||
|
||||
// Check the specialization type status of given bit lengths, minimum
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral<T::value>(),
|
||||
T::value, "a sized_integral<", ", signed>"), T::value && (T::value <=
|
||||
intmax_bits) );
|
||||
BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral<T::value>(),
|
||||
T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits );
|
||||
}
|
||||
|
||||
// Check the classic specialization type status of given bit lengths, minimum,
|
||||
// unsigned
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T,
|
||||
valid_bits_list )
|
||||
{
|
||||
// This test is supposed to replace the following printouts given in
|
||||
// puesdo-code by:
|
||||
// Routine: Template, Type
|
||||
// for N := 32 downto 0
|
||||
// cout << "Type '" << Template << "<" N << ">::" << Type << "' is '"
|
||||
// << typeid(Template<N>::Type).name << ".'\n"
|
||||
// end for
|
||||
// end Routine
|
||||
// with Template = {int_t, uint_t}; Type = {least, fast}
|
||||
// But now we'll use template meta-programming instead of macros. The limit
|
||||
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||
// have to take selected values. The only interesting part is if the bit
|
||||
// count is too large, and we can't check that yet.
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::uint_t<T::value>::least>::digits, >=, T::value );
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::uint_t<T::value>::fast>::digits, >=, T::value );
|
||||
}
|
||||
|
||||
// Check the classic specialization type status of given bit lengths, minimum,
|
||||
// signed
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T,
|
||||
valid_to_decrease_bits_list )
|
||||
{
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::int_t<T::value>::least>::digits, >=, T::value - 1 );
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::int_t<T::value>::fast>::digits, >=, T::value - 1 );
|
||||
}
|
||||
|
||||
// Check size comparisons of given value support, unsigned
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T,
|
||||
valid_to_increase_ubits_list )
|
||||
{
|
||||
// This test is supposed to replace the following printouts given in
|
||||
// puesdo-code by:
|
||||
// Routine: Type
|
||||
// for N := 30 downto 0
|
||||
// cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type
|
||||
// << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n"
|
||||
// end for
|
||||
// end Routine
|
||||
// with Type = {least, fast}
|
||||
// But now we'll use template meta-programming instead of macros. The limit
|
||||
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||
// have to take selected values. The interesting parts are where N is the
|
||||
// length of a integral type, so 1 << N would have to fit in the next larger
|
||||
// type. (This is why N can't be more than bitlength(uintmax_t) - 1.)
|
||||
boost::uintmax_t const one = 1u;
|
||||
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one
|
||||
<< T::value)>, unsigned_sized_integral<T::value + 1> >) );
|
||||
}
|
||||
|
||||
// Check size comparisons of given value support, signed
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T,
|
||||
valid_to_increase_sbits_list )
|
||||
{
|
||||
// This test is supposed to replace the following printouts given in
|
||||
// puesdo-code by:
|
||||
// Routine: Type
|
||||
// for N := 30 downto 0
|
||||
// cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" <<
|
||||
// Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name
|
||||
// << ".'\n"
|
||||
// cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" <<
|
||||
// Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name
|
||||
// << ".'\n"
|
||||
// end for
|
||||
// end Routine
|
||||
// with Type = {least, fast}
|
||||
// But now we'll use template meta-programming instead of macros. The limit
|
||||
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||
// have to take selected values. The interesting parts are where N is the
|
||||
// length of a integral type, so 1 << N would have to fit in the next larger
|
||||
// type. (This is why N can't be more than bitlength(intmax_t) - 1. Note
|
||||
// that bitlength(intmax_t) + 1 == bitlength(uintmax_t).)
|
||||
static boost::intmax_t const one = 1;
|
||||
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one
|
||||
<< T::value)>, signed_sized_integral<T::value + 1> >) );
|
||||
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one
|
||||
<< T::value)>, signed_sized_integral<T::value + 1> >) );
|
||||
}
|
||||
|
||||
// Check the specialization type status of given bit lengths, exact only
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list )
|
||||
{
|
||||
bool const is_exact_length = std::binary_search( integral_bit_lengths,
|
||||
integral_bit_lengths + integral_type_count, T::value );
|
||||
|
||||
BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral<T::value>(),
|
||||
T::value, "an exact_integral<", ", signed>"), is_exact_length );
|
||||
BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral<T::value>(),
|
||||
T::value, "an exact_integral<", ", unsigned>"), is_exact_length );
|
||||
}
|
||||
|
||||
// Check the classic specialization type status of given bit lengths, exact only
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T,
|
||||
distinct_integral_bit_counts )
|
||||
{
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::int_exact_t<T::value>::exact>::digits, ==, T::value - 1 );
|
||||
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||
boost::uint_exact_t<T::value>::exact>::digits, ==, T::value );
|
||||
}
|
||||
|
||||
// Check if MPL-compatible templates give bad returns for out-of-range values
|
||||
BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test )
|
||||
{
|
||||
typedef signed_sized_integral< 3> ssz3_type;
|
||||
typedef signed_sized_integral< 0> ssz0_type;
|
||||
typedef signed_sized_integral<-3> ssz3n_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count,
|
||||
"a sized_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count,
|
||||
"a sized_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count,
|
||||
"a sized_integral<", ", signed>") );
|
||||
|
||||
typedef unsigned_sized_integral< 3> usz3_type;
|
||||
typedef unsigned_sized_integral< 0> usz0_type;
|
||||
typedef unsigned_sized_integral<-3> usz3n_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count,
|
||||
"a sized_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count,
|
||||
"a sized_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count,
|
||||
"a sized_integral<", ", unsigned>") );
|
||||
|
||||
typedef signed_exact_integral< CHAR_BIT > se8_type;
|
||||
typedef signed_exact_integral< 3> se3_type;
|
||||
typedef signed_exact_integral< 0> se0_type;
|
||||
typedef signed_exact_integral<-3> se3n_type;
|
||||
typedef signed_exact_integral< - CHAR_BIT > se8n_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count,
|
||||
"an exact_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count,
|
||||
"an exact_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count,
|
||||
"an exact_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count,
|
||||
"an exact_integral<", ", signed>") );
|
||||
BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count,
|
||||
"an exact_integral<", ", signed>") );
|
||||
|
||||
typedef unsigned_exact_integral< CHAR_BIT > ue8_type;
|
||||
typedef unsigned_exact_integral< 3> ue3_type;
|
||||
typedef unsigned_exact_integral< 0> ue0_type;
|
||||
typedef unsigned_exact_integral<-3> ue3n_type;
|
||||
typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count,
|
||||
"an exact_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count,
|
||||
"an exact_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count,
|
||||
"an exact_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count,
|
||||
"an exact_integral<", ", unsigned>") );
|
||||
BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count,
|
||||
"an exact_integral<", ", unsigned>") );
|
||||
|
||||
typedef boost::maximum_signed_integral< 15> max15_type;
|
||||
typedef boost::maximum_signed_integral< 0> max0_type;
|
||||
typedef boost::maximum_signed_integral<-15> max15n_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(max15_type(), max15_type::bound,
|
||||
"a maximum_signed_integral<", ">") );
|
||||
BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound,
|
||||
"a maximum_signed_integral<", ">") );
|
||||
BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound,
|
||||
"a maximum_signed_integral<", ">") );
|
||||
|
||||
typedef boost::minimum_signed_integral< 15> min15_type;
|
||||
typedef boost::minimum_signed_integral< 0> min0_type;
|
||||
typedef boost::minimum_signed_integral<-15> min15n_type;
|
||||
|
||||
BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound,
|
||||
"a minimum_signed_integral<", ">") );
|
||||
BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound,
|
||||
"a minimum_signed_integral<", ">") );
|
||||
BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound,
|
||||
"a minimum_signed_integral<", ">") );
|
||||
|
||||
typedef boost::maximum_unsigned_integral<15> umax15_type;
|
||||
typedef boost::maximum_unsigned_integral< 0> umax0_type;
|
||||
|
||||
BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound,
|
||||
"a maximum_unsigned_integral<", ">") );
|
||||
BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound,
|
||||
"a maximum_unsigned_integral<", ">") );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
// Check if given constants can fit in given types
|
||||
BOOST_AUTO_TEST_SUITE( fit_type_tests )
|
||||
|
||||
// Check if large value can fit its minimum required size, by size
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
|
||||
valid_to_decrease_bits_list )
|
||||
{
|
||||
// This test is supposed to replace the following checks given in
|
||||
// puesdo-code by:
|
||||
// Routine: Template, Type
|
||||
// for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 )
|
||||
// Confirm( static_cast<typename Template<N>::Type>(V) == V );
|
||||
// end for
|
||||
// end Routine
|
||||
// with Template = {int_t, uint_t}; Type = {least, fast};
|
||||
// Template:Max = { intmax_t.Max for int_t, uintmax_t.Max for uint_t }
|
||||
// In other words, the selected type doesn't mask out any bits it's not
|
||||
// supposed to. But now we'll use template meta-programming instead of
|
||||
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||
// 64) elements, so we have to take selected values.
|
||||
static int const count = T::value;
|
||||
int const shift = uintmax_bits - count;
|
||||
boost::uintmax_t const value_u = uintmax_limits::max
|
||||
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
|
||||
boost::intmax_t const value_s = intmax_limits::max
|
||||
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
unsigned_sized_integral<count>::type>(value_u), value_u );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::uint_t<count>::least>(value_u), value_u );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::uint_t<count>::fast>(value_u), value_u );
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
signed_sized_integral<count>::type>(value_s), value_s );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_t<count>::least>(value_s), value_s );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_t<count>::fast>(value_s), value_s );
|
||||
}
|
||||
|
||||
// Check if a large value can only fit of its exact bit length
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T,
|
||||
distinct_integral_bit_counts )
|
||||
{
|
||||
typename boost::exact_integral<T::value, unsigned>::type const one_u( 1u ),
|
||||
high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) |
|
||||
high_bit_u );
|
||||
|
||||
BOOST_CHECK( high_bit_u );
|
||||
BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u );
|
||||
|
||||
typename boost::exact_integral<T::value, signed>::type const one_s( 1 ),
|
||||
high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) |
|
||||
high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s );
|
||||
|
||||
BOOST_CHECK( high_bit_s > 0 );
|
||||
BOOST_CHECK( repeated_bits_s < 0 );
|
||||
BOOST_CHECK_EQUAL( repeated_bits_s, repeated_2bits_s );
|
||||
}
|
||||
|
||||
// Check if large value can fit its minimum required size, by value, unsigned
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T,
|
||||
valid_to_increase_ubits_list )
|
||||
{
|
||||
// This test is supposed to replace the following checks given in
|
||||
// puesdo-code by:
|
||||
// Routine: Template, Type
|
||||
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
|
||||
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
|
||||
// end for
|
||||
// end Routine
|
||||
// with Template = {uint_value_t}; Type = {least, fast}; Template:Extreme =
|
||||
// {uintmax_t.Max for uint_value_t}
|
||||
// In other words, the selected type doesn't mask out any bits it's not
|
||||
// supposed to. But now we'll use template meta-programming instead of
|
||||
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||
// 64) elements, so we have to take selected values.
|
||||
using boost::uintmax_t;
|
||||
|
||||
typedef boost::mpl::shift_right<maximum_of<uintmax_t>, T> maxi_type;
|
||||
|
||||
uintmax_t const maxi = maxi_type::value;
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::uint_value_t<maxi_type::value>::least>(maxi), maxi );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::uint_value_t<maxi_type::value>::fast>(maxi), maxi );
|
||||
}
|
||||
|
||||
// Check if large value can fit its minimum required size, by value, signed
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T,
|
||||
valid_to_increase_sbits_list )
|
||||
{
|
||||
// This test is supposed to replace the following checks given in
|
||||
// puesdo-code by:
|
||||
// Routine: Template, Type
|
||||
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
|
||||
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
|
||||
// end for
|
||||
// end Routine
|
||||
// with Template = {int_max_value_t, int_min_value_t}; Type = {least, fast};
|
||||
// Template:Extreme = {intmax_t.Min for int_min_value_t, intmax_t.Max
|
||||
// for int_max_value_t}
|
||||
// In other words, the selected type doesn't mask out any bits it's not
|
||||
// supposed to. But now we'll use template meta-programming instead of
|
||||
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||
// 64) elements, so we have to take selected values.
|
||||
using boost::intmax_t;
|
||||
|
||||
typedef boost::mpl::shift_right<minimum_of<intmax_t>, T> mini_type;
|
||||
typedef boost::mpl::shift_right<maximum_of<intmax_t>, T> maxi_type;
|
||||
|
||||
intmax_t const maxi = maxi_type::value, mini = mini_type::value;
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_max_value_t<maxi_type::value>::least>(maxi), maxi );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_max_value_t<maxi_type::value>::fast>(maxi), maxi );
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_min_value_t<mini_type::value>::least>(mini), mini );
|
||||
BOOST_CHECK_EQUAL( static_cast<typename
|
||||
boost::int_min_value_t<mini_type::value>::fast>(mini), mini );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
// Verification of bugs and their fixes
|
||||
BOOST_AUTO_TEST_SUITE( bug_fix_tests )
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
102
test/integer_traits_test.cpp
Normal file
102
test/integer_traits_test.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/* boost integer_traits.hpp tests
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Revision history
|
||||
* 2000-02-22 Small improvements by Beman Dawes
|
||||
* 2000-06-27 Rework for better MSVC and BCC co-operation
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/integer_traits.hpp>
|
||||
// use int64_t instead of long long for better portability
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
* MSVC mis-compiles explicit function template instantiations.
|
||||
* For example, f<A>() and f<B>() are both compiled to call f<A>().
|
||||
* BCC is unable to implicitly convert a "const char *" to a std::string
|
||||
* when using 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; }
|
||||
inline int make_char_numeric_for_streaming(char c) { return c; }
|
||||
inline int make_char_numeric_for_streaming(signed char c) { return c; }
|
||||
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
void runtest(const char * type, T)
|
||||
{
|
||||
typedef boost::integer_traits<T> traits;
|
||||
std::cout << "Checking " << type
|
||||
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
|
||||
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
|
||||
<< std::endl;
|
||||
BOOST_CHECK(traits::is_specialized);
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
|
||||
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
|
||||
// generates different symbol names with a very long common prefix:
|
||||
// the dummy "&& true" disambiguates between the symbols generated by this
|
||||
// BOOST_CHECK instantiation and the preceding one.
|
||||
BOOST_CHECK(traits::is_integer && true);
|
||||
#else
|
||||
BOOST_CHECK(traits::is_integer);
|
||||
#endif
|
||||
BOOST_CHECK(traits::is_integral == true);
|
||||
BOOST_CHECK(traits::const_min == (traits::min)());
|
||||
BOOST_CHECK(traits::const_max == (traits::max)());
|
||||
}
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
runtest("bool", bool());
|
||||
runtest("char", char());
|
||||
typedef signed char signed_char;
|
||||
runtest("signed char", signed_char());
|
||||
typedef unsigned char unsigned_char;
|
||||
runtest("unsigned char", unsigned_char());
|
||||
runtest("wchar_t", wchar_t());
|
||||
runtest("short", short());
|
||||
typedef unsigned short unsigned_short;
|
||||
runtest("unsigned short", unsigned_short());
|
||||
runtest("int", int());
|
||||
typedef unsigned int unsigned_int;
|
||||
runtest("unsigned int", unsigned_int());
|
||||
runtest("long", long());
|
||||
typedef 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__)
|
||||
//
|
||||
// MS/Borland compilers can't support 64-bit member constants
|
||||
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
||||
runtest("int64_t (possibly long long)", boost::int64_t());
|
||||
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
|
||||
#else
|
||||
std::cout << "Skipped int64_t and uint64_t" << std::endl;
|
||||
#endif
|
||||
// Some compilers don't pay attention to std:3.6.1/5 and issue a
|
||||
// warning here if "return 0;" is omitted.
|
||||
return 0;
|
||||
}
|
||||
|
33
test/issue_2134.cpp
Normal file
33
test/issue_2134.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// boost Issue #2134 test program ------------------------------------------//
|
||||
|
||||
// Copyright Daryle Walker 2008. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See the accompanying file
|
||||
// LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
// See <http://www.boost.org/libs/integer> for documentation.
|
||||
// See <http://svn.boost.org/trac/boost/ticket/2134> for the issue involved.
|
||||
|
||||
// Revision History
|
||||
// 23 Jul 2008 Initial version
|
||||
|
||||
// Control if the inclusion error is triggered
|
||||
#ifndef CONTROL_INCLUDE_TRAITS
|
||||
#define CONTROL_INCLUDE_TRAITS 1
|
||||
#endif
|
||||
|
||||
#if CONTROL_INCLUDE_TRAITS
|
||||
// This file defines boost::detail::integer_traits.
|
||||
#include <boost/detail/numeric_traits.hpp>
|
||||
#endif
|
||||
|
||||
// This is the file with the issue. It has items within the boost::detail
|
||||
// namespace that referenced an unadorned "integer_traits". This was meant to
|
||||
// refer to boost::integer_traits. However, <boost/detail/numeric_traits.hpp>
|
||||
// defines a boost::detail::integer_traits. If that header is #included before
|
||||
// this one, then b.d.integer_traits (rightfully) took priority, which lead to a
|
||||
// syntax error.
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
|
||||
// Main program, minimal (since this is a compile test)
|
||||
int main() { return 0; }
|
150
test/static_log2_test.cpp
Normal file
150
test/static_log2_test.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
// Boost static_log2.hpp test program --------------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 01 Oct 2001 Initial version (Daryle Walker)
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp> // for main
|
||||
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/integer/static_log2.hpp> // for boost::static_log2
|
||||
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
|
||||
|
||||
// Macros to compact code
|
||||
#define PRIVATE_LB_TEST( v, e ) BOOST_CHECK( ::boost::static_log2<v>::value == e )
|
||||
|
||||
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
|
||||
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
|
||||
|
||||
// Control to check for a compile-time error
|
||||
#ifndef CONTROL_LB_0_TEST
|
||||
#define PRIVATE_LB_0_TEST
|
||||
#else
|
||||
#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 )
|
||||
#endif
|
||||
|
||||
|
||||
// Main testing function
|
||||
int
|
||||
test_main
|
||||
(
|
||||
int , // "argc" is unused
|
||||
char * [] // "argv" is unused
|
||||
)
|
||||
{
|
||||
std::cout << "Doing tests on static_log2." << std::endl;
|
||||
|
||||
PRIVATE_LB_0_TEST;
|
||||
|
||||
PRIVATE_LB_TEST( 1, 0 );
|
||||
|
||||
PRIVATE_LB_TEST( 2, 1 );
|
||||
PRIVATE_LB_TEST( 3, 1 );
|
||||
|
||||
PRIVATE_LB_TEST( 4, 2 );
|
||||
PRIVATE_LB_TEST( 5, 2 );
|
||||
PRIVATE_LB_TEST( 6, 2 );
|
||||
PRIVATE_LB_TEST( 7, 2 );
|
||||
|
||||
PRIVATE_LB_TEST( 8, 3 );
|
||||
PRIVATE_LB_TEST( 9, 3 );
|
||||
PRIVATE_LB_TEST( 10, 3 );
|
||||
PRIVATE_LB_TEST( 11, 3 );
|
||||
PRIVATE_LB_TEST( 12, 3 );
|
||||
PRIVATE_LB_TEST( 13, 3 );
|
||||
PRIVATE_LB_TEST( 14, 3 );
|
||||
PRIVATE_LB_TEST( 15, 3 );
|
||||
|
||||
PRIVATE_LB_TEST( 16, 4 );
|
||||
PRIVATE_LB_TEST( 17, 4 );
|
||||
PRIVATE_LB_TEST( 18, 4 );
|
||||
PRIVATE_LB_TEST( 19, 4 );
|
||||
PRIVATE_LB_TEST( 20, 4 );
|
||||
PRIVATE_LB_TEST( 21, 4 );
|
||||
PRIVATE_LB_TEST( 22, 4 );
|
||||
PRIVATE_LB_TEST( 23, 4 );
|
||||
PRIVATE_LB_TEST( 24, 4 );
|
||||
PRIVATE_LB_TEST( 25, 4 );
|
||||
PRIVATE_LB_TEST( 26, 4 );
|
||||
PRIVATE_LB_TEST( 27, 4 );
|
||||
PRIVATE_LB_TEST( 28, 4 );
|
||||
PRIVATE_LB_TEST( 29, 4 );
|
||||
PRIVATE_LB_TEST( 30, 4 );
|
||||
PRIVATE_LB_TEST( 31, 4 );
|
||||
|
||||
PRIVATE_LB_TEST( 32, 5 );
|
||||
PRIVATE_LB_TEST( 33, 5 );
|
||||
PRIVATE_LB_TEST( 34, 5 );
|
||||
PRIVATE_LB_TEST( 35, 5 );
|
||||
PRIVATE_LB_TEST( 36, 5 );
|
||||
PRIVATE_LB_TEST( 37, 5 );
|
||||
PRIVATE_LB_TEST( 38, 5 );
|
||||
PRIVATE_LB_TEST( 39, 5 );
|
||||
PRIVATE_LB_TEST( 40, 5 );
|
||||
|
||||
PRIVATE_LB_TEST( 63, 5 );
|
||||
|
||||
PRIVATE_LB_TEST( 64, 6 );
|
||||
PRIVATE_LB_TEST( 65, 6 );
|
||||
|
||||
PRIVATE_LB_TEST( 127, 6 );
|
||||
|
||||
PRIVATE_LB_TEST( 128, 7 );
|
||||
PRIVATE_LB_TEST( 129, 7 );
|
||||
|
||||
PRIVATE_LB_TEST( 255, 7 );
|
||||
|
||||
PRIVATE_LB_TEST( 256, 8 );
|
||||
PRIVATE_LB_TEST( 257, 8 );
|
||||
|
||||
PRIVATE_LB_TEST( 511, 8 );
|
||||
|
||||
PRIVATE_LB_TEST( 512, 9 );
|
||||
PRIVATE_LB_TEST( 513, 9 );
|
||||
|
||||
PRIVATE_LB_TEST( 1023, 9 );
|
||||
|
||||
PRIVATE_LB_TEST( 1024, 10 );
|
||||
PRIVATE_LB_TEST( 1025, 10 );
|
||||
|
||||
PRIVATE_LB_TEST( 2047, 10 );
|
||||
|
||||
PRIVATE_LB_TEST( 2048, 11 );
|
||||
PRIVATE_LB_TEST( 2049, 11 );
|
||||
|
||||
PRIVATE_LB_TEST( 4095, 11 );
|
||||
|
||||
PRIVATE_LB_TEST( 4096, 12 );
|
||||
PRIVATE_LB_TEST( 4097, 12 );
|
||||
|
||||
PRIVATE_LB_TEST( 8191, 12 );
|
||||
|
||||
PRIVATE_LB_TEST( 8192, 13 );
|
||||
PRIVATE_LB_TEST( 8193, 13 );
|
||||
|
||||
PRIVATE_LB_TEST( 16383, 13 );
|
||||
|
||||
PRIVATE_LB_TEST( 16384, 14 );
|
||||
PRIVATE_LB_TEST( 16385, 14 );
|
||||
|
||||
PRIVATE_LB_TEST( 32767, 14 );
|
||||
|
||||
PRIVATE_LB_TEST( 32768, 15 );
|
||||
PRIVATE_LB_TEST( 32769, 15 );
|
||||
|
||||
PRIVATE_LB_TEST( 65535, 15 );
|
||||
|
||||
PRIVATE_LB_TEST( 65536, 16 );
|
||||
PRIVATE_LB_TEST( 65537, 16 );
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
93
test/static_min_max_test.cpp
Normal file
93
test/static_min_max_test.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
// Boost static_min_max.hpp test program -----------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 23 Sep 2001 Initial version (Daryle Walker)
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp> // for main, BOOST_CHECK
|
||||
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
|
||||
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
|
||||
|
||||
// Main testing function
|
||||
int
|
||||
test_main
|
||||
(
|
||||
int , // "argc" is unused
|
||||
char * [] // "argv" is unused
|
||||
)
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using boost::static_signed_min;
|
||||
using boost::static_signed_max;
|
||||
using boost::static_unsigned_min;
|
||||
using boost::static_unsigned_max;
|
||||
|
||||
// Two positives
|
||||
cout << "Doing tests with two positive values." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min< 9, 14>::value) == 9 );
|
||||
BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_min<14, 9>::value) == 9 );
|
||||
BOOST_CHECK( (static_signed_max<14, 9>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_unsigned_min< 9, 14>::value) == 9 );
|
||||
BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 9>::value) == 9 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 9>::value) == 14 );
|
||||
|
||||
// Two negatives
|
||||
cout << "Doing tests with two negative values." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min< -8, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< -8, -101>::value) == -8 );
|
||||
BOOST_CHECK( (static_signed_min<-101, -8>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max<-101, -8>::value) == -8 );
|
||||
|
||||
// With zero
|
||||
cout << "Doing tests with zero and a positive or negative value." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min< 0, 14>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_min<14, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max<14, 0>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_unsigned_min< 0, 14>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 0>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min< 0, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< 0, -101>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_min<-101, 0>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max<-101, 0>::value) == 0 );
|
||||
|
||||
// With identical
|
||||
cout << "Doing tests with two identical values." << endl;
|
||||
|
||||
BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 );
|
||||
BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 );
|
||||
BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 );
|
||||
|
||||
BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 );
|
||||
BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 );
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
Reference in New Issue
Block a user