diff --git a/cstdint.htm b/cstdint.htm
index 0c2f893..9492827 100644
--- a/cstdint.htm
+++ b/cstdint.htm
@@ -18,7 +18,7 @@ writing portable code that requires certain integer widths. All typedef's are i
header <stdint.h>. The 64-bit types required by the C standard are not
required in the boost header, and may not be supplied in all implementations,
because long long
is not [yet] included in the C++ standard.
-Only some of the members are always present. The presence of other members
-and operations is flagged by the (always-present) is_specialized
.
-
-
-#include <boost/integer/integer_mask.hpp>
+#include <boost/integer/integer_mask.hpp>
//...
@@ -367,7 +200,7 @@ href="http://www.boost.org/people/daryle_walker.html">Daryle Walker.
-Revised July 29, 2008
+Revised September 23, 2001
© Copyright Daryle Walker 2001. Use, modification, and distribution are
subject to the Boost Software License, Version 1.0. (See accompanying file header. (John Maddock)
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
@@ -23,357 +17,108 @@
#include // self include
-#include // for BOOST_STATIC_CONSTANT, etc.
-#include // for boost::uintmax_t, intmax_t
-#include // for boost::integer_traits
-#include // for std::numeric_limits
-#include // for boost::enable_if_c
-
-#include // for BOOST_HAS_XINT, etc.
-
-#include // for UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, etc.
+#include // for boost::integer_traits
+#include // for std::numeric_limits
namespace boost
{
- // integer template mapping a type to its processor-optimized analog -----//
-
- // Some types can be handled better by the processor than others. This
- // template metafunction should map various built-in integral types to
- // the processor's perferred type for the given type's value range
- template < typename BaseInt >
- struct fast_integral
- {
- typedef BaseInt type;
- };
-
- // Platform-specific specializations should go here.
+ // Helper templates ------------------------------------------------------//
// fast integers from least integers
// int_fast_t<> works correctly for unsigned too, in spite of the name.
template< typename LeastInt >
- struct int_fast_t { typedef typename fast_integral::type fast; };
+ struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
-namespace detail
-{
+ // convert category to type
+ template< int Category > struct int_least_helper {}; // default is empty
- // Helper templates ------------------------------------------------------//
-
- // convert integer category to type ; default is empty
- template< int Rank, typename Signedness > struct int_least_helper {};
-
- // specializatons: 1=(unsigned) __int64/long long, 2=(unsigned) long,
- // 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char
- // no specializations for 0: requests for a type > (unsigned) (long) long are
- // in error
-#if BOOST_HAS_XINT
- template<> struct int_least_helper<1, signed> { typedef xint_t least; };
- template<> struct int_least_helper<1, unsigned> { typedef uxint_t least; };
-#endif
- template<> struct int_least_helper<2, signed> { typedef long least; };
- template<> struct int_least_helper<2, unsigned>
- { typedef unsigned long least; };
- template<> struct int_least_helper<3, signed> { typedef int least; };
- template<> struct int_least_helper<3, unsigned>
- { typedef unsigned int least; };
- template<> struct int_least_helper<4, signed> { typedef short least; };
- template<> struct int_least_helper<4, unsigned>
- { typedef unsigned short least; };
- template<> struct int_least_helper<5, signed> { typedef signed char least; };
- template<> struct int_least_helper<5, unsigned>
- { typedef unsigned char least; };
-
- // category bounds
- enum
- {
-#if BOOST_HAS_XINT
- lowest_integral_rank = 1,
-#else
- lowest_integral_rank = 2,
-#endif
- highest_integral_rank = 5
- };
-
- // map a bit count to a category
- template < int BitsIncludingSign >
- struct int_rank_helper
- {
- BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 );
-#if BOOST_HAS_XINT
- BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits<
- xint_t >::digits) );
-#else
- BOOST_STATIC_CONSTANT( int, extended_ = 1 );
-#endif
- BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * (extended_ +
- (mantissa <= std::numeric_limits< long >::digits) +
- (mantissa <= std::numeric_limits< int >::digits) +
- (mantissa <= std::numeric_limits< short >::digits) +
- (mantissa <= std::numeric_limits< signed char >::digits)) );
- };
-
- template < int Bits >
- struct uint_rank_helper
- {
-#if BOOST_HAS_XINT
- BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits<
- uxint_t >::digits) );
-#else
- BOOST_STATIC_CONSTANT( int, extended_ = 1 );
-#endif
- BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * (extended_ +
- (Bits <= std::numeric_limits< unsigned long >::digits) +
- (Bits <= std::numeric_limits< unsigned int >::digits) +
- (Bits <= std::numeric_limits< unsigned short >::digits) +
- (Bits <= std::numeric_limits< unsigned char >::digits)) );
- };
-
- template < int BitsIncludingSign >
- struct int_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
- template < int Bits >
- struct uint_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
-
-#define BOOST_PRIVATE_INT_EXACT_BUILDER(Type, Rank) \
- template < > \
- struct int_exact_rank_helper::digits + 1> \
- { BOOST_STATIC_CONSTANT( int, rank = Rank ); }
-#define BOOST_PRIVATE_UINT_EXACT_BUILDER(Type, Rank) \
- template < > \
- struct uint_exact_rank_helper::digits> \
- { BOOST_STATIC_CONSTANT( int, rank = Rank ); }
-
-#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
- BOOST_PRIVATE_INT_EXACT_BUILDER( xint_t, 1 );
- BOOST_PRIVATE_UINT_EXACT_BUILDER( uxint_t, 1 );
-#endif
-#if ULONG_MAX > UINT_MAX
- BOOST_PRIVATE_INT_EXACT_BUILDER( long, 2 );
- BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned long, 2 );
-#endif
-#if UINT_MAX > USHRT_MAX
- BOOST_PRIVATE_INT_EXACT_BUILDER( int, 3 );
- BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned, 3 );
-#endif
-#if USHRT_MAX > UCHAR_MAX
- BOOST_PRIVATE_INT_EXACT_BUILDER( short, 4 );
- BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned short, 4 );
-#endif
- BOOST_PRIVATE_INT_EXACT_BUILDER( signed char, 5 );
- BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned char, 5 );
-
-#undef BOOST_PRIVATE_INT_EXACT_BUILDER
-#undef BOOST_PRIVATE_UINT_EXACT_BUILDER
-
- // map an extreme value to a category
- template < intmax_t MaxValue >
- struct int_max_rank_helper
- {
-#if BOOST_HAS_XINT
- BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <=
- boost::integer_traits< xint_t >::const_max) );
-#else
- BOOST_STATIC_CONSTANT( int, extended_ = 1 );
-#endif
- BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ +
- (MaxValue <= boost::integer_traits< long >::const_max) +
- (MaxValue <= boost::integer_traits< int >::const_max) +
- (MaxValue <= boost::integer_traits< short >::const_max) +
- (MaxValue <= boost::integer_traits< signed char >::const_max)) );
- };
-
- template < intmax_t MinValue >
- struct int_min_rank_helper
- {
-#if BOOST_HAS_XINT
- BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >=
- boost::integer_traits< xint_t >::const_min) );
-#else
- BOOST_STATIC_CONSTANT( int, extended_ = 1 );
-#endif
- BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ +
- (MinValue >= boost::integer_traits< long >::const_min) +
- (MinValue >= boost::integer_traits< int >::const_min) +
- (MinValue >= boost::integer_traits< short >::const_min) +
- (MinValue >= boost::integer_traits< signed char >::const_min)) );
- };
-
- template < uintmax_t Value >
- struct uint_max_rank_helper
- {
-#if BOOST_HAS_XINT
- BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits<
- uxint_t >::const_max) );
-#else
- BOOST_STATIC_CONSTANT( int, extended_ = 1 );
-#endif
- BOOST_STATIC_CONSTANT( int, rank = extended_ +
- (Value <= boost::integer_traits< unsigned long >::const_max) +
- (Value <= boost::integer_traits< unsigned int >::const_max) +
- (Value <= boost::integer_traits< unsigned short >::const_max) +
- (Value <= boost::integer_traits< unsigned char >::const_max) );
- };
-
- // convert rank to type, Boost.MPL-style
- template < int Rank, typename Signedness, class Enable = void >
- struct integral_rank_to_type
- {
- BOOST_STATIC_CONSTANT( bool, is_specialized = false );
- // No "signed" nor "type" here
- };
-
- template < int Rank >
- struct integral_rank_to_type< Rank, signed, typename
- enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
- highest_integral_rank)>::type >
- {
- BOOST_STATIC_CONSTANT( bool, is_specialized = true );
- BOOST_STATIC_CONSTANT( bool, is_signed = true );
- typedef typename int_least_helper< Rank, signed >::least type;
- };
-
- template < int Rank >
- struct integral_rank_to_type< Rank, unsigned, typename
- enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
- highest_integral_rank)>::type >
- {
- BOOST_STATIC_CONSTANT( bool, is_specialized = true );
- BOOST_STATIC_CONSTANT( bool, is_signed = false );
- typedef typename int_least_helper< Rank, unsigned >::least type;
- };
-
-} // namespace detail
-
- // MPL-compatible integer-mapping class templates ------------------------//
-
- // minimum number of bits
- template < int Bits, typename Signedness >
- struct sized_integral
- {
- BOOST_STATIC_CONSTANT( bool, is_specialized = false );
- BOOST_STATIC_CONSTANT( int, bit_count = Bits );
- };
-
- template < int BitsIncludingSign >
- struct sized_integral< BitsIncludingSign, signed >
- : detail::integral_rank_to_type<
- detail::int_rank_helper::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::rank, unsigned >
- {
- BOOST_STATIC_CONSTANT( int, bit_count = Bits );
- };
-
- // exact number of bits
- template < int Bits, typename Signedness >
- struct exact_integral
- {
- BOOST_STATIC_CONSTANT( bool, is_specialized = false );
- BOOST_STATIC_CONSTANT( int, bit_count = Bits );
- };
-
- template < int BitsIncludingSign >
- struct exact_integral< BitsIncludingSign, signed >
- : detail::integral_rank_to_type<
- detail::int_exact_rank_helper::rank, signed >
- {
- BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign );
- };
-
- template < int Bits >
- struct exact_integral< Bits, unsigned >
- : detail::integral_rank_to_type<
- detail::uint_exact_rank_helper::rank, unsigned >
- {
- BOOST_STATIC_CONSTANT( int, bit_count = Bits );
- };
-
- // maximum supported (positive) value, signed
- template < intmax_t MaxValue >
- struct maximum_signed_integral
- : detail::integral_rank_to_type<
- detail::int_max_rank_helper::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::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::rank, unsigned >
- {
- BOOST_STATIC_CONSTANT( uintmax_t, bound = Value );
- };
+ // specializatons: 1=long, 2=int, 3=short, 4=signed char,
+ // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
+ // no specializations for 0 and 5: requests for a type > long are in error
+ template<> struct int_least_helper<1> { typedef long least; };
+ template<> struct int_least_helper<2> { typedef int least; };
+ template<> struct int_least_helper<3> { typedef short least; };
+ template<> struct int_least_helper<4> { typedef signed char least; };
+ template<> struct int_least_helper<6> { typedef unsigned long least; };
+ template<> struct int_least_helper<7> { typedef unsigned int least; };
+ template<> struct int_least_helper<8> { typedef unsigned short least; };
+ template<> struct int_least_helper<9> { typedef unsigned char least; };
// integer templates specifying number of bits ---------------------------//
// signed
- template< int Bits > // minimum bits (including sign) required
+ template< int Bits > // bits (including sign) required
struct int_t
{
- typedef typename sized_integral::type least;
- typedef typename int_fast_t::fast fast;
- };
-
- template< int Bits > // exact bits (including sign) desired
- struct int_exact_t
- {
- typedef typename exact_integral::type exact;
+ typedef typename int_least_helper
+ <
+ (Bits-1 <= std::numeric_limits::digits) +
+ (Bits-1 <= std::numeric_limits::digits) +
+ (Bits-1 <= std::numeric_limits::digits) +
+ (Bits-1 <= std::numeric_limits::digits)
+ >::least least;
+ typedef typename int_fast_t::fast fast;
};
// unsigned
- template< int Bits > // minimum bits required
+ template< int Bits > // bits required
struct uint_t
{
- typedef typename sized_integral::type least;
- typedef typename int_fast_t::fast fast;
+ typedef typename int_least_helper
+ <
+ 5 +
+ (Bits <= std::numeric_limits::digits) +
+ (Bits <= std::numeric_limits::digits) +
+ (Bits <= std::numeric_limits::digits) +
+ (Bits <= std::numeric_limits::digits)
+ >::least least;
+ typedef typename int_fast_t::fast fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
};
- template< int Bits > // exact bits desired
- struct uint_exact_t
- {
- typedef typename exact_integral::type exact;
- };
-
// integer templates specifying extreme value ----------------------------//
// signed
- template< intmax_t MaxValue > // maximum value to require support
+ template< long MaxValue > // maximum value to require support
struct int_max_value_t
{
- typedef typename maximum_signed_integral::type least;
- typedef typename int_fast_t::fast fast;
+ typedef typename int_least_helper
+ <
+ (MaxValue <= integer_traits::const_max) +
+ (MaxValue <= integer_traits::const_max) +
+ (MaxValue <= integer_traits::const_max) +
+ (MaxValue <= integer_traits::const_max)
+ >::least least;
+ typedef typename int_fast_t::fast fast;
};
- template< intmax_t MinValue > // minimum value to require support
+ template< long MinValue > // minimum value to require support
struct int_min_value_t
{
- typedef typename minimum_signed_integral::type least;
- typedef typename int_fast_t::fast fast;
+ typedef typename int_least_helper
+ <
+ (MinValue >= integer_traits::const_min) +
+ (MinValue >= integer_traits::const_min) +
+ (MinValue >= integer_traits::const_min) +
+ (MinValue >= integer_traits::const_min)
+ >::least least;
+ typedef typename int_fast_t::fast fast;
};
// unsigned
- template< uintmax_t Value > // maximum value to require support
+ template< unsigned long Value > // maximum value to require support
struct uint_value_t
{
- typedef typename maximum_unsigned_integral::type least;
- typedef typename int_fast_t::fast fast;
+ typedef typename int_least_helper
+ <
+ 5 +
+ (Value <= integer_traits::const_max) +
+ (Value <= integer_traits::const_max) +
+ (Value <= integer_traits::const_max) +
+ (Value <= integer_traits::const_max)
+ >::least least;
+ typedef typename int_fast_t::fast fast;
};
diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp
index a334d64..0a092d3 100644
--- a/include/boost/integer/integer_mask.hpp
+++ b/include/boost/integer/integer_mask.hpp
@@ -12,192 +12,81 @@
#include // self include
-#include // for BOOST_STATIC_CONSTANT
-#include // for boost::uintmax_t
-#include // for boost::sized_integral
-#include // for std::numeric_limits
-#include // for boost::mpl::and_
-#include // for boost::mpl::bitor_, shift_left
-#include // for boost::mpl::true_
-#include // for boost::mpl::greater_equal, etc.
-#include // for boost::mpl::empty_base
-#include // for boost::mpl::if_
-#include // for boost::mpl::int_
-#include // for boost::integral_c
-#include // for boost::mpl::next, prior
-#include // for boost::enable_if
+#include // for BOOST_STATIC_CONSTANT
+#include // for boost::uint_t
+#include // for UCHAR_MAX, etc.
#include // for std::size_t
+#include // for std::numeric_limits
+
namespace boost
{
-namespace detail
-{
-
-// Helper templates --------------------------------------------------------//
-
-template < int Bits >
-struct hi_integer_mask_builder1
-{
- typedef boost::mpl::int_ bit_count_type;
-
- typedef typename boost::mpl::next::type
- mask_length_type;
- typedef boost::sized_integral
- mask_type;
-
- typedef boost::mpl::integral_c one_type;
- typedef boost::mpl::shift_left result_type;
-};
-
-template < int Bits >
-struct hi_integer_mask_builder2
-{
- typedef boost::mpl::int_ bit_count_type;
-
- typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
- lo_bound_type;
- typedef boost::mpl::less< bit_count_type,
- boost::mpl::int_::digits> >
- hi_bound_type;
- typedef boost::mpl::and_ count_valid_type;
-};
-
-template < int Bits, class Enable = void >
-struct hi_integer_mask_builder3
-{
- BOOST_STATIC_CONSTANT( bool, is_specialized = false );
-};
-
-template < int Bits >
-struct hi_integer_mask_builder3< Bits, typename boost::enable_if::count_valid_type>::type >
- : hi_integer_mask_builder1::result_type
-{
- BOOST_STATIC_CONSTANT( bool, is_specialized = true );
-};
-
-template < int Bits >
-struct lo_integer_mask_builder1
-{
- typedef boost::mpl::int_ bit_count_type;
-
- typedef typename boost::mpl::prior::type
- shift_length_type;
- typedef boost::sized_integral
- mask_type;
-
- typedef boost::mpl::integral_c 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;
-};
-
-template < >
-struct lo_integer_mask_builder1< 0 >
-{
- // Let's not deal with negative interim values....
- typedef boost::mpl::integral_c result_type;
-};
-
-template < int Bits >
-struct lo_integer_mask_builder2
-{
- typedef boost::mpl::int_ bit_count_type;
-
- typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
- lo_bound_type;
- typedef boost::mpl::less_equal< bit_count_type,
- boost::mpl::int_::digits> >
- hi_bound_type;
- typedef boost::mpl::and_ count_valid_type;
-};
-
-template < >
-struct lo_integer_mask_builder2< 0 >
-{
- typedef boost::mpl::true_ count_valid_type;
-};
-
-template < int Bits, class Enable = void >
-struct lo_integer_mask_builder3
-{
- BOOST_STATIC_CONSTANT( bool, is_specialized = false );
- // No MPL Integral Constant to inherit from
-};
-
-template < int Bits >
-struct lo_integer_mask_builder3< Bits, typename enable_if::count_valid_type>::type >
- : lo_integer_mask_builder1::result_type
-{
- BOOST_STATIC_CONSTANT( bool, is_specialized = true );
-};
-
-} // namespace detail
-
-
-// MPL-compatible integer mask class templates -----------------------------//
-
-// Displaced single-bit mask, 1 << Offset, 0 <= Offset < BitLengthOf(uintmax_t)
-template < int Offset >
-struct integer_hi_mask
- : detail::hi_integer_mask_builder3
-{
- BOOST_STATIC_CONSTANT( int, bit_offset = Offset );
-};
-
-// Lowest bit-group mask, 2**Length - 1, 0 <= Length <= BitLengthOf(uintmax_t)
-template < int Length >
-struct integer_lo_mask
- : detail::lo_integer_mask_builder3
-{
- BOOST_STATIC_CONSTANT( int, bit_count = Length );
-};
// Specified single-bit mask class declaration -----------------------------//
// (Lowest bit starts counting at 0.)
template < std::size_t Bit >
-class high_bit_mask_t
+struct high_bit_mask_t
{
- typedef integer_hi_mask impl_type;
+ typedef typename uint_t<(Bit + 1)>::least least;
+ typedef typename uint_t<(Bit + 1)>::fast fast;
-public:
- typedef typename impl_type::value_type least;
- typedef typename int_fast_t::fast fast;
+ BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
+ BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
- BOOST_STATIC_CONSTANT( least, high_bit = impl_type::value );
- BOOST_STATIC_CONSTANT( fast, high_bit_fast = impl_type::value );
-
- BOOST_STATIC_CONSTANT( std::size_t, bit_position = impl_type::bit_offset );
+ BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
}; // boost::high_bit_mask_t
// Specified bit-block mask class declaration ------------------------------//
// Makes masks for the lowest N bits
+// (Specializations are needed when N fills up a type.)
template < std::size_t Bits >
-class low_bits_mask_t
+struct low_bits_mask_t
{
- typedef integer_lo_mask impl_type;
+ typedef typename uint_t::least least;
+ typedef typename uint_t::fast fast;
-public:
- typedef typename impl_type::value_type least;
- typedef typename int_fast_t::fast fast;
+ BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
+ BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
- BOOST_STATIC_CONSTANT( least, sig_bits = impl_type::value );
- BOOST_STATIC_CONSTANT( fast, sig_bits_fast = impl_type::value );
-
- BOOST_STATIC_CONSTANT( std::size_t, bit_count = impl_type::bit_count );
+ BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
}; // boost::low_bits_mask_t
+#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
+ template < > struct low_bits_mask_t< std::numeric_limits::digits > { \
+ typedef std::numeric_limits limits_type; \
+ typedef uint_t::least least; \
+ typedef uint_t::fast fast; \
+ BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
+ BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
+ BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
+ }
+
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
+
+#if USHRT_MAX > UCHAR_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
+#endif
+
+#if UINT_MAX > USHRT_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
+#endif
+
+#if ULONG_MAX > UINT_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
+#endif
+
+#undef BOOST_LOW_BITS_MASK_SPECIALIZE
+
+
} // namespace boost
diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp
index 3ece2e3..33cfc99 100644
--- a/include/boost/integer_fwd.hpp
+++ b/include/boost/integer_fwd.hpp
@@ -9,12 +9,11 @@
#ifndef BOOST_INTEGER_FWD_HPP
#define BOOST_INTEGER_FWD_HPP
+#include // for UCHAR_MAX, etc.
#include // for std::size_t
-#include // for BOOST_NO_INTRINSIC_WCHAR_T, etc.
-#include // for boost::uintmax_t, intmax_t
-
-#include // for BOOST_HAS_XINT, etc.
+#include // for BOOST_NO_INTRINSIC_WCHAR_T
+#include // for std::numeric_limits
namespace boost
@@ -25,13 +24,6 @@ namespace boost
// Only has typedefs or using statements, with #conditionals
-// ALERT: the forward declarations of items in need items
-// from this header. That means that cannot #include this
-// forwarding header, to avoid infinite recursion! One day, maybe
-// boost::uintmax_t and boost::intmax_t could be segregated into their own
-// header file (which can't #include this header), will use
-// that header, and could refer to .
-
// From -----------------------------------------//
@@ -73,73 +65,61 @@ template < >
template < >
class integer_traits< unsigned long >;
-#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
+#ifdef ULLONG_MAX
template < >
- class integer_traits< ::boost::detail::xint_t >;
+ class integer_traits< ::boost::long_long_type>;
template < >
- class integer_traits< ::boost::detail::uxint_t >;
+ class integer_traits< ::boost::ulong_long_type >;
#endif
// From ------------------------------------------------//
-template < typename BaseInt >
- struct fast_integral;
-
template < typename LeastInt >
struct int_fast_t;
-template < int Bits, typename Signedness >
- struct sized_integral;
-
-template < int Bits, typename Signedness >
- struct exact_integral;
-
-template < intmax_t MaxValue >
- struct maximum_signed_integral;
-
-template < intmax_t MinValue >
- struct minimum_signed_integral;
-
-template < uintmax_t Value >
- struct maximum_unsigned_integral;
-
template< int Bits >
struct int_t;
-template< int Bits >
- struct int_exact_t;
-
template< int Bits >
struct uint_t;
-template< int Bits >
- struct uint_exact_t;
-
-template< intmax_t MaxValue >
+template< long MaxValue >
struct int_max_value_t;
-template< intmax_t MinValue >
+template< long MinValue >
struct int_min_value_t;
-template< uintmax_t Value >
+template< unsigned long Value >
struct uint_value_t;
// From -----------------------------------//
-template < int Offset >
- struct integer_hi_mask;
-
-template < int Length >
- struct integer_lo_mask;
-
template < std::size_t Bit >
- class high_bit_mask_t;
+ struct high_bit_mask_t;
template < std::size_t Bits >
- class low_bits_mask_t;
+ struct low_bits_mask_t;
+
+template < >
+ struct low_bits_mask_t< ::std::numeric_limits::digits >;
+
+#if USHRT_MAX > UCHAR_MAX
+template < >
+ struct low_bits_mask_t< ::std::numeric_limits::digits >;
+#endif
+
+#if UINT_MAX > USHRT_MAX
+template < >
+ struct low_bits_mask_t< ::std::numeric_limits::digits >;
+#endif
+
+#if ULONG_MAX > UINT_MAX
+template < >
+ struct low_bits_mask_t< ::std::numeric_limits::digits >;
+#endif
// From ------------------------------------//
diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp
index 4cdc817..96b3526 100644
--- a/include/boost/integer_traits.hpp
+++ b/include/boost/integer_traits.hpp
@@ -27,8 +27,6 @@
#include
#endif
-#include // for BOOST_HAS_XINT, etc.
-
namespace boost {
template
@@ -157,18 +155,77 @@ class integer_traits
public detail::integer_traits_base
{ };
-#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
+#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
+#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
+
template<>
-class integer_traits< detail::xint_t >
- : public std::numeric_limits< detail::xint_t >,
- public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX >
+class integer_traits< ::boost::long_long_type>
+ : public std::numeric_limits< ::boost::long_long_type>,
+ public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
{ };
template<>
-class integer_traits< detail::uxint_t >
- : public std::numeric_limits< detail::uxint_t >,
- public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX >
+class integer_traits< ::boost::ulong_long_type>
+ : public std::numeric_limits< ::boost::ulong_long_type>,
+ public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
{ };
+
+#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
+
+template<>
+class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ };
+template<>
+class integer_traits< ::boost::ulong_long_type>
+ : public std::numeric_limits< ::boost::ulong_long_type>,
+ public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
+{ };
+
+#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
+
+template<>
+class integer_traits< ::boost::long_long_type>
+ : public std::numeric_limits< ::boost::long_long_type>,
+ public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
+{ };
+
+template<>
+class integer_traits< ::boost::ulong_long_type>
+ : public std::numeric_limits< ::boost::ulong_long_type>,
+ public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
+{ };
+
+#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
+
+template<>
+class integer_traits< ::boost::long_long_type>
+ : public std::numeric_limits< ::boost::long_long_type>,
+ public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
+{ };
+
+template<>
+class integer_traits< ::boost::ulong_long_type>
+ : public std::numeric_limits< ::boost::ulong_long_type>,
+ public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
+{ };
+
+#elif defined(BOOST_HAS_LONG_LONG)
+//
+// we have long long but no constants, this happens for example with gcc in -ansi mode,
+// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
+//
+template<>
+class integer_traits< ::boost::long_long_type>
+ : public std::numeric_limits< ::boost::long_long_type>,
+ public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
+{ };
+
+template<>
+class integer_traits< ::boost::ulong_long_type>
+ : public std::numeric_limits< ::boost::ulong_long_type>,
+ public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
+{ };
+
+#endif
#endif
} // namespace boost
diff --git a/integer.htm b/integer.htm
index 0130d7a..3d3f9c5 100644
--- a/integer.htm
+++ b/integer.htm
@@ -21,9 +21,8 @@ is particularly useful for solving generic programming problems.
- Contents
- Synopsis
- - Processor-Optimized Types
+ - Easiest-to-Manipulate Types
- Sized Types
- - MPL-Compatible Variants
- Example
- Demonstration Program
- Rationale
@@ -33,145 +32,67 @@ is particularly useful for solving generic programming problems.
-
-#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/integer_mask_test.cpp b/test/integer_mask_test.cpp
index 65b6fc2..6146ddf 100644
--- a/test/integer_mask_test.cpp
+++ b/test/integer_mask_test.cpp
@@ -8,164 +8,104 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
-// 29 Jul 2008 Added MPL-compatible variants of the integer-mask templates.
-// (Daryle Walker)
-// 27 Jul 2008 Changed tests to use the unit-test system; added
-// extended-integer support. (Daryle Walker)
// 23 Sep 2001 Initial version (Daryle Walker)
-#define BOOST_TEST_MODULE "Integer mask tests"
-#include // unit testing framework
+#define BOOST_INCLUDE_MAIN
+#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
-#include // for std::endl
+#include // for std::cout (std::endl indirectly)
-// Control if events will be printed conventionally, or just logged.
-#ifndef CONTROL_SHOW_TYPES
-#define CONTROL_SHOW_TYPES 0
-#endif
+#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
+ (v) >::high_bit == (1ul << (v)) );
+#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
+ (v) >::high_bit_fast == (1ul << (v)) );
+#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
+ PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
-// Logging
-#if CONTROL_SHOW_TYPES
-#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
-#else
-#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
-#endif
+#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
+ (v) >::sig_bits == ((1ul << (v)) - 1) );
+#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
+ (v) >::sig_bits_fast == ((1ul << (v)) - 1) );
+#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
+ PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
-// Custom types/templates, helper functions, and objects
-namespace
+int test_main( int, char*[] )
{
+ using std::cout;
+ using std::endl;
-// List the ranges of template parameters tests (ranges are half-open)
-int const max_offset = std::numeric_limits::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).
- PRIVATE_SHOW_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 )
-{
- PRIVATE_SHOW_MESSAGE( "There is no " << template_name << "<" << setting <<
- "> specialization." );
- return false;
-}
-
-} // unnamed namespace
-
-
-// Check the various integer-valued bit-masks
-BOOST_AUTO_TEST_SUITE( integer_mask_tests )
-
-// Check the bit-masks of one offset bit
-BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets )
-{
- typedef boost::mpl::integral_c::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()