-#include <boost/integer_fwd.hpp > // forwarding header
-#include <boost/cstdint.hpp > // for boost::uintmax_t, intmax_t
-
-namespace boost
+namespace boost
{
// fast integers from least integers
- template< typename BaseInt >
- struct fast_integral
- {
- typedef implementation_supplied 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 = implementation_supplied ;
- static bool const is_signed = implementation_supplied ;
- static int const bit_count = Bits;
-
- typedef implementation_supplied type;
- };
-
- template< int Bits, typename Signedness >
- struct exact_integral
- {
- static bool const is_specialized = implementation_supplied ;
- static bool const is_signed = implementation_supplied ;
- static int const bit_count = Bits;
-
- typedef implementation_supplied type;
- };
-
- template< intmax_t MaxValue >
- struct maximum_signed_integral
- {
- static bool const is_specialized = implementation_supplied ;
- static bool const is_signed = true;
- static intmax_t const bound = MaxValue;
-
- typedef implementation_supplied type;
- };
-
- template< intmax_t MinValue >
- struct minimum_signed_integral
- {
- static bool const is_specialized = implementation_supplied ;
- static bool const is_signed = true;
- static intmax_t const bound = MinValue;
-
- typedef implementation_supplied type;
- };
-
- template< uintmax_t Value >
- struct maximum_unsigned_integral
- {
- static bool const is_specialized = implementation_supplied ;
- static bool const is_signed = false;
- static uintmax_t const bound = Value;
-
- typedef implementation_supplied type;
+ typedef implementation_supplied 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 implementation_supplied 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 implementation_supplied 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 implementation_supplied 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 implementation_supplied 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 implementation_supplied least;
+ typedef int_fast_t<least>::fast fast;
};
} // namespace boost
-
+
-The fast_integral
class template maps its input type to the
+
The int_fast_t
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 char
objects may go faster
if they were converted to int
objects before processing.
-The input type, passed as the only template parameter, can be any built-in
-integral type besides bool
. The output type is given as the class
-member type
.
-
-The int_fast_t
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 fast
, defined to be the same as the corresponding
-result from the fast_integral
meta-function.
+The input type, passed as the only template parameter, must be a
+built-in integral type, except bool
. Unsigned integral
+types can be used, as well as signed integral types, despite the name.
+The output type is given as the class member fast
.
Implementation Notes
By default, the output type is identical to the input type. Eventually,
@@ -183,286 +104,72 @@ type.
-The int_t
, int_exact_t
, uint_t
,
-uint_exact_t
, int_max_value_t
,
-int_min_value_t
, and uint_value_t
class templates find
-the most appropriate built-in integral type for the given template parameter.
-This type is given by the class member least
or exact
.
-For the non-exact class templates, the easiest-to-manipulate version of that
-type is given by the class member fast
. The following table
-describes each template's criteria.
+The int_t
, uint_t
,
+int_max_value_t
, int_min_value_t
, and
+uint_value_t
class templates find the most appropiate
+built-in integral type for the given template parameter. This type is
+given by the class member least
. The easiest-to-manipulate
+version of that type is given by the class member fast
.
+The following table describes each template's criteria.
-
+
Criteria for the Sized Type Class Templates
- Class Template (all in name-space boost
)
+ Class Template
Template Parameter Mapping
- int_t
+ boost::int_t
The smallest built-in signed integral type with at least the
given number of bits, including the sign bit. The parameter
- must 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
- boost::intmax_t
.
+ long
.
- int_exact_t
- 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.
-
-
- uint_t
+ boost::uint_t
The smallest built-in unsigned integral type with at least
- the given number of bits. The parameter must be a
- non-negative number. A compile-time error results if the parameter
- is larger than the number of bits in a
- boost::uintmax_t
.
+ 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 unsigned
+ long
.
- uint_exact_t
- The smallest built-in unsigned integral type with exactly the given
- number of bits. A compile-time error results if no qualifying type
- exists.
-
-
- int_max_value_t
+ boost::int_max_value_t
The smallest built-in signed integral type that supports the
- given value as a maximum. The parameter must be a
+ given value as a maximum. The parameter should be a
positive number.
- int_min_value_t
+ boost::int_min_value_t
The smallest built-in signed integral type that supports the
- given value as a minimum. The parameter must be a
+ given value as a minimum. The parameter should be a
negative number.
- uint_value_t
+ boost::uint_value_t
The smallest built-in unsigned integral type that supports
the given value as a maximum. The parameter should be a
positive number.
-
-
-The bit-length sized-type class templates have several drawbacks:
-
-
- You must know the valid bit-lengths in advance.
- There is no way to inspect the parameter used after a size-type template
- class is aliased.
- Using an inappropriate parameter value results in a compiler
- diagnostic.
- The type names used are inconsistent with other transformations in
- Boost, like in MPL .
- The above two facts make use of the size-type class templates
- incompatible with template meta-programming techniques.
-
-
-The sized_integral
, exact_integral
,
-maximum_signed_integral
, minimum_signed_integral
, and
-maximum_unsigned_integral
class templates provide MPL-compatible
-alternatives. These alternatives generally have the form:
-
-
-template< SwitchType SwitchValue , typename Signedness >
-struct name
-{
- static bool const is_specialized = implementation_supplied ;
- static bool const is_signed = implementation_supplied ;
- static SwitchType const switch_id = SwitchValue ;
-
- typedef implementation_supplied type;
-};
-
-
-Each member, if present, is defined by:
-
-
- Members in MPL-Compatible Class Templates
-
- Class Template Member
- When Defined
- Meaning
-
-
- is_specialized
- Always
- Flag indicating when a particular template class instantiation is a
- valid meta-function (true
) or not (false
).
-
-
- is_signed
- is_specialized == true
- Flag indicating whether the signed-variant (true
) or
- the unsigned-variant (false
) of the meta-function is
- used. This is controlled by the Signedness
template
- parameter:
-
- Effect of Signedness
Setting
-
- Signedness
Type
- is_signed
-
-
- signed
- true
-
-
- unsigned
- false
-
-
- anything else
- not defined
-
-
- The type used is a programmer mnemonic; the compiler cannot prevent
- someone from using int
or signed int
- instead of signed
, or unsigned int
instead
- of unsigned
.
-
-
- switch_id
(Actual name is template-specific.)
- Always
- The value of the main control parameter, accessible even if the
- template class instantiation is aliased.
-
-
- type
- is_specialized == true
- 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.
-
-
-
-The exceptions are the extreme-value class templates
-(maximum_signed_integral
, minimum_signed_integral
, and
-maximum_unsigned_integral
), which do not take a Signedness
-template parameter because the meta-functions already inherently have signedness.
-
-
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 Signedness
-controls the appropriate emulation.)
-
-
- Criteria for the MPL-Compatible Class Templates
-
- Class Template (all in name-space boost
)
- Parameter Type (in name-space boost
as needed)
- Parameter Member ID
- Classic Equivalent
- Template Parameter Mapping (when type
is defined)
-
-
- Signed
- Unsigned
-
-
- sized_integral
- int
- bit_count
- int_t
- uint_t
- The smallest built-in integral type with at least
- bit_count
bits (including the sign bit when
- Signedness is signed
). Not present if no
- type qualifies.
-
-
- exact_integral
- int
- bit_count
- int_exact_t
- uint_exact_t
- The smallest built-in integral type with exactly
- bit_count
bits (including the sign bit when
- Signedness is signed
). Not present if no
- type qualifies.
-
-
- maximum_signed_integral
- intmax_t
- bound
- int_max_value_t
- The smallest built-in integral type that can perserve the value in
- bound
. Not present if bound
is non-positive.
- It is possible for a type
to be absent if
- a platform supports really-extended integral types (beyond long
- long
or __int64
), support for those types goes
- into <boost/cstdint.hpp >,
- but said support hadn't yet been added to <boost/integer.hpp >
-
-
- minimum_signed_integral
- intmax_t
- bound
- int_min_value_t
- The smallest built-in integral type that can perserve the value in
- bound
. Not present if bound
is non-negative.
-
-
- maximum_unsigned_integral
- uintmax_t
- bound
- uint_value_t
- The smallest built-in integral type that can perserve the value in
- bound
. Should always be present.
-
-
-
-
-#include <boost/integer.hpp >
-#include <boost/mpl/int.hpp >
-#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;
-}
+#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;
//...
}
-The program integer_test.cpp is a
+
The program integer_test.cpp is a
simplistic demonstration of the results from instantiating various
examples of the sized type class templates.
@@ -491,11 +198,11 @@ to Valentin Bonnard and
Kevlin Henney for sharing
their designs for similar templates. Daryle Walker designed the
-exact and value-based sized templates, and the MPL-compatible templates.
+value-based sized templates.
-Revised July 16, 2008
+Revised May 20, 2001
© Copyright Beman Dawes 1999. Use, modification, and distribution are
subject to the Boost Software License, Version 1.0. (See accompanying file
-The program integer_traits_test.cpp
+The program integer_traits_test.cpp
exercises the integer_traits
class.
Acknowledgements
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index 50fceee..1609bf5 100644
--- a/test/Jamfile.v2
+++ b/test/Jamfile.v2
@@ -16,5 +16,5 @@ test-suite integer
/boost/test//boost_test_exec_monitor/ static ]
[ run static_min_max_test.cpp
/boost/test//boost_test_exec_monitor/ static ]
- [ compile issue_2134.cpp ]
+# [ compile issue_2134.cpp ]
;
diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp
index c3a0854..38f5211 100644
--- a/test/integer_mask_test.cpp
+++ b/test/integer_mask_test.cpp
@@ -8,149 +8,103 @@
// 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 // unit testing framework
+#include // for main
-#include // for boost::uintmax_t
+#include // for boost::exit_success
#include // for boost::high_bit_mask_t, etc.
-#include // for std::numeric_limits
-#include // for BOOST_MPL_ASSERT_RELATION,etc.
-#include // for boost::mpl::bool_
-#include // for boost::mpl::bitor_, shift_left
-#include // for boost::mpl::equal_to
-#include // for boost::mpl::int_
-#include // for boost::mpl::integral_c
-#include // for boost::mpl::prior
-#include // for boost::mpl::range_c
-#include // for std::size_t
-#include // for std::hex
+#include // for std::cout (std::endl indirectly)
-// Custom types/templates, helper functions, and objects
-namespace
+#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)
+
+#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)
+
+
+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::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 high_bit_offsets;
-typedef boost::mpl::range_c low_bit_lengths;
-typedef boost::mpl::range_c 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 wild_bit_lengths;
-
-// Use SFINAE to check if a particular parameter is supported
-template < typename ValueT, template class Tmpl, ValueT Value >
-bool
-print_out_template( Tmpl const &, ValueT setting, char const
- *template_name, typename Tmpl::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).
- BOOST_TEST_MESSAGE( "There is an " << template_name << "<" << setting <<
- "> specialization with type '" << typeid(typename
- Tmpl::value_type).name() << "' and value '" << std::hex <<
- Tmpl::value << "'." );
- return true;
+ return boost::exit_success;
}
-
-template < typename ValueT, typename T >
-bool
-print_out_template( T const &, ValueT setting, char const *template_name )
-{
- BOOST_TEST_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::least, 1u> one_type;
- typedef boost::mpl::shift_left result_type;
-
- BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit, ==,
- result_type::value );
- BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::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::type shift_type;
- typedef boost::mpl::integral_c::least, 1u> one_type;
- typedef boost::mpl::shift_left high_bit_type;
- typedef typename boost::mpl::prior::type low_bits_type;
- typedef boost::mpl::bitor_ result_type;
-
- BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits, ==,
- result_type::value );
- BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::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 hi_type;
- typedef boost::mpl::int_ hi_offset_type;
- typedef boost::mpl::bool_ 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 lo_type;
- typedef boost::mpl::int_ lo_length_type;
- typedef boost::mpl::bool_ 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()
diff --git a/test/integer_test.cpp b/test/integer_test.cpp
index 3749183..6bfff11 100644
--- a/test/integer_test.cpp
+++ b/test/integer_test.cpp
@@ -4,666 +4,288 @@
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
// See http://www.boost.org/libs/integer for documentation.
// Revision History
-// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
-// based integer templates. (Daryle Walker)
-// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
-// processor-optimized integer template. (Daryle Walker)
-// 14 Jul 08 Improved testing of processor-optimized integer template; added
-// extended-integer support. (Daryle Walker)
-// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker)
-// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker)
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
// 31 Aug 99 Initial version
-#define BOOST_TEST_MODULE "Integer size-selection tests"
+#include // for main, BOOST_CHECK
-#include // unit testing framework
+#include // for BOOST_NO_USING_TEMPLATE
+#include // for boost::exit_success
+#include // for boost::int_t, boost::uint_t
-#include // for BOOST_NO_SFINAE
-#include // for boost::uintmax_t, intmax_t
-#include // for boost::int_t, boost::uint_t, etc.
-#include // for boost::integer_traits
-#include // for std::numeric_limits
-
-#include // BOOST_HAS_XINT, BOOST_UXINT_MAX
-
-#include // for boost::mpl::plus, divides
-#include // for BOOST_MPL_ASSERT_RELATION, etc.
-#include // for boost::mpl::back
-#include // for boost::mpl::copy
-#include // for boost::mpl::equal
-#include // for boost::mpl::front_inserter
-#include // for boost::mpl::int_
-#include // for boost::mpl::integral_c
-#include // for boost::mpl::joint_view
-#include // for boost::mpl::pop_back
-#include // for boost::mpl::push_back
-#include // for boost::mpl::push_front
-#include // for boost::mpl::range_c
-#include // for boost::mpl::shift_right
-#include // for boost::mpl::sort
-#include // for boost::mpl::transform
-#include // for boost::mpl::transform_view
-#include // for boost::mpl::unpack_args
-#include // for boost::mpl::vector
-#include // for boost::mpl::zip_view
-
-#include // for boost::is_same
-#include // for boost::make_signed
-
-#include // for std::binary_search
-#include // for ULONG_MAX, LONG_MAX, LONG_MIN, etc.
-#include // for std::size_t
-#include // for std::type_info
+#include // for ULONG_MAX, LONG_MAX, LONG_MIN
+#include // for std::cout (std::endl indirectly)
+#include // for std::type_info
-// Control what the "fast" specialization of "short" is
-#ifndef CONTROL_FAST_SHORT
-#define CONTROL_FAST_SHORT long
-#endif
-
-// Control if every potential bit-count is used, or only a selection
-// For me, full counts increase compile time from 90 seconds to 20 minutes!
-#ifndef CONTROL_FULL_COUNTS
-#define CONTROL_FULL_COUNTS 1
+// 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. If there
-// is a specialization for "short," make sure that CONTROL_FAST_SHORT
-// is set to a type distinct from "short" and the default implementation.
+// the effects of the "fast" types by making a specialization.
namespace boost
{
template < >
- struct fast_integral< short >
+ struct int_fast_t< short >
{
- typedef CONTROL_FAST_SHORT type;
+ typedef long fast;
};
}
-// Custom types/templates, helper functions, and objects
-namespace
-{
-
-// List the built-in integral types, excluding the ones that are strong-typedefs
-// of a lower type.
-typedef boost::mpl::vector<
- unsigned char
-#if USHRT_MAX > UCHAR_MAX
- , unsigned short
-#endif
-#if UINT_MAX > USHRT_MAX
- , unsigned int
-#endif
-#if ULONG_MAX > UINT_MAX
- , unsigned long
-#endif
-#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
- , boost::detail::uxint_t
-#endif
-> distinct_unsigned_types;
-
-typedef boost::mpl::transform<
- distinct_unsigned_types,
- boost::make_signed< boost::mpl::_1 >
->::type distinct_signed_types;
-
-// List the digit counts for each integral type
-template < typename T >
-struct digits_of
- : boost::mpl::int_< std::numeric_limits::digits >
-{
-};
-
-typedef boost::mpl::transform<
- distinct_unsigned_types,
- digits_of< boost::mpl::_1 >
->::type distinct_integral_bit_counts;
-
-// Make list of bit counts between each offical point, plus CHAR_BIT/2
-typedef boost::mpl::transform_view<
- boost::mpl::zip_view<
- boost::mpl::vector<
- boost::mpl::push_front<
- boost::mpl::pop_back< distinct_integral_bit_counts >::type,
- boost::mpl::integral_c< int, 0 >
- >::type,
- distinct_integral_bit_counts
- >
- >,
- boost::mpl::unpack_args<
- boost::mpl::divides<
- boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >,
- boost::mpl::integral_c< int, 2 >
- >
- >
-> median_bit_counts;
-
-// Maximum number of bits allowed
-typedef std::numeric_limits intmax_limits;
-typedef std::numeric_limits uintmax_limits;
-
-int const intmax_bits = intmax_limits::digits + 1;
-int const uintmax_bits = uintmax_limits::digits;
-
-// Make master lists including an outlier beyond all valid bit counts
-#if CONTROL_FULL_COUNTS
-typedef boost::mpl::range_c bits_list;
+// 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
-typedef boost::mpl::sort<
- boost::mpl::copy<
- boost::mpl::joint_view<
- distinct_integral_bit_counts,
- median_bit_counts
- >,
- boost::mpl::front_inserter<
- boost::mpl::vector<
- boost::mpl::integral_c
- >
- >
- >::type
->::type bits_list;
+#define SHOW_TYPE(Template, Number, Type)
#endif
-// Remove the outlier when all bits counts must be valid
-#if CONTROL_FULL_COUNTS
-typedef boost::mpl::range_c valid_bits_list;
+#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
-typedef boost::mpl::pop_back::type valid_bits_list;
+#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
-// Replace the minimum bit count with one more, so right-shifting by a stored
-// value doesn't give an invalid result
-#if CONTROL_FULL_COUNTS
-typedef boost::mpl::range_c
- valid_to_decrease_bits_list;
+#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
-typedef valid_bits_list valid_to_decrease_bits_list;
+ using namespace boost;
#endif
-// Replace the maximum bit count with one less, so left-shifting by a stored
-// value doesn't give an invalid result
-#if CONTROL_FULL_COUNTS
-typedef boost::mpl::range_c valid_to_increase_ubits_list;
-#else
-typedef boost::mpl::push_back<
- boost::mpl::pop_back< valid_bits_list >::type,
- boost::mpl::integral_c< int, uintmax_bits - 1 >
->::type valid_to_increase_ubits_list;
-#endif
-
-// Do it again for signed types since they have one-less bit to use for the
-// mantissa (don't want to shift into the sign bit)
-#if CONTROL_FULL_COUNTS
-typedef boost::mpl::range_c
- valid_to_increase_sbits_list;
-#else
-typedef boost::mpl::push_back<
- boost::mpl::pop_back< valid_bits_list >::type,
- boost::mpl::integral_c< int, intmax_bits - 3 >
->::type valid_to_increase_sbits_list;
-#endif
-
-// List the digit counts for each integral type, this time as an object, an
-// array working as a sorted list
-int const integral_bit_lengths[] = {
- std::numeric_limits< unsigned char >::digits
-#if USHRT_MAX > UCHAR_MAX
- , std::numeric_limits< unsigned short >::digits
-#endif
-#if UINT_MAX > USHRT_MAX
- , std::numeric_limits< unsigned int >::digits
-#endif
-#if ULONG_MAX > UINT_MAX
- , std::numeric_limits< unsigned long >::digits
-#endif
-#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
- , std::numeric_limits< boost::detail::uxint_t >::digits
-#endif
-};
-
-std::size_t const integral_type_count = sizeof(integral_bit_lengths) /
- sizeof(integral_bit_lengths[0]);
-
-// "Template-typedefs" to reduce two-argument templates to single-argument.
-// This way, all the MPL-compatible templates have the same form, for below.
-template < int Bits >
-struct signed_sized_integral : boost::sized_integral {};
-
-template < int Bits >
-struct unsigned_sized_integral : boost::sized_integral {};
-
-template < int Bits >
-struct signed_exact_integral : boost::exact_integral {};
-
-template < int Bits >
-struct unsigned_exact_integral : boost::exact_integral {};
-
-// Use SFINAE to check if a particular parameter is supported
-#ifndef BOOST_NO_SFINAE
-template < typename ValueT, template class Tmpl, ValueT Value >
-bool
-print_out_template( Tmpl const &, ValueT setting, char const
- *template_pre_name, char const *template_post_name, typename Tmpl::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).
- BOOST_TEST_MESSAGE( "This is " << template_pre_name << setting
- << template_post_name << " specialization, with type '" << typeid(typename
- Tmpl::type).name() << "'." );
- return true;
+ 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;
}
-
-template < typename ValueT, typename T >
-bool
-print_out_template( T const &, ValueT setting, char const *template_pre_name,
- char const *template_post_name )
-{
- BOOST_TEST_MESSAGE( "Looking for " << template_pre_name << setting
- << template_post_name << " specialization? It doesn't exist." );
- return false;
-}
-#else
-#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error"
-#endif
-
-// Get the extreme values for each integral type
-template < typename T >
-struct minimum_of
- : boost::mpl::integral_c< T, boost::integer_traits::const_min >
-{
-};
-
-template < typename T >
-struct maximum_of
- : boost::mpl::integral_c< T, boost::integer_traits::const_max >
-{
-};
-
-} // unnamed namespace
-
-
-// Check the processor-optimzed type system
-BOOST_AUTO_TEST_SUITE( optimized_type_tests )
-
-// Check the optimzed type override of a given type
-BOOST_AUTO_TEST_CASE( fast_type_test )
-{
- typedef short least_type;
- typedef boost::int_fast_t::fast fast_type;
- typedef std::numeric_limits least_limits;
- typedef std::numeric_limits fast_limits;
-
- typedef boost::fast_integral::type real_fast_type;
-
- BOOST_MPL_ASSERT_RELATION( (boost::is_same::value),
- ==, false );
- BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), ==, true );
- BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true );
- BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed &&
- fast_limits::is_bounded, ==, true );
- BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 );
- BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits );
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-// Check if given types can support given size parameters
-BOOST_AUTO_TEST_SUITE( show_type_tests )
-
-// Check the specialization type status of given bit lengths, minimum
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list )
-{
- BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral(),
- T::value, "a sized_integral<", ", signed>"), T::value && (T::value <=
- intmax_bits) );
- BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral(),
- T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits );
-}
-
-// Check the classic specialization type status of given bit lengths, minimum,
-// unsigned
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T,
- valid_bits_list )
-{
- // This test is supposed to replace the following printouts given in
- // puesdo-code by:
- // Routine: Template, Type
- // for N := 32 downto 0
- // cout << "Type '" << Template << "<" N << ">::" << Type << "' is '"
- // << typeid(Template::Type).name << ".'\n"
- // end for
- // end Routine
- // with Template = {int_t, uint_t}; Type = {least, fast}
- // But now we'll use template meta-programming instead of macros. The limit
- // of type-lists is usually less than 32 (not to mention 64) elements, so we
- // have to take selected values. The only interesting part is if the bit
- // count is too large, and we can't check that yet.
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value );
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value );
-}
-
-// Check the classic specialization type status of given bit lengths, minimum,
-// signed
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T,
- valid_to_decrease_bits_list )
-{
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value - 1 );
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value - 1 );
-}
-
-// Check size comparisons of given value support, unsigned
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T,
- valid_to_increase_ubits_list )
-{
- // This test is supposed to replace the following printouts given in
- // puesdo-code by:
- // Routine: Type
- // for N := 30 downto 0
- // cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type
- // << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n"
- // end for
- // end Routine
- // with Type = {least, fast}
- // But now we'll use template meta-programming instead of macros. The limit
- // of type-lists is usually less than 32 (not to mention 64) elements, so we
- // have to take selected values. The interesting parts are where N is the
- // length of a integral type, so 1 << N would have to fit in the next larger
- // type. (This is why N can't be more than bitlength(uintmax_t) - 1.)
- boost::uintmax_t const one = 1u;
-
- BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one
- << T::value)>, unsigned_sized_integral >) );
-}
-
-// Check size comparisons of given value support, signed
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T,
- valid_to_increase_sbits_list )
-{
- // This test is supposed to replace the following printouts given in
- // puesdo-code by:
- // Routine: Type
- // for N := 30 downto 0
- // cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" <<
- // Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name
- // << ".'\n"
- // cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" <<
- // Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name
- // << ".'\n"
- // end for
- // end Routine
- // with Type = {least, fast}
- // But now we'll use template meta-programming instead of macros. The limit
- // of type-lists is usually less than 32 (not to mention 64) elements, so we
- // have to take selected values. The interesting parts are where N is the
- // length of a integral type, so 1 << N would have to fit in the next larger
- // type. (This is why N can't be more than bitlength(intmax_t) - 1. Note
- // that bitlength(intmax_t) + 1 == bitlength(uintmax_t).)
- static boost::intmax_t const one = 1;
-
- BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one
- << T::value)>, signed_sized_integral >) );
- BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one
- << T::value)>, signed_sized_integral >) );
-}
-
-// Check the specialization type status of given bit lengths, exact only
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list )
-{
- bool const is_exact_length = std::binary_search( integral_bit_lengths,
- integral_bit_lengths + integral_type_count, T::value );
-
- BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral(),
- T::value, "an exact_integral<", ", signed>"), is_exact_length );
- BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral(),
- T::value, "an exact_integral<", ", unsigned>"), is_exact_length );
-}
-
-// Check the classic specialization type status of given bit lengths, exact only
-BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T,
- distinct_integral_bit_counts )
-{
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value - 1 );
- BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value );
-}
-
-// Check if MPL-compatible templates give bad returns for out-of-range values
-BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test )
-{
- typedef signed_sized_integral< 3> ssz3_type;
- typedef signed_sized_integral< 0> ssz0_type;
- typedef signed_sized_integral<-3> ssz3n_type;
-
- BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count,
- "a sized_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count,
- "a sized_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count,
- "a sized_integral<", ", signed>") );
-
- typedef unsigned_sized_integral< 3> usz3_type;
- typedef unsigned_sized_integral< 0> usz0_type;
- typedef unsigned_sized_integral<-3> usz3n_type;
-
- BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count,
- "a sized_integral<", ", unsigned>") );
- BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count,
- "a sized_integral<", ", unsigned>") );
- BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count,
- "a sized_integral<", ", unsigned>") );
-
- typedef signed_exact_integral< CHAR_BIT > se8_type;
- typedef signed_exact_integral< 3> se3_type;
- typedef signed_exact_integral< 0> se0_type;
- typedef signed_exact_integral<-3> se3n_type;
- typedef signed_exact_integral< - CHAR_BIT > se8n_type;
-
- BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count,
- "an exact_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count,
- "an exact_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count,
- "an exact_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count,
- "an exact_integral<", ", signed>") );
- BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count,
- "an exact_integral<", ", signed>") );
-
- typedef unsigned_exact_integral< CHAR_BIT > ue8_type;
- typedef unsigned_exact_integral< 3> ue3_type;
- typedef unsigned_exact_integral< 0> ue0_type;
- typedef unsigned_exact_integral<-3> ue3n_type;
- typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type;
-
- BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count,
- "an exact_integral<", ", unsigned>") );
- BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count,
- "an exact_integral<", ", unsigned>") );
- BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count,
- "an exact_integral<", ", unsigned>") );
- BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count,
- "an exact_integral<", ", unsigned>") );
- BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count,
- "an exact_integral<", ", unsigned>") );
-
- typedef boost::maximum_signed_integral< 15> max15_type;
- typedef boost::maximum_signed_integral< 0> max0_type;
- typedef boost::maximum_signed_integral<-15> max15n_type;
-
- BOOST_CHECK( print_out_template(max15_type(), max15_type::bound,
- "a maximum_signed_integral<", ">") );
- BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound,
- "a maximum_signed_integral<", ">") );
- BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound,
- "a maximum_signed_integral<", ">") );
-
- typedef boost::minimum_signed_integral< 15> min15_type;
- typedef boost::minimum_signed_integral< 0> min0_type;
- typedef boost::minimum_signed_integral<-15> min15n_type;
-
- BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound,
- "a minimum_signed_integral<", ">") );
- BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound,
- "a minimum_signed_integral<", ">") );
- BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound,
- "a minimum_signed_integral<", ">") );
-
- typedef boost::maximum_unsigned_integral<15> umax15_type;
- typedef boost::maximum_unsigned_integral< 0> umax0_type;
-
- BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound,
- "a maximum_unsigned_integral<", ">") );
- BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound,
- "a maximum_unsigned_integral<", ">") );
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-// Check if given constants can fit in given types
-BOOST_AUTO_TEST_SUITE( fit_type_tests )
-
-// Check if large value can fit its minimum required size, by size
-BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
- valid_to_decrease_bits_list )
-{
- // This test is supposed to replace the following checks given in
- // puesdo-code by:
- // Routine: Template, Type
- // for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 )
- // Confirm( static_cast::Type>(V) == V );
- // end for
- // end Routine
- // with Template = {int_t, uint_t}; Type = {least, fast};
- // Template:Max = { intmax_t.Max for int_t, uintmax_t.Max for uint_t }
- // In other words, the selected type doesn't mask out any bits it's not
- // supposed to. But now we'll use template meta-programming instead of
- // macros. The limit of type-lists is usually less than 32 (not to mention
- // 64) elements, so we have to take selected values.
- static int const count = T::value;
- int const shift = uintmax_bits - count;
- boost::uintmax_t const value_u = uintmax_limits::max
- BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
- boost::intmax_t const value_s = intmax_limits::max
- BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
-
- BOOST_CHECK_EQUAL( static_cast::type>(value_u), value_u );
- BOOST_CHECK_EQUAL( static_cast::least>(value_u), value_u );
- BOOST_CHECK_EQUAL( static_cast::fast>(value_u), value_u );
-
- BOOST_CHECK_EQUAL( static_cast::type>(value_s), value_s );
- BOOST_CHECK_EQUAL( static_cast::least>(value_s), value_s );
- BOOST_CHECK_EQUAL( static_cast::fast>(value_s), value_s );
-}
-
-// Check if a large value can only fit of its exact bit length
-BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T,
- distinct_integral_bit_counts )
-{
- typename boost::exact_integral::type const one_u( 1u ),
- high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) |
- high_bit_u );
-
- BOOST_CHECK( high_bit_u );
- BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u );
-
- typename boost::exact_integral::type const one_s( 1 ),
- high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) |
- high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s );
-
- BOOST_CHECK( high_bit_s > 0 );
- BOOST_CHECK( repeated_bits_s < 0 );
- BOOST_CHECK_EQUAL( repeated_bits_s, repeated_2bits_s );
-}
-
-// Check if large value can fit its minimum required size, by value, unsigned
-BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T,
- valid_to_increase_ubits_list )
-{
- // This test is supposed to replace the following checks given in
- // puesdo-code by:
- // Routine: Template, Type
- // for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
- // Confirm( static_cast::Type>(V) == V );
- // end for
- // end Routine
- // with Template = {uint_value_t}; Type = {least, fast}; Template:Extreme =
- // {uintmax_t.Max for uint_value_t}
- // In other words, the selected type doesn't mask out any bits it's not
- // supposed to. But now we'll use template meta-programming instead of
- // macros. The limit of type-lists is usually less than 32 (not to mention
- // 64) elements, so we have to take selected values.
- using boost::uintmax_t;
-
- typedef boost::mpl::shift_right, T> maxi_type;
-
- uintmax_t const maxi = maxi_type::value;
-
- BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi );
- BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi );
-}
-
-// Check if large value can fit its minimum required size, by value, signed
-BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T,
- valid_to_increase_sbits_list )
-{
- // This test is supposed to replace the following checks given in
- // puesdo-code by:
- // Routine: Template, Type
- // for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
- // Confirm( static_cast::Type>(V) == V );
- // end for
- // end Routine
- // with Template = {int_max_value_t, int_min_value_t}; Type = {least, fast};
- // Template:Extreme = {intmax_t.Min for int_min_value_t, intmax_t.Max
- // for int_max_value_t}
- // In other words, the selected type doesn't mask out any bits it's not
- // supposed to. But now we'll use template meta-programming instead of
- // macros. The limit of type-lists is usually less than 32 (not to mention
- // 64) elements, so we have to take selected values.
- using boost::intmax_t;
-
- typedef boost::mpl::shift_right, T> mini_type;
- typedef boost::mpl::shift_right, T> maxi_type;
-
- intmax_t const maxi = maxi_type::value, mini = mini_type::value;
-
- BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi );
- BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi );
-
- BOOST_CHECK_EQUAL( static_cast::least>(mini), mini );
- BOOST_CHECK_EQUAL( static_cast::fast>(mini), mini );
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-// Verification of bugs and their fixes
-BOOST_AUTO_TEST_SUITE( bug_fix_tests )
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/issue_2134.cpp b/test/issue_2134.cpp
deleted file mode 100644
index 26f8962..0000000
--- a/test/issue_2134.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// boost Issue #2134 test program ------------------------------------------//
-
-// Copyright Daryle Walker 2008. Distributed under the Boost
-// Software License, Version 1.0. (See the accompanying file
-// LICENSE_1_0.txt or a copy at .)
-
-// See for documentation.
-// See for the issue involved.
-
-// Revision History
-// 23 Jul 2008 Initial version
-
-// Control if the inclusion error is triggered
-#ifndef CONTROL_INCLUDE_TRAITS
-#define CONTROL_INCLUDE_TRAITS 1
-#endif
-
-#if CONTROL_INCLUDE_TRAITS
-// This file defines boost::detail::integer_traits.
-#include
-#endif
-
-// This is the file with the issue. It has items within the boost::detail
-// namespace that referenced an unadorned "integer_traits". This was meant to
-// refer to boost::integer_traits. However,
-// defines a boost::detail::integer_traits. If that header is #included before
-// this one, then b.d.integer_traits (rightfully) took priority, which lead to a
-// syntax error.
-#include
-
-
-// Main program, minimal (since this is a compile test)
-int main() { return 0; }