diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index c5516fe..ec232c7 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -9,6 +9,7 @@ // See http://www.boost.org for most recent version including documentation. // Revision History +// 22 Sep 01 Added value-based integer templates. (Daryle Walker) // 01 Apr 01 Modified to use new header. (John Maddock) // 30 Jul 00 Add typename syntax fix (Jens Maurer) // 28 Aug 99 Initial version @@ -16,7 +17,10 @@ #ifndef BOOST_INTEGER_HPP #define BOOST_INTEGER_HPP -#include +#include // self include + +#include // for boost::integer_traits +#include // for std::numeric_limits namespace boost { @@ -75,11 +79,51 @@ namespace boost // int_fast_t<> works correctly for unsigned too, in spite of the name. }; -// The same dispatching technique can be used to select types based on -// values. That will be added once boost::integer_traits is available. + // integer templates specifying extreme value ----------------------------// + + // signed + template< long MaxValue > // maximum value to require support + struct int_max_value_t + { + 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< long MinValue > // minimum value to require support + struct int_min_value_t + { + 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< unsigned long Value > // maximum value to require support + struct uint_value_t + { + 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; + }; } // namespace boost #endif // BOOST_INTEGER_HPP - diff --git a/index.htm b/index.htm index 00134aa..d6f176f 100644 --- a/index.htm +++ b/index.htm @@ -1,98 +1,128 @@ + - - - - - Boost Integer Library - - - - - - - - - - - + +
c++boost.gif (8819 bytes)Home Libraries People FAQ More
+ + + + + + + +
c++boost.gif (8819 bytes)HomeLibrariesPeopleFAQMore

Boost Integer Library

- - - - - - - + + + + + + + + + + + - - - - - + + - - - - - + + + - - - + + + + + + + + + + + + + + + +
Header / DocsContentsUse
<boost/cstdint.hpp>
+
Header / DocsContentsUse
<boost/integer_fwd.hpp>Forward declarations of classes and class templatesWhen just the name of a class is needed
<boost/cstdint.hpp>

documentation
Typedef's based on the 1999 C Standard header <stdint.h>, wrapped in namespace boost. + Typedef's based on the 1999 C Standard header <stdint.h>, wrapped in namespace boost. This implementation may #include the compiler supplied <stdint.h>, if present. Supplies typedefs for standard integer types such as int32_t or uint_least16_t. + Supplies typedefs for standard integer types such as int32_t or uint_least16_t. Use in preference to <stdint.h> for enhanced portability. Furthermore, all names are safely placed in the boost namespace.
<boost/integer_traits.hpp>
+
<boost/integer_traits.hpp>

documentation
Template class boost::integer_traits, derived from std::numeric_limits.  + Template class boost::integer_traits, derived from std::numeric_limits.  Adds const_min and const_max members.Use to obtain the characteristics of a known integer type.
<boost/integer.hpp>
+
Use to obtain the characteristics of a known integer type.
<boost/integer.hpp>

documentation
Templates for integer type selection based on properties such as + Templates for integer type selection based on properties such as maximum value or number of bits.Use to select the type an integer when some property such as maximum value or number of bits is known. + Use to select the type an integer when some property such as maximum value or number of bits is known. Useful for generic programming.
<boost/integer/integer_mask.hpp>
+
+
documentation
Templates for the selection of integer masks, single or lowest group, based on the number of bits.Use to select a particular mask when the bit position(s) are based on a compile-time variable. + Useful for generic programming.
<boost/integer/static_log2.hpp>
+
+
documentation
Template for finding the highest power of two in a number.Use to find the bit-size/range based on a maximum value. + Useful for generic programming.
<boost/integer/static_min_max.hpp>
+
+
documentation
Templates for finding the extrema of two numbers.Use to find a bound based on a minimum or maximum value. + Useful for generic programming.

Rationale

-

The organization of boost integer headers and classes is designed to take -advantage of <stdint.h> types from the 1999 C standard -without resorting to undefined behavior in terms of -the 1998 C++ standard.  The header <boost/cstdint.hpp> -makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than -compete with the C++ Standard Library.  Should some future C++ standard -include <stdint.h> and <cstdint>, then <boost/cstdint.hpp> -will continue to function, but will become redundant and may be safely deprecated.

-

Because these are boost headers, their names conform to boost header naming -conventions rather than C++ Standard Library header naming conventions. -

Caveat emptor

-

As an - implementation artifact, certain C <limits.h> macro names may possibly be -visible to users of <boost/cstdint.hpp>.  Don't use these macros; they are not part of -any Boost specified interface.  - Use boost:: integer_traits<> or std::numeric_limits<> instead.

+

The organization of boost integer headers and classes is designed to +take advantage of <stdint.h> types from the 1999 C +standard without resorting to undefined behavior in terms of the 1998 +C++ standard. The header <boost/cstdint.hpp> makes +the standard integer types safely available in namespace +boost without placing any names in namespace +std. As always, the intension is to complement rather than +compete with the C++ Standard Library. Should some future C++ standard +include <stdint.h> and <cstdint>, +then <boost/cstdint.hpp> will continue to function, +but will become redundant and may be safely deprecated.

-

-As another implementation artifact, certain C -<stdint.h> typedef names may possibly be visible in the -global namespace to users of <boost/cstdint.hpp>. -Don't use these names, they are not part of any Boost specified +

Because these are boost headers, their names conform to boost header +naming conventions rather than C++ Standard Library header naming +conventions.

+ +

Caveat emptor

+ +

As an implementation artifact, certain C +<limits.h> macro names may possibly be visible to +users of <boost/cstdint.hpp>. Don't use these +macros; they are not part of any Boost-specified interface. Use +boost::integer_traits<> or +std::numeric_limits<> instead.

+ +

As another implementation artifact, certain C +<stdint.h> typedef names may possibly be visible in +the global namespace to users of <boost/cstdint.hpp>. + Don't use these names, they are not part of any Boost-specified interface. Use the respective names in namespace boost -instead. +instead.


-

Revised: 19 Aug 2001 +

Revised: 03 Oct 2001

- diff --git a/integer.htm b/integer.htm index e4d3473..62f50bd 100644 --- a/integer.htm +++ b/integer.htm @@ -1,112 +1,214 @@ + - - - - Integer Type Selection Templates - + +

c++boost.gif (8819 bytes)Integer Type Selection +Templates

-

c++boost.gif (8819 bytes)Integer -Type Selection Templates

-

The <boost/integer.hpp> -type selection templates allow integer types to be selected based on desired -characteristics such as number of bits or maximum value.  This facility is -particularly useful for solving generic programming problems.

+

The <boost/integer.hpp> type +selection templates allow integer types to be selected based on desired +characteristics such as number of bits or maximum value. This facility +is particularly useful for solving generic programming problems.

-

The templates int_t<> and uint_t<> supply typedefs least -and fast.  The least type be the smallest type which holds at -least the number of bits (including sign) specified. The fast type will -be at least as large as the least type, but may possible be larger.  -There is no guarantee that the fast type will actually be faster than -other possible types.

+

Contents

-

Alternative

+ -

If the number of bits required is known beforehand, it may be more -appropriate to use the types supplied in <boost/cstdint.hpp>.

+

Synopsis

-

Synopsis

- -
-
namespace boost
+
+namespace boost
 {
   //  fast integers from least integers
-  // int_fast_t<> works correctly for unsigned too, in spite of the name.
-  template< typename LeastInt >  // Required: LeastInt is integral type, not bool
-  struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
+  template< typename LeastInt >
+  struct int_fast_t
+  {
+      typedef implementation_supplied  fast;
+  };
 
   //  signed
-  template< int Bits >   // bits (including sign) required, 0-32 valid
+  template< int Bits >
   struct int_t 
   {
-      typedef implementation-supplied  least;
+      typedef implementation_supplied  least;
       typedef int_fast_t<least>::fast  fast;
   };
 
   //  unsigned
-  template< int Bits >   // bits required, 0-32 valid
+  template< int Bits >
   struct uint_t 
   {
-      typedef implementation-supplied  least;
+      typedef implementation_supplied  least;
+      typedef int_fast_t<least>::fast  fast;
+  };
+
+  //  signed
+  template< long MaxValue >
+  struct int_max_value_t 
+  {
+      typedef implementation_supplied  least;
+      typedef int_fast_t<least>::fast  fast;
+  };
+
+  template< long MinValue >
+  struct int_min_value_t 
+  {
+      typedef implementation_supplied  least;
+      typedef int_fast_t<least>::fast  fast;
+  };
+
+  //  unsigned
+  template< unsigned long Value >
+  struct uint_value_t 
+  {
+      typedef implementation_supplied  least;
       typedef int_fast_t<least>::fast  fast;
-      // int_fast_t<> works correctly for unsigned too, in spite of the name.
   };
 } // namespace boost
-
+
- -

[Templates to select type based on maximum value are under development.] -

+

Easiest-to-Manipulate Types

-

Example

+

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, 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.

-
-
#include <boost/integer.hpp>
-using boost::int_t;
+

Implementation Notes
+By default, the output type is identical to the input type. Eventually, +this code's implementation should be conditionalized for each platform +to give accurate mappings between the built-in types and the +easiest-to-manipulate built-in types. Also, there is no guarantee that +the output type actually is easier to manipulate than the input +type.

-... -int_t<24>::least my_var;
+

Sized Types

-
-

Demonstration Program

+

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.

-

The program integer_test.cpp is a not very -smart demonstration of the results from instantiating various int_t<> -and uint_t<> examples.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Criteria for the Sized Type Class Templates
Class TemplateTemplate Parameter Mapping
boost::int_tThe smallest built-in signed integral type with at least the + given number of 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 a + long.
boost::uint_tThe smallest built-in unsigned integral type with at least + 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.
boost::int_max_value_tThe smallest built-in signed integral type that supports the + given value as a maximum. The parameter should be a + positive number.
boost::int_min_value_tThe smallest built-in signed integral type that supports the + given value as a minimum. The parameter should be a + negative number.
boost::uint_value_tThe smallest built-in unsigned integral type that supports + the given value as a maximum. The parameter should be a + positive number.
-

Rationale

+

Example

+ +
+#include <boost/integer.hpp>
+
+//...
+
+int main()
+{
+    boost::int_t<24>::least my_var;
+    //...
+}
+
+ +

Demonstration Program

+ +

The program integer_test.cpp is a +simplistic demonstration of the results from instantiating various +examples of the sized type class templates.

+ +

Rationale

The rationale for the design of the templates in this header includes:

    -
  • Avoid  recursion because of concern about C++'s limited guaranteed - recursion depth (17).
  • -
  • Avoid macros on general principles.
  • -
  • Try to keep the design as simple as possible.
  • +
  • Avoid recursion because of concern about C++'s limited + guaranteed recursion depth (17).
  • +
  • Avoid macros on general principles.
  • +
  • Try to keep the design as simple as possible.
-

Credits

+

Alternative

-

The author of the Boost integer type choosing templates is Beman -Dawes.  He thanks to Valentin Bonnard and - Kevlin Henney for sharing their designs for similar templates.

+

If the number of bits required is known beforehand, it may be more +appropriate to use the types supplied in <boost/cstdint.hpp>.

+ +

Credits

+ +

The author of most of the Boost integer type choosing templates is Beman Dawes. He gives thanks +to Valentin Bonnard and + Kevlin Henney for sharing +their designs for similar templates. Daryle Walker designed the +value-based sized templates.


-

Revised  August 31, 1999

- -

© Copyright Beman Dawes 1999. Permission to copy, use, modify, sell -and distribute this document is granted provided this copyright notice appears in all -copies. This document is provided "as is" without express or implied warranty, -and with no claim as to its suitability for any purpose.

- -

- -

 

+

Revised May 20, 2001

+

© Copyright Beman Dawes 1999. Permission to copy, use, modify, +sell and distribute this document is granted provided this copyright +notice appears in all copies. This document is provided "as +is" without express or implied warranty, and with no claim as to +its suitability for any purpose.

- diff --git a/integer_test.cpp b/integer_test.cpp index 0b74566..b60760c 100644 --- a/integer_test.cpp +++ b/integer_test.cpp @@ -9,313 +9,247 @@ // See http://www.boost.org for most recent version including documentation. // Revision History +// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker) // 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) // 31 Aug 99 Initial version -#include -#include +#define BOOST_INCLUDE_MAIN +#include // for main, BOOST_TEST -#define BOOST_INCLUDE_MAIN -#include +#include // for BOOST_NO_USING_TEMPLATE +#include // for boost::exit_success +#include // for boost::int_t, boost::uint_t -namespace -{ - void test( long ) { std::cout << "long\n"; } - void test( int ) { std::cout << "int\n"; } - void test( short ) { std::cout << "short\n"; } - void test( signed char ) { std::cout << "signed char\n"; } - void test( unsigned long ) { std::cout << "unsigned long\n"; } - void test( unsigned int ) { std::cout << "unsigned int\n"; } - void test( unsigned short ) { std::cout << "unsigned short\n"; } - void test( unsigned char ) { std::cout << "unsigned char\n"; } -} // unnamed namespace +#include // for ULONG_MAX, LONG_MAX, LONG_MIN +#include // for std::cout (std::endl indirectly) +#include // for std::type_info -// just to prove it works, specialize int_fast_t to yield long + +// Control if the names of the types for each version +// of the integer templates will be printed. +#ifndef CONTROL_SHOW_TYPES +#define CONTROL_SHOW_TYPES 0 +#endif + + +// If specializations have not already been done, then we can confirm +// the effects of the "fast" types by making a specialization. namespace boost { - template<> struct int_fast_t { typedef long fast; }; + template < > + struct int_fast_t< short > + { + typedef long fast; + }; } -int test_main(int,char**) + +// 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_TEST( Template < Number > :: Type ( Value ) == Value ) + +#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 ) + +#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( 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_TEST( 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_TEST( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value ) + +#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 2, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 3, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 4, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 5, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 6, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 7, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 8, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 9, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 10, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 11, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 12, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 13, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 14, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 15, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 16, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 17, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 18, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 19, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 20, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 21, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 22, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 23, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 24, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 25, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 26, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 27, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \ + PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false ) + + +// Test program +int +test_main +( + int, + char*[] +) { #ifndef BOOST_NO_USING_TEMPLATE - using boost::int_t; - using boost::uint_t; + using boost::int_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; + using namespace boost; #endif -#ifdef BOOST_SHOW_TYPES - std::cout << 32 << ' '; test( int_t<32>::least() ); - std::cout << 31 << ' '; test( int_t<31>::least() ); - std::cout << 30 << ' '; test( int_t<30>::least() ); - std::cout << 29 << ' '; test( int_t<29>::least() ); - std::cout << 28 << ' '; test( int_t<28>::least() ); - std::cout << 27 << ' '; test( int_t<27>::least() ); - std::cout << 26 << ' '; test( int_t<26>::least() ); - std::cout << 25 << ' '; test( int_t<25>::least() ); - std::cout << 24 << ' '; test( int_t<24>::least() ); - std::cout << 23 << ' '; test( int_t<23>::least() ); - std::cout << 22 << ' '; test( int_t<22>::least() ); - std::cout << 21 << ' '; test( int_t<21>::least() ); - std::cout << 20 << ' '; test( int_t<20>::least() ); - std::cout << 19 << ' '; test( int_t<19>::least() ); - std::cout << 18 << ' '; test( int_t<18>::least() ); - std::cout << 17 << ' '; test( int_t<17>::least() ); - std::cout << 16 << ' '; test( int_t<16>::least() ); - std::cout << 15 << ' '; test( int_t<15>::least() ); - std::cout << 14 << ' '; test( int_t<14>::least() ); - std::cout << 13 << ' '; test( int_t<13>::least() ); - std::cout << 12 << ' '; test( int_t<12>::least() ); - std::cout << 11 << ' '; test( int_t<11>::least() ); - std::cout << 10 << ' '; test( int_t<10>::least() ); - std::cout << 9 << ' '; test( int_t<9>::least() ); - std::cout << 8 << ' '; test( int_t<8>::least() ); - std::cout << 7 << ' '; test( int_t<7>::least() ); - std::cout << 6 << ' '; test( int_t<6>::least() ); - std::cout << 5 << ' '; test( int_t<5>::least() ); - std::cout << 4 << ' '; test( int_t<4>::least() ); - std::cout << 3 << ' '; test( int_t<3>::least() ); - std::cout << 2 << ' '; test( int_t<2>::least() ); - std::cout << 1 << ' '; test( int_t<1>::least() ); - std::cout << 0 << ' '; test( int_t<0>::least() ); - std::cout << 32 << ' '; test( int_t<32>::fast() ); - std::cout << 31 << ' '; test( int_t<31>::fast() ); - std::cout << 30 << ' '; test( int_t<30>::fast() ); - std::cout << 29 << ' '; test( int_t<29>::fast() ); - std::cout << 28 << ' '; test( int_t<28>::fast() ); - std::cout << 27 << ' '; test( int_t<27>::fast() ); - std::cout << 26 << ' '; test( int_t<26>::fast() ); - std::cout << 25 << ' '; test( int_t<25>::fast() ); - std::cout << 24 << ' '; test( int_t<24>::fast() ); - std::cout << 23 << ' '; test( int_t<23>::fast() ); - std::cout << 22 << ' '; test( int_t<22>::fast() ); - std::cout << 21 << ' '; test( int_t<21>::fast() ); - std::cout << 20 << ' '; test( int_t<20>::fast() ); - std::cout << 19 << ' '; test( int_t<19>::fast() ); - std::cout << 18 << ' '; test( int_t<18>::fast() ); - std::cout << 17 << ' '; test( int_t<17>::fast() ); - std::cout << 16 << ' '; test( int_t<16>::fast() ); - std::cout << 15 << ' '; test( int_t<15>::fast() ); - std::cout << 14 << ' '; test( int_t<14>::fast() ); - std::cout << 13 << ' '; test( int_t<13>::fast() ); - std::cout << 12 << ' '; test( int_t<12>::fast() ); - std::cout << 11 << ' '; test( int_t<11>::fast() ); - std::cout << 10 << ' '; test( int_t<10>::fast() ); - std::cout << 9 << ' '; test( int_t<9>::fast() ); - std::cout << 8 << ' '; test( int_t<8>::fast() ); - std::cout << 7 << ' '; test( int_t<7>::fast() ); - std::cout << 6 << ' '; test( int_t<6>::fast() ); - std::cout << 5 << ' '; test( int_t<5>::fast() ); - std::cout << 4 << ' '; test( int_t<4>::fast() ); - std::cout << 3 << ' '; test( int_t<3>::fast() ); - std::cout << 2 << ' '; test( int_t<2>::fast() ); - std::cout << 1 << ' '; test( int_t<1>::fast() ); - std::cout << 0 << ' '; test( int_t<0>::fast() ); - std::cout << 32 << ' '; test( uint_t<32>::least() ); - std::cout << 31 << ' '; test( uint_t<31>::least() ); - std::cout << 30 << ' '; test( uint_t<30>::least() ); - std::cout << 29 << ' '; test( uint_t<29>::least() ); - std::cout << 28 << ' '; test( uint_t<28>::least() ); - std::cout << 27 << ' '; test( uint_t<27>::least() ); - std::cout << 26 << ' '; test( uint_t<26>::least() ); - std::cout << 25 << ' '; test( uint_t<25>::least() ); - std::cout << 24 << ' '; test( uint_t<24>::least() ); - std::cout << 23 << ' '; test( uint_t<23>::least() ); - std::cout << 22 << ' '; test( uint_t<22>::least() ); - std::cout << 21 << ' '; test( uint_t<21>::least() ); - std::cout << 20 << ' '; test( uint_t<20>::least() ); - std::cout << 19 << ' '; test( uint_t<19>::least() ); - std::cout << 18 << ' '; test( uint_t<18>::least() ); - std::cout << 17 << ' '; test( uint_t<17>::least() ); - std::cout << 16 << ' '; test( uint_t<16>::least() ); - std::cout << 15 << ' '; test( uint_t<15>::least() ); - std::cout << 14 << ' '; test( uint_t<14>::least() ); - std::cout << 13 << ' '; test( uint_t<13>::least() ); - std::cout << 12 << ' '; test( uint_t<12>::least() ); - std::cout << 11 << ' '; test( uint_t<11>::least() ); - std::cout << 10 << ' '; test( uint_t<10>::least() ); - std::cout << 9 << ' '; test( uint_t<9>::least() ); - std::cout << 8 << ' '; test( uint_t<8>::least() ); - std::cout << 7 << ' '; test( uint_t<7>::least() ); - std::cout << 6 << ' '; test( uint_t<6>::least() ); - std::cout << 5 << ' '; test( uint_t<5>::least() ); - std::cout << 4 << ' '; test( uint_t<4>::least() ); - std::cout << 3 << ' '; test( uint_t<3>::least() ); - std::cout << 2 << ' '; test( uint_t<2>::least() ); - std::cout << 1 << ' '; test( uint_t<1>::least() ); - std::cout << 0 << ' '; test( uint_t<0>::least() ); - std::cout << 32 << ' '; test( uint_t<32>::fast() ); - std::cout << 31 << ' '; test( uint_t<31>::fast() ); - std::cout << 30 << ' '; test( uint_t<30>::fast() ); - std::cout << 29 << ' '; test( uint_t<29>::fast() ); - std::cout << 28 << ' '; test( uint_t<28>::fast() ); - std::cout << 27 << ' '; test( uint_t<27>::fast() ); - std::cout << 26 << ' '; test( uint_t<26>::fast() ); - std::cout << 25 << ' '; test( uint_t<25>::fast() ); - std::cout << 24 << ' '; test( uint_t<24>::fast() ); - std::cout << 23 << ' '; test( uint_t<23>::fast() ); - std::cout << 22 << ' '; test( uint_t<22>::fast() ); - std::cout << 21 << ' '; test( uint_t<21>::fast() ); - std::cout << 20 << ' '; test( uint_t<20>::fast() ); - std::cout << 19 << ' '; test( uint_t<19>::fast() ); - std::cout << 18 << ' '; test( uint_t<18>::fast() ); - std::cout << 17 << ' '; test( uint_t<17>::fast() ); - std::cout << 16 << ' '; test( uint_t<16>::fast() ); - std::cout << 15 << ' '; test( uint_t<15>::fast() ); - std::cout << 14 << ' '; test( uint_t<14>::fast() ); - std::cout << 13 << ' '; test( uint_t<13>::fast() ); - std::cout << 12 << ' '; test( uint_t<12>::fast() ); - std::cout << 11 << ' '; test( uint_t<11>::fast() ); - std::cout << 10 << ' '; test( uint_t<10>::fast() ); - std::cout << 9 << ' '; test( uint_t<9>::fast() ); - std::cout << 8 << ' '; test( uint_t<8>::fast() ); - std::cout << 7 << ' '; test( uint_t<7>::fast() ); - std::cout << 6 << ' '; test( uint_t<6>::fast() ); - std::cout << 5 << ' '; test( uint_t<5>::fast() ); - std::cout << 4 << ' '; test( uint_t<4>::fast() ); - std::cout << 3 << ' '; test( uint_t<3>::fast() ); - std::cout << 2 << ' '; test( uint_t<2>::fast() ); - std::cout << 1 << ' '; test( uint_t<1>::fast() ); - std::cout << 0 << ' '; test( uint_t<0>::fast() ); -#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 ); - long v = 0x7FFFFFFF; - BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1; - BOOST_TEST( int_t<0>::least(v) == v ); - v = 0x7FFFFFFF; - BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1; - BOOST_TEST( int_t<0>::fast(v) == v ); - unsigned long u = 0xFFFFFFFF; - BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1; - BOOST_TEST( uint_t<0>::least(u) == u ); - u = 0xFFFFFFFF; - BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1; - BOOST_TEST( uint_t<0>::fast(u) == u ); + 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 0; + return boost::exit_success; }