diff --git a/cstdint.htm b/cstdint.htm deleted file mode 100644 index 9492827..0000000 --- a/cstdint.htm +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - -Header boost/cstdint.hpp - - - - -

boost.png (6897 bytes)Header -boost/cstdint.hpp 

-

The header <boost/cstdint.hpp> -provides the typedef's useful for -writing portable code that requires certain integer widths. All typedef's are in namespace boost.

-

The specifications are based on the ISO/IEC 9899:1999 C Language standard -header <stdint.h>.  The 64-bit types required by the C standard are not -required in the boost header, and may not be supplied in all implementations, -because long long is not [yet] included in the C++ standard.

-

See cstdint_test.cpp for a test program.

-

Exact-width integer types

-

The typedef int#_t, with # replaced by the width, designates a -signed integer type of exactly # bits; int8_t denotes an 8-bit -signed integer type.  Similarly, the typedef uint#_t -designates and unsigned integer type of exactly # bits.

-

These types are optional. However, if an implementation provides integer -types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding -typedef names.

-

Minimum-width integer types

-

The typedef int_least#_t, with # replaced by the width,  -designates a signed integer type with a width of at least # bits, such that no -signed integer type with lesser size has at least the specified width. Thus, int_least32_t -denotes a signed integer type with a width of at least 32 bits. Similarly, the -typedef name uint_least#_t designates an unsigned integer type with -a width of at least # bits, such that no unsigned integer type with lesser size -has at least the specified width.

-

Required minimum-width integer types:

- -

All other minimum-width integer types are optional.

-

Fastest minimum-width integer types

-

The typedef int_fast#_t, with # replaced by the width, -designates the fastest signed integer type with a width of at least # bits. -Similarly, the typedef name uint_fast#_t designates the fastest -unsigned integer type with a width of at least # bits.

-

There is no guarantee that these types are fastest for all purposes.  In -any case, however, they satisfy  the signedness and width requirements.

-

Required fastest minimum-width integer types:

- -

All other fastest minimum-width integer types are optional.

-

Greatest-width integer types

-

The typedef intmax_t designates a signed integer type capable of -representing any value of any signed integer type.

-

The typedef uintmax_t designates an unsigned integer type -capable of representing any value of any unsigned integer type.

-

These types are required.

-
-

Revised 06 Nov 2007 -

-

© Copyright Beman Dawes 2000

- -

Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

- - - - \ No newline at end of file diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..18c50ae --- /dev/null +++ b/doc/Jamfile.v2 @@ -0,0 +1,59 @@ + + +# Copyright John Maddock 2005. Use, modification, and distribution are +# subject to 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) + +using quickbook ; + +xml integer : integer.qbk ; +boostbook standalone + : + integer + : + # HTML options first: + # Use graphics not text for navigation: + navig.graphics=1 + # How far down we chunk nested sections, basically all of them: + chunk.section.depth=1 + # Don't put the first section on the same page as the TOC: + chunk.first.sections=0 + # How far down sections get TOC's + toc.section.depth=1 + # Max depth in each TOC: + toc.max.depth=1 + # How far down we go with TOC's + generate.section.toc.level=4 + # Path for links to Boost: + boost.root=../../../.. + # Path for libraries index: + boost.libraries=../../../../libs/libraries.htm + # Use the main Boost stylesheet: + html.stylesheet=../../../../doc/html/boostbook.css + + # PDF Options: + # TOC Generation: this is needed for FOP-0.9 and later: + fop1.extensions=0 + # Or enable this if you're using XEP: + xep.extensions=1 + # TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9! + fop.extensions=0 + # No indent on body text: + body.start.indent=0pt + # Margin size: + page.margin.inner=0.5in + # Margin size: + page.margin.outer=0.5in + # Yes, we want graphics for admonishments: + admon.graphics=1 + # Set this one for PDF generation *only*: + # default pnd graphics are awful in PDF form, + # better use SVG's instead: + pdf:admon.graphics.extension=".svg" + pdf:admon.graphics.path=$(boost-images)/ + pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/libs/regex/doc/html + ; + +install pdf-install : standalone : . PDF ; + + diff --git a/doc/html/boost_integer/cstdint.html b/doc/html/boost_integer/cstdint.html new file mode 100644 index 0000000..d233f43 --- /dev/null +++ b/doc/html/boost_integer/cstdint.html @@ -0,0 +1,257 @@ + + + +Standard Integer Types + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
+ +

+ The header <boost/cstdint.hpp> + provides the typedef's useful for writing portable code that requires certain + integer widths. All typedef's are in namespace boost. +

+

+ The specifications for these types are based on the ISO/IEC 9899:1999 C Language + standard header <stdint.h>. The 64-bit types required by the C standard + are not required in the boost header, and may not be + supplied for all platforms/compilers, because long long + is not [yet] included in the C++ standard. +

+

+ See cstdint_test.cpp for + a test program. +

+
+
+ +

+ The organization of the Boost.Integer headers and classes is designed to + take advantage of <stdint.h> types from the 1999 C standard without + causing 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. 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. +

+
+
+ +

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

+
+
+ +

+ The typedef int#_t, with # replaced by the width, designates + a signed integer type of exactly # bits; for example int8_t + denotes an 8-bit signed integer type. Similarly, the typedef uint#_t + designates an unsigned integer type of exactly # bits. +

+

+ These types are optional. However, if a platform supports integer types with + widths of 8, 16, 32, 64, or any combination thereof, then <boost/cstdint.hpp> + does provide the corresponding typedefs. +

+

+ The absence of int64_t and uint64_t is indicated by the macro BOOST_NO_INT64_T. +

+
+
+ +

+ The typedef int_least#_t, with # replaced by the width, + designates a signed integer type with a width of at least # bits, such that + no signed integer type with lesser size has at least the specified width. + Thus, int_least32_t denotes the smallest signed integer + type with a width of at least 32 bits. Similarly, the typedef name uint_least#_t + designates an unsigned integer type with a width of at least # bits, such + that no unsigned integer type with lesser size has at least the specified + width. +

+

+ The following minimum-width integer types are provided for all platforms: +

+
    +
  • int_least8_t
  • +
  • int_least16_t
  • +
  • int_least32_t
  • +
  • uint_least8_t
  • +
  • uint_least16_t
  • +
  • uint_least32_t
  • +
+

+ The following types are available only if, after including <boost/cstdint.hpp>, + the macro BOOST_NO_INT64_T is not defined: +

+
    +
  • int_least64_t
  • +
  • uint_least64_t
  • +
+

+ All other minimum-width integer types are optional. +

+
+
+ +

+ The typedef int_fast#_t, with # replaced by the width, + designates the fastest signed integer type with a width of at least # bits. + Similarly, the typedef name uint_fast#_t designates the + fastest unsigned integer type with a width of at least # bits. +

+

+ There is no guarantee that these types are fastest for all purposes. In any + case, however, they satisfy the signedness and width requirements. +

+

+ The following fastest minimum-width integer types are provided for all platforms: +

+
    +
  • int_fast8_t
  • +
  • int_fast16_t
  • +
  • int_fast32_t
  • +
  • uint_fast8_t
  • +
  • uint_fast16_t
  • +
  • uint_fast32_t
  • +
+

+ The following types are available only if, after including <boost/cstdint.hpp>, + the macro BOOST_NO_INT64_T is not defined: +

+
    +
  • int_fast64_t
  • +
  • uint_fast64_t
  • +
+

+ All other fastest minimum-width integer types are optional. +

+
+
+ +

+ The typedef intmax_t designates a signed integer type + capable of representing any value of any signed integer type. +

+

+ The typedef uintmax_t designates an unsigned integer type + capable of representing any value of any unsigned integer type. +

+

+ These types are provided for all platforms. +

+
+
+ +

+ The following macros are always defined after inclusion of this header, these + allow integer constants of at least the specified width to be declared: INT8_C, + UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C. +

+

+ The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T + is not defined. +

+

+ The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the + implementation. +

+

+ For example: +

+
#include <boost/cstdint.hpp>
+
+// Here the constant 0x1FFFFFFFF has the correct suffix applied:
+static const boost::uint64_t c = INT64_C(0x1FFFFFFFF); 
+
+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_integer/history.html b/doc/html/boost_integer/history.html new file mode 100644 index 0000000..b92217e --- /dev/null +++ b/doc/html/boost_integer/history.html @@ -0,0 +1,82 @@ + + + +History + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHome +
+
+ +
+ + 1.42.0 +
+
    +
  • + Reverted Trunk to release branch state (i.e. a "known good state"). +
  • +
  • + Fixed issues: 653, + 3084, + 3177, + 3180, + 3568, + 3657, + 2134. +
  • +
  • + Added long long support to boost::static_log2, boost::static_signed_min, + boost::static_signed_max, boost::static_unsigned_minboost::static_unsigned_max, + when available. +
  • +
  • + The argument type and the result type of boost::static_signed_min + etc are now typedef'd. Formerly, they were hardcoded as unsigned + long and int respectively. Please, use the provided + typedefs in new code (and update old code as soon as possible). +
  • +
+
+ + 1.32.0 +
+
  • + The argument type and the result type of boost::static_log2 + are now typedef'd. Formerly, they were hardcoded as unsigned long + and int respectively. Please, use the provided typedefs + in new code (and update old code as soon as possible). +
+
+ + + +
+
+
+PrevUpHome +
+ + diff --git a/doc/html/boost_integer/integer.html b/doc/html/boost_integer/integer.html new file mode 100644 index 0000000..8c022fa --- /dev/null +++ b/doc/html/boost_integer/integer.html @@ -0,0 +1,430 @@ + + + +Integer Type Selection + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

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

+
+ +
namespace boost
+{
+  //  fast integers from least integers
+  template<typename LeastInt>
+  struct int_fast_t
+  {
+      typedef implementation-defined-type  type;
+  };
+
+  //  signed
+  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;
+  };
+
+  //  unsigned
+  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;
+  };
+
+  //  signed
+  template<long long MaxValue>
+  struct int_max_value_t 
+  {
+      typedef implementation-defined-type  least;
+      typedef int_fast_t<least>::fast      fast;
+  };
+
+  template<long long MinValue>
+  struct int_min_value_t 
+  {
+      typedef implementation-defined-type  least;
+      typedef int_fast_t<least>::fast      fast;
+  };
+
+  //  unsigned
+  template<unsigned long long Value>
+  struct uint_value_t 
+  {
+      typedef implementation-defined-type  least;
+      typedef int_fast_t<least>::fast      fast;
+  };
+} // namespace boost
+
+
+
+ +

+ 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. The output type is given as the nested type fast. +

+

+ Implementation Notes: By default, the output + type is identical to the input type. Eventually, this code's implementation + should be customized 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. +

+
+
+ +

+ 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 nested type least. + The easiest-to-manipulate version of that type is given by the nested type + fast. The following table describes each template's criteria. +

+
+

Table 1. Criteria for the Sized Type Class Templates

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Class Template +

+
+

+ Template Parameter Mapping +

+
+

+ boost::int_t<N>::least +

+
+

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

+
+

+ boost::int_t<N>::fast +

+
+

+ The easiest-to-manipulate, 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. +

+
+

+ boost::int_t<N>::exact +

+
+

+ A built-in, signed integral type with exactly N + bits, including the sign bit. The parameter should be a positive number. + Note that the member exact is defined only if there exists a type with exactly N + bits. +

+
+

+ boost::uint_t<N>::least +

+
+

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

+
+

+ boost::uint_t<N>::fast +

+
+

+ The easiest-to-manipulate, 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. +

+
+

+ boost::uint_t<N>::exact +

+
+

+ A built-in, unsigned integral type with exactly 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. Note that the member exact is defined + only if there exists a type with exactly + N bits. +

+
+

+ boost::int_max_value_t<V>::last +

+
+

+ The smallest, built-in, signed integral type that can hold all the + values in the inclusive range 0 - V. The parameter + should be a positive number. +

+
+

+ boost::int_max_value_t<V>::fast +

+
+

+ The easiest-to-manipulate, built-in, signed integral type that can + hold all the values in the inclusive range 0 - V. + The parameter should be a positive number. +

+
+

+ boost::int_min_value_t<V>::least +

+
+

+ The smallest, built-in, signed integral type that can hold all the + values in the inclusive range V - 0. The parameter + should be a negative number. +

+
+

+ boost::int_min_value_t<V>::fast +

+
+

+ The easiest-to-manipulate, built-in, signed integral type that can + hold all the values in the inclusive range V - 0. + The parameter should be a negative number. +

+
+

+ boost::uint_value_t<V>::least +

+
+

+ The smallest, built-in, unsigned integral type that can hold all positive + values up to and including V. The parameter should + be a positive number. +

+
+

+ boost::uint_value_t<V>::fast +

+
+

+ The easiest-to-manipulate, built-in, unsigned integral type that can + hold all positive values up to and including V. + The parameter should be a positive number. +

+
+
+
+
+
+ +
#include <boost/integer.hpp>
+
+//...
+
+int main()
+{
+    boost::int_t<24>::least my_var;  // my_var has at least 24-bits
+    //...
+    // This one is guarenteed not to be truncated:
+    boost::int_max_value_t<1000>::least my1000 = 1000;
+    //...
+    // This one is guarenteed not to be truncated, and as fast
+    // to manipulate as possible, its size may be greater than
+    // that of my1000:
+    boost::int_max_value_t<1000>::fast my_fast1000 = 1000;
+}
+
+
+
+ +

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

+
+
+ +

+ 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. +
  • +
+
+
+ +

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

+
+
+ +

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

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_integer/log2.html b/doc/html/boost_integer/log2.html new file mode 100644 index 0000000..cb234bd --- /dev/null +++ b/doc/html/boost_integer/log2.html @@ -0,0 +1,151 @@ + + + +Compile Time log2 Calculation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

+ The class template in <boost/integer/static_log2.hpp> + determines the position of the highest bit in a given value. This facility + is useful for solving generic programming problems. +

+
+ +
namespace boost
+{
+
+  typedef implementation-defined static_log2_argument_type;
+  typedef implementation-defined static_log2_result_type;
+
+  template <static_log2_argument_type arg>
+  struct static_log2
+  {
+    static const static_log2_result_type value = implementation-defined;
+  };
+
+
+  template < >
+  struct static_log2< 0 >
+  {
+    // The logarithm of zero is undefined.
+  };
+
+
+}  // namespace boost
+
+
+
+

+Usage +

+

+ The boost::static_log2 class template takes one template + parameter, a value of type static_log2_argument_type. + The template only defines one member, value, which gives + the truncated, base-two logarithm of the template argument. +

+

+ Since the logarithm of zero, for any base, is undefined, there is a specialization + of static_log2 for a template argument of zero. This specialization + has no members, so an attempt to use the base-two logarithm of zero results + in a compile-time error. +

+

+ Note: +

+
    +
  • +static_log2_argument_type is an unsigned integer + type (C++ standard, 3.9.1p3). +
  • +
  • +static_log2_result_type is an integer type + (C++ standard, 3.9.1p7). +
  • +
+
+
+ +

+ The program static_log2_test.cpp + is a simplistic demonstration of the results from instantiating various examples + of the binary logarithm class template. +

+
+
+ +

+ The base-two (binary) logarithm, abbreviated lb, function is occasionally + used to give order-estimates of computer algorithms. The truncated logarithm + can be considered the highest power-of-two in a value, which corresponds + to the value's highest set bit (for binary integers). Sometimes the highest-bit + position could be used in generic programming, which requires the position + to be available statically (i.e. at compile-time). +

+
+
+ +

+ The original version of the Boost binary logarithm class template was written + by Daryle Walker + and then enhanced by Giovanni Bajo with support for compilers without partial + template specialization. The current version was suggested, together with + a reference implementation, by Vesa Karvonen. Gennaro Prota wrote the actual + source file. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_integer/mask.html b/doc/html/boost_integer/mask.html new file mode 100644 index 0000000..f7bfc12 --- /dev/null +++ b/doc/html/boost_integer/mask.html @@ -0,0 +1,375 @@ + + + +Integer Masks + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
+ +

+ The class templates in <boost/integer/integer_mask.hpp> + provide bit masks for a certain bit position or a contiguous-bit pack of + a certain size. The types of the masking constants come from the integer + type selection templates header. +

+
+
+ +
#include <cstddef>  // for std::size_t
+
+namespace boost
+{
+
+template <std::size_t Bit>
+struct high_bit_mask_t
+{
+    typedef implementation-defined-type  least;
+    typedef implementation-defined-type  fast;
+
+    static const least       high_bit       = implementation-defined;
+    static const fast        high_bit_fast  = implementation-defined;
+
+    static const std::size_t bit_position   = Bit;
+};
+
+template <std::size_t Bits>
+struct low_bits_mask_t
+{
+    typedef implementation-defined-type  least;
+    typedef implementation-defined-type  fast;
+
+    static const least       sig_bits       = implementation-defined;
+    static const fast        sig_bits_fast  = implementation-defined;
+
+    static const std::size_t bit_count      = Bits;
+};
+
+// Specializations for low_bits_mask_t exist for certain bit counts.
+
+}  // namespace boost
+
+
+
+ +

+ The boost::high_bit_mask_t class template provides constants + for bit masks representing the bit at a certain position. The masks are equivalent + to the value 2Bit, where Bit is the template parameter. + The bit position must be a nonnegative number from zero to Max, + where Max is one less than the number of bits supported by the largest unsigned + built-in integral type. The following table describes the members of an instantiation + of high_bit_mask_t. +

+
+

Table 2. Members of the `boost::high_bit_mask_t` Class Template

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Member +

+
+

+ Meaning +

+
+

+ least +

+
+

+ The smallest, unsigned, built-in type that supports the given bit position. +

+
+

+ fast +

+
+

+ The easiest-to-manipulate analog of least. +

+
+

+ high_bit +

+
+

+ A least constant of the value 2Bit. +

+
+

+ high_bit_fast +

+
+

+ A fast analog of high_bit. +

+
+

+ bit_position +

+
+

+ The value of the template parameter, in case its needed from a renamed + instantiation of the class template. +

+
+
+
+
+
+ +

+ The boost::low_bits_mask_t class template provides constants + for bit masks equivalent to the value (2Bits - 1), where Bits + is the template parameter. The parameter Bits must be + a non-negative integer from zero to Max, where Max is + the number of bits supported by the largest, unsigned, built-in integral + type. The following table describes the members of low_bits_mask_t. +

+
+

Table 3. Members of the [^boost::low_bits_mask_t] Class Template

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Member +

+
+

+ Meaning +

+
+

+ least +

+
+

+ The smallest, unsigned built-in type that supports the given bit count. +

+
+

+ fast +

+
+

+ The easiest-to-manipulate analog of least. +

+
+

+ sig_bits +

+
+

+ A least constant of the desired bit-masking value. +

+
+

+ sig_bits_fast +

+
+

+ A fast analog of sig_bits. +

+
+

+ bit_count +

+
+

+ The value of the template parameter, in case its needed from a renamed + instantiation of the class template. +

+
+
+
+
+
+ +

+ When Bits is the exact size of a built-in unsigned type, + the implementation has to change to prevent undefined behavior. Therefore, + there are specializations of low_bits_mask_t at those + bit counts. +

+
+
+ +
#include <boost/integer/integer_mask.hpp>
+
+//...
+
+int main()
+{
+    typedef boost::high_bit_mask_t<29>  mask1_type;
+    typedef boost::low_bits_mask_t<15>  mask2_type;
+
+    mask1_type::least  my_var1;
+    mask2_type::fast   my_var2;
+    //...
+
+    my_var1 |= mask1_type::high_bit;
+    my_var2 &= mask2_type::sig_bits_fast;
+
+    //...
+}
+
+
+
+ +

+ The program integer_mask_test.cpp + is a simplistic demonstration of the results from instantiating various examples + of the bit mask class templates. +

+
+
+ +

+ The class templates in this header are an extension of the integer + type selection class templates. The new class templates provide the + same sized types, but also convenient masks to use when extracting the highest + or all the significant bits when the containing built-in type contains more + bits. This prevents contamination of values by the higher, unused bits. +

+
+
+ +

+ The author of the Boost bit mask class templates is Daryle + Walker. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_integer/minmax.html b/doc/html/boost_integer/minmax.html new file mode 100644 index 0000000..7b1fea0 --- /dev/null +++ b/doc/html/boost_integer/minmax.html @@ -0,0 +1,160 @@ + + + +Compile time min/max calculation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

+ The class templates in <boost/integer/static_min_max.hpp> + provide a compile-time evaluation of the minimum or maximum of two integers. + These facilities are useful for generic programming problems. +

+
+ +
namespace boost
+{
+
+typedef implementation-defined static_min_max_signed_type;
+typedef implementation-defined static_min_max_unsigned_type;
+
+template <static_min_max_signed_type Value1, static_min_max_signed_type Value2 >
+    struct static_signed_min;
+
+template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
+    struct static_signed_max;
+
+template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
+    struct static_unsigned_min;
+
+template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
+    struct static_unsigned_max;
+
+}
+
+
+
+

+Usage +

+

+ The four class templates provide the combinations for finding the minimum + or maximum of two signed or unsigned + (long) parameters, Value1 and Value2, + at compile-time. Each template has a single static data member, value, + which is set to the respective minimum or maximum of the template's parameters. +

+
+
+ +
#include <boost/integer/static_min_max.hpp>
+
+template < unsigned long AddendSize1, unsigned long AddendSize2 >
+class adder
+{
+public:
+    static  unsigned long  const  addend1_size = AddendSize1;
+    static  unsigned long  const  addend2_size = AddendSize2;
+    static  unsigned long  const  sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
+
+    typedef int  addend1_type[ addend1_size ];
+    typedef int  addend2_type[ addend2_size ];
+    typedef int  sum_type[ sum_size ];
+
+    void  operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const;
+};
+
+//...
+
+int main()
+{
+    int const   a1[] = { 0, 4, 3 };  // 340
+    int const   a2[] = { 9, 8 };     //  89
+    int         s[ 4 ];
+    adder<3,2>  obj;
+
+    obj( a1, a2, s );  // 's' should be 429 or { 9, 2, 4, 0 }
+    //...
+}
+
+
+
+ +

+ The program static_min_max_test.cpp + is a simplistic demonstration of various comparisons using the compile-time + extrema class templates. +

+
+
+ +

+ Sometimes the minimum or maximum of several values needs to be found for + later compile-time processing, e.g. for a bound for + another class template. +

+
+
+ +

+ The author of the Boost compile-time extrema class templates is Daryle + Walker. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost_integer/traits.html b/doc/html/boost_integer/traits.html new file mode 100644 index 0000000..7c197d7 --- /dev/null +++ b/doc/html/boost_integer/traits.html @@ -0,0 +1,215 @@ + + + +Integer Traits + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
+ +

+ The C++ Standard Library <limits> header supplies a class template + numeric_limits<> + with specializations for each fundamental type. +

+

+ For integer types, the interesting members of std::numeric_limits<> are: +

+
static const bool is_specialized;      // Will be true for integer types.
+static T min() throw();                // Smallest representable value.
+static T max() throw();                // Largest representable value.
+static const int digits;               // For integers, the number of value bits.
+static const int digits10;             // The number of base 10 digits that can be represented.
+static const bool is_signed;           // True if the type is signed.
+static const bool is_integer;          // Will be true for all integer types.
+
+

+ For many uses, these are sufficient. But min() and max() are problematical + because they are not constant expressions (std::5.19), yet some usages require + constant expressions. +

+

+ The template class integer_traits addresses this problem. +

+
+
+ +
namespace boost {
+  template<class T>
+  class integer_traits : public std::numeric_limits<T>
+  {
+  public:
+     static const bool is_integral = false;
+     //
+     // These members are defined only if T is a built-in
+     // integal type:
+     //
+     static const T const_min = implementation-defined;
+     static const T const_max = implementation-defined;
+  };
+}
+
+
+
+ +

+ Template class integer_traits is derived from std::numeric_limits. + The primary specialization adds the single bool member + is_integral with the compile-time constant value false. + However, for all integral types T (std::3.9.1/7 [basic.fundamental]), + there are specializations provided with the following compile-time constants + defined: +

+
+++++ + + + + + + + + + + + + + + + + + + + + + + +
+

+ member +

+
+

+ type +

+
+

+ value +

+
+

+ is_integral +

+
+

+ bool +

+
+

+ true +

+
+

+ const_min +

+
+

+ T +

+
+

+ equivalent to std::numeric_limits<T>::min() +

+
+

+ const_max +

+
+

+ T +

+
+

+ equivalent to std::numeric_limits<T>::max() +

+
+

+ Note: The is_integral flag is provided, because a user-defined + integer class should specialize std::numeric_limits<>::is_integer + = true, while compile-time constants const_min + and const_max are not provided for that user-defined class, + unless boost::integer_traits is also specialized. +

+
+
+ +

+ The program integer_traits_test.cpp + exercises the integer_traits class. +

+
+
+ +

+ Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer + traits idea on the boost mailing list in August 1999. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/index.html b/doc/html/index.html new file mode 100644 index 0000000..97bf531 --- /dev/null +++ b/doc/html/index.html @@ -0,0 +1,246 @@ + + + +Boost.Integer + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
Next
+
+
+
+

+Boost.Integer

+
+

+Beman Dawes +

+

+Daryle Walker +

+

+Gennaro Prota +

+

+John Maddock +

+
+
+
+

+ 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) +

+
+
+
+
+ +
+ +

+ Boost.Integer provides integer type support, particularly helpful in generic + programming. It provides standard C99 integer types, such as might be found + in <stdint.h>, without requiring that header. It provides the means to + select an integer type based upon its properties, like the number of bits or + the maximum supported value, as well as compile-time bit mask selection. There + is a derivative of std::numeric_limits that provides integral constant expressions + for min and max. + Finally, it provides two compile-time algorithms: determining the highest power + of two in a compile-time value; and computing min and max of constant expressions. +

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Component +

+
+

+ Header +

+
+

+ Purpose +

+
+

+ Forward Declarations. +

+
+

+ <boost/integer_fwd.hpp> +

+
+

+ Forward declarations of classes and class templates - for use when + just the name of a class is needed. +

+
+

+ Standard Integer Types. +

+
+

+ <boost/cstdint.hpp> +

+
+

+ Provides 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. +

+
+

+ Integer Traits. +

+
+

+ <boost/integer_traits.hpp> +

+
+

+ Class template boost::integer_traits, derives from + std::numeric_limits and adds const_min + and const_max members. +

+
+

+ Integer Type Selection. +

+
+

+ <boost/integer.hpp> +

+
+

+ Templates for integer type selection based on properties such as maximum + value or number of bits: Use to select the type of an integer when + some property such as maximum value or number of bits is known. Useful + for generic programming. +

+
+

+ Integer Masks. +

+
+

+ <boost/integer/integer_mask.hpp> +

+
+

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

+
+

+ Compile time log2 Calculation. +

+
+

+ <boost/integer/static_log2.hpp> +

+
+

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

+
+

+ Compile time min/max calculation. +

+
+

+ <boost/integer/static_min_max.hpp> +

+
+

+ Templates for finding the extrema of two numbers: Use to find a bound + based on a minimum or maximum value. Useful for generic programming. +

+
+
+
+ + + +

Last revised: December 11, 2009 at 17:54:58 GMT

+
+
Next
+ + diff --git a/doc/integer.qbk b/doc/integer.qbk new file mode 100644 index 0000000..c5d6e70 --- /dev/null +++ b/doc/integer.qbk @@ -0,0 +1,840 @@ +[article Boost.Integer + [quickbook 1.5] + [copyright 2001-2009 Beman Dawes, Daryle Walker, Gennaro Prota, John Maddock] + [purpose Integer Type Selection] + [license + 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]) + ] + [authors [Dawes, Beman], [Walker, Daryle], [Prota, Gennaro], [Maddock, John]] + [/last-revision $Date: 2008-02-21 12:58:15 +0000 (Thu, 21 Feb 2008) $] +] + +[template super[x]''''''[x]''''''] + +[section:overview Overview] + +Boost.Integer provides integer type support, particularly helpful in generic programming. It provides standard +C99 integer types, such as might be found in , without requiring that header. +It provides the means to select an integer type based upon its properties, like the number of bits or +the maximum supported value, as well as compile-time bit mask selection. There is a derivative of +std::numeric_limits that provides integral constant expressions for `min` and `max`. +Finally, it provides two compile-time algorithms: determining the highest power of two in a +compile-time value; and computing min and max of constant expressions. + +[table + [[Component][Header][Purpose]] + [ + [Forward Declarations.] + [[^[@../../../../boost/integer_fwd.hpp ]]] + [Forward declarations of classes and class templates - for use when just the name of a class is needed.] + ] + [ + [[link boost_integer.cstdint Standard Integer Types].] + [[^[@../../../../boost/cstdint.hpp ]]] + [Provides typedef's based on the 1999 C Standard header ``, wrapped in namespace boost. + This implementation may #include the compiler supplied ``, if present.] + ] + [ + [[link boost_integer.traits Integer Traits].] + [[^[@../../../../boost/integer_traits.hpp ]]] + [Class template [^boost::integer_traits], derives from [^std::numeric_limits] and adds [^const_min] and [^const_max] members.] + ] + [ + [[link boost_integer.integer Integer Type Selection].] + [[^[@../../../../boost/hpp ]]] + [Templates for integer type selection based on properties such as maximum value or number of bits: + Use to select the type of an integer when some property such as maximum value or number of bits is known. + Useful for generic programming. ] + ] + [ + [[link boost_integer.mask Integer Masks].] + [[^[@../../../../boost/integer/integer_mask.hpp ]]] + [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. ] + ] + [ + [[link boost_integer.log2 Compile time log2 Calculation].] + [[^[@../../../../boost/integer/static_log2.hpp ]]] + [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. ] + ] + [ + [[link boost_integer.minmax Compile time min/max calculation].] + [[^[@../../../../boost/integer/static_min_max.hpp ]]] + [Templates for finding the extrema of two numbers: + Use to find a bound based on a minimum or maximum value. Useful for generic programming. ] + ] +] + +[endsect] + +[section:cstdint Standard Integer Types] + +[section Overview] + +The header [^[@../../../../boost/cstdint.hpp ]] provides the typedef's useful +for writing portable code that requires certain integer widths. All typedef's are in namespace boost. + +The specifications for these types are based on the ISO/IEC 9899:1999 C Language standard header . +The 64-bit types required by the C standard are ['not required] in the boost header, +and may not be supplied for all platforms/compilers, because [^long long] is not [yet] included in the C++ standard. + +See [@../../test/cstdint_test.cpp cstdint_test.cpp] for a test program. + +[endsect] + +[section:rationale Rationale] + +The organization of the Boost.Integer headers and classes is designed to take advantage of types from the +1999 C standard without causing undefined behavior in terms of the 1998 C++ standard. +The header makes the standard integer types safely available in namespace [^boost] +without placing any names in namespace [^std]. The intension is to complement rather than compete +with the C++ Standard Library. Should some future C++ standard include and , +then 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. + +[endsect] + +[section:ce ['Caveat emptor]] + +As an implementation artifact, certain C macro names may possibly be +visible to users of . 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 typedef names may possibly be visible +in the global namespace to users of . Don't use these names, they are not part of +any Boost-specified interface. Use the respective names in namespace [^boost] instead. + +[endsect] + +[section Exact-width integer types] + +The typedef [^int#_t], with # replaced by the width, designates a signed integer type of exactly # bits; +for example [^int8_t] denotes an 8-bit signed integer type. Similarly, the typedef [^uint#_t] designates an unsigned +integer type of exactly # bits. + +These types are optional. However, if a platform supports integer types with widths of +8, 16, 32, 64, or any combination thereof, then does provide the +corresponding typedefs. + +The absence of int64_t and uint64_t is indicated by the macro `BOOST_NO_INT64_T`. + +[endsect] + +[section Minimum-width integer types] + +The typedef [^int_least#_t], with # replaced by the width, designates a signed integer type with a width +of at least # bits, such that no signed integer type with lesser size has at least the specified width. +Thus, [^int_least32_t] denotes the smallest signed integer type with a width of at least 32 bits. +Similarly, the typedef name [^uint_least#_t] designates an unsigned integer type with a width of at least # bits, +such that no unsigned integer type with lesser size has at least the specified width. + +The following minimum-width integer types are provided for all platforms: + +* [^int_least8_t] +* [^int_least16_t] +* [^int_least32_t] +* [^uint_least8_t] +* [^uint_least16_t] +* [^uint_least32_t] + +The following types are available only if, after including , the macro BOOST_NO_INT64_T is not defined: + +* [^int_least64_t] +* [^uint_least64_t] + + +All other minimum-width integer types are optional. + +[endsect] + +[section Fastest minimum-width integer types] + +The typedef [^int_fast#_t], with # replaced by the width, designates the fastest signed integer type +with a width of at least # bits. Similarly, the typedef name [^uint_fast#_t] designates the fastest +unsigned integer type with a width of at least # bits. + +There is no guarantee that these types are fastest for all purposes. In any case, however, they satisfy +the signedness and width requirements. + +The following fastest minimum-width integer types are provided for all platforms: + +* [^int_fast8_t] +* [^int_fast16_t] +* [^int_fast32_t] +* [^uint_fast8_t] +* [^uint_fast16_t] +* [^uint_fast32_t] + +The following types are available only if, after including , the macro BOOST_NO_INT64_T is not defined: + +* [^int_fast64_t] +* [^uint_fast64_t] + +All other fastest minimum-width integer types are optional. + +[endsect] + +[section Greatest-width integer types] + +The typedef [^intmax_t ]designates a signed integer type capable of representing any value of any signed integer type. + +The typedef [^uintmax_t] designates an unsigned integer type capable of representing any value of any unsigned integer type. + +These types are provided for all platforms. + +[endsect] + +[section Integer Constant Macros] + +The following macros are always defined after inclusion of this header, these allow +integer constants of at least the specified width to be declared: +INT8_C, UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C. + +The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T is not defined. + +The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the implementation. + +For example: + + #include + + // Here the constant 0x1FFFFFFFF has the correct suffix applied: + static const boost::uint64_t c = INT64_C(0x1FFFFFFFF); + +[endsect] + +[endsect] + +[section:traits Integer Traits] + +[section Motivation] + +The C++ Standard Library header supplies a class template `numeric_limits<>` with specializations for each fundamental type. + +For integer types, the interesting members of `std::numeric_limits<>` are: + + static const bool is_specialized; // Will be true for integer types. + static T min() throw(); // Smallest representable value. + static T max() throw(); // Largest representable value. + static const int digits; // For integers, the number of value bits. + static const int digits10; // The number of base 10 digits that can be represented. + static const bool is_signed; // True if the type is signed. + static const bool is_integer; // Will be true for all integer types. + +For many uses, these are sufficient. +But min() and max() are problematical because they are not constant expressions (std::5.19), +yet some usages require constant expressions. + +The template class [^integer_traits] addresses this problem. + +[endsect] + +[section Synopsis] + + namespace boost { + template + class integer_traits : public std::numeric_limits + { + public: + static const bool is_integral = false; + // + // These members are defined only if T is a built-in + // integal type: + // + static const T const_min = ``['implementation-defined]``; + static const T const_max = ``['implementation-defined]``; + }; + } + +[endsect] + +[section Description] + +Template class [^integer_traits] is derived from [^std::numeric_limits]. The primary specialization adds the single +[^bool] member [^is_integral] with the compile-time constant value [^false]. +However, for all integral types [^T] (std::3.9.1/7 [basic.fundamental]), there are specializations +provided with the following compile-time constants defined: + +[table + [[member][type][value]] + [[[^is_integral]][bool][[^true]]] + [[[^const_min]][[^T]][equivalent to [^std::numeric_limits::min()]]] + [[[^const_max]][[^T]][equivalent to [^std::numeric_limits::max()]]] +] + +Note: The /is_integral/ flag is provided, because a user-defined integer class should specialize +[^std::numeric_limits<>::is_integer = true], while compile-time constants +[^const_min] and [^const_max] are not provided for that user-defined class, unless boost::integer_traits is also specialized. + +[endsect] + +[section Test Program] + +The program [^[@../../test/integer_traits_test.cpp integer_traits_test.cpp]] exercises the [^integer_traits] class. + +[endsect] + +[section Acknowledgements] + +Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer traits idea on the boost mailing list in August 1999. + +[endsect] +[endsect] + +[section:integer Integer Type Selection] + +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. + +[section:synopsis Synopsis] + + namespace boost + { + // fast integers from least integers + template + struct int_fast_t + { + typedef ``['implementation-defined-type]`` type; + }; + + // signed + template + 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::fast fast; + }; + + // unsigned + template + 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::fast fast; + }; + + // signed + template + struct int_max_value_t + { + typedef ``['implementation-defined-type]`` least; + typedef int_fast_t::fast fast; + }; + + template + struct int_min_value_t + { + typedef ``['implementation-defined-type]`` least; + typedef int_fast_t::fast fast; + }; + + // unsigned + template + struct uint_value_t + { + typedef ``['implementation-defined-type]`` least; + typedef int_fast_t::fast fast; + }; + } // namespace boost + +[endsect] + +[section:easiest Easiest-to-Manipulate Types] + +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. +The output type is given as the nested type [^fast]. + +[*Implementation Notes:] +By default, the output type is identical to the input type. Eventually, this code's implementation should +be customized 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. + +[endsect] + +[section:sized Sized Types] + +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 +nested type [^least]. The easiest-to-manipulate version of that type is given by the nested type [^fast]. +The following table describes each template's criteria. + +[table Criteria for the Sized Type Class Templates + [ + [Class Template][Template Parameter Mapping] + ] + [ + [[^boost::int_t::least]] + [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.] + ] + [ + [[^boost::int_t::fast]] + [The easiest-to-manipulate, 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.] + ] + [ + [[^boost::int_t::exact]] + [A built-in, signed integral type with exactly /N/ bits, including the sign bit. + The parameter should be a positive number. Note that the member /exact/ is defined + [*only] if there exists a type with exactly /N/ bits.] + ] + [ + [[^boost::uint_t::least]] + [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.] + ] + [ + [[^boost::uint_t::fast]] + [The easiest-to-manipulate, 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.] + ] + [ + [[^boost::uint_t::exact]] + [A built-in, unsigned integral type with exactly /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. + Note that the member /exact/ is defined + [*only] if there exists a type with exactly N bits.] + ] + [ + [[^boost::int_max_value_t::last]] + [The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V]. + The parameter should be a positive number.] + ] + [ + [[^boost::int_max_value_t::fast]] + [The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V]. + The parameter should be a positive number.] + ] + [ + [[^boost::int_min_value_t::least]] + [The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0]. + The parameter should be a negative number.] + ] + [ + [[^boost::int_min_value_t::fast]] + [The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0]. + The parameter should be a negative number.] + ] + [ + [[^boost::uint_value_t::least]] + [The smallest, built-in, unsigned integral type that can hold all positive values + up to and including /V/. The parameter should be a positive number.] + ] + [ + [[^boost::uint_value_t::fast]] + [The easiest-to-manipulate, built-in, unsigned integral type that can hold all positive values + up to and including /V/. The parameter should be a positive number.] + ] +] + +[endsect] + +[section Example] + + #include + + //... + + int main() + { + boost::int_t<24>::least my_var; // my_var has at least 24-bits + //... + // This one is guarenteed not to be truncated: + boost::int_max_value_t<1000>::least my1000 = 1000; + //... + // This one is guarenteed not to be truncated, and as fast + // to manipulate as possible, its size may be greater than + // that of my1000: + boost::int_max_value_t<1000>::fast my_fast1000 = 1000; + } + +[endsect] + +[section Demonstration Program] + +The program [@../../test/integer_test.cpp integer_test.cpp] is a simplistic demonstration of the results from instantiating +various examples of the sized type class templates. + +[endsect] + +[section 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. + +[endsect] + +[section Alternative] + +If the number of bits required is known beforehand, it may be more appropriate to use the types supplied +in [@../../../../boost/cstdint.hpp ]. + +[endsect] + +[section Credits] + +The author of most of the Boost integer type choosing templates is +[@http://www.boost.org/people/beman_dawes.html Beman Dawes]. +He gives thanks to Valentin Bonnard and [@http://www.boost.org/people/kevlin_henney.htm Kevlin Henney] +for sharing their designs for similar templates. +[@http://www.boost.org/people/daryle_walker.html Daryle Walker] designed the value-based sized templates. + +[endsect] +[endsect] + + + +[section:mask Integer Masks] + +[section Overview] + +The class templates in [@../../../../boost/integer/integer_mask.hpp ] +provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. +The types of the masking constants come from the [link boost_integer.integer integer type selection templates] header. + +[endsect] + +[section Synopsis] + + #include // for std::size_t + + namespace boost + { + + template + struct high_bit_mask_t + { + typedef ``['implementation-defined-type]`` least; + typedef ``['implementation-defined-type]`` fast; + + static const least high_bit = ``['implementation-defined]``; + static const fast high_bit_fast = ``['implementation-defined]``; + + static const std::size_t bit_position = Bit; + }; + + template + struct low_bits_mask_t + { + typedef ``['implementation-defined-type]`` least; + typedef ``['implementation-defined-type]`` fast; + + static const least sig_bits = ``['implementation-defined]``; + static const fast sig_bits_fast = ``['implementation-defined]``; + + static const std::size_t bit_count = Bits; + }; + + // Specializations for low_bits_mask_t exist for certain bit counts. + + } // namespace boost + +[endsect] + +[section Single Bit-Mask Class Template] + +The [^boost::high_bit_mask_t] class template provides constants for bit masks representing the bit at a +certain position. The masks are equivalent to the value 2[super Bit], where [^Bit] is the template parameter. +The bit position must be a nonnegative number from zero to ['Max], where Max is one less than the +number of bits supported by the largest unsigned built-in integral type. The following table describes +the members of an instantiation of [^high_bit_mask_t]. + +[table Members of the `boost::high_bit_mask_t` Class Template + [[Member][Meaning]] + [[[^least]][The smallest, unsigned, built-in type that supports the given bit position.]] + [[[^fast]][The easiest-to-manipulate analog of [^least].]] + [[[^high_bit]][A [^least] constant of the value 2[super Bit].]] + [[[^high_bit_fast]][A [^fast] analog of [^high_bit].]] + [[[^bit_position]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]] +] + +[endsect] + +[section Group Bit-Mask Class Template] + +The [^boost::low_bits_mask_t] class template provides constants for bit masks +equivalent to the value (2[super Bits] - 1), where [^Bits] is the template parameter. +The parameter [^Bits] must be a non-negative integer from +zero to ['Max], where Max is the number of bits supported by the largest, unsigned, built-in integral type. +The following table describes the members of [^low_bits_mask_t]. + +[table Members of the [^boost::low_bits_mask_t] Class Template +[[Member][Meaning]] +[[[^least]][The smallest, unsigned built-in type that supports the given bit count.]] +[[[^fast]][The easiest-to-manipulate analog of [^least].]] +[[[^sig_bits]][A [^least] constant of the desired bit-masking value.]] +[[[^sig_bits_fast]][A [^fast] analog of [^sig_bits].]] +[[[^bit_count]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]] +] + +[endsect] + +[section Implementation Notes] + +When [^Bits] is the exact size of a built-in unsigned type, the implementation has to change to +prevent undefined behavior. Therefore, there are specializations of [^low_bits_mask_t] at those bit counts. + +[endsect] + +[section Example] + + #include + + //... + + int main() + { + typedef boost::high_bit_mask_t<29> mask1_type; + typedef boost::low_bits_mask_t<15> mask2_type; + + mask1_type::least my_var1; + mask2_type::fast my_var2; + //... + + my_var1 |= mask1_type::high_bit; + my_var2 &= mask2_type::sig_bits_fast; + + //... + } + +[endsect] + +[section Demonstration Program] + +The program [@../../test/integer_mask_test.cpp integer_mask_test.cpp] is a simplistic demonstration of the +results from instantiating various examples of the bit mask class templates. + +[endsect] + +[section Rationale] + +The class templates in this header are an extension of the [link boost_integer.integer integer type selection class templates]. +The new class templates provide the same sized types, but also convenient masks to use when extracting the +highest or all the significant bits when the containing built-in type contains more bits. +This prevents contamination of values by the higher, unused bits. + +[endsect] + +[section Credits] + +The author of the Boost bit mask class templates is [@http://www.boost.org/people/daryle_walker.html Daryle Walker]. + +[endsect] +[endsect] + +[section:log2 Compile Time log2 Calculation] + +The class template in [@../../../../boost/integer/static_log2.hpp ] +determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems. + +[section Synopsis] + + namespace boost + { + + typedef ``['implementation-defined]`` static_log2_argument_type; + typedef ``['implementation-defined]`` static_log2_result_type; + + template + struct static_log2 + { + static const static_log2_result_type value = ``['implementation-defined]``; + }; + + + template < > + struct static_log2< 0 > + { + // The logarithm of zero is undefined. + }; + + + } // namespace boost + +[endsect] + +[section Usage] + +The [^boost::static_log2] class template takes one template parameter, a value of type +[^static_log2_argument_type]. The template only defines one member, [^value], which gives the +truncated, base-two logarithm of the template argument. + +Since the logarithm of zero, for any base, is undefined, there is a specialization of [^static_log2] +for a template argument of zero. This specialization has no members, so an attempt to use the base-two +logarithm of zero results in a compile-time error. + +Note: + +* [^static_log2_argument_type] is an ['unsigned integer type] (C++ standard, 3.9.1p3). +* [^static_log2_result_type] is an ['integer type] (C++ standard, 3.9.1p7). + +[endsect] + +[section Demonstration Program] + +The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic +demonstration of the results from instantiating various examples of the binary logarithm class template. + +[endsect] + +[section Rationale] + +The base-two (binary) logarithm, abbreviated lb, function is occasionally used to give order-estimates +of computer algorithms. The truncated logarithm can be considered the highest power-of-two in a value, +which corresponds to the value's highest set bit (for binary integers). Sometimes the highest-bit position +could be used in generic programming, which requires the position to be available statically (['i.e.] at compile-time). + +[endsect] + +[section Credits] + +The original version of the Boost binary logarithm class template was +written by [@http://www.boost.org/people/daryle_walker.html Daryle Walker] and then +enhanced by Giovanni Bajo with support for compilers without partial template specialization. +The current version was suggested, together with a reference implementation, by Vesa Karvonen. +Gennaro Prota wrote the actual source file. + +[endsect] +[endsect] + +[section:minmax Compile time min/max calculation] + +The class templates in [@../../../../boost/integer/static_min_max.hpp ] +provide a compile-time evaluation of the minimum or maximum of two integers. These facilities are useful +for generic programming problems. + +[section Synopsis] + + namespace boost + { + + typedef ``['implementation-defined]`` static_min_max_signed_type; + typedef ``['implementation-defined]`` static_min_max_unsigned_type; + + template + struct static_signed_min; + + template + struct static_signed_max; + + template + struct static_unsigned_min; + + template + struct static_unsigned_max; + + } + +[endsect] + +[section Usage] + +The four class templates provide the combinations for finding the minimum or maximum of two [^signed] or +[^unsigned] ([^long]) parameters, /Value1/ and /Value2/, at compile-time. Each template has a single static data member, +[^value], which is set to the respective minimum or maximum of the template's parameters. + +[endsect] + +[section Example] + + #include + + template < unsigned long AddendSize1, unsigned long AddendSize2 > + class adder + { + public: + static unsigned long const addend1_size = AddendSize1; + static unsigned long const addend2_size = AddendSize2; + static unsigned long const sum_size = boost::static_unsigned_max::value + 1; + + typedef int addend1_type[ addend1_size ]; + typedef int addend2_type[ addend2_size ]; + typedef int sum_type[ sum_size ]; + + void operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const; + }; + + //... + + int main() + { + int const a1[] = { 0, 4, 3 }; // 340 + int const a2[] = { 9, 8 }; // 89 + int s[ 4 ]; + adder<3,2> obj; + + obj( a1, a2, s ); // 's' should be 429 or { 9, 2, 4, 0 } + //... + } + +[endsect] + +[section Demonstration Program] + +The program [@../../test/static_min_max_test.cpp static_min_max_test.cpp] is a simplistic demonstration of +various comparisons using the compile-time extrema class templates. + +[endsect] + +[section Rationale] + +Sometimes the minimum or maximum of several values needs to be found for later compile-time processing, +['e.g.] for a bound for another class template. + +[endsect] + +[section Credits] + +The author of the Boost compile-time extrema class templates is [@http://www.boost.org/people/daryle_walker.html Daryle Walker]. + +[endsect] +[endsect] + +[section:history History] + +[h4 1.42.0] + +* Reverted Trunk to release branch state (i.e. a "known good state"). +* Fixed issues: [@https://svn.boost.org/trac/boost/ticket/653 653], +[@https://svn.boost.org/trac/boost/ticket/3084 3084], +[@https://svn.boost.org/trac/boost/ticket/3177 3177], +[@https://svn.boost.org/trac/boost/ticket/3180 3180], +[@https://svn.boost.org/trac/boost/ticket/3548 3568], +[@https://svn.boost.org/trac/boost/ticket/3657 3657], +[@https://svn.boost.org/trac/boost/ticket/2134 2134]. +* Added long long support to [^boost::static_log2], [^boost::static_signed_min], [^boost::static_signed_max], +[^boost::static_unsigned_min][^boost::static_unsigned_max], when available. +* The argument type and the result type of [^boost::static_signed_min] etc are now typedef'd. +Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the +provided typedefs in new code (and update old code as soon as possible). + +[h4 1.32.0] + +* The argument type and the result type of [^boost::static_log2] are now typedef'd. +Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the +provided typedefs in new code (and update old code as soon as possible). + +[endsect] + diff --git a/doc/integer_mask.html b/doc/integer_mask.html deleted file mode 100644 index 5bc7301..0000000 --- a/doc/integer_mask.html +++ /dev/null @@ -1,210 +0,0 @@ - - - -Integer Bit Mask Templates - - - -

boost.png (6897 bytes)Integer Bit Mask Templates

- -

The class templates in <boost/integer/integer_mask.hpp> provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. The types of the masking constants come from the integer type selection templates header.

- -

Contents

- - - -

Synopsis

- -
-#include <cstddef>  // for std::size_t
-
-namespace boost
-{
-
-template < std::size_t Bit >
-struct high_bit_mask_t
-{
-    typedef implementation_supplied  least;
-    typedef implementation_supplied   fast;
-
-    static const least  high_bit = implementation_defined;
-    static const fast   high_bit_fast = implementation_defined;
-
-    static const std::size_t  bit_position = Bit;
-
-};
-
-template < std::size_t Bits >
-struct low_bits_mask_t
-{
-    typedef implementation_supplied  least;
-    typedef implementation_supplied   fast;
-
-    static const least  sig_bits = implementation_defined;
-    static const fast   sig_bits_fast = implementation_defined;
-
-    static const std::size_t  bit_count = Bits;
-
-};
-
-// Specializations for low_bits_mask_t exist for certain bit counts.
-
-}  // namespace boost
-
- -

Single Bit-Mask Class Template

- -

The boost::high_bit_mask_t class template provides -constants for bit masks representing the bit at a certain position. The -masks are equivalent to the value 2Bit, where -Bit is the template parameter. The bit position must be a -nonnegative number from zero to Max, where Max is one -less than the number of bits supported by the largest unsigned built-in -integral type. The following table describes the members of an -instantiation of high_bit_mask_t.

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Members of the boost::high_bit_mask_t Class - Template
MemberMeaning
leastThe smallest unsigned built-in type that supports the given - bit position.
fastThe quick-to-manipulate analog of least.
high_bitA least constant of the desired bit-masking - value.
high_bit_fastA fast analog of high_bit.
bit_positionThe value of the template parameter, in case its needed from - a renamed instantiation of the class template.
- -

Group Bit-Mask Class Template

- -

The boost::low_bits_mask_t class template provides -constants for bit masks representing the lowest bits of a certain -amount. The masks are equivalent to the value -(2Bits - 1), where Bits is the -template parameter. The bit amount must be a nonnegative number from -zero to Max, where Max is the number of bits supported -by the largest unsigned built-in integral type. The following table -describes the members of an instantiation of -low_bits_mask_t.

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Members of the boost::low_bits_mask_t Class - Template
MemberMeaning
leastThe smallest unsigned built-in type that supports the given - bit count.
fastThe quick-to-manipulate analog of least.
sig_bitsA least constant of the desired bit-masking - value.
sig_bits_fastA fast analog of sig_bits.
bit_countThe value of the template parameter, in case its needed from - a renamed instantiation of the class template.
- -

Implementation Note
-When Bits is the exact size of a built-in unsigned type, -the implementation has to change to prevent undefined behavior. -Therefore, there are specializations of low_bits_mask_t at -those bit counts.

- -

Example

- -
-#include <boost/integer/integer_mask.hpp>
-
-//...
-
-int main()
-{
-    typedef boost::high_bit_mask_t<29>  mask1_type;
-    typedef boost::low_bits_mask_t<15>  mask2_type;
-
-    mask1_type::least  my_var1;
-    mask2_type::fast   my_var2;
-    //...
-
-    my_var1 |= mask1_type::high_bit;
-    my_var2 &= mask2_type::sig_bits_fast;
-
-    //...
-}
-
- -

Demonstration Program

- -

The program integer_mask_test.cpp -is a simplistic demonstration of the results from instantiating various -examples of the bit mask class templates.

- -

Rationale

- -

The class templates in this header are an extension of the integer type selection class templates. The new -class templates provide the same sized types, but also convienent masks -to use when extracting the highest or all the significant bits when the -containing built-in type contains more bits. This prevents -contaimination of values by the higher, unused bits.

- -

Credits

- -

The author of the Boost bit mask class templates is Daryle Walker.

- -
- -

Revised September 23, 2001

- -

© Copyright Daryle Walker 2001. Use, modification, and distribution are -subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)

- - diff --git a/doc/static_log2.html b/doc/static_log2.html deleted file mode 100644 index b77874c..0000000 --- a/doc/static_log2.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - -Binary Logarithm Template - - - - - - - -

boost.png (6897 bytes)Binary Logarithm Template

- - -

The class template in <boost/integer/static_log2.hpp> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.

- - - -

Contents

- - - - - - -

Synopsis

- - - -
-
-namespace boost
-{
-
-  typedef implementation-defined static_log2_argument_type;
-  typedef implementation-defined static_log2_result_type;
-
-  template < static_log2_argument_type arg >
-  struct static_log2
-  {
-    static const static_log2_result_type value = implementation-defined;
-  };
-
-
-  template < >
-  struct static_log2< 0 >
-  {
-    // The logarithm of zero is undefined.
-  };
-
-
-}  // namespace boost
-
-
- - - - -

Usage

- - - -

The boost::static_log2 class template takes one template -parameter, a value of type static_log2_argument_type. The template -only defines one member, value, which gives the truncated -base-two logarithm of the template argument.

- -

Since the logarithm of zero, for any base, is undefined, there is a -specialization of static_log2 for a template argument -of zero. This specialization has no members, so an attempt to use -the base-two logarithm of zero results in a compile-time error.

- -

Note:

    - -
  • static_log2_argument_type is an unsigned integer - type (C++ standard, 3.9.1p3).
  • - -
  • static_log2_result_type is an integer type - (C++ standard, 3.9.1p7).
  • - -
- - - -

Example

- - - -
-
-#include "boost/integer/static_log2.hpp"
-
-
-template < boost::static_log2_argument_type value >
-bool is_it_what()
-{
-    typedef boost::static_log2<value>  lb_type;
-
-    int  temp = lb_type::value;
-    //...
-    return (temp % 2) != 0;
-}
-
-//...
-
-int main()
-{
-    bool  temp = is_it_what<2000>();
-    //...
-# if 0
-    temp = is_it_what<0>();  // would give an error
-# endif
-    //...
-    temp = is_it_what<24>();
-    //...
-}
-
-
- - - -

Demonstration Program

- - - -

The program static_log2_test.cpp -is a simplistic demonstration of the results from instantiating various -examples of the binary logarithm class template.

- - - -

Rationale

- - - -

The base-two (binary) logarithm, abbreviated lb, function -is occasionally used to give order-estimates of computer algorithms. -The truncated logarithm can be considered the highest power-of-two in a -value, which corresponds to the value's highest set bit (for binary -integers). Sometimes the highest-bit position could be used in generic -programming, which requires the position to be statically (i.e. -at compile-time) available.

- - - -

Changes from previous versions:

- - - -
    -
  • New in version 1.32.0:

    - -The argument type and the result type of boost::static_log2 -are now typedef'd. Formerly, they were hardcoded as unsigned long -and int respectively. Please, use the provided typedefs in new -code (and update old code as soon as possible). -
  • -
- - - -

Credits

- - - -

The original version of the Boost binary logarithm class template was -written by Daryle Walker -and then enhanced by Giovanni Bajo with support for compilers without -partial template specialization. The current version was suggested, -together with a reference implementation, by Vesa Karvonen. Gennaro Prota -wrote the actual source file. -

- -
- - - -

Revised July 19, 2004

- -

© Copyright Daryle Walker 2001.
- © Copyright Gennaro Prota 2004.

- - 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) - -
- - - - - diff --git a/doc/static_min_max.html b/doc/static_min_max.html deleted file mode 100644 index 1beb503..0000000 --- a/doc/static_min_max.html +++ /dev/null @@ -1,120 +0,0 @@ - - - -Compile-Time Extrema Templates - - - -

boost.png (6897 bytes)Compile-Time Extrema -Templates

- -

The class templates in <boost/integer/static_min_max.hpp> -provide a compile-time evaluation of the minimum or maximum of -two integers. These facilities are useful for generic programming problems.

- -

Contents

- - - -

Synopsis

- -
-namespace boost
-{
-
-template < long Value1, long Value2 >
-    struct static_signed_min;
-
-template < long Value1, long Value2 >
-    struct static_signed_max;
-
-template < unsigned long Value1, unsigned long Value2 >
-    struct static_unsigned_min;
-
-template < unsigned long Value1, unsigned long Value2 >
-    struct static_unsigned_max;
-
-}
-
- -

Usage

- -

The four class templates provide the combinations for finding the -minimum or maximum of two signed or unsigned -(long) parameters, Value1 and Value2, -at compile-time. Each template has a single static data member, -value, which is set to the respective minimum or maximum -of the template's parameters.

- -

Example

- -
-#include <boost/integer/static_min_max.hpp>
-
-template < unsigned long AddendSize1, unsigned long AddendSize2 >
-class adder
-{
-public:
-    static  unsigned long  const  addend1_size = AddendSize1;
-    static  unsigned long  const  addend2_size = AddendSize2;
-    static  unsigned long  const  sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
-
-    typedef int  addend1_type[ addend1_size ];
-    typedef int  addend2_type[ addend2_size ];
-    typedef int  sum_type[ sum_size ];
-
-    void  operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const;
-};
-
-//...
-
-int main()
-{
-    int const   a1[] = { 0, 4, 3 };  // 340
-    int const   a2[] = { 9, 8 };     //  89
-    int         s[ 4 ];
-    adder<3,2>  obj;
-
-    obj( a1, a2, s );  // 's' should be 429 or { 9, 2, 4, 0 }
-    //...
-}
-
- -

Demonstration Program

- -

The program static_min_max_test.cpp is a -simplistic demonstration of various comparisons using the compile-time -extrema class templates.

- -

Rationale

- -

Sometimes the minimum or maximum of several values needs to be found -for later compile-time processing, e.g. for a bound for another -class template.

- -

Credits

- -

The author of the Boost compile-time extrema class templates is Daryle Walker.

- -
- -

Revised October 12, 2001

- -

© Copyright Daryle Walker 2001. Use, modification, and distribution are -subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)

- - diff --git a/include/boost/cstdint.hpp b/include/boost/cstdint.hpp index d55a484..47e6a16 100644 --- a/include/boost/cstdint.hpp +++ b/include/boost/cstdint.hpp @@ -23,10 +23,25 @@ #ifndef BOOST_CSTDINT_HPP #define BOOST_CSTDINT_HPP +// +// Since we always define the INT#_C macros as per C++0x, +// define __STDC_CONSTANT_MACROS so that does the right +// thing if possible, and so that the user knows that the macros +// are actually defined as per C99. +// +#ifndef __STDC_CONSTANT_MACROS +# define __STDC_CONSTANT_MACROS +#endif + #include - -#ifdef BOOST_HAS_STDINT_H +// +// Note that GLIBC is a bit inconsistent about whether int64_t is defined or not +// depending upon what headers happen to have been included first... +// so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG. +// See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990 +// +#if defined(BOOST_HAS_STDINT_H) && (!defined(__GLIBC__) || defined(__GLIBC_HAVE_LONG_LONG)) // The following #include is an implementation artifact; not part of interface. # ifdef __hpux @@ -220,6 +235,15 @@ namespace boost typedef unsigned short uint_least16_t; typedef unsigned short uint_fast16_t; # endif +# elif (USHRT_MAX == 0xffffffff) && defined(__MTA__) + // On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified + // MTA / XMT does support the following non-standard integer types + typedef __short16 int16_t; + typedef __short16 int_least16_t; + typedef __short16 int_fast16_t; + typedef unsigned __short16 uint16_t; + typedef unsigned __short16 uint_least16_t; + typedef unsigned __short16 uint_fast16_t; # elif (USHRT_MAX == 0xffffffff) && defined(CRAY) // no 16-bit types on Cray: typedef short int_least16_t; @@ -246,6 +270,14 @@ namespace boost typedef unsigned int uint32_t; typedef unsigned int uint_least32_t; typedef unsigned int uint_fast32_t; +# elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__) + // Integers are 64 bits on the MTA / XMT + typedef __int32 int32_t; + typedef __int32 int_least32_t; + typedef __int32 int_fast32_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int32 uint_least32_t; + typedef unsigned __int32 uint_fast32_t; # else # error defaults not correct; you must hand modify boost/cstdint.hpp # endif @@ -326,19 +358,16 @@ namespace boost Macro definition section: -Define various INTXX_C macros only if -__STDC_CONSTANT_MACROS is defined. - -Undefine the macros if __STDC_CONSTANT_MACROS is -not defined and the macros are (cf ). - Added 23rd September 2000 (John Maddock). Modified 11th September 2001 to be excluded when BOOST_HAS_STDINT_H is defined (John Maddock). +Modified 11th Dec 2009 to always define the +INT#_C macros if they're not already defined (John Maddock). ******************************************************/ -#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H) +#if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(INT8_C) +#include # define BOOST__STDC_CONSTANT_MACROS_DEFINED # if defined(BOOST_HAS_MS_INT64) // @@ -390,27 +419,40 @@ BOOST_HAS_STDINT_H is defined (John Maddock). // 64-bit types + intmax_t and uintmax_t ----------------------------------// # if defined(BOOST_HAS_LONG_LONG) && \ - (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)) + (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX)) # if defined(__hpux) - // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions -# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \ - (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \ - (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U) + // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions +# define INT64_C(value) value##LL +# define UINT64_C(value) value##uLL +# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \ + (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \ + (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \ + (defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL) +# define INT64_C(value) value##LL +# define UINT64_C(value) value##uLL # else # error defaults not correct; you must hand modify boost/cstdint.hpp # endif -# define INT64_C(value) value##LL -# define UINT64_C(value) value##uLL # elif ULONG_MAX != 0xffffffff -# if ULONG_MAX == 18446744073709551615 // 2**64 - 1 +# if ULONG_MAX == 18446744073709551615U // 2**64 - 1 # define INT64_C(value) value##L # define UINT64_C(value) value##uL # else # error defaults not correct; you must hand modify boost/cstdint.hpp # endif +# elif defined(BOOST_HAS_LONG_LONG) + // Usual macros not defined, work things out for ourselves: +# if(~0uLL == 18446744073709551615ULL) +# define INT64_C(value) value##LL +# define UINT64_C(value) value##uLL +# else +# error defaults not correct; you must hand modify boost/cstdint.hpp +# endif +# else +# error defaults not correct; you must hand modify boost/cstdint.hpp # endif # ifdef BOOST_NO_INT64_T @@ -423,23 +465,7 @@ BOOST_HAS_STDINT_H is defined (John Maddock). # endif // Borland/Microsoft specific width suffixes - -#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H) -// -// undef all the macros: -// -# undef INT8_C -# undef INT16_C -# undef INT32_C -# undef INT64_C -# undef UINT8_C -# undef UINT16_C -# undef UINT32_C -# undef UINT64_C -# undef INTMAX_C -# undef UINTMAX_C - -#endif // __STDC_CONSTANT_MACROS_DEFINED etc. +#endif // INT#_C macros. diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index dc57dff..3393c81 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -17,8 +17,21 @@ #include // self include -#include // for boost::integer_traits -#include // for std::numeric_limits +#include // for boost::::boost::integer_traits +#include // for ::std::numeric_limits +#include // 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 { @@ -28,7 +41,13 @@ namespace boost // fast integers from least integers // int_fast_t<> works correctly for unsigned too, in spite of the name. template< typename LeastInt > - struct int_fast_t { typedef LeastInt fast; }; // imps may specialize + struct int_fast_t + { + typedef LeastInt fast; + typedef fast type; + }; // imps may specialize + + namespace detail{ // convert category to type template< int Category > struct int_least_helper {}; // default is empty @@ -36,89 +55,196 @@ namespace boost // specializatons: 1=long, 2=int, 3=short, 4=signed char, // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char // no specializations for 0 and 5: requests for a type > long are in error - template<> struct int_least_helper<1> { typedef long least; }; - template<> struct int_least_helper<2> { typedef int least; }; - template<> struct int_least_helper<3> { typedef short least; }; - template<> struct int_least_helper<4> { typedef signed char least; }; - template<> struct int_least_helper<6> { typedef unsigned long least; }; - template<> struct int_least_helper<7> { typedef unsigned int least; }; - template<> struct int_least_helper<8> { typedef unsigned short least; }; - template<> struct int_least_helper<9> { typedef unsigned char least; }; +#ifdef BOOST_HAS_LONG_LONG + template<> struct int_least_helper<1> { typedef boost::long_long_type least; }; +#endif + template<> struct int_least_helper<2> { typedef long least; }; + template<> struct int_least_helper<3> { typedef int least; }; + template<> struct int_least_helper<4> { typedef short least; }; + template<> struct int_least_helper<5> { typedef signed char least; }; +#ifdef BOOST_HAS_LONG_LONG + template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; }; +#endif + template<> struct int_least_helper<7> { typedef unsigned long least; }; + template<> struct int_least_helper<8> { typedef unsigned int least; }; + template<> struct int_least_helper<9> { typedef unsigned short least; }; + template<> struct int_least_helper<10> { typedef unsigned char least; }; + + template + struct exact_signed_base_helper{}; + template + struct exact_unsigned_base_helper{}; + + template <> struct exact_signed_base_helper { typedef signed char exact; }; + template <> struct exact_unsigned_base_helper { typedef unsigned char exact; }; +#if USHRT_MAX != UCHAR_MAX + template <> struct exact_signed_base_helper { typedef short exact; }; + template <> struct exact_unsigned_base_helper { typedef unsigned short exact; }; +#endif +#if UINT_MAX != USHRT_MAX + template <> struct exact_signed_base_helper { typedef int exact; }; + template <> struct exact_unsigned_base_helper { typedef unsigned int exact; }; +#endif +#if ULONG_MAX != UINT_MAX + template <> struct exact_signed_base_helper { typedef long exact; }; + template <> struct exact_unsigned_base_helper { 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 { typedef boost::long_long_type exact; }; + template <> struct exact_unsigned_base_helper { typedef boost::ulong_long_type 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 { - typedef typename int_least_helper + typedef typename detail::int_least_helper < - (Bits-1 <= std::numeric_limits::digits) + - (Bits-1 <= std::numeric_limits::digits) + - (Bits-1 <= std::numeric_limits::digits) + - (Bits-1 <= std::numeric_limits::digits) +#ifdef BOOST_HAS_LONG_LONG + (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) + +#else + 1 + +#endif + (Bits-1 <= ::std::numeric_limits::digits) + + (Bits-1 <= ::std::numeric_limits::digits) + + (Bits-1 <= ::std::numeric_limits::digits) + + (Bits-1 <= ::std::numeric_limits::digits) >::least least; - typedef typename int_fast_t::fast fast; + typedef typename int_fast_t::type fast; }; // unsigned template< int Bits > // bits required - struct uint_t + struct uint_t : public detail::exact_unsigned_base_helper { - typedef typename int_least_helper +#if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T) + // It's really not clear why this workaround should be needed... shrug I guess! JM + BOOST_STATIC_CONSTANT(int, s = + 6 + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits)); + typedef typename detail::int_least_helper< ::boost::uint_t::s>::least least; +#else + typedef typename detail::int_least_helper < 5 + - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) +#ifdef BOOST_HAS_LONG_LONG + (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) + +#else + 1 + +#endif + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) >::least least; - typedef typename int_fast_t::fast fast; +#endif + typedef typename int_fast_t::type fast; // int_fast_t<> works correctly for unsigned too, in spite of the name. }; // integer templates specifying extreme value ----------------------------// // signed +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MaxValue > // maximum value to require support +#else template< long MaxValue > // maximum value to require support +#endif struct int_max_value_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + (MaxValue <= ::boost::integer_traits::const_max) + +#else + 1 + +#endif + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) >::least least; - typedef typename int_fast_t::fast fast; + typedef typename int_fast_t::type fast; }; +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MinValue > // minimum value to require support +#else template< long MinValue > // minimum value to require support +#endif struct int_min_value_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + (MinValue >= ::boost::integer_traits::const_min) + +#else + 1 + +#endif + (MinValue >= ::boost::integer_traits::const_min) + + (MinValue >= ::boost::integer_traits::const_min) + + (MinValue >= ::boost::integer_traits::const_min) + + (MinValue >= ::boost::integer_traits::const_min) >::least least; - typedef typename int_fast_t::fast fast; + typedef typename int_fast_t::type fast; }; // unsigned - template< unsigned long Value > // maximum value to require support +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::ulong_long_type MaxValue > // minimum value to require support +#else + template< unsigned long MaxValue > // minimum value to require support +#endif struct uint_value_t { - typedef typename int_least_helper +#if (defined(__BORLANDC__) || defined(__CODEGEAR__)) + // It's really not clear why this workaround should be needed... shrug I guess! JM +#if defined(BOOST_NO_INTEGRAL_INT64_T) + BOOST_STATIC_CONSTANT(unsigned, which = + 6 + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max)); + typedef typename detail::int_least_helper< ::boost::uint_value_t::which>::least least; +#else // BOOST_NO_INTEGRAL_INT64_T + BOOST_STATIC_CONSTANT(unsigned, which = + 5 + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max)); + typedef typename detail::int_least_helper< ::boost::uint_value_t::which>::least least; +#endif // BOOST_NO_INTEGRAL_INT64_T +#else + typedef typename detail::int_least_helper < 5 + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + (MaxValue <= ::boost::integer_traits::const_max) + +#else + 1 + +#endif + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) >::least least; - typedef typename int_fast_t::fast fast; +#endif + typedef typename int_fast_t::type fast; }; diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp index 0a092d3..8c4e1bb 100644 --- a/include/boost/integer/integer_mask.hpp +++ b/include/boost/integer/integer_mask.hpp @@ -70,6 +70,11 @@ struct low_bits_mask_t BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ } +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch +#endif + BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); #if USHRT_MAX > UCHAR_MAX @@ -84,6 +89,10 @@ BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); #endif +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + #undef BOOST_LOW_BITS_MASK_SPECIALIZE diff --git a/include/boost/integer/static_log2.hpp b/include/boost/integer/static_log2.hpp index 219a48e..56c7a00 100644 --- a/include/boost/integer/static_log2.hpp +++ b/include/boost/integer/static_log2.hpp @@ -16,7 +16,7 @@ #ifndef BOOST_INTEGER_STATIC_LOG2_HPP #define BOOST_INTEGER_STATIC_LOG2_HPP -#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT +#include "boost/integer_fwd.hpp" // for boost::intmax_t namespace boost { @@ -41,9 +41,8 @@ namespace boost { // terminates with x = 1 and n = 0 (see the algorithm's // invariant). - typedef unsigned long argument_type; - typedef int result_type; - + typedef boost::static_log2_argument_type argument_type; + typedef boost::static_log2_result_type result_type; template struct choose_initial_n { @@ -107,10 +106,6 @@ namespace boost { // static_log2 // ---------------------------------------- - typedef detail::static_log2_impl::argument_type static_log2_argument_type; - typedef detail::static_log2_impl::result_type static_log2_result_type; - - template struct static_log2 { diff --git a/include/boost/integer/static_min_max.hpp b/include/boost/integer/static_min_max.hpp index 2646037..ee76fd4 100644 --- a/include/boost/integer/static_min_max.hpp +++ b/include/boost/integer/static_min_max.hpp @@ -12,39 +12,35 @@ #include // self include -#include // for BOOST_STATIC_CONSTANT - - namespace boost { - // Compile-time extrema class declarations ---------------------------------// // Get the minimum or maximum of two values, signed or unsigned. -template < long Value1, long Value2 > +template struct static_signed_min { - BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 ); + BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 > Value2) ? Value2 : Value1 ); }; -template < long Value1, long Value2 > +template struct static_signed_max { - BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 ); + BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 < Value2) ? Value2 : Value1 ); }; -template < unsigned long Value1, unsigned long Value2 > +template struct static_unsigned_min { - BOOST_STATIC_CONSTANT( unsigned long, value + BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value = (Value1 > Value2) ? Value2 : Value1 ); }; -template < unsigned long Value1, unsigned long Value2 > +template struct static_unsigned_max { - BOOST_STATIC_CONSTANT( unsigned long, value + BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value = (Value1 < Value2) ? Value2 : Value1 ); }; diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 33cfc99..01b0a08 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -14,11 +14,23 @@ #include // for BOOST_NO_INTRINSIC_WCHAR_T #include // for std::numeric_limits +#include // For intmax_t namespace boost { +#ifdef BOOST_NO_INTEGRAL_INT64_T + typedef unsigned long static_log2_argument_type; + typedef int static_log2_result_type; + typedef long static_min_max_signed_type; + typedef unsigned long static_min_max_unsigned_type; +#else + typedef boost::uintmax_t static_min_max_unsigned_type; + typedef boost::intmax_t static_min_max_signed_type; + typedef boost::uintmax_t static_log2_argument_type; + typedef int static_log2_result_type; +#endif // From ------------------------------------------------// @@ -65,7 +77,7 @@ template < > template < > class integer_traits< unsigned long >; -#ifdef ULLONG_MAX +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) template < > class integer_traits< ::boost::long_long_type>; @@ -85,13 +97,25 @@ template< int Bits > template< int Bits > struct uint_t; -template< long MaxValue > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MaxValue > // maximum value to require support +#else + template< long MaxValue > // maximum value to require support +#endif struct int_max_value_t; -template< long MinValue > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::long_long_type MinValue > // minimum value to require support +#else + template< long MinValue > // minimum value to require support +#endif struct int_min_value_t; -template< unsigned long Value > +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + template< boost::ulong_long_type MaxValue > // maximum value to require support +#else + template< unsigned long MaxValue > // maximum value to require support +#endif struct uint_value_t; @@ -124,28 +148,26 @@ template < > // From ------------------------------------// -template < unsigned long Value > +template struct static_log2; -template < > - struct static_log2< 0ul >; +template <> struct static_log2<0u>; // From ---------------------------------// -template < long Value1, long Value2 > +template struct static_signed_min; -template < long Value1, long Value2 > +template struct static_signed_max; -template < unsigned long Value1, unsigned long Value2 > +template struct static_unsigned_min; -template < unsigned long Value1, unsigned long Value2 > +template struct static_unsigned_max; - } // namespace boost diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 96b3526..34b3570 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -27,6 +27,17 @@ #include #endif +// +// We simply cannot include this header on gcc without getting copious warnings of the kind: +// +// ../../../boost/integer_traits.hpp:164:66: 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 { template @@ -225,6 +236,20 @@ class integer_traits< ::boost::ulong_long_type> public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL> { }; +#elif defined(BOOST_HAS_MS_INT64) + +template<> +class integer_traits< __int64> + : public std::numeric_limits< __int64>, + public detail::integer_traits_base< __int64, _I64_MIN, _I64_MAX> +{ }; + +template<> +class integer_traits< unsigned __int64> + : public std::numeric_limits< unsigned __int64>, + public detail::integer_traits_base< unsigned __int64, 0, _UI64_MAX> +{ }; + #endif #endif diff --git a/index.html b/index.html index 1f0f83c..dfc23cc 100644 --- a/index.html +++ b/index.html @@ -1,133 +1,16 @@ - -Boost Integer Library + - - - - - - - - - - - -
boost.png (6897 bytes)HomeLibrariesPeopleFAQMore
- -

Boost Integer Library

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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. - 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. - Use in preference to <stdint.h> - for enhanced portability. Furthermore, all names are safely placed in the boost namespace.
<boost/integer_traits.hpp>
-
- documentation -
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>
-
-
documentation
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. - 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.

- -

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.

- -
- -

Revised: 06 Nov 2007 -

- -

© Copyright Beman Dawes 2003

- -

Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

- + +Automatic redirection failed, please go to +doc/html/index.html. +

Copyright Beman Dawes, Daryle Walker, Gennaro Prota and John Maddock 2001-2009

+

Distributed under the Boost Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt).

- \ No newline at end of file + + + + + diff --git a/integer.htm b/integer.htm deleted file mode 100644 index 3d3f9c5..0000000 --- a/integer.htm +++ /dev/null @@ -1,212 +0,0 @@ - - - -Integer Type Selection Templates - - - -

-boost.png (6897 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.

- -

Contents

- - - -

Synopsis

- -
namespace boost
-{
-  //  fast integers from least integers
-  template< typename LeastInt >
-  struct int_fast_t
-  {
-      typedef implementation_supplied  fast;
-  };
-
-  //  signed
-  template< int Bits >
-  struct int_t 
-  {
-      typedef implementation_supplied  least;
-      typedef int_fast_t<least>::fast  fast;
-  };
-
-  //  unsigned
-  template< int Bits >
-  struct uint_t 
-  {
-      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;
-  };
-} // namespace boost
-
- -

Easiest-to-Manipulate Types

- -

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.

- -

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.

- -

Sized Types

- -

The int_t, uint_t, -int_max_value_t, int_min_value_t, and -uint_value_t class templates find the most appropiate -built-in integral type for the given template parameter. This type is -given by the class member least. The easiest-to-manipulate -version of that type is given by the class member fast. -The following table describes each template's criteria.

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Criteria for the Sized Type Class Templates
Class 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.
- -

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

Alternative

- -

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 May 20, 2001

- -

© Copyright Beman Dawes 1999. Use, modification, and distribution are -subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)

- - diff --git a/integer_traits.html b/integer_traits.html deleted file mode 100644 index 6fc75b8..0000000 --- a/integer_traits.html +++ /dev/null @@ -1,94 +0,0 @@ - - - - - -integer_traits: Compile-Time Limits for Integral Types - - - - -

boost.png (6897 bytes)Compile-Time Integral -Type Limits

- -

-The C++ Standard Library <limits> header supplies a class template -numeric_limits<> with specializations for each fundamental -type.

-

-For integer types, the interesting members of std::numeric_limits<> are: -

   static const bool is_specialized; // will be true for integers
-   static T min() throw();
-   static T max() throw();
-   static const int digits;     // for integers, # value bits
-   static const int digits10;     
-   static const bool is_signed;
-   static const bool is_integer; // will be true for integers
-For many uses, these are sufficient. But min() and max() are problematical because they are not constant expressions -(std::5.19), yet some usages require constant expressions. -

-The template class integer_traits addresses this -problem. - - -

Header integer_traits.hpp Synopsis

- -
namespace boost {
-  template<class T>
-  class integer_traits : public std::numeric_limits<T>
-  {
-    static const bool is_integral = false;
-  };
-
-  // specializations for all integral types
-}
- - -

Description

- -Template class integer_traits is derived from -std::numeric_limits. In general, it adds the single -bool member is_integral with the -compile-time constant value false. However, for all -integral types T (std::3.9.1/7 [basic.fundamental]), -there are specializations provided with the following compile-time -constants defined: -

- - - - - -
membertypevalue
is_integralbooltrue
const_minTequivalent -to std::numeric_limits<T>::min()
const_maxTequivalent -to std::numeric_limits<T>::max()
- -

- -Note: A flag is_integral is provided, because a -user-defined integer class should specialize -std::numeric_limits<>::is_integer = true, -nonetheless compile-time constants const_min and -const_max cannot be provided for that user-defined class. - -

- -Test Program

- -

- -The program integer_traits_test.cpp -exercises the integer_traits class. - -

Acknowledgements

- -Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer -traits idea on the boost mailing list in August 1999. -
-

Revised -06 November 2007

-

© Copyright Beman Dawes 2000

- -

Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

- diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1609bf5..690befa 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -4,17 +4,22 @@ import testing ; +project : requirements all gcc:-Wextra ; + test-suite integer - : [ run cstdint_test.cpp ] - [ run integer_test.cpp - /boost/test//boost_unit_test_framework ] - [ run integer_traits_test.cpp - /boost/test//boost_test_exec_monitor/static ] - [ run integer_mask_test.cpp - /boost/test//boost_unit_test_framework ] - [ run static_log2_test.cpp - /boost/test//boost_test_exec_monitor/static ] - [ run static_min_max_test.cpp - /boost/test//boost_test_exec_monitor/static ] -# [ compile issue_2134.cpp ] + : + [ run cstdint_test.cpp : : : gcc:-Wno-long-long darwin:-Wno-long-long ] + [ run cstdint_test2.cpp : : : gcc:-Wno-long-long darwin:-Wno-long-long ] + [ run integer_traits_test.cpp ] + [ run integer_test.cpp : : : gcc:-Wno-long-long darwin:-Wno-long-long sun:"-Qoption ccfe -tmpldepth=128" ] + [ run integer_mask_test.cpp ] + [ run static_log2_test.cpp ] + [ run static_min_max_test.cpp ] + [ compile cstdint_include_test.cpp ] + [ compile integer_traits_include_test.cpp ] + [ compile integer_include_test.cpp ] + [ compile integer_mask_include_test.cpp ] + [ compile static_log2_include_test.cpp ] + [ compile static_min_max_include_test.cpp ] + [ compile integer_fwd_include_test.cpp ] ; diff --git a/test/cstdint_include_test.cpp b/test/cstdint_include_test.cpp new file mode 100644 index 0000000..aac2e21 --- /dev/null +++ b/test/cstdint_include_test.cpp @@ -0,0 +1,69 @@ +// 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) + +#define __STDC_CONSTANT_MACROS +#include // must be the only #include! + +int main() +{ + boost::int8_t i8 = INT8_C(0); + (void)i8; + boost::uint8_t ui8 = UINT8_C(0); + (void)ui8; + boost::int16_t i16 = INT16_C(0); + (void)i16; + boost::uint16_t ui16 = UINT16_C(0); + (void)ui16; + boost::int32_t i32 = INT32_C(0); + (void)i32; + boost::uint32_t ui32 = UINT32_C(0); + (void)ui32; +#ifndef BOOST_NO_INT64_T + boost::int64_t i64 = 0; + (void)i64; + boost::uint64_t ui64 = 0; + (void)ui64; +#endif + boost::int_least8_t i8least = INT8_C(0); + (void)i8least; + boost::uint_least8_t ui8least = UINT8_C(0); + (void)ui8least; + boost::int_least16_t i16least = INT16_C(0); + (void)i16least; + boost::uint_least16_t ui16least = UINT16_C(0); + (void)ui16least; + boost::int_least32_t i32least = INT32_C(0); + (void)i32least; + boost::uint_least32_t ui32least = UINT32_C(0); + (void)ui32least; +#ifndef BOOST_NO_INT64_T + boost::int_least64_t i64least = 0; + (void)i64least; + boost::uint_least64_t ui64least = 0; + (void)ui64least; +#endif + boost::int_fast8_t i8fast = INT8_C(0); + (void)i8fast; + boost::uint_fast8_t ui8fast = UINT8_C(0); + (void)ui8fast; + boost::int_fast16_t i16fast = INT16_C(0); + (void)i16fast; + boost::uint_fast16_t ui16fast = UINT16_C(0); + (void)ui16fast; + boost::int_fast32_t i32fast = INT32_C(0); + (void)i32fast; + boost::uint_fast32_t ui32fast = UINT32_C(0); + (void)ui32fast; +#ifndef BOOST_NO_INT64_T + boost::int_fast64_t i64fast = 0; + (void)i64fast; + boost::uint_fast64_t ui64fast = 0; + (void)ui64fast; +#endif + boost::intmax_t im = 0; + (void)im; + boost::uintmax_t uim = 0; + (void)uim; +} diff --git a/test/cstdint_test.cpp b/test/cstdint_test.cpp index 88422de..f3cbd9b 100644 --- a/test/cstdint_test.cpp +++ b/test/cstdint_test.cpp @@ -12,18 +12,24 @@ // 12 Nov 00 Adapted to merged // 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock). // 28 Jun 00 Initial version -#define __STDC_CONSTANT_MACROS -#include -#include -#include -#ifdef NDEBUG -int main() -{ - std::cout << "This test makes no sense with NDEBUG defined.\n"; - return 0; -} -#else +// +// There are two ways to test this: in version 1, we include cstdint.hpp as the first +// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined. +// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first, +// and check that we still end up with compatible definitions for the INT#_C macros. +// +// This is version 1. +// + +#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) +// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits : +#pragma GCC diagnostic ignored "-Wtype-limits" +#endif + +#include +#include +#include #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION // @@ -62,24 +68,24 @@ struct integral_constant_checker 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_TEST( int8 == -127 ); + BOOST_TEST( int_least8 == -127 ); + BOOST_TEST( int_fast8 == -127 ); + BOOST_TEST( uint8 == 255u ); + BOOST_TEST( uint_least8 == 255u ); + BOOST_TEST( uint_fast8 == 255u ); + BOOST_TEST( int16 == -32767 ); + BOOST_TEST( int_least16 == -32767 ); + BOOST_TEST( int_fast16 == -32767 ); + BOOST_TEST( uint16 == 65535u ); + BOOST_TEST( uint_least16 == 65535u ); + BOOST_TEST( uint_fast16 == 65535u ); + BOOST_TEST( int32 == -2147483647 ); + BOOST_TEST( int_least32 == -2147483647 ); + BOOST_TEST( int_fast32 == -2147483647 ); + BOOST_TEST( uint32 == 4294967295u ); + BOOST_TEST( uint_least32 == 4294967295u ); + BOOST_TEST( uint_fast32 == 4294967295u ); } #endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION @@ -108,10 +114,10 @@ void integral_constant_type_check(T1, T2) // 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_TEST(sizeof(T1) <= sizeof(T2)); #else - assert(sizeof(T1) == sizeof(T2)); - assert(t1 == t2); + BOOST_TEST(sizeof(T1) == sizeof(T2)); + BOOST_TEST(t1 == t2); #endif #if defined(BOOST_HAS_STDINT_H) // native headers are permitted to promote small @@ -119,22 +125,22 @@ void integral_constant_type_check(T1, T2) if(sizeof(T1) >= sizeof(int)) { if(t1 > 0) - assert(t2 > 0); + BOOST_TEST(t2 > 0); else - assert(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); } else if(t1 < 0) - assert(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); #else if(t1 > 0) - assert(t2 > 0); + BOOST_TEST(t2 > 0); else - assert(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); #endif } -int main() +int main(int, char*[]) { #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION integral_constant_checker::check(); @@ -193,41 +199,40 @@ int main() 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_TEST( int8 == -127 ); + BOOST_TEST( int_least8 == -127 ); + BOOST_TEST( int_fast8 == -127 ); + BOOST_TEST( uint8 == 255u ); + BOOST_TEST( uint_least8 == 255u ); + BOOST_TEST( uint_fast8 == 255u ); + BOOST_TEST( int16 == -32767 ); + BOOST_TEST( int_least16 == -32767 ); + BOOST_TEST( int_fast16 == -32767 ); + BOOST_TEST( uint16 == 65535u ); + BOOST_TEST( uint_least16 == 65535u ); + BOOST_TEST( uint_fast16 == 65535u ); + BOOST_TEST( int32 == -2147483647 ); + BOOST_TEST( int_least32 == -2147483647 ); + BOOST_TEST( int_fast32 == -2147483647 ); + BOOST_TEST( uint32 == 4294967295u ); + BOOST_TEST( uint_least32 == 4294967295u ); + BOOST_TEST( 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_TEST( int64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( uint64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( intmax == INT64_C(-9223372036854775807) ); + BOOST_TEST( uintmax == UINT64_C(18446744073709551615) ); #else - assert( intmax == -2147483647 ); - assert( uintmax == 4294967295u ); + BOOST_TEST( intmax == -2147483647 ); + BOOST_TEST( uintmax == 4294967295u ); #endif std::cout << "OK\n"; - return 0; + return boost::report_errors(); } -#endif diff --git a/test/cstdint_test2.cpp b/test/cstdint_test2.cpp new file mode 100644 index 0000000..91ff28f --- /dev/null +++ b/test/cstdint_test2.cpp @@ -0,0 +1,248 @@ +// boost cstdint.hpp test program ------------------------------------------// + +// Copyright Beman Dawes 2000. 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) + + +// See http://www.boost.org/libs/integer for documentation. + +// Revision History +// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock) +// 12 Nov 00 Adapted to merged +// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock). +// 28 Jun 00 Initial version + +// +// There are two ways to test this: in version 1, we include cstdint.hpp as the first +// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined. +// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first, +// and check that we still end up with compatible definitions for the INT#_C macros. +// +// This is version 2. +// + +#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) +// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits : +#pragma GCC diagnostic ignored "-Wtype-limits" +#endif + +#include + +#ifdef BOOST_HAS_STDINT_H +#ifdef __hpux +# include +#else +# include +#endif +#endif + +#include +#include +#include + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// +// the following class is designed to verify +// that the various INTXX_C macros can be used +// in integral constant expressions: +// +struct integral_constant_checker +{ + static const boost::int8_t int8 = INT8_C(-127); + static const boost::int_least8_t int_least8 = INT8_C(-127); + static const boost::int_fast8_t int_fast8 = INT8_C(-127); + + static const boost::uint8_t uint8 = UINT8_C(255); + static const boost::uint_least8_t uint_least8 = UINT8_C(255); + static const boost::uint_fast8_t uint_fast8 = UINT8_C(255); + + static const boost::int16_t int16 = INT16_C(-32767); + static const boost::int_least16_t int_least16 = INT16_C(-32767); + static const boost::int_fast16_t int_fast16 = INT16_C(-32767); + + static const boost::uint16_t uint16 = UINT16_C(65535); + static const boost::uint_least16_t uint_least16 = UINT16_C(65535); + static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535); + + static const boost::int32_t int32 = INT32_C(-2147483647); + static const boost::int_least32_t int_least32 = INT32_C(-2147483647); + static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647); + + static const boost::uint32_t uint32 = UINT32_C(4294967295); + static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295); + static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295); + + static void check(); +}; + +void integral_constant_checker::check() +{ + BOOST_TEST( int8 == -127 ); + BOOST_TEST( int_least8 == -127 ); + BOOST_TEST( int_fast8 == -127 ); + BOOST_TEST( uint8 == 255u ); + BOOST_TEST( uint_least8 == 255u ); + BOOST_TEST( uint_fast8 == 255u ); + BOOST_TEST( int16 == -32767 ); + BOOST_TEST( int_least16 == -32767 ); + BOOST_TEST( int_fast16 == -32767 ); + BOOST_TEST( uint16 == 65535u ); + BOOST_TEST( uint_least16 == 65535u ); + BOOST_TEST( uint_fast16 == 65535u ); + BOOST_TEST( int32 == -2147483647 ); + BOOST_TEST( int_least32 == -2147483647 ); + BOOST_TEST( int_fast32 == -2147483647 ); + BOOST_TEST( uint32 == 4294967295u ); + BOOST_TEST( uint_least32 == 4294967295u ); + BOOST_TEST( uint_fast32 == 4294967295u ); +} +#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION + +// +// the following function simply verifies that the type +// of an integral constant is correctly defined: +// +#ifdef __BORLANDC__ +#pragma option -w-8008 +#pragma option -w-8066 +#endif +template +void integral_constant_type_check(T1, T2) +{ + // + // the types T1 and T2 may not be exactly + // the same type, but they should be the + // same size and signedness. We could use + // numeric_limits to verify this, but + // numeric_limits implementations currently + // vary too much, or are incomplete or missing. + // + T1 t1 = static_cast(-1); // cast suppresses warnings + T2 t2 = static_cast(-1); // ditto +#if defined(BOOST_HAS_STDINT_H) + // if we have a native stdint.h + // then the INTXX_C macros may define + // a type that's wider than required: + BOOST_TEST(sizeof(T1) <= sizeof(T2)); +#else + BOOST_TEST(sizeof(T1) == sizeof(T2)); + BOOST_TEST(t1 == t2); +#endif +#if defined(BOOST_HAS_STDINT_H) + // native headers are permitted to promote small + // unsigned types to type int: + if(sizeof(T1) >= sizeof(int)) + { + if(t1 > 0) + BOOST_TEST(t2 > 0); + else + BOOST_TEST(!(t2 > 0)); + } + else if(t1 < 0) + BOOST_TEST(!(t2 > 0)); +#else + if(t1 > 0) + BOOST_TEST(t2 > 0); + else + BOOST_TEST(!(t2 > 0)); +#endif +} + + +int main(int, char*[]) +{ +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + integral_constant_checker::check(); +#endif + // + // verify the types of the integral constants: + // + integral_constant_type_check(boost::int8_t(0), INT8_C(0)); + integral_constant_type_check(boost::uint8_t(0), UINT8_C(0)); + integral_constant_type_check(boost::int16_t(0), INT16_C(0)); + integral_constant_type_check(boost::uint16_t(0), UINT16_C(0)); + integral_constant_type_check(boost::int32_t(0), INT32_C(0)); + integral_constant_type_check(boost::uint32_t(0), UINT32_C(0)); +#ifndef BOOST_NO_INT64_T + integral_constant_type_check(boost::int64_t(0), INT64_C(0)); + integral_constant_type_check(boost::uint64_t(0), UINT64_C(0)); +#endif + // + boost::int8_t int8 = INT8_C(-127); + boost::int_least8_t int_least8 = INT8_C(-127); + boost::int_fast8_t int_fast8 = INT8_C(-127); + + boost::uint8_t uint8 = UINT8_C(255); + boost::uint_least8_t uint_least8 = UINT8_C(255); + boost::uint_fast8_t uint_fast8 = UINT8_C(255); + + boost::int16_t int16 = INT16_C(-32767); + boost::int_least16_t int_least16 = INT16_C(-32767); + boost::int_fast16_t int_fast16 = INT16_C(-32767); + + boost::uint16_t uint16 = UINT16_C(65535); + boost::uint_least16_t uint_least16 = UINT16_C(65535); + boost::uint_fast16_t uint_fast16 = UINT16_C(65535); + + boost::int32_t int32 = INT32_C(-2147483647); + boost::int_least32_t int_least32 = INT32_C(-2147483647); + boost::int_fast32_t int_fast32 = INT32_C(-2147483647); + + boost::uint32_t uint32 = UINT32_C(4294967295); + boost::uint_least32_t uint_least32 = UINT32_C(4294967295); + boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295); + +#ifndef BOOST_NO_INT64_T + boost::int64_t int64 = INT64_C(-9223372036854775807); + boost::int_least64_t int_least64 = INT64_C(-9223372036854775807); + boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807); + + boost::uint64_t uint64 = UINT64_C(18446744073709551615); + boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615); + boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615); + + boost::intmax_t intmax = INTMAX_C(-9223372036854775807); + boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615); +#else + boost::intmax_t intmax = INTMAX_C(-2147483647); + boost::uintmax_t uintmax = UINTMAX_C(4294967295); +#endif + + BOOST_TEST( int8 == -127 ); + BOOST_TEST( int_least8 == -127 ); + BOOST_TEST( int_fast8 == -127 ); + BOOST_TEST( uint8 == 255u ); + BOOST_TEST( uint_least8 == 255u ); + BOOST_TEST( uint_fast8 == 255u ); + BOOST_TEST( int16 == -32767 ); + BOOST_TEST( int_least16 == -32767 ); + BOOST_TEST( int_fast16 == -32767 ); + BOOST_TEST( uint16 == 65535u ); + BOOST_TEST( uint_least16 == 65535u ); + BOOST_TEST( uint_fast16 == 65535u ); + BOOST_TEST( int32 == -2147483647 ); + BOOST_TEST( int_least32 == -2147483647 ); + BOOST_TEST( int_fast32 == -2147483647 ); + BOOST_TEST( uint32 == 4294967295u ); + BOOST_TEST( uint_least32 == 4294967295u ); + BOOST_TEST( uint_fast32 == 4294967295u ); + +#ifndef BOOST_NO_INT64_T + BOOST_TEST( int64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) ); + BOOST_TEST( uint64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) ); + BOOST_TEST( intmax == INT64_C(-9223372036854775807) ); + BOOST_TEST( uintmax == UINT64_C(18446744073709551615) ); +#else + BOOST_TEST( intmax == -2147483647 ); + BOOST_TEST( uintmax == 4294967295u ); +#endif + + + std::cout << "OK\n"; + return boost::report_errors(); +} diff --git a/test/integer_fwd_include_test.cpp b/test/integer_fwd_include_test.cpp new file mode 100644 index 0000000..4346b69 --- /dev/null +++ b/test/integer_fwd_include_test.cpp @@ -0,0 +1,22 @@ +// 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) + +#include // must be the only #include! + +// just declare some functions that use the incomplete types in the header: + +void f1(const boost::integer_traits*); +void f2(const boost::int_fast_t*); +void f3(const boost::int_t<12>*); +void f4(const boost::uint_t<31>*); +void f5(const boost::int_max_value_t<100>*); +void f6(const boost::int_min_value_t<-100>*); +void f7(const boost::uint_value_t<100>*); +void f8(const boost::high_bit_mask_t<10>*); +void f9(const boost::low_bits_mask_t<10>*); +void f10(boost::static_log2_argument_type, boost::static_log2_result_type, boost::static_log2<10>*); +void f11(boost::static_min_max_signed_type, boost::static_min_max_unsigned_type); +void f12(boost::static_signed_min<1, 2>*, boost::static_signed_max<1,2>*); +void f13(boost::static_unsigned_min<1,2>*, boost::static_unsigned_min<1,2>*); diff --git a/test/integer_include_test.cpp b/test/integer_include_test.cpp new file mode 100644 index 0000000..653a197 --- /dev/null +++ b/test/integer_include_test.cpp @@ -0,0 +1,36 @@ +// 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) + +#include // must be the only #include! + +int main() +{ + boost::int_fast_t::fast f = 0; + (void)f; + boost::int_t<16>::fast f2 = 0; + (void)f2; + boost::int_t<32>::exact e = 0; + (void)e; + boost::int_t<12>::least l = 0; + (void)l; + boost::uint_t<16>::fast uf2 = 0; + (void)uf2; + boost::uint_t<32>::exact ue = 0; + (void)ue; + boost::uint_t<12>::least ul = 0; + (void)ul; + boost::int_max_value_t<200>::fast v1 = 0; + (void)v1; + boost::int_max_value_t<2000>::least v2 = 0; + (void)v2; + boost::int_min_value_t<-200>::fast v3 = 0; + (void)v3; + boost::int_min_value_t<-2000>::least v4 = 0; + (void)v4; + boost::uint_value_t<200>::fast v5 = 0; + (void)v5; + boost::uint_value_t<2000>::least v6 = 0; + (void)v6; +} diff --git a/test/integer_mask_include_test.cpp b/test/integer_mask_include_test.cpp new file mode 100644 index 0000000..09af189 --- /dev/null +++ b/test/integer_mask_include_test.cpp @@ -0,0 +1,18 @@ +// 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) + +#include // must be the only #include! + +int main() +{ + boost::high_bit_mask_t<20>::least l = boost::high_bit_mask_t<20>::high_bit; + boost::high_bit_mask_t<12>::fast f = boost::high_bit_mask_t<12>::high_bit_fast; + l += f + boost::high_bit_mask_t<12>::bit_position; + (void)l; + boost::low_bits_mask_t<20>::least l2 = boost::low_bits_mask_t<20>::sig_bits; + boost::low_bits_mask_t<12>::fast f2 = boost::low_bits_mask_t<12>::sig_bits_fast; + l2 += f2 + boost::low_bits_mask_t<12>::bit_count; + (void)l2; +} diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 38f5211..4c1bb4b 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -10,30 +10,43 @@ // Revision History // 23 Sep 2001 Initial version (Daryle Walker) -#include // for main +#include #include // for boost::exit_success #include // for boost::high_bit_mask_t, etc. #include // for std::cout (std::endl indirectly) +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif -#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ +#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ (v) >::high_bit == (1ul << (v)) ); -#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ +#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ (v) >::high_bit_fast == (1ul << (v)) ); #define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) -#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); +#define PRIVATE_LOW_BITS_SLOW_TEST(v) \ + do{ \ + unsigned long mask = 0;\ + if(v > 0)\ + { mask = ((1ul << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \ + }while(false); +#define PRIVATE_LOW_BITS_FAST_TEST(v) \ + do{ \ + unsigned long mask = 0;\ + if(v > 0)\ + { mask = ((1ul << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\ + }while(false); #define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) -int test_main( int, char*[] ) +int main( int, char*[] ) { using std::cout; using std::endl; @@ -73,7 +86,7 @@ int test_main( int, char*[] ) PRIVATE_HIGH_BIT_TEST( 0 ); cout << "Doing low_bits_mask_t tests." << endl; - PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops! + PRIVATE_LOW_BITS_TEST( 32 ); PRIVATE_LOW_BITS_TEST( 31 ); PRIVATE_LOW_BITS_TEST( 30 ); PRIVATE_LOW_BITS_TEST( 29 ); @@ -106,5 +119,5 @@ int test_main( int, char*[] ) PRIVATE_LOW_BITS_TEST( 2 ); PRIVATE_LOW_BITS_TEST( 1 ); - return boost::exit_success; + return boost::report_errors(); } diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 6bfff11..bef0308 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -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) @@ -12,280 +15,249 @@ // 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) // 31 Aug 99 Initial version -#include // for main, BOOST_CHECK - -#include // for BOOST_NO_USING_TEMPLATE -#include // for boost::exit_success +#include // for main, BOOST_TEST #include // for boost::int_t, boost::uint_t +#include #include // for ULONG_MAX, LONG_MAX, LONG_MIN #include // for std::cout (std::endl indirectly) #include // for std::type_info - -// 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 +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif +#if defined( __BORLANDC__ ) +# pragma option -w-8008 -w-8066 // condition is always true #endif +// +// Keep track of error count, so we can print out detailed +// info only if we need it: +// +int 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 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(boost::long_long_type){ return "boost::long_long_type"; } +const char* get_name_of_type(boost::ulong_long_type){ return "boost::ulong_long_type"; } +#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 +void do_test_exact(boost::mpl::true_ const&) { - template < > - struct int_fast_t< short > - { - typedef long fast; - }; + // Test the ::exact member: + typedef typename boost::int_t::exact int_exact; + typedef typename boost::uint_t::exact uint_exact; + typedef typename boost::int_t::least least_int; + typedef typename boost::uint_t::least least_uint; + + BOOST_TEST((boost::is_same::value)); + BOOST_TEST((boost::is_same::value)); +} +template +void do_test_exact(boost::mpl::false_ const&) +{ + // 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) +template +void do_test_bits() +{ + // + // Recurse to next smallest number of bits: + // + do_test_bits(); + // + // Test exact types if we have them: + // + do_test_exact( + 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(boost::ulong_long_type) * CHAR_BIT == Bits) #endif + >()); + // + // We need to check all aspects of the members of int_t and uint_t: + // + typedef typename boost::int_t::least least_int; + typedef typename boost::int_t::least fast_int; + typedef typename boost::uint_t::least least_uint; + typedef typename boost::uint_t::fast fast_uint; -#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) + if(std::numeric_limits::is_specialized) + { + BOOST_TEST(std::numeric_limits::digits + 1 >= Bits); + } + if(std::numeric_limits::is_specialized) + { + BOOST_TEST(std::numeric_limits::digits >= Bits); + } + BOOST_TEST(sizeof(least_int) * CHAR_BIT >= Bits); + BOOST_TEST(sizeof(least_uint) * CHAR_BIT >= Bits); + BOOST_TEST(sizeof(fast_int) >= sizeof(least_int)); + BOOST_TEST(sizeof(fast_uint) >= sizeof(least_uint)); + // + // There should be no type smaller than least_* that also has enough bits: + // + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + } + } + } + } + // And again, but unsigned: + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_TEST(std::numeric_limits::digits < Bits); + } + } + } + } -#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type) + if(boost::detail::test_errors() != last_error_count) + { + last_error_count = boost::detail::test_errors(); + 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 SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type) - -#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type) - -#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type) - - -// Test if a constant can fit within a certain type -#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value ) - -#if ULONG_MAX > 0xFFFFFFFFL -#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ - PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false ) -#else -#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ - PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false ) -#endif - -#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 +void test_min_max_type(Expected val) +{ + typedef typename Traits::least least_type; + typedef typename Traits::fast fast_type; + BOOST_TEST((boost::is_same::value)); + BOOST_TEST(sizeof(fast_type) >= sizeof(least_type)); + BOOST_TEST((std::numeric_limits::min)() <= val); + BOOST_TEST((std::numeric_limits::max)() >= val); + if(boost::detail::test_errors() != last_error_count) + { + last_error_count = boost::detail::test_errors(); + std::cout << "Traits type is: " << typeid(Traits).name() << std::endl; + std::cout << "Least type is: " << get_name_of_type(least_type(0)) << std::endl; + std::cout << "Fast type is: " << get_name_of_type(fast_type(0)) << std::endl; + std::cout << "Expected type is: " << get_name_of_type(Expected(0)) << std::endl; + std::cout << "Required value is: " << val << std::endl; + } +} // Test program -int -test_main -( - int, - char*[] -) +int 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; -#endif + // Test int_t and unint_t first: + if(std::numeric_limits::is_specialized) + do_test_bits::digits>(); + else + do_test_bits::digits>(); - 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; + // + // Test min and max value types: + // + test_min_max_type, signed char>(SCHAR_MAX); + test_min_max_type, signed char>(SCHAR_MIN); + test_min_max_type, unsigned char>(UCHAR_MAX); +#if(USHRT_MAX != UCHAR_MAX) + test_min_max_type, short>(SCHAR_MAX+1); + test_min_max_type, short>(SCHAR_MIN-1); + test_min_max_type, unsigned short>(UCHAR_MAX+1); + test_min_max_type, short>(SHRT_MAX); + test_min_max_type, short>(SHRT_MIN); + test_min_max_type, unsigned short>(USHRT_MAX); +#endif +#if(UINT_MAX != USHRT_MAX) + test_min_max_type, int>(SHRT_MAX+1); + test_min_max_type, int>(SHRT_MIN-1); + test_min_max_type, unsigned int>(USHRT_MAX+1); + test_min_max_type, int>(INT_MAX); + test_min_max_type, int>(INT_MIN); + test_min_max_type, unsigned int>(UINT_MAX); +#endif +#if(ULONG_MAX != UINT_MAX) + test_min_max_type, long>(INT_MAX+1L); + test_min_max_type, long>(INT_MIN-1L); + test_min_max_type, unsigned long>(UINT_MAX+1uL); + test_min_max_type, long>(LONG_MAX); + test_min_max_type, long>(LONG_MIN); + test_min_max_type, unsigned long>(ULONG_MAX); +#endif +#ifndef BOOST_NO_INTEGRAL_INT64_T +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) + test_min_max_type, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type, boost::long_long_type>(LLONG_MAX); + test_min_max_type, boost::long_long_type>(LLONG_MIN); + test_min_max_type, boost::ulong_long_type>(ULLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) + test_min_max_type, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type, boost::long_long_type>(LONG_LONG_MAX); + test_min_max_type, boost::long_long_type>(LONG_LONG_MIN); + test_min_max_type, boost::ulong_long_type>(ULONG_LONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) + test_min_max_type, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type, boost::long_long_type>(LONGLONG_MAX); + test_min_max_type, boost::long_long_type>(LONGLONG_MAX); + test_min_max_type, boost::ulong_long_type>(ULONGLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(_ULLONG_MAX) && defined(_LLONG_MIN) && (_ULLONG_MAX != ULONG_MAX)) + test_min_max_type, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type, boost::long_long_type>(_LLONG_MAX); + test_min_max_type, boost::long_long_type>(_LLONG_MIN); + test_min_max_type, boost::ulong_long_type>(_ULLONG_MAX); +#endif // BOOST_HAS_LONG_LONG +#endif // BOOST_NO_INTEGRAL_INT64_T + return boost::report_errors(); } diff --git a/test/integer_traits_include_test.cpp b/test/integer_traits_include_test.cpp new file mode 100644 index 0000000..a71fb33 --- /dev/null +++ b/test/integer_traits_include_test.cpp @@ -0,0 +1,37 @@ +// 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) + +#include // must be the only #include! + +template +void check_numeric_limits_derived(const std::numeric_limits&){} + +template +void check() +{ + typedef boost::integer_traits traits; + check_numeric_limits_derived(traits()); + bool b = traits::is_integral; + (void)b; + T v = traits::const_min + traits::const_max; + (void)v; +} + +int main() +{ + check(); + check(); + check(); + check(); + check(); + check(); + check(); + check(); + check(); +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + check(); + check(); +#endif +} diff --git a/test/integer_traits_test.cpp b/test/integer_traits_test.cpp index e3de239..b6e0d49 100644 --- a/test/integer_traits_test.cpp +++ b/test/integer_traits_test.cpp @@ -17,8 +17,7 @@ // use int64_t instead of long long for better portability #include -#define BOOST_INCLUDE_MAIN -#include +#include /* * General portability note: @@ -53,22 +52,22 @@ void runtest(const char * type, T) << "; min is " << make_char_numeric_for_streaming((traits::min)()) << ", max is " << make_char_numeric_for_streaming((traits::max)()) << std::endl; - BOOST_CHECK(traits::is_specialized); + BOOST_TEST(traits::is_specialized); #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200) // MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler // generates different symbol names with a very long common prefix: // the dummy "&& true" disambiguates between the symbols generated by this - // BOOST_CHECK instantiation and the preceding one. - BOOST_CHECK(traits::is_integer && true); + // BOOST_TEST instantiation and the preceding one. + BOOST_TEST(traits::is_integer && true); #else - BOOST_CHECK(traits::is_integer); + BOOST_TEST(traits::is_integer); #endif - BOOST_CHECK(traits::is_integral == true); - BOOST_CHECK(traits::const_min == (traits::min)()); - BOOST_CHECK(traits::const_max == (traits::max)()); + BOOST_TEST(traits::is_integral == true); + BOOST_TEST(traits::const_min == (traits::min)()); + BOOST_TEST(traits::const_max == (traits::max)()); } -int test_main(int, char*[]) +int main(int, char*[]) { runtest("bool", bool()); runtest("char", char()); @@ -86,7 +85,7 @@ int test_main(int, char*[]) runtest("long", long()); typedef unsigned long unsigned_long; runtest("unsigned long", unsigned_long()); -#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__) +#ifndef BOOST_NO_INTEGRAL_INT64_T // // MS/Borland compilers can't support 64-bit member constants // BeOS doesn't have specialisations for long long in SGI's header. @@ -97,6 +96,6 @@ int test_main(int, char*[]) #endif // Some compilers don't pay attention to std:3.6.1/5 and issue a // warning here if "return 0;" is omitted. - return 0; + return boost::report_errors(); } diff --git a/test/static_log2_include_test.cpp b/test/static_log2_include_test.cpp new file mode 100644 index 0000000..d39b871 --- /dev/null +++ b/test/static_log2_include_test.cpp @@ -0,0 +1,14 @@ +// 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) + +#include // must be the only #include! + +int main() +{ + boost::static_log2_argument_type arg = 0; + (void)arg; + boost::static_log2_result_type result = boost::static_log2<30>::value; + (void)result; +} diff --git a/test/static_log2_test.cpp b/test/static_log2_test.cpp index 68628f6..f92d801 100644 --- a/test/static_log2_test.cpp +++ b/test/static_log2_test.cpp @@ -10,8 +10,7 @@ // Revision History // 01 Oct 2001 Initial version (Daryle Walker) -#define BOOST_INCLUDE_MAIN -#include // for main +#include // for main #include // for boost::exit_success #include // for boost::static_log2 @@ -20,7 +19,7 @@ // Macros to compact code -#define PRIVATE_LB_TEST( v, e ) BOOST_CHECK( ::boost::static_log2::value == e ) +#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2::value == e ) #define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \ << "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl @@ -35,7 +34,7 @@ // Main testing function int -test_main +main ( int , // "argc" is unused char * [] // "argv" is unused @@ -146,5 +145,5 @@ test_main PRIVATE_LB_TEST( 65536, 16 ); PRIVATE_LB_TEST( 65537, 16 ); - return boost::exit_success; + return boost::report_errors(); } diff --git a/test/static_min_max_include_test.cpp b/test/static_min_max_include_test.cpp new file mode 100644 index 0000000..8055062 --- /dev/null +++ b/test/static_min_max_include_test.cpp @@ -0,0 +1,14 @@ +// 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) + +#include // must be the only #include! + +int main() +{ + boost::static_min_max_signed_type m = boost::static_signed_min<2, 3>::value + boost::static_signed_max<2, 3>::value; + (void)m; + boost::static_min_max_unsigned_type u = boost::static_unsigned_min<2, 3>::value + boost::static_unsigned_max<2, 3>::value; + (void)u; +} diff --git a/test/static_min_max_test.cpp b/test/static_min_max_test.cpp index ed081f7..124e137 100644 --- a/test/static_min_max_test.cpp +++ b/test/static_min_max_test.cpp @@ -10,8 +10,7 @@ // Revision History // 23 Sep 2001 Initial version (Daryle Walker) -#define BOOST_INCLUDE_MAIN -#include // for main, BOOST_CHECK +#include // for main, BOOST_TEST #include // for boost::exit_success #include // for boost::static_signed_min, etc. @@ -21,7 +20,7 @@ // Main testing function int -test_main +main ( int , // "argc" is unused char * [] // "argv" is unused @@ -37,57 +36,57 @@ test_main // Two positives cout << "Doing tests with two positive values." << endl; - BOOST_CHECK( (static_signed_min< 9, 14>::value) == 9 ); - BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 ); - BOOST_CHECK( (static_signed_min<14, 9>::value) == 9 ); - BOOST_CHECK( (static_signed_max<14, 9>::value) == 14 ); + BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 ); + BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 ); + BOOST_TEST( (static_signed_min<14, 9>::value) == 9 ); + BOOST_TEST( (static_signed_max<14, 9>::value) == 14 ); - BOOST_CHECK( (static_unsigned_min< 9, 14>::value) == 9 ); - BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 ); - BOOST_CHECK( (static_unsigned_min<14, 9>::value) == 9 ); - BOOST_CHECK( (static_unsigned_max<14, 9>::value) == 14 ); + BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 ); + BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 ); + BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 ); // Two negatives cout << "Doing tests with two negative values." << endl; - BOOST_CHECK( (static_signed_min< -8, -101>::value) == -101 ); - BOOST_CHECK( (static_signed_max< -8, -101>::value) == -8 ); - BOOST_CHECK( (static_signed_min<-101, -8>::value) == -101 ); - BOOST_CHECK( (static_signed_max<-101, -8>::value) == -8 ); + BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 ); + BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 ); + BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 ); // With zero cout << "Doing tests with zero and a positive or negative value." << endl; - BOOST_CHECK( (static_signed_min< 0, 14>::value) == 0 ); - BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 ); - BOOST_CHECK( (static_signed_min<14, 0>::value) == 0 ); - BOOST_CHECK( (static_signed_max<14, 0>::value) == 14 ); + BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 ); + BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 ); + BOOST_TEST( (static_signed_min<14, 0>::value) == 0 ); + BOOST_TEST( (static_signed_max<14, 0>::value) == 14 ); - BOOST_CHECK( (static_unsigned_min< 0, 14>::value) == 0 ); - BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 ); - BOOST_CHECK( (static_unsigned_min<14, 0>::value) == 0 ); - BOOST_CHECK( (static_unsigned_max<14, 0>::value) == 14 ); + BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 ); + BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 ); - BOOST_CHECK( (static_signed_min< 0, -101>::value) == -101 ); - BOOST_CHECK( (static_signed_max< 0, -101>::value) == 0 ); - BOOST_CHECK( (static_signed_min<-101, 0>::value) == -101 ); - BOOST_CHECK( (static_signed_max<-101, 0>::value) == 0 ); + BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 ); + BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 ); + BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 ); // With identical cout << "Doing tests with two identical values." << endl; - BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 ); - BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 ); - BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 ); - BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 ); + BOOST_TEST( (static_signed_min<0, 0>::value) == 0 ); + BOOST_TEST( (static_signed_max<0, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 ); - BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 ); - BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 ); - BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 ); - BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 ); + BOOST_TEST( (static_signed_min<14, 14>::value) == 14 ); + BOOST_TEST( (static_signed_max<14, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 ); - BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 ); - BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 ); + BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 ); - return boost::exit_success; + return boost::report_errors(); }