Added MPL-compatible variants of the minimum-size and value-based integer templates, which fixes #1224

[SVN r47470]
This commit is contained in:
Daryle Walker
2008-07-16 09:55:31 +00:00
parent f27ad7b337
commit ed80575830
4 changed files with 416 additions and 76 deletions

View File

@ -7,6 +7,8 @@
// 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)
@ -255,6 +257,30 @@ 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
@ -279,17 +305,41 @@ namespace detail
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
};
// maximum supported (positive) value, signed
template < intmax_t MaxValue >
struct maximum_signed_integral
: detail::integral_rank_to_type<
detail::int_max_rank_helper<MaxValue>::rank, signed >
{
BOOST_STATIC_CONSTANT( intmax_t, bound = MaxValue );
};
// minimum supported (negative) value
template < intmax_t MinValue >
struct minimum_signed_integral
: detail::integral_rank_to_type<
detail::int_min_rank_helper<MinValue>::rank, signed >
{
BOOST_STATIC_CONSTANT( intmax_t, bound = MinValue );
};
// maximum supported (nonnegative) value, unsigned
template < uintmax_t Value >
struct maximum_unsigned_integral
: detail::integral_rank_to_type<
detail::uint_max_rank_helper<Value>::rank, unsigned >
{
BOOST_STATIC_CONSTANT( uintmax_t, bound = Value );
};
// integer templates specifying number of bits ---------------------------//
// signed
template< int Bits > // minimum bits (including sign) required
struct int_t
{
typedef typename detail::int_least_helper
<
detail::int_rank_helper<Bits>::rank,
signed>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef typename sized_integral<Bits, signed>::type least;
typedef typename int_fast_t<least>::fast fast;
};
template< int Bits > // exact bits (including sign) desired
@ -302,11 +352,8 @@ namespace detail
template< int Bits > // minimum bits required
struct uint_t
{
typedef typename detail::int_least_helper
<
detail::uint_rank_helper<Bits>::rank,
unsigned>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef typename sized_integral<Bits, unsigned>::type least;
typedef typename int_fast_t<least>::fast fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
};
@ -322,32 +369,23 @@ namespace detail
template< intmax_t MaxValue > // maximum value to require support
struct int_max_value_t
{
typedef typename detail::int_least_helper
<
detail::int_max_rank_helper<MaxValue>::rank,
signed>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef typename maximum_signed_integral<MaxValue>::type least;
typedef typename int_fast_t<least>::fast fast;
};
template< intmax_t MinValue > // minimum value to require support
struct int_min_value_t
{
typedef typename detail::int_least_helper
<
detail::int_min_rank_helper<MinValue>::rank,
signed>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef typename minimum_signed_integral<MinValue>::type least;
typedef typename int_fast_t<least>::fast fast;
};
// unsigned
template< uintmax_t Value > // maximum value to require support
struct uint_value_t
{
typedef typename detail::int_least_helper
<
detail::uint_max_rank_helper<Value>::rank,
unsigned>::least least;
typedef typename int_fast_t<least>::fast fast;
typedef typename maximum_unsigned_integral<Value>::type least;
typedef typename int_fast_t<least>::fast fast;
};

View File

@ -90,9 +90,21 @@ template < typename BaseInt >
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;

View File

@ -53,6 +53,16 @@ namespace boost
};
// MPL-compatible
template&lt; int Bits, typename Signedness &gt;
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&lt; int Bits, typename Signedness &gt;
struct exact_integral
{
@ -63,12 +73,42 @@ namespace boost
typedef <em>implementation_supplied</em> type;
};
template&lt; intmax_t MaxValue &gt;
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&lt; intmax_t MinValue &gt;
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&lt; uintmax_t Value &gt;
struct maximum_unsigned_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = false;
static uintmax_t const bound = Value;
typedef <em>implementation_supplied</em> type;
};
// signed
template&lt; int Bits &gt;
struct int_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
typedef typename sized_integral&lt;Bits, signed&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; int Bits &gt;
@ -81,8 +121,8 @@ namespace boost
template&lt; int Bits &gt;
struct uint_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
typedef typename sized_integral&lt;Bits, unsigned&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; int Bits &gt;
@ -95,23 +135,23 @@ namespace boost
template&lt; intmax_t MaxValue &gt;
struct int_max_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
typedef typename maximum_signed_integral&lt;MaxValue&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; intmax_t MinValue &gt;
struct int_min_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
typedef typename minimum_signed_integral&lt;MinValue&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
// unsigned
template&lt; uintmax_t Value &gt;
struct uint_value_t
{
typedef <em>implementation_supplied</em> least;
typedef int_fast_t&lt;least&gt;::fast fast;
typedef typename maximum_unsigned_integral&lt;Value&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
} // namespace boost
</pre></blockquote>
@ -222,8 +262,10 @@ describes each template's criteria.</p>
incompatible with template meta-programming techniques.</li>
</ul>
<p>The <code>exact_integral</code> class template provides an MPL-compatible
alternative. This alternative has the form:</p>
<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&lt; <var>SwitchType</var> <var>SwitchValue</var>, typename Signedness &gt;
@ -299,6 +341,11 @@ struct <var>name</var>
</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>
@ -308,24 +355,66 @@ controls the appropriate emulation.)</p>
<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</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">Template Parameter Mapping (when <code>type</code> is defined)</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>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>
<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 &lt;<a href="../../boost/cstdint.hpp">boost/cstdint.hpp</a>&gt;,
but said support hadn't yet been added to &lt;<a
href="../../boost/integer.hpp">boost/integer.hpp</a>&gt;</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>
@ -406,7 +495,7 @@ exact and value-based sized templates, and the MPL-compatible templates.</p>
<hr>
<p>Revised July 15, 2008</p>
<p>Revised July 16, 2008</p>
<p>&copy; Copyright Beman Dawes 1999. Use, modification, and distribution are
subject to the Boost Software License, Version 1.0. (See accompanying file <a

View File

@ -4,10 +4,11 @@
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
// based integer templates. (Daryle Walker)
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
// processor-optimized integer template. (Daryle Walker)
// 14 Jul 08 Improved testing of processor-optimized integer template; added
@ -33,6 +34,7 @@
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION, etc.
#include <boost/mpl/back.hpp> // for boost::mpl::back
#include <boost/mpl/copy.hpp> // for boost::mpl::copy
#include <boost/mpl/equal.hpp> // for boost::mpl::equal
#include <boost/mpl/front_inserter.hpp> // for boost::mpl::front_inserter
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
#include <boost/mpl/joint_view.hpp> // for boost::mpl::joint_view
@ -221,13 +223,53 @@ std::size_t const integral_type_count = sizeof(integral_bit_lengths) /
// Use SFINAE to check if a particular bit-count is supported
template < int Bits >
bool
print_out_exact_signed( boost::mpl::integral_c<int, Bits> const &x, int bits,
typename boost::exact_integral<Bits, signed>::type *unused = 0 )
print_out_sized_signed( boost::mpl::integral_c<int, Bits> const &x, int bits,
typename boost::sized_integral<Bits, signed>::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 a sized_integral<" << bits <<
", signed> specialization, with type '" << typeid(typename
boost::sized_integral<Bits, signed>::type).name() << "'." );
return true;
}
template < typename T >
bool
print_out_sized_signed( T const &x, int bits )
{
PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits <<
", signed> specialization." );
return false;
}
template < int Bits >
bool
print_out_sized_unsigned( boost::mpl::integral_c<int, Bits> const &x, int bits,
typename boost::sized_integral<Bits, unsigned>::type *unused = 0 )
{
PRIVATE_SHOW_MESSAGE( "There is a sized_integral<" << bits <<
", unsigned> specialization, with type '" << typeid(typename
boost::sized_integral<Bits, unsigned>::type).name() << "'." );
return true;
}
template < typename T >
bool
print_out_sized_unsigned( T const &x, int bits )
{
PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits <<
", unsigned> specialization." );
return false;
}
template < int Bits >
bool
print_out_exact_signed( boost::mpl::integral_c<int, Bits> const &x, int bits,
typename boost::exact_integral<Bits, signed>::type *unused = 0 )
{
PRIVATE_SHOW_MESSAGE( "There is an exact_integral<" << bits <<
", signed> specialization, with type '" << typeid(typename
boost::exact_integral<Bits, signed>::type).name() << "'." );
@ -263,6 +305,69 @@ print_out_exact_unsigned( T const &x, int bits )
return false;
}
template < boost::intmax_t Value >
bool
print_out_maximum_signed( boost::maximum_signed_integral<Value> const &x,
boost::intmax_t value, typename boost::maximum_signed_integral<Value>::type
*unused = 0 )
{
PRIVATE_SHOW_MESSAGE( "There is a maximum_signed_integral<" << value <<
"> specialization, with type '" << typeid(typename
boost::maximum_signed_integral<Value>::type).name() << "'." );
return true;
}
template < typename T >
bool
print_out_maximum_signed( T const &x, boost::intmax_t value )
{
PRIVATE_SHOW_MESSAGE( "There is no maximum_signed_integral<" << value <<
"> specialization." );
return false;
}
template < boost::intmax_t Value >
bool
print_out_minimum_signed( boost::minimum_signed_integral<Value> const &x,
boost::intmax_t value, typename boost::minimum_signed_integral<Value>::type
*unused = 0 )
{
PRIVATE_SHOW_MESSAGE( "There is a minimum_signed_integral<" << value <<
"> specialization, with type '" << typeid(typename
boost::minimum_signed_integral<Value>::type).name() << "'." );
return true;
}
template < typename T >
bool
print_out_minimum_signed( T const &x, boost::intmax_t value )
{
PRIVATE_SHOW_MESSAGE( "There is no minimum_signed_integral<" << value <<
"> specialization." );
return false;
}
template < boost::uintmax_t Value >
bool
print_out_maximum_unsigned( boost::maximum_unsigned_integral<Value> const &x,
boost::uintmax_t value, typename boost::maximum_unsigned_integral<Value>::type
*unused = 0 )
{
PRIVATE_SHOW_MESSAGE( "There is a maximum_unsigned_integral<" << value <<
"> specialization, with type '" << typeid(typename
boost::maximum_unsigned_integral<Value>::type).name() << "'." );
return true;
}
template < typename T >
bool
print_out_maximum_unsigned( T const &x, boost::uintmax_t value )
{
PRIVATE_SHOW_MESSAGE( "There is no maximum_unsigned_integral<" << value <<
"> specialization." );
return false;
}
} // unnamed namespace
@ -303,8 +408,18 @@ BOOST_AUTO_TEST_SUITE_END()
// Check if given types can support given size parameters
BOOST_AUTO_TEST_SUITE( show_type_tests )
// Check the specialization type status of given bit lengths, exact or higher
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, valid_bits_list )
// Check the specialization type status of given bit lengths, minimum
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list )
{
BOOST_CHECK_EQUAL( print_out_sized_signed(T(), T::value), T::value <=
intmax_bits );
BOOST_CHECK_EQUAL( print_out_sized_unsigned(T(), T::value), T::value <=
uintmax_bits );
}
// Check the classic specialization type status of given bit lengths, minimum
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_test, T,
valid_bits_list )
{
// This test is supposed to replace the following printouts given in
// puesdo-code by:
@ -357,22 +472,23 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T,
// length of a integral type, so 1 << N would have to fit in the next larger
// type. (This is why N can't be more than bitlength(uintmax_t) - 1.)
#ifndef BOOST_NO_USING_TEMPLATE
using boost::is_same;
using boost::uint_value_t;
using boost::uint_t;
using boost::mpl::equal;
using boost::maximum_unsigned_integral;
using boost::sized_integral;
#else
using namespace boost::mpl;
using namespace boost;
#endif
boost::uintmax_t const one = 1u;
int const count = T::value;
BOOST_MPL_ASSERT( (is_same<typename uint_value_t<(one << (count -
2))>::least, typename uint_t<count - 1>::least>::value) );
BOOST_MPL_ASSERT( (is_same<typename uint_value_t<(one << (count -
1))>::least, typename uint_t<count>::least>::value) );
BOOST_MPL_ASSERT( (is_same<typename uint_value_t<(one << count)>::least,
typename uint_t<count + 1>::least>::value) );
BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 2))>,
sized_integral<count - 1, unsigned> >) );
BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 1))>,
sized_integral<count, unsigned> >) );
BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << count)>,
sized_integral<count + 1, unsigned> >) );
}
// Check size comparisons of given value support, signed
@ -399,31 +515,32 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T,
// type. (This is why N can't be more than bitlength(intmax_t) - 1. Note
// that bitlength(intmax_t) + 1 == bitlength(uintmax_t).)
#ifndef BOOST_NO_USING_TEMPLATE
using boost::is_same;
using boost::int_max_value_t;
using boost::int_t;
using boost::int_min_value_t;
using boost::mpl::equal;
using boost::maximum_signed_integral;
using boost::sized_integral;
using boost::minimum_signed_integral;
#else
using namespace boost::mpl;
using namespace boost;
#endif
boost::intmax_t const one = 1;
int const count = T::value;
BOOST_MPL_ASSERT( (is_same<typename int_max_value_t<+(one << (count -
2))>::least, typename int_t<count - 1>::least>::value) );
BOOST_MPL_ASSERT( (is_same<typename int_min_value_t<-(one << (count -
2))>::least, typename int_t<count - 1>::least>::value) );
BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 2))>,
sized_integral<count - 1, signed> >) );
BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 2))>,
sized_integral<count - 1, signed> >) );
BOOST_MPL_ASSERT( (is_same<typename int_max_value_t<+(one << (count -
1))>::least, typename int_t<count>::least>::value) );
BOOST_MPL_ASSERT( (is_same<typename int_min_value_t<-(one << (count -
1))>::least, typename int_t<count>::least>::value) );
BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 1))>,
sized_integral<count, signed> >) );
BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 1))>,
sized_integral<count, signed> >) );
BOOST_MPL_ASSERT( (is_same<typename int_max_value_t<+(one << count)>::least,
typename int_t<count + 1>::least>::value) );
BOOST_MPL_ASSERT( (is_same<typename int_min_value_t<-(one << count)>::least,
typename int_t<count + 1>::least>::value) );
BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << count)>,
sized_integral<count + 1, signed> >) );
BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << count)>,
sized_integral<count + 1, signed> >) );
}
// Check the specialization type status of given bit lengths, exact only
@ -462,6 +579,88 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T,
uint_exact_t<T::value>::exact>::digits, ==, T::value );
}
// Check if MPL-compatible templates give bad returns for out-of-range values
BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test )
{
#ifndef BOOST_NO_USING_TEMPLATE
using boost::sized_integral;
using boost::mpl::integral_c;
using boost::exact_integral;
using boost::maximum_signed_integral;
using boost::minimum_signed_integral;
using boost::maximum_unsigned_integral;
#else
using namespace boost;
using namespace boost::mpl;
#endif
typedef sized_integral< 3, signed> ssz3_type;
typedef sized_integral< 0, signed> ssz0_type;
typedef sized_integral<-3, signed> ssz3n_type;
BOOST_CHECK( print_out_sized_signed(integral_c<int, ssz3_type::bit_count>(),
ssz3_type::bit_count) );
BOOST_CHECK( !print_out_sized_signed(integral_c<int, ssz0_type::bit_count>(),
ssz0_type::bit_count) );
BOOST_CHECK( !print_out_sized_signed(integral_c<int, ssz3n_type::bit_count>(),
ssz3n_type::bit_count) );
typedef sized_integral< 3, unsigned> usz3_type;
typedef sized_integral< 0, unsigned> usz0_type;
typedef sized_integral<-3, unsigned> usz3n_type;
BOOST_CHECK( print_out_sized_unsigned(integral_c<int, usz3_type::bit_count>(),
usz3_type::bit_count) );
BOOST_CHECK( print_out_sized_unsigned(integral_c<int, usz0_type::bit_count>(),
usz0_type::bit_count) );
BOOST_CHECK( !print_out_sized_unsigned(integral_c<int, usz3n_type::bit_count>(),
usz3n_type::bit_count) );
typedef exact_integral< 3, signed> se3_type;
typedef exact_integral< 0, signed> se0_type;
typedef exact_integral<-3, signed> se3n_type;
BOOST_CHECK( !print_out_exact_signed(integral_c<int, se3_type::bit_count>(),
se3_type::bit_count) );
BOOST_CHECK( !print_out_exact_signed(integral_c<int, se0_type::bit_count>(),
se0_type::bit_count) );
BOOST_CHECK( !print_out_exact_signed(integral_c<int, se3n_type::bit_count>(),
se3n_type::bit_count) );
typedef exact_integral< 3, unsigned> ue3_type;
typedef exact_integral< 0, unsigned> ue0_type;
typedef exact_integral<-3, unsigned> ue3n_type;
BOOST_CHECK( !print_out_exact_unsigned(integral_c<int, ue3_type::bit_count>(),
ue3_type::bit_count) );
BOOST_CHECK( !print_out_exact_unsigned(integral_c<int, ue0_type::bit_count>(),
ue0_type::bit_count) );
BOOST_CHECK( !print_out_exact_unsigned(integral_c<int, ue3n_type::bit_count>(),
ue3n_type::bit_count) );
typedef maximum_signed_integral< 15> max15_type;
typedef maximum_signed_integral< 0> max0_type;
typedef maximum_signed_integral<-15> max15n_type;
BOOST_CHECK( print_out_maximum_signed(max15_type(), max15_type::bound) );
BOOST_CHECK( !print_out_maximum_signed(max0_type(), max0_type::bound) );
BOOST_CHECK( !print_out_maximum_signed(max15n_type(), max15n_type::bound) );
typedef minimum_signed_integral< 15> min15_type;
typedef minimum_signed_integral< 0> min0_type;
typedef minimum_signed_integral<-15> min15n_type;
BOOST_CHECK( !print_out_minimum_signed(min15_type(), min15_type::bound) );
BOOST_CHECK( !print_out_minimum_signed(min0_type(), min0_type::bound) );
BOOST_CHECK( print_out_minimum_signed(min15n_type(), min15n_type::bound) );
typedef maximum_unsigned_integral<15> umax15_type;
typedef maximum_unsigned_integral< 0> umax0_type;
BOOST_CHECK( print_out_maximum_unsigned(umax15_type(), umax15_type::bound) );
BOOST_CHECK( print_out_maximum_unsigned(umax0_type(), umax0_type::bound) );
}
BOOST_AUTO_TEST_SUITE_END()
// Check if given constants can fit in given types
@ -485,6 +684,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
// macros. The limit of type-lists is usually less than 32 (not to mention
// 64) elements, so we have to take selected values.
#ifndef BOOST_NO_USING_TEMPLATE
using boost::sized_integral;
using boost::uint_t;
using boost::int_t;
#else
@ -497,7 +697,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
boost::intmax_t const value_s = intmax_limits::max
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
BOOST_CHECK_EQUAL( typename uint_t<count>::least(value_u), value_u );
BOOST_CHECK_EQUAL( (typename sized_integral<count, unsigned>::type(value_u)),
value_u );
BOOST_CHECK_EQUAL( typename uint_t<count - 1>::least(value_u >> 1), value_u
>> 1 );
BOOST_CHECK_EQUAL( typename uint_t<count>::fast(value_u), value_u );
@ -505,8 +706,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
>> 1 );
BOOST_CHECK_EQUAL( typename int_t<count>::least(value_s), value_s );
BOOST_CHECK_EQUAL( typename int_t<count - 1>::least(value_s >> 1), value_s
>> 1 );
BOOST_CHECK_EQUAL( (typename sized_integral<count - 1, signed>::type(value_s
>> 1)), value_s >> 1 );
BOOST_CHECK_EQUAL( typename int_t<count>::fast(value_s), value_s );
BOOST_CHECK_EQUAL( typename int_t<count - 1>::fast(value_s >> 1), value_s >>
1 );