forked from boostorg/integer
Compare commits
12 Commits
master
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
229056d7bc | |||
648ff2fe0c | |||
85e4d3e23d | |||
550fe9d89f | |||
19ed0e48e0 | |||
559b44c259 | |||
b162db6b72 | |||
f17447cd24 | |||
4935afbcd4 | |||
167961aba1 | |||
7ce7ba6bfd | |||
c8cb2b24a1 |
@ -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="test/cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
<p>See <a href="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
|
||||
|
233
cstdint_test.cpp
Normal file
233
cstdint_test.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// 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/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>
|
||||
|
||||
#ifdef NDEBUG
|
||||
int main()
|
||||
{
|
||||
std::cout << "This test makes no sense with NDEBUG defined.\n";
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
// the following class is designed to verify
|
||||
// that the various INTXX_C macros can be used
|
||||
// in integral constant expressions:
|
||||
//
|
||||
struct integral_constant_checker
|
||||
{
|
||||
static const boost::int8_t int8 = INT8_C(-127);
|
||||
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
static const boost::int16_t int16 = INT16_C(-32767);
|
||||
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
static void check();
|
||||
};
|
||||
|
||||
void integral_constant_checker::check()
|
||||
{
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
}
|
||||
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
//
|
||||
// the following function simply verifies that the type
|
||||
// of an integral constant is correctly defined:
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option -w-8008
|
||||
#pragma option -w-8066
|
||||
#endif
|
||||
template <class T1, class T2>
|
||||
void integral_constant_type_check(T1, T2)
|
||||
{
|
||||
//
|
||||
// the types T1 and T2 may not be exactly
|
||||
// the same type, but they should be the
|
||||
// same size and signedness. We could use
|
||||
// numeric_limits to verify this, but
|
||||
// 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));
|
||||
assert(t1 == t2);
|
||||
#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));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
integral_constant_checker::check();
|
||||
#endif
|
||||
//
|
||||
// verify the types of the integral constants:
|
||||
//
|
||||
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||
#endif
|
||||
//
|
||||
boost::int8_t int8 = INT8_C(-127);
|
||||
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
boost::uint8_t uint8 = UINT8_C(255);
|
||||
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
boost::int16_t int16 = INT16_C(-32767);
|
||||
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
boost::uint16_t uint16 = UINT16_C(65535);
|
||||
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
boost::int32_t int32 = INT32_C(-2147483647);
|
||||
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||
|
||||
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||
|
||||
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||
#else
|
||||
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||
#endif
|
||||
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
assert( int64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_least64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_fast64 == INT64_C(-9223372036854775807) );
|
||||
assert( uint64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_least64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||
assert( intmax == INT64_C(-9223372036854775807) );
|
||||
assert( uintmax == UINT64_C(18446744073709551615) );
|
||||
#else
|
||||
assert( intmax == -2147483647 );
|
||||
assert( uintmax == 4294967295u );
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -8,11 +8,7 @@
|
||||
<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>
|
||||
<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>
|
||||
|
||||
@ -21,7 +17,6 @@ href="../integer.htm">integer type selection templates</a> header.</p>
|
||||
<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>
|
||||
@ -31,68 +26,39 @@ href="../integer.htm">integer type selection templates</a> header.</p>
|
||||
<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>
|
||||
#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
|
||||
struct high_bit_mask_t
|
||||
{
|
||||
public:
|
||||
typedef typename integer_hi_mask<Bit>::value_type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
|
||||
static const least high_bit = integer_hi_mask<Bit>::value;
|
||||
static const fast high_bit_fast = high_bit;
|
||||
static const least high_bit = <em>implementation_defined</em>;
|
||||
static const fast high_bit_fast = <em>implementation_defined</em>;
|
||||
|
||||
static const std::size_t bit_position = Bit;
|
||||
|
||||
};
|
||||
|
||||
// group
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
public:
|
||||
typedef typename integer_lo_mask<Bits>::value_type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
|
||||
static const least sig_bits = integer_lo_mask<Bits>::value;
|
||||
static const fast sig_bits_fast = sig_bits;
|
||||
static const least sig_bits = <em>implementation_defined</em>;
|
||||
static const fast sig_bits_fast = <em>implementation_defined</em>;
|
||||
|
||||
static const std::size_t bit_count = Bits;
|
||||
|
||||
};
|
||||
|
||||
// Specializations for low_bits_mask_t exist for certain bit counts.
|
||||
|
||||
} // namespace boost
|
||||
</pre></blockquote>
|
||||
|
||||
@ -183,149 +149,16 @@ describes the members of an instantiation of
|
||||
</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>
|
||||
<p><strong>Implementation Note</strong><br>
|
||||
When <code>Bits</code> is the exact size of a built-in unsigned type,
|
||||
the implementation has to change to prevent undefined behavior.
|
||||
Therefore, there are specializations of <code>low_bits_mask_t</code> at
|
||||
those bit counts.</p>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <<a href="../../../boost/integer/integer_mask.hpp">boost/integer/integer_mask.hpp</a>>
|
||||
#include <boost/integer/integer_mask.hpp>
|
||||
|
||||
//...
|
||||
|
||||
@ -367,7 +200,7 @@ href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised July 29, 2008</p>
|
||||
<p>Revised September 23, 2001</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
|
@ -7,12 +7,6 @@
|
||||
// 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 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)
|
||||
@ -23,357 +17,108 @@
|
||||
|
||||
#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.
|
||||
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// 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.
|
||||
// Helper templates ------------------------------------------------------//
|
||||
|
||||
// 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 typename fast_integral<LeastInt>::type fast; };
|
||||
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// convert category to type
|
||||
template< int Category > struct int_least_helper {}; // default is empty
|
||||
|
||||
// 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 );
|
||||
};
|
||||
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
|
||||
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
|
||||
// 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; };
|
||||
|
||||
// integer templates specifying number of bits ---------------------------//
|
||||
|
||||
// signed
|
||||
template< int Bits > // minimum bits (including sign) required
|
||||
template< int Bits > // bits (including sign) required
|
||||
struct int_t
|
||||
{
|
||||
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;
|
||||
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;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // minimum bits required
|
||||
template< int Bits > // bits required
|
||||
struct uint_t
|
||||
{
|
||||
typedef typename sized_integral<Bits, unsigned>::type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
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;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
};
|
||||
|
||||
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
|
||||
template< long 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;
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
(MaxValue <= integer_traits<long>::const_max) +
|
||||
(MaxValue <= integer_traits<int>::const_max) +
|
||||
(MaxValue <= integer_traits<short>::const_max) +
|
||||
(MaxValue <= integer_traits<signed char>::const_max)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< intmax_t MinValue > // minimum value to require support
|
||||
template< long 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;
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
(MinValue >= integer_traits<long>::const_min) +
|
||||
(MinValue >= integer_traits<int>::const_min) +
|
||||
(MinValue >= integer_traits<short>::const_min) +
|
||||
(MinValue >= integer_traits<signed char>::const_min)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< uintmax_t Value > // maximum value to require support
|
||||
template< unsigned long 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;
|
||||
typedef typename int_least_helper
|
||||
<
|
||||
5 +
|
||||
(Value <= integer_traits<unsigned long>::const_max) +
|
||||
(Value <= integer_traits<unsigned int>::const_max) +
|
||||
(Value <= integer_traits<unsigned short>::const_max) +
|
||||
(Value <= integer_traits<unsigned char>::const_max)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,192 +12,81 @@
|
||||
|
||||
#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 <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
#include <boost/integer.hpp> // for boost::uint_t
|
||||
|
||||
#include <climits> // for UCHAR_MAX, etc.
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
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
|
||||
struct high_bit_mask_t
|
||||
{
|
||||
typedef integer_hi_mask<Bit> impl_type;
|
||||
typedef typename uint_t<(Bit + 1)>::least least;
|
||||
typedef typename uint_t<(Bit + 1)>::fast fast;
|
||||
|
||||
public:
|
||||
typedef typename impl_type::value_type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
|
||||
BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
|
||||
|
||||
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_STATIC_CONSTANT( std::size_t, bit_position = Bit );
|
||||
|
||||
}; // boost::high_bit_mask_t
|
||||
|
||||
|
||||
// Specified bit-block mask class declaration ------------------------------//
|
||||
// Makes masks for the lowest N bits
|
||||
// (Specializations are needed when N fills up a type.)
|
||||
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
typedef integer_lo_mask<Bits> impl_type;
|
||||
typedef typename uint_t<Bits>::least least;
|
||||
typedef typename uint_t<Bits>::fast fast;
|
||||
|
||||
public:
|
||||
typedef typename impl_type::value_type least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
|
||||
|
||||
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_STATIC_CONSTANT( std::size_t, bit_count = Bits );
|
||||
|
||||
}; // boost::low_bits_mask_t
|
||||
|
||||
|
||||
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
|
||||
template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
|
||||
typedef std::numeric_limits<Type> limits_type; \
|
||||
typedef uint_t<limits_type::digits>::least least; \
|
||||
typedef uint_t<limits_type::digits>::fast fast; \
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
|
||||
}
|
||||
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
|
||||
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
|
||||
#endif
|
||||
|
||||
#undef BOOST_LOW_BITS_MASK_SPECIALIZE
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
@ -9,12 +9,11 @@
|
||||
#ifndef BOOST_INTEGER_FWD_HPP
|
||||
#define BOOST_INTEGER_FWD_HPP
|
||||
|
||||
#include <climits> // for UCHAR_MAX, etc.
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T, etc.
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
|
||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
|
||||
|
||||
namespace boost
|
||||
@ -25,13 +24,6 @@ namespace boost
|
||||
|
||||
// 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> -----------------------------------------//
|
||||
|
||||
@ -73,73 +65,61 @@ template < >
|
||||
template < >
|
||||
class integer_traits< unsigned long >;
|
||||
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
|
||||
#ifdef ULLONG_MAX
|
||||
template < >
|
||||
class integer_traits< ::boost::detail::xint_t >;
|
||||
class integer_traits< ::boost::long_long_type>;
|
||||
|
||||
template < >
|
||||
class integer_traits< ::boost::detail::uxint_t >;
|
||||
class integer_traits< ::boost::ulong_long_type >;
|
||||
#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 >
|
||||
template< long MaxValue >
|
||||
struct int_max_value_t;
|
||||
|
||||
template< intmax_t MinValue >
|
||||
template< long MinValue >
|
||||
struct int_min_value_t;
|
||||
|
||||
template< uintmax_t Value >
|
||||
template< unsigned long 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;
|
||||
struct high_bit_mask_t;
|
||||
|
||||
template < std::size_t Bits >
|
||||
class low_bits_mask_t;
|
||||
struct low_bits_mask_t;
|
||||
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned char>::digits >;
|
||||
|
||||
#if USHRT_MAX > UCHAR_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned short>::digits >;
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > USHRT_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned int>::digits >;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX > UINT_MAX
|
||||
template < >
|
||||
struct low_bits_mask_t< ::std::numeric_limits<unsigned long>::digits >;
|
||||
#endif
|
||||
|
||||
|
||||
// From <boost/integer/static_log2.hpp> ------------------------------------//
|
||||
|
@ -27,8 +27,6 @@
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
|
||||
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
@ -157,18 +155,77 @@ class integer_traits<unsigned long>
|
||||
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
||||
{ };
|
||||
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
|
||||
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits< detail::xint_t >
|
||||
: public std::numeric_limits< detail::xint_t >,
|
||||
public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX >
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< detail::uxint_t >
|
||||
: public std::numeric_limits< detail::uxint_t >,
|
||||
public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX >
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ };
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
|
||||
{ };
|
||||
|
||||
#elif defined(BOOST_HAS_LONG_LONG)
|
||||
//
|
||||
// we have long long but no constants, this happens for example with gcc in -ansi mode,
|
||||
// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
|
||||
//
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
class integer_traits< ::boost::ulong_long_type>
|
||||
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
|
||||
{ };
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
391
integer.htm
391
integer.htm
@ -21,9 +21,8 @@ is particularly useful for solving generic programming problems.</p>
|
||||
<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="#easy">Easiest-to-Manipulate 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>
|
||||
@ -33,145 +32,67 @@ is particularly useful for solving generic programming problems.</p>
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></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
|
||||
|
||||
namespace boost
|
||||
<blockquote><pre>namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
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;
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< int Bits >
|
||||
struct int_t
|
||||
{
|
||||
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;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits >
|
||||
struct uint_t
|
||||
{
|
||||
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;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< intmax_t MaxValue >
|
||||
template< long MaxValue >
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef typename maximum_signed_integral<MaxValue>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< intmax_t MinValue >
|
||||
template< long MinValue >
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef typename minimum_signed_integral<MinValue>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< uintmax_t Value >
|
||||
template< unsigned long Value >
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef typename maximum_unsigned_integral<Value>::type least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
} // namespace boost
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="easy">Processor-Optimized Types</a></h2>
|
||||
<h2><a name="easy">Easiest-to-Manipulate Types</a></h2>
|
||||
|
||||
<p>The <code>fast_integral</code> class template maps its input type to the
|
||||
<p>The <code>int_fast_t</code> class template maps its input type to the
|
||||
next-largest type that the processor can manipulate the easiest, or to
|
||||
itself if the input type is already an easy-to-manipulate type. For
|
||||
instance, processing a bunch of <code>char</code> objects may go faster
|
||||
if they were converted to <code>int</code> objects before processing.
|
||||
The input type, passed as the only template parameter, can be any built-in
|
||||
integral type besides <code>bool</code>. The output type is given as the class
|
||||
member <code>type</code>.</p>
|
||||
|
||||
<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>
|
||||
The input type, passed as the only template parameter, must be a
|
||||
built-in integral type, except <code>bool</code>. Unsigned integral
|
||||
types can be used, as well as signed integral types, despite the name.
|
||||
The output type is given as the class member <code>fast</code>.</p>
|
||||
|
||||
<p><strong>Implementation Notes</strong><br>
|
||||
By default, the output type is identical to the input type. Eventually,
|
||||
@ -183,286 +104,72 @@ type.</p>
|
||||
|
||||
<h2><a name="sized">Sized Types</a></h2>
|
||||
|
||||
<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>
|
||||
<p>The <code>int_t</code>, <code>uint_t</code>,
|
||||
<code>int_max_value_t</code>, <code>int_min_value_t</code>, and
|
||||
<code>uint_value_t</code> class templates find the most appropiate
|
||||
built-in integral type for the given template parameter. This type is
|
||||
given by the class member <code>least</code>. The easiest-to-manipulate
|
||||
version of that type is given by the class member <code>fast</code>.
|
||||
The following table describes each template's criteria.</p>
|
||||
|
||||
<table border="2" cellpadding="5">
|
||||
<table border="1" cellpadding="5">
|
||||
<caption>Criteria for the Sized Type Class Templates</caption>
|
||||
<tr>
|
||||
<th>Class Template (all in name-space <code>boost</code>)</th>
|
||||
<th>Class Template</th>
|
||||
<th>Template Parameter Mapping</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>int_t</code></td>
|
||||
<td><code>boost::int_t</code></td>
|
||||
<td>The smallest built-in signed integral type with at least the
|
||||
given number of bits, including the sign bit. The parameter
|
||||
<em>must</em> be a positive number. A compile-time error results if
|
||||
should 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>
|
||||
<code>long</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><code>boost::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>
|
||||
the given number of bits. The parameter should be a positive
|
||||
number. A compile-time error results if the parameter is
|
||||
larger than the number of bits in an <code>unsigned
|
||||
long</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>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><code>boost::int_max_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a maximum. The parameter <em>must</em> be a
|
||||
given value as a maximum. The parameter should be a
|
||||
positive number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>int_min_value_t</code></td>
|
||||
<td><code>boost::int_min_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a minimum. The parameter <em>must</em> be a
|
||||
given value as a minimum. The parameter should be a
|
||||
negative number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>uint_value_t</code></td>
|
||||
<td><code>boost::uint_value_t</code></td>
|
||||
<td>The smallest built-in unsigned integral type that supports
|
||||
the given value as a maximum. The parameter should be a
|
||||
positive number.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a name="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;
|
||||
}
|
||||
<blockquote><pre>#include <boost/integer.hpp>
|
||||
|
||||
//...
|
||||
|
||||
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;
|
||||
|
||||
boost::int_t<24>::least my_var;
|
||||
//...
|
||||
}
|
||||
</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
|
||||
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a
|
||||
simplistic demonstration of the results from instantiating various
|
||||
examples of the sized type class templates.</p>
|
||||
|
||||
@ -491,11 +198,11 @@ 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>
|
||||
value-based sized templates.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised July 16, 2008</p>
|
||||
<p>Revised May 20, 2001</p>
|
||||
|
||||
<p>© Copyright Beman Dawes 1999. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
|
291
integer_test.cpp
Normal file
291
integer_test.cpp
Normal file
@ -0,0 +1,291 @@
|
||||
// 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
|
||||
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
|
||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||
// 31 Aug 99 Initial version
|
||||
|
||||
#include <boost/test/minimal.hpp> // for main, BOOST_CHECK
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t
|
||||
|
||||
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
#include <typeinfo> // for std::type_info
|
||||
|
||||
|
||||
// Control if the names of the types for each version
|
||||
// of the integer templates will be printed.
|
||||
#ifndef CONTROL_SHOW_TYPES
|
||||
#define CONTROL_SHOW_TYPES 0
|
||||
#endif
|
||||
|
||||
|
||||
// If specializations have not already been done, then we can confirm
|
||||
// the effects of the "fast" types by making a specialization.
|
||||
namespace boost
|
||||
{
|
||||
template < >
|
||||
struct int_fast_t< short >
|
||||
{
|
||||
typedef long fast;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Show the types of an integer template version
|
||||
#if CONTROL_SHOW_TYPES
|
||||
#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \
|
||||
#Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \
|
||||
Number > :: Type).name() << ".\"\n"
|
||||
#else
|
||||
#define SHOW_TYPE(Template, Number, Type)
|
||||
#endif
|
||||
|
||||
#define SHOW_TYPES(Template, Type) SHOW_TYPE(Template, 32, Type); \
|
||||
SHOW_TYPE(Template, 31, Type); SHOW_TYPE(Template, 30, Type); \
|
||||
SHOW_TYPE(Template, 29, Type); SHOW_TYPE(Template, 28, Type); \
|
||||
SHOW_TYPE(Template, 27, Type); SHOW_TYPE(Template, 26, Type); \
|
||||
SHOW_TYPE(Template, 25, Type); SHOW_TYPE(Template, 24, Type); \
|
||||
SHOW_TYPE(Template, 23, Type); SHOW_TYPE(Template, 22, Type); \
|
||||
SHOW_TYPE(Template, 21, Type); SHOW_TYPE(Template, 20, Type); \
|
||||
SHOW_TYPE(Template, 19, Type); SHOW_TYPE(Template, 18, Type); \
|
||||
SHOW_TYPE(Template, 17, Type); SHOW_TYPE(Template, 16, Type); \
|
||||
SHOW_TYPE(Template, 15, Type); SHOW_TYPE(Template, 14, Type); \
|
||||
SHOW_TYPE(Template, 13, Type); SHOW_TYPE(Template, 12, Type); \
|
||||
SHOW_TYPE(Template, 11, Type); SHOW_TYPE(Template, 10, Type); \
|
||||
SHOW_TYPE(Template, 9, Type); SHOW_TYPE(Template, 8, Type); \
|
||||
SHOW_TYPE(Template, 7, Type); SHOW_TYPE(Template, 6, Type); \
|
||||
SHOW_TYPE(Template, 5, Type); SHOW_TYPE(Template, 4, Type); \
|
||||
SHOW_TYPE(Template, 3, Type); SHOW_TYPE(Template, 2, Type); \
|
||||
SHOW_TYPE(Template, 1, Type); SHOW_TYPE(Template, 0, Type)
|
||||
|
||||
#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type)
|
||||
|
||||
#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \
|
||||
SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type)
|
||||
|
||||
#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type)
|
||||
|
||||
#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \
|
||||
SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type)
|
||||
|
||||
#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type)
|
||||
|
||||
#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \
|
||||
SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type)
|
||||
|
||||
|
||||
// Test if a constant can fit within a certain type
|
||||
#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value )
|
||||
|
||||
#if ULONG_MAX > 0xFFFFFFFFL
|
||||
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
||||
#else
|
||||
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
||||
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
||||
#endif
|
||||
|
||||
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (ULONG_MAX >> Number) > :: Type ( Value ) == Value )
|
||||
|
||||
#define PRIVATE_SHIFTED_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
||||
PRIVATE_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
||||
|
||||
#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (LONG_MAX >> Number) > :: Type ( Value ) == Value )
|
||||
|
||||
#define PRIVATE_POS_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
||||
|
||||
#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value )
|
||||
|
||||
#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
||||
|
||||
|
||||
// Test program
|
||||
int
|
||||
test_main
|
||||
(
|
||||
int,
|
||||
char*[]
|
||||
)
|
||||
{
|
||||
#ifndef BOOST_NO_USING_TEMPLATE
|
||||
using boost::int_t;
|
||||
using boost::uint_t;
|
||||
using boost::int_max_value_t;
|
||||
using boost::int_min_value_t;
|
||||
using boost::uint_value_t;
|
||||
#else
|
||||
using namespace boost;
|
||||
#endif
|
||||
|
||||
SHOW_TYPES( int_t, least );
|
||||
SHOW_TYPES( int_t, fast );
|
||||
SHOW_TYPES( uint_t, least );
|
||||
SHOW_TYPES( uint_t, fast );
|
||||
SHOW_POS_SHIFTED_TYPES( int_max_value_t, least );
|
||||
SHOW_POS_SHIFTED_TYPES( int_max_value_t, fast );
|
||||
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, least );
|
||||
SHOW_NEG_SHIFTED_TYPES( int_min_value_t, fast );
|
||||
SHOW_SHIFTED_TYPES( uint_value_t, least );
|
||||
SHOW_SHIFTED_TYPES( uint_value_t, fast );
|
||||
|
||||
PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX );
|
||||
PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX );
|
||||
PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX );
|
||||
PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX );
|
||||
PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX );
|
||||
PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX );
|
||||
PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN );
|
||||
PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN );
|
||||
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX );
|
||||
PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX );
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
@ -77,7 +77,7 @@ Test Program</h2>
|
||||
|
||||
<p>
|
||||
|
||||
The program <code><a href="test/integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
The program <code><a href="integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
exercises the <code>integer_traits</code> class.
|
||||
|
||||
<h2>Acknowledgements</h2>
|
||||
|
102
integer_traits_test.cpp
Normal file
102
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;
|
||||
}
|
||||
|
@ -8,164 +8,104 @@
|
||||
// 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
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp> // for main
|
||||
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#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
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
|
||||
|
||||
// Control if events will be printed conventionally, or just logged.
|
||||
#ifndef CONTROL_SHOW_TYPES
|
||||
#define CONTROL_SHOW_TYPES 0
|
||||
#endif
|
||||
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
|
||||
(v) >::high_bit == (1ul << (v)) );
|
||||
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
|
||||
(v) >::high_bit_fast == (1ul << (v)) );
|
||||
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
|
||||
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
|
||||
|
||||
// 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
|
||||
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
|
||||
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
||||
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
|
||||
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
|
||||
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
|
||||
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
|
||||
|
||||
|
||||
// Custom types/templates, helper functions, and objects
|
||||
namespace
|
||||
int test_main( int, char*[] )
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// List the ranges of template parameters tests (ranges are half-open)
|
||||
int const max_offset = std::numeric_limits<boost::uintmax_t>::digits;
|
||||
cout << "Doing high_bit_mask_t tests." << endl;
|
||||
PRIVATE_HIGH_BIT_TEST( 31 );
|
||||
PRIVATE_HIGH_BIT_TEST( 30 );
|
||||
PRIVATE_HIGH_BIT_TEST( 29 );
|
||||
PRIVATE_HIGH_BIT_TEST( 28 );
|
||||
PRIVATE_HIGH_BIT_TEST( 27 );
|
||||
PRIVATE_HIGH_BIT_TEST( 26 );
|
||||
PRIVATE_HIGH_BIT_TEST( 25 );
|
||||
PRIVATE_HIGH_BIT_TEST( 24 );
|
||||
PRIVATE_HIGH_BIT_TEST( 23 );
|
||||
PRIVATE_HIGH_BIT_TEST( 22 );
|
||||
PRIVATE_HIGH_BIT_TEST( 21 );
|
||||
PRIVATE_HIGH_BIT_TEST( 20 );
|
||||
PRIVATE_HIGH_BIT_TEST( 19 );
|
||||
PRIVATE_HIGH_BIT_TEST( 18 );
|
||||
PRIVATE_HIGH_BIT_TEST( 17 );
|
||||
PRIVATE_HIGH_BIT_TEST( 16 );
|
||||
PRIVATE_HIGH_BIT_TEST( 15 );
|
||||
PRIVATE_HIGH_BIT_TEST( 14 );
|
||||
PRIVATE_HIGH_BIT_TEST( 13 );
|
||||
PRIVATE_HIGH_BIT_TEST( 12 );
|
||||
PRIVATE_HIGH_BIT_TEST( 11 );
|
||||
PRIVATE_HIGH_BIT_TEST( 10 );
|
||||
PRIVATE_HIGH_BIT_TEST( 9 );
|
||||
PRIVATE_HIGH_BIT_TEST( 8 );
|
||||
PRIVATE_HIGH_BIT_TEST( 7 );
|
||||
PRIVATE_HIGH_BIT_TEST( 6 );
|
||||
PRIVATE_HIGH_BIT_TEST( 5 );
|
||||
PRIVATE_HIGH_BIT_TEST( 4 );
|
||||
PRIVATE_HIGH_BIT_TEST( 3 );
|
||||
PRIVATE_HIGH_BIT_TEST( 2 );
|
||||
PRIVATE_HIGH_BIT_TEST( 1 );
|
||||
PRIVATE_HIGH_BIT_TEST( 0 );
|
||||
|
||||
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;
|
||||
cout << "Doing low_bits_mask_t tests." << endl;
|
||||
PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops!
|
||||
PRIVATE_LOW_BITS_TEST( 31 );
|
||||
PRIVATE_LOW_BITS_TEST( 30 );
|
||||
PRIVATE_LOW_BITS_TEST( 29 );
|
||||
PRIVATE_LOW_BITS_TEST( 28 );
|
||||
PRIVATE_LOW_BITS_TEST( 27 );
|
||||
PRIVATE_LOW_BITS_TEST( 26 );
|
||||
PRIVATE_LOW_BITS_TEST( 25 );
|
||||
PRIVATE_LOW_BITS_TEST( 24 );
|
||||
PRIVATE_LOW_BITS_TEST( 23 );
|
||||
PRIVATE_LOW_BITS_TEST( 22 );
|
||||
PRIVATE_LOW_BITS_TEST( 21 );
|
||||
PRIVATE_LOW_BITS_TEST( 20 );
|
||||
PRIVATE_LOW_BITS_TEST( 19 );
|
||||
PRIVATE_LOW_BITS_TEST( 18 );
|
||||
PRIVATE_LOW_BITS_TEST( 17 );
|
||||
PRIVATE_LOW_BITS_TEST( 16 );
|
||||
PRIVATE_LOW_BITS_TEST( 15 );
|
||||
PRIVATE_LOW_BITS_TEST( 14 );
|
||||
PRIVATE_LOW_BITS_TEST( 13 );
|
||||
PRIVATE_LOW_BITS_TEST( 12 );
|
||||
PRIVATE_LOW_BITS_TEST( 11 );
|
||||
PRIVATE_LOW_BITS_TEST( 10 );
|
||||
PRIVATE_LOW_BITS_TEST( 9 );
|
||||
PRIVATE_LOW_BITS_TEST( 8 );
|
||||
PRIVATE_LOW_BITS_TEST( 7 );
|
||||
PRIVATE_LOW_BITS_TEST( 6 );
|
||||
PRIVATE_LOW_BITS_TEST( 5 );
|
||||
PRIVATE_LOW_BITS_TEST( 4 );
|
||||
PRIVATE_LOW_BITS_TEST( 3 );
|
||||
PRIVATE_LOW_BITS_TEST( 2 );
|
||||
PRIVATE_LOW_BITS_TEST( 1 );
|
||||
|
||||
// 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;
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
||||
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()
|
||||
|
Reference in New Issue
Block a user