diff --git a/cstdint.htm b/cstdint.htm deleted file mode 100644 index 43b828f..0000000 --- a/cstdint.htm +++ /dev/null @@ -1,78 +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 19 Aug 2001 -

-

 

- - - - diff --git a/cstdint_test.cpp b/cstdint_test.cpp deleted file mode 100644 index 08c13be..0000000 --- a/cstdint_test.cpp +++ /dev/null @@ -1,219 +0,0 @@ -// 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 -#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 - -#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() -{ - 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 ); -} -#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: - assert(sizeof(T1) <= sizeof(T2)); -#else - assert(sizeof(T1) == sizeof(T2)); - assert(t1 == t2); -#endif - if(t1 > 0) - assert(t2 > 0); - else - assert(!(t2 > 0)); -} - - -int main() -{ -#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 - - 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 ); - -#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) ); -#else - assert( intmax == -2147483647 ); - assert( uintmax == 4294967295u ); -#endif - - - std::cout << "OK\n"; - return 0; -} -#endif diff --git a/doc/integer_mask.html b/doc/integer_mask.html deleted file mode 100644 index 357b2c8..0000000 --- a/doc/integer_mask.html +++ /dev/null @@ -1,211 +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. Permission to copy, use, -modify, sell and distribute this document is granted provided this -copyright notice appears in all copies. This document is provided -"as is" without express or implied warranty, and with no claim -as to its suitability for any purpose.

- - diff --git a/doc/static_log2.html b/doc/static_log2.html deleted file mode 100644 index e353da4..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 c9619ef..0000000 --- a/doc/static_min_max.html +++ /dev/null @@ -1,121 +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. Permission to copy, use, -modify, sell and distribute this document is granted provided this -copyright notice appears in all copies. This document is provided -"as is" without express or implied warranty, and with no claim -as to its suitability for any purpose.

- - diff --git a/index.html b/index.html deleted file mode 100644 index 7ab3ea0..0000000 --- a/index.html +++ /dev/null @@ -1,128 +0,0 @@ - - - -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: 03 Oct 2001 -

- - - diff --git a/integer.htm b/integer.htm deleted file mode 100644 index 7ab168c..0000000 --- a/integer.htm +++ /dev/null @@ -1,213 +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. Permission to copy, use, modify, -sell and distribute this document is granted provided this copyright -notice appears in all copies. This document is provided "as -is" without express or implied warranty, and with no claim as to -its suitability for any purpose.

- - \ No newline at end of file diff --git a/integer_test.cpp b/integer_test.cpp deleted file mode 100644 index 6bfff11..0000000 --- a/integer_test.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// boost integer.hpp test program ------------------------------------------// - -// Copyright Beman Dawes 1999. 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 -// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker) -// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) -// 31 Aug 99 Initial version - -#include // for main, BOOST_CHECK - -#include // for BOOST_NO_USING_TEMPLATE -#include // for boost::exit_success -#include // for boost::int_t, boost::uint_t - -#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 -#endif - - -// If specializations have not already been done, then we can confirm -// the effects of the "fast" types by making a specialization. -namespace boost -{ - template < > - struct int_fast_t< short > - { - typedef long fast; - }; -} - - -// Show the types of an integer template version -#if CONTROL_SHOW_TYPES -#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \ - #Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \ - Number > :: Type).name() << ".\"\n" -#else -#define SHOW_TYPE(Template, Number, Type) -#endif - -#define SHOW_TYPES(Template, Type) SHOW_TYPE(Template, 32, Type); \ - SHOW_TYPE(Template, 31, Type); SHOW_TYPE(Template, 30, Type); \ - SHOW_TYPE(Template, 29, Type); SHOW_TYPE(Template, 28, Type); \ - SHOW_TYPE(Template, 27, Type); SHOW_TYPE(Template, 26, Type); \ - SHOW_TYPE(Template, 25, Type); SHOW_TYPE(Template, 24, Type); \ - SHOW_TYPE(Template, 23, Type); SHOW_TYPE(Template, 22, Type); \ - SHOW_TYPE(Template, 21, Type); SHOW_TYPE(Template, 20, Type); \ - SHOW_TYPE(Template, 19, Type); SHOW_TYPE(Template, 18, Type); \ - SHOW_TYPE(Template, 17, Type); SHOW_TYPE(Template, 16, Type); \ - SHOW_TYPE(Template, 15, Type); SHOW_TYPE(Template, 14, Type); \ - SHOW_TYPE(Template, 13, Type); SHOW_TYPE(Template, 12, Type); \ - SHOW_TYPE(Template, 11, Type); SHOW_TYPE(Template, 10, Type); \ - SHOW_TYPE(Template, 9, Type); SHOW_TYPE(Template, 8, Type); \ - SHOW_TYPE(Template, 7, Type); SHOW_TYPE(Template, 6, Type); \ - SHOW_TYPE(Template, 5, Type); SHOW_TYPE(Template, 4, Type); \ - SHOW_TYPE(Template, 3, Type); SHOW_TYPE(Template, 2, Type); \ - SHOW_TYPE(Template, 1, Type); SHOW_TYPE(Template, 0, Type) - -#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type) - -#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type) - -#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type) - -#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type) - - -// Test if a constant can fit within a certain type -#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value ) - -#if ULONG_MAX > 0xFFFFFFFFL -#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 ) - - -// Test program -int -test_main -( - int, - char*[] -) -{ -#ifndef BOOST_NO_USING_TEMPLATE - using boost::int_t; - using boost::uint_t; - using boost::int_max_value_t; - using boost::int_min_value_t; - using boost::uint_value_t; -#else - using namespace boost; -#endif - - SHOW_TYPES( int_t, least ); - SHOW_TYPES( int_t, fast ); - SHOW_TYPES( uint_t, least ); - SHOW_TYPES( uint_t, fast ); - SHOW_POS_SHIFTED_TYPES( int_max_value_t, least ); - SHOW_POS_SHIFTED_TYPES( int_max_value_t, fast ); - SHOW_NEG_SHIFTED_TYPES( int_min_value_t, least ); - SHOW_NEG_SHIFTED_TYPES( int_min_value_t, fast ); - SHOW_SHIFTED_TYPES( uint_value_t, least ); - SHOW_SHIFTED_TYPES( uint_value_t, fast ); - - PRIVATE_FIT_TESTS( int_t, least, long, LONG_MAX ); - PRIVATE_FIT_TESTS( int_t, fast, long, LONG_MAX ); - PRIVATE_FIT_TESTS( uint_t, least, unsigned long, ULONG_MAX ); - PRIVATE_FIT_TESTS( uint_t, fast, unsigned long, ULONG_MAX ); - PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX ); - PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX ); - PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN ); - PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN ); - PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX ); - PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX ); - - return boost::exit_success; -} diff --git a/integer_traits.html b/integer_traits.html deleted file mode 100644 index b52b76a..0000000 --- a/integer_traits.html +++ /dev/null @@ -1,89 +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. -
- -Jens Maurer, 2000-02-20 \ No newline at end of file diff --git a/integer_traits_test.cpp b/integer_traits_test.cpp deleted file mode 100644 index e3de239..0000000 --- a/integer_traits_test.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* boost integer_traits.hpp tests - * - * Copyright Jens Maurer 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) - * - * $Id$ - * - * Revision history - * 2000-02-22 Small improvements by Beman Dawes - * 2000-06-27 Rework for better MSVC and BCC co-operation - */ - -#include -#include -// use int64_t instead of long long for better portability -#include - -#define BOOST_INCLUDE_MAIN -#include - -/* - * General portability note: - * MSVC mis-compiles explicit function template instantiations. - * For example, f() and f() are both compiled to call f(). - * BCC is unable to implicitly convert a "const char *" to a std::string - * when using explicit function template instantiations. - * - * Therefore, avoid explicit function template instantiations. - */ - -#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300) -template inline T make_char_numeric_for_streaming(T x) { return x; } -namespace fix{ -inline int make_char_numeric_for_streaming(char c) { return c; } -inline int make_char_numeric_for_streaming(signed char c) { return c; } -inline int make_char_numeric_for_streaming(unsigned char c) { return c; } -} -using namespace fix; -#else -template inline T make_char_numeric_for_streaming(T x) { return x; } -inline int make_char_numeric_for_streaming(char c) { return c; } -inline int make_char_numeric_for_streaming(signed char c) { return c; } -inline int make_char_numeric_for_streaming(unsigned char c) { return c; } -#endif - -template -void runtest(const char * type, T) -{ - typedef boost::integer_traits traits; - std::cout << "Checking " << type - << "; 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); -#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); -#else - BOOST_CHECK(traits::is_integer); -#endif - BOOST_CHECK(traits::is_integral == true); - BOOST_CHECK(traits::const_min == (traits::min)()); - BOOST_CHECK(traits::const_max == (traits::max)()); -} - -int test_main(int, char*[]) -{ - runtest("bool", bool()); - runtest("char", char()); - typedef signed char signed_char; - runtest("signed char", signed_char()); - typedef unsigned char unsigned_char; - runtest("unsigned char", unsigned_char()); - runtest("wchar_t", wchar_t()); - runtest("short", short()); - typedef unsigned short unsigned_short; - runtest("unsigned short", unsigned_short()); - runtest("int", int()); - typedef unsigned int unsigned_int; - runtest("unsigned int", unsigned_int()); - 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__) - // - // MS/Borland compilers can't support 64-bit member constants - // BeOS doesn't have specialisations for long long in SGI's header. - runtest("int64_t (possibly long long)", boost::int64_t()); - runtest("uint64_t (possibly unsigned long long)", boost::uint64_t()); -#else - std::cout << "Skipped int64_t and uint64_t" << std::endl; -#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; -} - diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp deleted file mode 100644 index cbe3d87..0000000 --- a/test/integer_mask_test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// boost integer_mask.hpp test program -------------------------------------// - -// (C) Copyright Daryle Walker 2001. -// 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 for most recent version including documentation. - -// Revision History -// 23 Sep 2001 Initial version (Daryle Walker) - -#define BOOST_INCLUDE_MAIN -#include // for main - -#include // for boost::exit_success -#include // for boost::high_bit_mask_t, etc. - -#include // for std::cout (std::endl indirectly) - - -#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_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_TEST( ::boost::low_bits_mask_t< \ - (v) >::sig_bits == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \ - (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ - PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) - - -int test_main( int, char*[] ) -{ - using std::cout; - using std::endl; - - cout << "Doing high_bit_mask_t tests." << endl; - PRIVATE_HIGH_BIT_TEST( 31 ); - PRIVATE_HIGH_BIT_TEST( 30 ); - PRIVATE_HIGH_BIT_TEST( 29 ); - PRIVATE_HIGH_BIT_TEST( 28 ); - PRIVATE_HIGH_BIT_TEST( 27 ); - PRIVATE_HIGH_BIT_TEST( 26 ); - PRIVATE_HIGH_BIT_TEST( 25 ); - PRIVATE_HIGH_BIT_TEST( 24 ); - PRIVATE_HIGH_BIT_TEST( 23 ); - PRIVATE_HIGH_BIT_TEST( 22 ); - PRIVATE_HIGH_BIT_TEST( 21 ); - PRIVATE_HIGH_BIT_TEST( 20 ); - PRIVATE_HIGH_BIT_TEST( 19 ); - PRIVATE_HIGH_BIT_TEST( 18 ); - PRIVATE_HIGH_BIT_TEST( 17 ); - PRIVATE_HIGH_BIT_TEST( 16 ); - PRIVATE_HIGH_BIT_TEST( 15 ); - PRIVATE_HIGH_BIT_TEST( 14 ); - PRIVATE_HIGH_BIT_TEST( 13 ); - PRIVATE_HIGH_BIT_TEST( 12 ); - PRIVATE_HIGH_BIT_TEST( 11 ); - PRIVATE_HIGH_BIT_TEST( 10 ); - PRIVATE_HIGH_BIT_TEST( 9 ); - PRIVATE_HIGH_BIT_TEST( 8 ); - PRIVATE_HIGH_BIT_TEST( 7 ); - PRIVATE_HIGH_BIT_TEST( 6 ); - PRIVATE_HIGH_BIT_TEST( 5 ); - PRIVATE_HIGH_BIT_TEST( 4 ); - PRIVATE_HIGH_BIT_TEST( 3 ); - PRIVATE_HIGH_BIT_TEST( 2 ); - PRIVATE_HIGH_BIT_TEST( 1 ); - PRIVATE_HIGH_BIT_TEST( 0 ); - - cout << "Doing low_bits_mask_t tests." << endl; - PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops! - PRIVATE_LOW_BITS_TEST( 31 ); - PRIVATE_LOW_BITS_TEST( 30 ); - PRIVATE_LOW_BITS_TEST( 29 ); - PRIVATE_LOW_BITS_TEST( 28 ); - PRIVATE_LOW_BITS_TEST( 27 ); - PRIVATE_LOW_BITS_TEST( 26 ); - PRIVATE_LOW_BITS_TEST( 25 ); - PRIVATE_LOW_BITS_TEST( 24 ); - PRIVATE_LOW_BITS_TEST( 23 ); - PRIVATE_LOW_BITS_TEST( 22 ); - PRIVATE_LOW_BITS_TEST( 21 ); - PRIVATE_LOW_BITS_TEST( 20 ); - PRIVATE_LOW_BITS_TEST( 19 ); - PRIVATE_LOW_BITS_TEST( 18 ); - PRIVATE_LOW_BITS_TEST( 17 ); - PRIVATE_LOW_BITS_TEST( 16 ); - PRIVATE_LOW_BITS_TEST( 15 ); - PRIVATE_LOW_BITS_TEST( 14 ); - PRIVATE_LOW_BITS_TEST( 13 ); - PRIVATE_LOW_BITS_TEST( 12 ); - PRIVATE_LOW_BITS_TEST( 11 ); - PRIVATE_LOW_BITS_TEST( 10 ); - PRIVATE_LOW_BITS_TEST( 9 ); - PRIVATE_LOW_BITS_TEST( 8 ); - PRIVATE_LOW_BITS_TEST( 7 ); - PRIVATE_LOW_BITS_TEST( 6 ); - PRIVATE_LOW_BITS_TEST( 5 ); - PRIVATE_LOW_BITS_TEST( 4 ); - PRIVATE_LOW_BITS_TEST( 3 ); - PRIVATE_LOW_BITS_TEST( 2 ); - PRIVATE_LOW_BITS_TEST( 1 ); - - return boost::exit_success; -} diff --git a/test/static_log2_test.cpp b/test/static_log2_test.cpp deleted file mode 100644 index d7b8d59..0000000 --- a/test/static_log2_test.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// Boost static_log2.hpp test program --------------------------------------// - -// (C) Copyright Daryle Walker 2001. -// 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 for most recent version including documentation. - -// Revision History -// 01 Oct 2001 Initial version (Daryle Walker) - -#define BOOST_INCLUDE_MAIN -#include // for main - -#include // for boost::exit_success -#include // for boost::static_log2 - -#include // for std::cout (std::endl indirectly) - - -// Macros to compact code -#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 - -// Control to check for a compile-time error -#ifndef CONTROL_LB_0_TEST -#define PRIVATE_LB_0_TEST -#else -#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 ) -#endif - - -// Main testing function -int -test_main -( - int , // "argc" is unused - char * [] // "argv" is unused -) -{ - std::cout << "Doing tests on static_log2." << std::endl; - - PRIVATE_LB_0_TEST; - - PRIVATE_LB_TEST( 1, 0 ); - - PRIVATE_LB_TEST( 2, 1 ); - PRIVATE_LB_TEST( 3, 1 ); - - PRIVATE_LB_TEST( 4, 2 ); - PRIVATE_LB_TEST( 5, 2 ); - PRIVATE_LB_TEST( 6, 2 ); - PRIVATE_LB_TEST( 7, 2 ); - - PRIVATE_LB_TEST( 8, 3 ); - PRIVATE_LB_TEST( 9, 3 ); - PRIVATE_LB_TEST( 10, 3 ); - PRIVATE_LB_TEST( 11, 3 ); - PRIVATE_LB_TEST( 12, 3 ); - PRIVATE_LB_TEST( 13, 3 ); - PRIVATE_LB_TEST( 14, 3 ); - PRIVATE_LB_TEST( 15, 3 ); - - PRIVATE_LB_TEST( 16, 4 ); - PRIVATE_LB_TEST( 17, 4 ); - PRIVATE_LB_TEST( 18, 4 ); - PRIVATE_LB_TEST( 19, 4 ); - PRIVATE_LB_TEST( 20, 4 ); - PRIVATE_LB_TEST( 21, 4 ); - PRIVATE_LB_TEST( 22, 4 ); - PRIVATE_LB_TEST( 23, 4 ); - PRIVATE_LB_TEST( 24, 4 ); - PRIVATE_LB_TEST( 25, 4 ); - PRIVATE_LB_TEST( 26, 4 ); - PRIVATE_LB_TEST( 27, 4 ); - PRIVATE_LB_TEST( 28, 4 ); - PRIVATE_LB_TEST( 29, 4 ); - PRIVATE_LB_TEST( 30, 4 ); - PRIVATE_LB_TEST( 31, 4 ); - - PRIVATE_LB_TEST( 32, 5 ); - PRIVATE_LB_TEST( 33, 5 ); - PRIVATE_LB_TEST( 34, 5 ); - PRIVATE_LB_TEST( 35, 5 ); - PRIVATE_LB_TEST( 36, 5 ); - PRIVATE_LB_TEST( 37, 5 ); - PRIVATE_LB_TEST( 38, 5 ); - PRIVATE_LB_TEST( 39, 5 ); - PRIVATE_LB_TEST( 40, 5 ); - - PRIVATE_LB_TEST( 63, 5 ); - - PRIVATE_LB_TEST( 64, 6 ); - PRIVATE_LB_TEST( 65, 6 ); - - PRIVATE_LB_TEST( 127, 6 ); - - PRIVATE_LB_TEST( 128, 7 ); - PRIVATE_LB_TEST( 129, 7 ); - - PRIVATE_LB_TEST( 255, 7 ); - - PRIVATE_LB_TEST( 256, 8 ); - PRIVATE_LB_TEST( 257, 8 ); - - PRIVATE_LB_TEST( 511, 8 ); - - PRIVATE_LB_TEST( 512, 9 ); - PRIVATE_LB_TEST( 513, 9 ); - - PRIVATE_LB_TEST( 1023, 9 ); - - PRIVATE_LB_TEST( 1024, 10 ); - PRIVATE_LB_TEST( 1025, 10 ); - - PRIVATE_LB_TEST( 2047, 10 ); - - PRIVATE_LB_TEST( 2048, 11 ); - PRIVATE_LB_TEST( 2049, 11 ); - - PRIVATE_LB_TEST( 4095, 11 ); - - PRIVATE_LB_TEST( 4096, 12 ); - PRIVATE_LB_TEST( 4097, 12 ); - - PRIVATE_LB_TEST( 8191, 12 ); - - PRIVATE_LB_TEST( 8192, 13 ); - PRIVATE_LB_TEST( 8193, 13 ); - - PRIVATE_LB_TEST( 16383, 13 ); - - PRIVATE_LB_TEST( 16384, 14 ); - PRIVATE_LB_TEST( 16385, 14 ); - - PRIVATE_LB_TEST( 32767, 14 ); - - PRIVATE_LB_TEST( 32768, 15 ); - PRIVATE_LB_TEST( 32769, 15 ); - - PRIVATE_LB_TEST( 65535, 15 ); - - PRIVATE_LB_TEST( 65536, 16 ); - PRIVATE_LB_TEST( 65537, 16 ); - - return boost::exit_success; -} diff --git a/test/static_min_max_test.cpp b/test/static_min_max_test.cpp deleted file mode 100644 index 017b408..0000000 --- a/test/static_min_max_test.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Boost static_min_max.hpp test program -----------------------------------// - -// (C) Copyright Daryle Walker 2001. -// 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 for most recent version including documentation. - -// Revision History -// 23 Sep 2001 Initial version (Daryle Walker) - -#define BOOST_INCLUDE_MAIN -#include // for main, BOOST_TEST - -#include // for boost::exit_success -#include // for boost::static_signed_min, etc. - -#include // for std::cout (std::endl indirectly) - - -// Main testing function -int -test_main -( - int , // "argc" is unused - char * [] // "argv" is unused -) -{ - using std::cout; - using std::endl; - using boost::static_signed_min; - using boost::static_signed_max; - using boost::static_unsigned_min; - using boost::static_unsigned_max; - - // Two positives - cout << "Doing tests with two positive values." << endl; - - 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_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_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_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_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_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_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_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_TEST( (static_signed_min< -101, -101>::value) == -101 ); - BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 ); - - return boost::exit_success; -}