Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57941 - in trunk: boost libs/integer/doc libs/integer/doc/html libs/integer/doc/html/boost_integer libs/integer/test
From: john_at_[hidden]
Date: 2009-11-26 06:08:29


Author: johnmaddock
Date: 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
New Revision: 57941
URL: http://svn.boost.org/trac/boost/changeset/57941

Log:
Added support for exact width integer type to int_t and uint_t
Updated docs to match.
Fixes #1225.
Text files modified:
   trunk/boost/integer.hpp | 45 +++
   trunk/libs/integer/doc/html/boost_integer/history.html | 4
   trunk/libs/integer/doc/html/boost_integer/integer.html | 14
   trunk/libs/integer/doc/html/boost_integer/mask.html | 4
   trunk/libs/integer/doc/html/index.html | 4
   trunk/libs/integer/doc/integer.qbk | 11
   trunk/libs/integer/test/Jamfile.v2 | 6
   trunk/libs/integer/test/cstdint_test.cpp | 120 ++++-----
   trunk/libs/integer/test/integer_test.cpp | 470 +++++++++++++++++----------------------
   9 files changed, 339 insertions(+), 339 deletions(-)

Modified: trunk/boost/integer.hpp
==============================================================================
--- trunk/boost/integer.hpp (original)
+++ trunk/boost/integer.hpp 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -21,6 +21,18 @@
 #include <boost/limits.hpp> // for ::std::numeric_limits
 #include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
 
+//
+// We simply cannot include this header on gcc without getting copious warnings of the kind:
+//
+// boost/integer.hpp:77:30: warning: use of C99 long long integer constant
+//
+// And yet there is no other reasonable implementation, so we declare this a system header
+// to suppress these warnings.
+//
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#pragma GCC system_header
+#endif
+
 namespace boost
 {
 
@@ -54,13 +66,42 @@
   template<> struct int_least_helper<9> { typedef unsigned short least; };
   template<> struct int_least_helper<10> { typedef unsigned char least; };
 
+ template <int Bits>
+ struct exact_signed_base_helper{};
+ template <int Bits>
+ struct exact_unsigned_base_helper{};
+
+ template <> struct exact_signed_base_helper<sizeof(signed char)* CHAR_BIT> { typedef signed char exact; };
+ template <> struct exact_unsigned_base_helper<sizeof(unsigned char)* CHAR_BIT> { typedef unsigned char exact; };
+#if USHRT_MAX != UCHAR_MAX
+ template <> struct exact_signed_base_helper<sizeof(short)* CHAR_BIT> { typedef short exact; };
+ template <> struct exact_unsigned_base_helper<sizeof(unsigned short)* CHAR_BIT> { typedef unsigned short exact; };
+#endif
+#if UINT_MAX != USHRT_MAX
+ template <> struct exact_signed_base_helper<sizeof(int)* CHAR_BIT> { typedef int exact; };
+ template <> struct exact_unsigned_base_helper<sizeof(unsigned int)* CHAR_BIT> { typedef unsigned int exact; };
+#endif
+#if ULONG_MAX != UINT_MAX
+ template <> struct exact_signed_base_helper<sizeof(long)* CHAR_BIT> { typedef long exact; };
+ template <> struct exact_unsigned_base_helper<sizeof(unsigned long)* CHAR_BIT> { typedef unsigned long exact; };
+#endif
+#if defined(BOOST_HAS_LONG_LONG) &&\
+ ((defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) ||\
+ (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) ||\
+ (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) ||\
+ (defined(_ULLONG_MAX) && (_ULLONG_MAX != ULONG_MAX)))
+ template <> struct exact_signed_base_helper<sizeof(long long)* CHAR_BIT> { typedef long long exact; };
+ template <> struct exact_unsigned_base_helper<sizeof(unsigned long long)* CHAR_BIT> { typedef unsigned long long exact; };
+#endif
+
+
   } // namespace detail
 
   // integer templates specifying number of bits ---------------------------//
 
   // signed
   template< int Bits > // bits (including sign) required
- struct int_t
+ struct int_t : public detail::exact_signed_base_helper<Bits>
   {
       typedef typename detail::int_least_helper
         <
@@ -79,7 +120,7 @@
 
   // unsigned
   template< int Bits > // bits required
- struct uint_t
+ struct uint_t : public detail::exact_unsigned_base_helper<Bits>
   {
       typedef typename detail::int_least_helper
         <

Modified: trunk/libs/integer/doc/html/boost_integer/history.html
==============================================================================
--- trunk/libs/integer/doc/html/boost_integer/history.html (original)
+++ trunk/libs/integer/doc/html/boost_integer/history.html 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -26,7 +26,7 @@
 <a name="boost_integer.history"></a><a class="link" href="history.html" title="History"> History</a>
 </h2></div></div></div>
 <a name="boost_integer.history.1_42_0"></a><h5>
-<a name="id677364"></a>
+<a name="id785558"></a>
       <a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
     </h5>
 <div class="itemizedlist"><ul type="disc">
@@ -55,7 +55,7 @@
       </li>
 </ul></div>
 <a name="boost_integer.history.1_32_0"></a><h5>
-<a name="id677466"></a>
+<a name="id785660"></a>
       <a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
     </h5>
 <div class="itemizedlist"><ul type="disc"><li>

Modified: trunk/libs/integer/doc/html/boost_integer/integer.html
==============================================================================
--- trunk/libs/integer/doc/html/boost_integer/integer.html (original)
+++ trunk/libs/integer/doc/html/boost_integer/integer.html 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -61,6 +61,8 @@
 </span> <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">&gt;</span>
   <span class="keyword">struct</span> <span class="identifier">int_t</span>
   <span class="special">{</span>
+ <span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
+ <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
       <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
       <span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
   <span class="special">};</span>
@@ -69,6 +71,8 @@
 </span> <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">&gt;</span>
   <span class="keyword">struct</span> <span class="identifier">uint_t</span>
   <span class="special">{</span>
+ <span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
+ <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
       <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
       <span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
   <span class="special">};</span>
@@ -136,7 +140,7 @@
         <code class="literal">fast</code>. The following table describes each template's criteria.
       </p>
 <div class="table">
-<a name="id673121"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
+<a name="id781298"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
 <div class="table-contents"><table class="table" summary="Criteria for the Sized Type Class Templates">
 <colgroup>
 <col>
@@ -166,7 +170,9 @@
               The smallest built-in signed integral type with at least <span class="emphasis"><em>N</em></span>
               bits, including the sign bit. The parameter should be a positive number.
               A compile-time error results if the parameter is larger than the number
- of bits in the largest integer type.
+ of bits in the largest integer type. Note that the member <span class="emphasis"><em>exact</em></span>
+ is defined <span class="bold"><strong>only</strong></span> if there is a type
+ with exactly N bits.
             </p>
             </td>
 </tr>
@@ -181,7 +187,9 @@
               The smallest built-in unsigned integral type with at least <span class="emphasis"><em>N</em></span>
               bits. The parameter should be a positive number. A compile-time error
               results if the parameter is larger than the number of bits in the largest
- integer type.
+ integer type. Note that the member <span class="emphasis"><em>exact</em></span> is defined
+ <span class="bold"><strong>only</strong></span> if there is a type with exactly
+ N bits.
             </p>
             </td>
 </tr>

Modified: trunk/libs/integer/doc/html/boost_integer/mask.html
==============================================================================
--- trunk/libs/integer/doc/html/boost_integer/mask.html (original)
+++ trunk/libs/integer/doc/html/boost_integer/mask.html 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -105,7 +105,7 @@
         of <code class="literal">high_bit_mask_t</code>.
       </p>
 <div class="table">
-<a name="id674116"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
+<a name="id782311"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
 <div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
 <colgroup>
 <col>
@@ -205,7 +205,7 @@
         the members of an instantiation of <code class="literal">low_bits_mask_t</code>.
       </p>
 <div class="table">
-<a name="id674318"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
+<a name="id782512"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
 <div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
 <colgroup>
 <col>

Modified: trunk/libs/integer/doc/html/index.html
==============================================================================
--- trunk/libs/integer/doc/html/index.html (original)
+++ trunk/libs/integer/doc/html/index.html 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -40,7 +40,7 @@
 <div><p class="copyright">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
       John Maddock</p></div>
 <div><div class="legalnotice">
-<a name="id662860"></a><p>
+<a name="id770995"></a><p>
         Distributed under the Boost Software License, Version 1.0. (See accompanying
         file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       </p>
@@ -229,7 +229,7 @@
 </div>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: November 25, 2009 at 12:02:32 GMT</small></p></td>
+<td align="left"><p><small>Last revised: November 26, 2009 at 11:06:43 GMT</small></p></td>
 <td align="right"><div class="copyright-footer"></div></td>
 </tr></table>
 <hr>

Modified: trunk/libs/integer/doc/integer.qbk
==============================================================================
--- trunk/libs/integer/doc/integer.qbk (original)
+++ trunk/libs/integer/doc/integer.qbk 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -282,6 +282,8 @@
      template<int Bits>
      struct int_t
      {
+ /* Member exact may or may not be defined depending upon Bits */
+ typedef ``['implementation-defined-type]`` exact;
          typedef ``['implementation-defined-type]`` least;
          typedef int_fast_t<least>::fast fast;
      };
@@ -290,6 +292,8 @@
      template<int Bits>
      struct uint_t
      {
+ /* Member exact may or may not be defined depending upon Bits */
+ typedef ``['implementation-defined-type]`` exact;
          typedef ``['implementation-defined-type]`` least;
          typedef int_fast_t<least>::fast fast;
      };
@@ -351,13 +355,16 @@
       [[^boost::int_t<N>]]
       [The smallest built-in signed integral type with at least /N/ bits, including the sign bit.
       The parameter should be a positive number. A compile-time error results if the parameter is
- larger than the number of bits in the largest integer type.]
+ larger than the number of bits in the largest integer type. Note that the member /exact/ is defined
+ [*only] if there is a type with exactly N bits.]
    ]
    [
       [[^boost::uint_t<N>]]
       [The smallest built-in unsigned integral type with at least /N/ bits.
       The parameter should be a positive number. A compile-time error results if the
- parameter is larger than the number of bits in the largest integer type.]
+ parameter is larger than the number of bits in the largest integer type.
+ Note that the member /exact/ is defined
+ [*only] if there is a type with exactly N bits.]
    ]
    [
       [[^boost::int_max_value_t<V>]]

Modified: trunk/libs/integer/test/Jamfile.v2
==============================================================================
--- trunk/libs/integer/test/Jamfile.v2 (original)
+++ trunk/libs/integer/test/Jamfile.v2 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -5,11 +5,11 @@
 import testing ;
 
 test-suite integer
- : [ run cstdint_test.cpp ]
- [ run integer_test.cpp
- /boost/test//minimal ]
+ : [ run cstdint_test.cpp /boost/test//minimal ]
         [ run integer_traits_test.cpp
             /boost/test//boost_test_exec_monitor ]
+ [ run integer_test.cpp
+ /boost/test//minimal ]
         [ run integer_mask_test.cpp
             /boost/test//minimal ]
         [ run static_log2_test.cpp

Modified: trunk/libs/integer/test/cstdint_test.cpp
==============================================================================
--- trunk/libs/integer/test/cstdint_test.cpp (original)
+++ trunk/libs/integer/test/cstdint_test.cpp 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -13,17 +13,10 @@
 // 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
 // 28 Jun 00 Initial version
 #define __STDC_CONSTANT_MACROS
-#include <cassert>
 #include <iostream>
 #include <boost/cstdint.hpp>
+#include <boost/test/minimal.hpp>
 
-#ifdef NDEBUG
-int main()
-{
- std::cout << "This test makes no sense with NDEBUG defined.\n";
- return 0;
-}
-#else
 
 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
 //
@@ -62,24 +55,24 @@
 
 void integral_constant_checker::check()
 {
- assert( int8 == -127 );
- assert( int_least8 == -127 );
- assert( int_fast8 == -127 );
- assert( uint8 == 255u );
- assert( uint_least8 == 255u );
- assert( uint_fast8 == 255u );
- assert( int16 == -32767 );
- assert( int_least16 == -32767 );
- assert( int_fast16 == -32767 );
- assert( uint16 == 65535u );
- assert( uint_least16 == 65535u );
- assert( uint_fast16 == 65535u );
- assert( int32 == -2147483647 );
- assert( int_least32 == -2147483647 );
- assert( int_fast32 == -2147483647 );
- assert( uint32 == 4294967295u );
- assert( uint_least32 == 4294967295u );
- assert( uint_fast32 == 4294967295u );
+ BOOST_CHECK( int8 == -127 );
+ BOOST_CHECK( int_least8 == -127 );
+ BOOST_CHECK( int_fast8 == -127 );
+ BOOST_CHECK( uint8 == 255u );
+ BOOST_CHECK( uint_least8 == 255u );
+ BOOST_CHECK( uint_fast8 == 255u );
+ BOOST_CHECK( int16 == -32767 );
+ BOOST_CHECK( int_least16 == -32767 );
+ BOOST_CHECK( int_fast16 == -32767 );
+ BOOST_CHECK( uint16 == 65535u );
+ BOOST_CHECK( uint_least16 == 65535u );
+ BOOST_CHECK( uint_fast16 == 65535u );
+ BOOST_CHECK( int32 == -2147483647 );
+ BOOST_CHECK( int_least32 == -2147483647 );
+ BOOST_CHECK( int_fast32 == -2147483647 );
+ BOOST_CHECK( uint32 == 4294967295u );
+ BOOST_CHECK( uint_least32 == 4294967295u );
+ BOOST_CHECK( uint_fast32 == 4294967295u );
 }
 #endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
 
@@ -108,10 +101,10 @@
    // if we have a native stdint.h
    // then the INTXX_C macros may define
    // a type that's wider than required:
- assert(sizeof(T1) <= sizeof(T2));
+ BOOST_CHECK(sizeof(T1) <= sizeof(T2));
 #else
- assert(sizeof(T1) == sizeof(T2));
- assert(t1 == t2);
+ BOOST_CHECK(sizeof(T1) == sizeof(T2));
+ BOOST_CHECK(t1 == t2);
 #endif
 #if defined(BOOST_HAS_STDINT_H)
    // native headers are permitted to promote small
@@ -119,22 +112,22 @@
    if(sizeof(T1) >= sizeof(int))
    {
       if(t1 > 0)
- assert(t2 > 0);
+ BOOST_CHECK(t2 > 0);
       else
- assert(!(t2 > 0));
+ BOOST_CHECK(!(t2 > 0));
    }
    else if(t1 < 0)
- assert(!(t2 > 0));
+ BOOST_CHECK(!(t2 > 0));
 #else
    if(t1 > 0)
- assert(t2 > 0);
+ BOOST_CHECK(t2 > 0);
    else
- assert(!(t2 > 0));
+ BOOST_CHECK(!(t2 > 0));
 #endif
 }
 
 
-int main()
+int test_main(int, char*[])
 {
 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
   integral_constant_checker::check();
@@ -193,41 +186,40 @@
   boost::uintmax_t uintmax = UINTMAX_C(4294967295);
 #endif
 
- assert( int8 == -127 );
- assert( int_least8 == -127 );
- assert( int_fast8 == -127 );
- assert( uint8 == 255u );
- assert( uint_least8 == 255u );
- assert( uint_fast8 == 255u );
- assert( int16 == -32767 );
- assert( int_least16 == -32767 );
- assert( int_fast16 == -32767 );
- assert( uint16 == 65535u );
- assert( uint_least16 == 65535u );
- assert( uint_fast16 == 65535u );
- assert( int32 == -2147483647 );
- assert( int_least32 == -2147483647 );
- assert( int_fast32 == -2147483647 );
- assert( uint32 == 4294967295u );
- assert( uint_least32 == 4294967295u );
- assert( uint_fast32 == 4294967295u );
+ BOOST_CHECK( int8 == -127 );
+ BOOST_CHECK( int_least8 == -127 );
+ BOOST_CHECK( int_fast8 == -127 );
+ BOOST_CHECK( uint8 == 255u );
+ BOOST_CHECK( uint_least8 == 255u );
+ BOOST_CHECK( uint_fast8 == 255u );
+ BOOST_CHECK( int16 == -32767 );
+ BOOST_CHECK( int_least16 == -32767 );
+ BOOST_CHECK( int_fast16 == -32767 );
+ BOOST_CHECK( uint16 == 65535u );
+ BOOST_CHECK( uint_least16 == 65535u );
+ BOOST_CHECK( uint_fast16 == 65535u );
+ BOOST_CHECK( int32 == -2147483647 );
+ BOOST_CHECK( int_least32 == -2147483647 );
+ BOOST_CHECK( int_fast32 == -2147483647 );
+ BOOST_CHECK( uint32 == 4294967295u );
+ BOOST_CHECK( uint_least32 == 4294967295u );
+ BOOST_CHECK( uint_fast32 == 4294967295u );
 
 #ifndef BOOST_NO_INT64_T
- assert( int64 == INT64_C(-9223372036854775807) );
- assert( int_least64 == INT64_C(-9223372036854775807) );
- assert( int_fast64 == INT64_C(-9223372036854775807) );
- assert( uint64 == UINT64_C(18446744073709551615) );
- assert( uint_least64 == UINT64_C(18446744073709551615) );
- assert( uint_fast64 == UINT64_C(18446744073709551615) );
- assert( intmax == INT64_C(-9223372036854775807) );
- assert( uintmax == UINT64_C(18446744073709551615) );
+ BOOST_CHECK( int64 == INT64_C(-9223372036854775807) );
+ BOOST_CHECK( int_least64 == INT64_C(-9223372036854775807) );
+ BOOST_CHECK( int_fast64 == INT64_C(-9223372036854775807) );
+ BOOST_CHECK( uint64 == UINT64_C(18446744073709551615) );
+ BOOST_CHECK( uint_least64 == UINT64_C(18446744073709551615) );
+ BOOST_CHECK( uint_fast64 == UINT64_C(18446744073709551615) );
+ BOOST_CHECK( intmax == INT64_C(-9223372036854775807) );
+ BOOST_CHECK( uintmax == UINT64_C(18446744073709551615) );
 #else
- assert( intmax == -2147483647 );
- assert( uintmax == 4294967295u );
+ BOOST_CHECK( intmax == -2147483647 );
+ BOOST_CHECK( uintmax == 4294967295u );
 #endif
 
 
   std::cout << "OK\n";
   return 0;
 }
-#endif

Modified: trunk/libs/integer/test/integer_test.cpp
==============================================================================
--- trunk/libs/integer/test/integer_test.cpp (original)
+++ trunk/libs/integer/test/integer_test.cpp 2009-11-26 06:08:27 EST (Thu, 26 Nov 2009)
@@ -1,6 +1,9 @@
 // boost integer.hpp test program ------------------------------------------//
 
-// Copyright Beman Dawes 1999. Distributed under the Boost
+// Copyright Beman Dawes 1999.
+// Copyright Daryle Walker 2001.
+// Copyright John Maddock 2009.
+// Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
@@ -13,10 +16,8 @@
 // 31 Aug 99 Initial version
 
 #include <boost/test/minimal.hpp> // for main, BOOST_CHECK
-
-#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
-#include <boost/cstdlib.hpp> // for boost::exit_success
 #include <boost/integer.hpp> // for boost::int_t, boost::uint_t
+#include <boost/type_traits/is_same.hpp>
 
 #include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
 #include <iostream> // for std::cout (std::endl indirectly)
@@ -25,271 +26,222 @@
 #ifdef BOOST_MSVC
 #pragma warning(disable:4127) // conditional expression is constant
 #endif
-
-
-// Control if the names of the types for each version
-// of the integer templates will be printed.
-#ifndef CONTROL_SHOW_TYPES
-#define CONTROL_SHOW_TYPES 0
+//
+// Keep track of error count, so we can print out detailed
+// info only if we need it:
+//
+unsigned last_error_count = 0;
+//
+// Helpers to print out the name of a type,
+// we use these as typeid(X).name() doesn't always
+// return a human readable string:
+//
+template <class T> const char* get_name_of_type(T){ return typeid(T).name(); }
+const char* get_name_of_type(signed char){ return "signed char"; }
+const char* get_name_of_type(unsigned char){ return "unsigned char"; }
+const char* get_name_of_type(short){ return "short"; }
+const char* get_name_of_type(unsigned short){ return "unsigned short"; }
+const char* get_name_of_type(int){ return "int"; }
+const char* get_name_of_type(unsigned int){ return "unsigned int"; }
+const char* get_name_of_type(long){ return "long"; }
+const char* get_name_of_type(unsigned long){ return "unsigned long"; }
+#ifdef BOOST_HAS_LONG_LONG
+const char* get_name_of_type(long long){ return "long long"; }
+const char* get_name_of_type(unsigned long long){ return "unsigned long long"; }
 #endif
 
+template <int Bits>
+void do_test_exact(boost::mpl::true_ const&)
+{
+ // Test the ::exact member:
+ typedef typename boost::int_t<Bits>::exact int_exact;
+ typedef typename boost::uint_t<Bits>::exact uint_exact;
+ typedef typename boost::int_t<Bits>::least least_int;
+ typedef typename boost::uint_t<Bits>::least least_uint;
 
-// If specializations have not already been done, then we can confirm
-// the effects of the "fast" types by making a specialization.
-namespace boost
+ BOOST_CHECK((boost::is_same<int_exact, least_int>::value));
+ BOOST_CHECK((boost::is_same<uint_exact, least_uint>::value));
+}
+template <int Bits>
+void do_test_exact(boost::mpl::false_ const&)
 {
- template < >
- struct int_fast_t< short >
- {
- typedef long fast;
- };
+ // Nothing to do, type does not have an ::extact member.
 }
 
-
-// Show the types of an integer template version
-#if CONTROL_SHOW_TYPES
-#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \
- #Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \
- Number > :: Type).name() << ".\"\n"
-#else
-#define SHOW_TYPE(Template, Number, Type)
-#endif
-
-#define SHOW_TYPES(Template, Type) SHOW_TYPE(Template, 32, Type); \
- SHOW_TYPE(Template, 31, Type); SHOW_TYPE(Template, 30, Type); \
- SHOW_TYPE(Template, 29, Type); SHOW_TYPE(Template, 28, Type); \
- SHOW_TYPE(Template, 27, Type); SHOW_TYPE(Template, 26, Type); \
- SHOW_TYPE(Template, 25, Type); SHOW_TYPE(Template, 24, Type); \
- SHOW_TYPE(Template, 23, Type); SHOW_TYPE(Template, 22, Type); \
- SHOW_TYPE(Template, 21, Type); SHOW_TYPE(Template, 20, Type); \
- SHOW_TYPE(Template, 19, Type); SHOW_TYPE(Template, 18, Type); \
- SHOW_TYPE(Template, 17, Type); SHOW_TYPE(Template, 16, Type); \
- SHOW_TYPE(Template, 15, Type); SHOW_TYPE(Template, 14, Type); \
- SHOW_TYPE(Template, 13, Type); SHOW_TYPE(Template, 12, Type); \
- SHOW_TYPE(Template, 11, Type); SHOW_TYPE(Template, 10, Type); \
- SHOW_TYPE(Template, 9, Type); SHOW_TYPE(Template, 8, Type); \
- SHOW_TYPE(Template, 7, Type); SHOW_TYPE(Template, 6, Type); \
- SHOW_TYPE(Template, 5, Type); SHOW_TYPE(Template, 4, Type); \
- SHOW_TYPE(Template, 3, Type); SHOW_TYPE(Template, 2, Type); \
- SHOW_TYPE(Template, 1, Type); SHOW_TYPE(Template, 0, Type)
-
-#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type)
-
-#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \
- SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \
- SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \
- SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \
- SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \
- SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \
- SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \
- SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \
- SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \
- SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \
- SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \
- SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \
- SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \
- SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \
- SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \
- SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type)
-
-#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type)
-
-#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \
- SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type)
-
-#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type)
-
-#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \
- SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type)
-
-
-// Test if a constant can fit within a certain type
-#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value )
-
-#if (ULONG_MAX > 0xFFFFFFFFL) || !defined(BOOST_NO_INTEGRAL_INT64_T)
-#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
- PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
-#else
-#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
- PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
- PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
+template <int Bits>
+void do_test_bits()
+{
+ //
+ // Recurse to next smallest number of bits:
+ //
+ do_test_bits<Bits - 1>();
+ //
+ // Test exact types if we have them:
+ //
+ do_test_exact<Bits>(
+ boost::mpl::bool_<
+ (sizeof(unsigned char) * CHAR_BIT == Bits)
+ || (sizeof(unsigned short) * CHAR_BIT == Bits)
+ || (sizeof(unsigned int) * CHAR_BIT == Bits)
+ || (sizeof(unsigned long) * CHAR_BIT == Bits)
+#ifdef BOOST_HAS_LONG_LONG
+ || (sizeof(unsigned long long) * CHAR_BIT == Bits)
 #endif
+ >());
+ //
+ // We need to check all aspects of the members of int_t<Bits> and uint_t<Bits>:
+ //
+ typedef typename boost::int_t<Bits>::least least_int;
+ typedef typename boost::int_t<Bits>::least fast_int;
+ typedef typename boost::uint_t<Bits>::least least_uint;
+ typedef typename boost::uint_t<Bits>::fast fast_uint;
+
+ if(std::numeric_limits<least_int>::is_specialized)
+ {
+ BOOST_CHECK(std::numeric_limits<least_int>::digits + 1 >= Bits);
+ }
+ if(std::numeric_limits<least_uint>::is_specialized)
+ {
+ BOOST_CHECK(std::numeric_limits<least_uint>::digits >= Bits);
+ }
+ BOOST_CHECK(sizeof(least_int) * CHAR_BIT >= Bits);
+ BOOST_CHECK(sizeof(least_uint) * CHAR_BIT >= Bits);
+ BOOST_CHECK(sizeof(fast_int) >= sizeof(least_int));
+ BOOST_CHECK(sizeof(fast_uint) >= sizeof(least_uint));
+ //
+ // There should be no type smaller than least_* that also has enough bits:
+ //
+ if(!boost::is_same<signed char, least_int>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<signed char>::digits < Bits);
+ if(!boost::is_same<short, least_int>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<short>::digits < Bits);
+ if(!boost::is_same<int, least_int>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<int>::digits < Bits);
+ if(!boost::is_same<long, least_int>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<long>::digits < Bits);
+ }
+ }
+ }
+ }
+ // And again, but unsigned:
+ if(!boost::is_same<unsigned char, least_uint>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<unsigned char>::digits < Bits);
+ if(!boost::is_same<unsigned short, least_uint>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<unsigned short>::digits < Bits);
+ if(!boost::is_same<unsigned int, least_uint>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<unsigned int>::digits < Bits);
+ if(!boost::is_same<unsigned long, least_uint>::value)
+ {
+ BOOST_CHECK(std::numeric_limits<unsigned long>::digits < Bits);
+ }
+ }
+ }
+ }
+
+ if(boost::minimal_test::errors_counter() != last_error_count)
+ {
+ last_error_count = boost::minimal_test::errors_counter();
+ std::cout << "Errors occured while testing with bit count = " << Bits << std::endl;
+ std::cout << "Type int_t<" << Bits << ">::least was " << get_name_of_type(least_int(0)) << std::endl;
+ std::cout << "Type int_t<" << Bits << ">::fast was " << get_name_of_type(fast_int(0)) << std::endl;
+ std::cout << "Type uint_t<" << Bits << ">::least was " << get_name_of_type(least_uint(0)) << std::endl;
+ std::cout << "Type uint_t<" << Bits << ">::fast was " << get_name_of_type(fast_uint(0)) << std::endl;
+ }
+}
+template <>
+void do_test_bits<-1>()
+{
+ // Nothing to do here!!
+}
 
-#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 )
-
+template <class Traits, class Expected>
+void test_min_max_type(Expected val)
+{
+ typedef typename Traits::least least_type;
+ typedef typename Traits::fast fast_type;
+ BOOST_CHECK((boost::is_same<least_type, Expected>::value));
+ BOOST_CHECK(sizeof(fast_type) >= sizeof(least_type));
+ BOOST_CHECK((std::numeric_limits<least_type>::min)() <= val);
+ BOOST_CHECK((std::numeric_limits<least_type>::max)() >= val);
+}
 
 // Test program
-int
-test_main
-(
- int,
- char*[]
-)
+int test_main(int, char*[])
 {
-#ifndef BOOST_NO_USING_TEMPLATE
- using boost::int_t;
- using boost::uint_t;
- using boost::int_max_value_t;
- using boost::int_min_value_t;
- using boost::uint_value_t;
-#else
- using namespace boost;
+ // Test int_t and unint_t first:
+ if(std::numeric_limits<boost::intmax_t>::is_specialized)
+ do_test_bits<std::numeric_limits<boost::uintmax_t>::digits>();
+ else
+ do_test_bits<std::numeric_limits<long>::digits>();
+
+ //
+ // Test min and max value types:
+ //
+ test_min_max_type<boost::int_max_value_t<SCHAR_MAX>, signed char>(SCHAR_MAX);
+ test_min_max_type<boost::int_min_value_t<SCHAR_MIN>, signed char>(SCHAR_MIN);
+ test_min_max_type<boost::uint_value_t<UCHAR_MAX>, unsigned char>(UCHAR_MAX);
+#if(USHRT_MAX != UCHAR_MAX)
+ test_min_max_type<boost::int_max_value_t<SCHAR_MAX+1>, short>(SCHAR_MAX+1);
+ test_min_max_type<boost::int_min_value_t<SCHAR_MIN-1>, short>(SCHAR_MIN-1);
+ test_min_max_type<boost::uint_value_t<UCHAR_MAX+1>, unsigned short>(UCHAR_MAX+1);
+ test_min_max_type<boost::int_max_value_t<SHRT_MAX>, short>(SHRT_MAX);
+ test_min_max_type<boost::int_min_value_t<SHRT_MIN>, short>(SHRT_MIN);
+ test_min_max_type<boost::uint_value_t<USHRT_MAX>, unsigned short>(USHRT_MAX);
 #endif
-
- SHOW_TYPES( int_t, least );
- SHOW_TYPES( int_t, fast );
- SHOW_TYPES( uint_t, least );
- SHOW_TYPES( uint_t, fast );
- SHOW_POS_SHIFTED_TYPES( int_max_value_t, least );
- SHOW_POS_SHIFTED_TYPES( int_max_value_t, fast );
- SHOW_NEG_SHIFTED_TYPES( int_min_value_t, least );
- SHOW_NEG_SHIFTED_TYPES( int_min_value_t, fast );
- SHOW_SHIFTED_TYPES( uint_value_t, least );
- SHOW_SHIFTED_TYPES( uint_value_t, fast );
-
- PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX );
- PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX );
- PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX );
- PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX );
- PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX );
- PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX );
- PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN );
- PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN );
- PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX );
- PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX );
-
- return boost::exit_success;
+#if(UINT_MAX != USHRT_MAX)
+ test_min_max_type<boost::int_max_value_t<SHRT_MAX+1>, int>(SHRT_MAX+1);
+ test_min_max_type<boost::int_min_value_t<SHRT_MIN-1>, int>(SHRT_MIN-1);
+ test_min_max_type<boost::uint_value_t<USHRT_MAX+1>, unsigned int>(USHRT_MAX+1);
+ test_min_max_type<boost::int_max_value_t<INT_MAX>, int>(INT_MAX);
+ test_min_max_type<boost::int_min_value_t<INT_MIN>, int>(INT_MIN);
+ test_min_max_type<boost::uint_value_t<UINT_MAX>, unsigned int>(UINT_MAX);
+#endif
+#if(ULONG_MAX != UINT_MAX)
+ test_min_max_type<boost::int_max_value_t<INT_MAX+1L>, long>(INT_MAX+1L);
+ test_min_max_type<boost::int_min_value_t<INT_MIN-1L>, long>(INT_MIN-1L);
+ test_min_max_type<boost::uint_value_t<UINT_MAX+1uL>, unsigned long>(UINT_MAX+1uL);
+ test_min_max_type<boost::int_max_value_t<LONG_MAX>, long>(LONG_MAX);
+ test_min_max_type<boost::int_min_value_t<LONG_MIN>, long>(LONG_MIN);
+ test_min_max_type<boost::uint_value_t<ULONG_MAX>, unsigned long>(ULONG_MAX);
+#endif
+#if defined(BOOST_HAS_LONG_LONG) && (defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX))
+ test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, long long>(LONG_MAX+1LL);
+ test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, long long>(LONG_MIN-1LL);
+ test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, unsigned long long>(ULONG_MAX+1uLL);
+ test_min_max_type<boost::int_max_value_t<LLONG_MAX>, long long>(LLONG_MAX);
+ test_min_max_type<boost::int_min_value_t<LLONG_MIN>, long long>(LLONG_MIN);
+ test_min_max_type<boost::uint_value_t<ULLONG_MAX>, unsigned long long>(ULLONG_MAX);
+#endif
+#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX))
+ test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, long long>(LONG_MAX+1LL);
+ test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, long long>(LONG_MIN-1LL);
+ test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, unsigned long long>(ULONG_MAX+1uLL);
+ test_min_max_type<boost::int_max_value_t<LONG_LONG_MAX>, long long>(LONG_LONG_MAX);
+ test_min_max_type<boost::int_min_value_t<LONG_LONG_MIN>, long long>(LONG_LONG_MIN);
+ test_min_max_type<boost::uint_value_t<ULONG_LONG_MAX>, unsigned long long>(ULONG_LONG_MAX);
+#endif
+#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX))
+ test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, long long>(LONG_MAX+1LL);
+ test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, long long>(LONG_MIN-1LL);
+ test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, unsigned long long>(ULONG_MAX+1uLL);
+ test_min_max_type<boost::int_max_value_t<LONGLONG_MAX>, long long>(LONGLONG_MAX);
+ test_min_max_type<boost::int_min_value_t<LONGLONG_MIN>, long long>(LONGLONG_MAX);
+ test_min_max_type<boost::uint_value_t<ULONGLONG_MAX>, unsigned long long>(ULONGLONG_MAX);
+#endif
+#if defined(BOOST_HAS_LONG_LONG) && (defined(_ULLONG_MAX) && defined(_LLONG_MIN) && (_ULLONG_MAX != ULONG_MAX))
+ test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, long long>(LONG_MAX+1LL);
+ test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, long long>(LONG_MIN-1LL);
+ test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, unsigned long long>(ULONG_MAX+1uLL);
+ test_min_max_type<boost::int_max_value_t<_LLONG_MAX>, long long>(_LLONG_MAX);
+ test_min_max_type<boost::int_min_value_t<_LLONG_MIN>, long long>(_LLONG_MIN);
+ test_min_max_type<boost::uint_value_t<_ULLONG_MAX>, unsigned long long>(_ULLONG_MAX);
+#endif
+ return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk