From cd99f24a87fbe67773ae6712e99c4f6ab2d7d87f Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 26 Sep 2006 09:04:05 +0000 Subject: [PATCH 01/64] Changed test to reflect changes made to C99 in the TC. [SVN r35333] --- cstdint_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cstdint_test.cpp b/cstdint_test.cpp index 08c13be..88422de 100644 --- a/cstdint_test.cpp +++ b/cstdint_test.cpp @@ -113,10 +113,24 @@ void integral_constant_type_check(T1, T2) assert(sizeof(T1) == sizeof(T2)); assert(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) + assert(t2 > 0); + else + assert(!(t2 > 0)); + } + else if(t1 < 0) + assert(!(t2 > 0)); +#else if(t1 > 0) assert(t2 > 0); else assert(!(t2 > 0)); +#endif } From a1cc143de74115e5c351dd9ddc4dd56a47aa379b Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sat, 4 Nov 2006 22:58:43 +0000 Subject: [PATCH 02/64] Added license to a person profile; updated license on Boost.Integer and Boost.IO doc files; changed 'BOOST_TEST' to 'BOOST_CHECK' on Boost.Integer testing *.cpp files [SVN r35844] --- doc/integer_mask.html | 9 +++-- doc/static_min_max.html | 9 +++-- integer.htm | 9 +++-- test/integer_mask_test.cpp | 8 ++--- test/static_log2_test.cpp | 2 +- test/static_min_max_test.cpp | 70 ++++++++++++++++++------------------ 6 files changed, 52 insertions(+), 55 deletions(-) diff --git a/doc/integer_mask.html b/doc/integer_mask.html index 357b2c8..0328bbc 100644 --- a/doc/integer_mask.html +++ b/doc/integer_mask.html @@ -202,10 +202,9 @@ href="../../../people/daryle_walker.html">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.

+

© 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_min_max.html b/doc/static_min_max.html index c9619ef..8163aa4 100644 --- a/doc/static_min_max.html +++ b/doc/static_min_max.html @@ -112,10 +112,9 @@ href="../../../people/daryle_walker.html">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.

+

© 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/integer.htm b/integer.htm index 7ab168c..4dfd977 100644 --- a/integer.htm +++ b/integer.htm @@ -204,10 +204,9 @@ 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.

+

© 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>.)

\ No newline at end of file diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index cbe3d87..6146ddf 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -19,16 +19,16 @@ #include // for std::cout (std::endl indirectly) -#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ +#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ (v) >::high_bit == (1ul << (v)) ); -#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ +#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ (v) >::high_bit_fast == (1ul << (v)) ); #define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) -#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \ +#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_TEST( ::boost::low_bits_mask_t< \ +#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); #define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) diff --git a/test/static_log2_test.cpp b/test/static_log2_test.cpp index d7b8d59..68628f6 100644 --- a/test/static_log2_test.cpp +++ b/test/static_log2_test.cpp @@ -20,7 +20,7 @@ // Macros to compact code -#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2::value == e ) +#define PRIVATE_LB_TEST( v, e ) BOOST_CHECK( ::boost::static_log2::value == e ) #define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \ << "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl diff --git a/test/static_min_max_test.cpp b/test/static_min_max_test.cpp index 017b408..ed081f7 100644 --- a/test/static_min_max_test.cpp +++ b/test/static_min_max_test.cpp @@ -11,7 +11,7 @@ // 23 Sep 2001 Initial version (Daryle Walker) #define BOOST_INCLUDE_MAIN -#include // for main, BOOST_TEST +#include // for main, BOOST_CHECK #include // for boost::exit_success #include // for boost::static_signed_min, etc. @@ -37,57 +37,57 @@ test_main // 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_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_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 ); + 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 ); // 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 ); + 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 ); // 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_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_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_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_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 ); + 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 ); // 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_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<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<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< -101, -101>::value) == -101 ); - BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 ); + BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 ); + BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 ); return boost::exit_success; } From 7d8e93a6acc2b220442ced673da6f39c0775eca7 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Wed, 29 Aug 2007 19:54:14 +0000 Subject: [PATCH 03/64] Fixed comments listed in #766 that didn't match their described code [SVN r39062] --- include/boost/integer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index aa8b22c..dc57dff 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -34,7 +34,7 @@ namespace boost template< int Category > struct int_least_helper {}; // default is empty // specializatons: 1=long, 2=int, 3=short, 4=signed char, - // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long + // 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; }; From 0d058f42cc2d7efbf3f6e241cd995e0954e97ca6 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 6 Nov 2007 13:41:19 +0000 Subject: [PATCH 04/64] Add missing copyright and license [SVN r40835] --- cstdint.htm | 11 +++++++---- index.html | 9 +++++++-- integer_traits.html | 9 +++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cstdint.htm b/cstdint.htm index 43b828f..9492827 100644 --- a/cstdint.htm +++ b/cstdint.htm @@ -2,7 +2,7 @@ - + Header boost/cstdint.hpp @@ -69,10 +69,13 @@ representing any value of any signed integer type.

capable of representing any value of any unsigned integer type.

These types are required.


-

Revised 19 Aug 2001 +

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/index.html b/index.html index 7ab3ea0..0a6bbb0 100644 --- a/index.html +++ b/index.html @@ -121,8 +121,13 @@ instead.


-

Revised: 03 Oct 2001 +

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

+ - + \ No newline at end of file diff --git a/integer_traits.html b/integer_traits.html index b52b76a..6fc75b8 100644 --- a/integer_traits.html +++ b/integer_traits.html @@ -85,5 +85,10 @@ 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.
- -Jens Maurer, 2000-02-20 \ No newline at end of file +

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

+ From cd6a9565ff450559c84f6cdcf4d12864e34766b6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 9 Feb 2008 13:02:45 +0000 Subject: [PATCH 05/64] Fix the link to the license. [SVN r43193] --- integer.htm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integer.htm b/integer.htm index 4dfd977..37f6c19 100644 --- a/integer.htm +++ b/integer.htm @@ -206,7 +206,7 @@ value-based sized templates.

© 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 <LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)

- \ No newline at end of file + From 94ace806183f7e9d8a2cb97e20e7617d4f1b9e42 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 10 Feb 2008 14:56:22 +0000 Subject: [PATCH 06/64] Link to people pages on the website, as they've been removed from the download. [SVN r43209] --- doc/integer_mask.html | 2 +- doc/static_log2.html | 2 +- doc/static_min_max.html | 2 +- index.html | 2 +- integer.htm | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/integer_mask.html b/doc/integer_mask.html index 0328bbc..5bc7301 100644 --- a/doc/integer_mask.html +++ b/doc/integer_mask.html @@ -196,7 +196,7 @@ contaimination of values by the higher, unused bits.

Credits

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

+href="http://www.boost.org/people/daryle_walker.html">Daryle Walker.


diff --git a/doc/static_log2.html b/doc/static_log2.html index e353da4..b77874c 100644 --- a/doc/static_log2.html +++ b/doc/static_log2.html @@ -186,7 +186,7 @@ code (and update old code as soon as possible).

The original version of the Boost binary logarithm class template was -written by Daryle Walker +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 diff --git a/doc/static_min_max.html b/doc/static_min_max.html index 8163aa4..1beb503 100644 --- a/doc/static_min_max.html +++ b/doc/static_min_max.html @@ -106,7 +106,7 @@ class template.

Credits

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

+href="http://www.boost.org/people/daryle_walker.html">Daryle Walker.


diff --git a/index.html b/index.html index 0a6bbb0..033af09 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ boost.png (6897 bytes) Home Libraries - People + People FAQ More diff --git a/integer.htm b/integer.htm index 37f6c19..3d3f9c5 100644 --- a/integer.htm +++ b/integer.htm @@ -193,11 +193,11 @@ href="../../boost/cstdint.hpp"><boost/cstdint.hpp>.

Credits

The author of most of the Boost integer type choosing templates is Beman Dawes. He gives thanks +href="http://www.boost.org/people/beman_dawes.html">Beman Dawes. He gives thanks to Valentin Bonnard and - Kevlin Henney for sharing + Kevlin Henney for sharing their designs for similar templates. Daryle Walker designed the +href="http://www.boost.org/people/daryle_walker.html">Daryle Walker designed the value-based sized templates.


From 4e2c8440b559cec5bd3a967a7b09dac406a9416f Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 10 Feb 2008 15:02:17 +0000 Subject: [PATCH 07/64] Point links to the pages that used to be in 'more' to the site. [SVN r43210] --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 033af09..1f0f83c 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ Home Libraries People - FAQ + FAQ More From 600801670ea4fcfd4a3ad2f3ff0357e157115079 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 13 Apr 2008 23:00:19 +0000 Subject: [PATCH 08/64] Move integer tests into canonical test subdir structure. [SVN r44384] --- integer_traits.html | 2 +- test/Jamfile.v2 | 12 ++++++++++++ cstdint_test.cpp => test/cstdint_test.cpp | 0 integer_test.cpp => test/integer_test.cpp | 0 .../integer_traits_test.cpp | 0 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/Jamfile.v2 rename cstdint_test.cpp => test/cstdint_test.cpp (100%) rename integer_test.cpp => test/integer_test.cpp (100%) rename integer_traits_test.cpp => test/integer_traits_test.cpp (100%) diff --git a/integer_traits.html b/integer_traits.html index 6fc75b8..0a9f80d 100644 --- a/integer_traits.html +++ b/integer_traits.html @@ -77,7 +77,7 @@ Test Program

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

Acknowledgements

diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 0000000..c75db05 --- /dev/null +++ b/test/Jamfile.v2 @@ -0,0 +1,12 @@ +#~ Copyright Rene Rivera 2008 +#~ 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) + +import testing ; + +test-suite integer + : [ run cstdint_test.cpp ] + [ run integer_test.cpp ] + [ run integer_traits_test.cpp + /boost/test//boost_test_exec_monitor/static ] + ; diff --git a/cstdint_test.cpp b/test/cstdint_test.cpp similarity index 100% rename from cstdint_test.cpp rename to test/cstdint_test.cpp diff --git a/integer_test.cpp b/test/integer_test.cpp similarity index 100% rename from integer_test.cpp rename to test/integer_test.cpp diff --git a/integer_traits_test.cpp b/test/integer_traits_test.cpp similarity index 100% rename from integer_traits_test.cpp rename to test/integer_traits_test.cpp From 3c7910fad3c5709cc89c8906905553ab69df9bc1 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 6 Jul 2008 00:58:34 +0000 Subject: [PATCH 09/64] Added entries for the forgotten tests [SVN r47123] --- test/Jamfile.v2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c75db05..9ad6eec 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -9,4 +9,10 @@ test-suite integer [ run integer_test.cpp ] [ run integer_traits_test.cpp /boost/test//boost_test_exec_monitor/static ] + [ run integer_mask_test.cpp + /boost/test//boost_test_exec_monitor/static ] + [ 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 ] ; From edfaeb6c0e3362ea965173683f2491b55a9b7ee7 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 7 Jul 2008 23:13:43 +0000 Subject: [PATCH 10/64] Changed the Integer-selection test to use the unit-test system [SVN r47200] --- test/Jamfile.v2 | 3 +- test/integer_test.cpp | 89 ++++++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9ad6eec..f85e614 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -6,7 +6,8 @@ import testing ; test-suite integer : [ run cstdint_test.cpp ] - [ run integer_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 diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 6bfff11..f572ebf 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -12,11 +12,12 @@ // 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) // 31 Aug 99 Initial version -#include // for main, BOOST_CHECK +#define BOOST_TEST_MODULE "Integer size-selection tests" + +#include // unit testing framework #include // for BOOST_NO_USING_TEMPLATE -#include // for boost::exit_success -#include // for boost::int_t, boost::uint_t +#include // for boost::int_t, boost::uint_t, etc. #include // for ULONG_MAX, LONG_MAX, LONG_MIN #include // for std::cout (std::endl indirectly) @@ -128,7 +129,7 @@ namespace boost // 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 ) +#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( Template < Number > :: Type ( Value ) , Value ) #if ULONG_MAX > 0xFFFFFFFFL #define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ @@ -186,7 +187,7 @@ namespace boost 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_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( 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; \ @@ -206,7 +207,7 @@ namespace boost 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_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( 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; \ @@ -226,7 +227,7 @@ namespace boost 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_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( 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; \ @@ -247,17 +248,56 @@ namespace boost 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*[] -) +// Check if given types can support given size parameters +BOOST_AUTO_TEST_SUITE( show_type_tests ) + +// Check size parameters given by bit length +BOOST_AUTO_TEST_CASE( show_bit_length_type_test ) +{ + SHOW_TYPES( boost::int_t, least ); + SHOW_TYPES( boost::int_t, fast ); + SHOW_TYPES( boost::uint_t, least ); + SHOW_TYPES( boost::uint_t, fast ); +} + +// Check size parameters given by maximum or minimum (i.e. extreme) value +BOOST_AUTO_TEST_CASE( show_extreme_type_test ) +{ + SHOW_POS_SHIFTED_TYPES( boost::int_max_value_t, least ); + SHOW_POS_SHIFTED_TYPES( boost::int_max_value_t, fast ); + + SHOW_NEG_SHIFTED_TYPES( boost::int_min_value_t, least ); + SHOW_NEG_SHIFTED_TYPES( boost::int_min_value_t, fast ); + + SHOW_SHIFTED_TYPES( boost::uint_value_t, least ); + SHOW_SHIFTED_TYPES( boost::uint_value_t, fast ); +} + +BOOST_AUTO_TEST_SUITE_END() + +// Check if given constants can fit in given types +BOOST_AUTO_TEST_SUITE( fit_type_tests ) + +// Check against large initial value +BOOST_AUTO_TEST_CASE( show_bit_length_type_test ) { #ifndef BOOST_NO_USING_TEMPLATE using boost::int_t; using boost::uint_t; +#else + using namespace boost; +#endif + + 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 ); +} + +// Check against (absolutely) large initial value +BOOST_AUTO_TEST_CASE( show_extreme_type_test ) +{ +#ifndef BOOST_NO_USING_TEMPLATE using boost::int_max_value_t; using boost::int_min_value_t; using boost::uint_value_t; @@ -265,27 +305,14 @@ test_main 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; } + +BOOST_AUTO_TEST_SUITE_END() From 422ef1ebe607b6ff4830c9ebf40a4c51f3801b43 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 13 Jul 2008 21:08:16 +0000 Subject: [PATCH 11/64] Replaced comprehensive macros with focused templates [SVN r47404] --- test/integer_test.cpp | 534 ++++++++++++++++++++++++------------------ 1 file changed, 311 insertions(+), 223 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index f572ebf..d296011 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -8,19 +8,44 @@ // See http://www.boost.org/libs/integer for documentation. // Revision History +// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker) +// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker) // 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 #define BOOST_TEST_MODULE "Integer size-selection tests" -#include // unit testing framework +#include // unit testing framework +#include // ..BOOST_AUTO_TEST_CASE_TEMPLATE #include // for BOOST_NO_USING_TEMPLATE #include // for boost::int_t, boost::uint_t, etc. +#include // for std::numeric_limits -#include // for ULONG_MAX, LONG_MAX, LONG_MIN -#include // for std::cout (std::endl indirectly) +#include // for boost::mpl::plus, divides +#include // for BOOST_MPL_ASSERT_RELATION, etc. +#include // for boost::mpl::back +#include // for boost::mpl::copy +#include // for boost::mpl::front_inserter +#include // for boost::mpl::integral_c +#include // for boost::mpl::joint_view +#include // for boost::mpl::pop_back +#include // for boost::mpl::push_back +#include // for boost::mpl::push_front +#include // for boost::mpl::sort +#include // for boost::mpl::transform +#include // for boost::mpl::transform_view +#include // for boost::mpl::unpack_args +#include // for boost::mpl::vector +#include // for boost::mpl::zip_view + +#include // for boost::is_same +#include // for boost::make_signed + +#include // for ULONG_MAX, LONG_MAX, LONG_MIN, etc. +#include // for std::cout +#include // for std::endl #include // for std::type_info @@ -43,234 +68,239 @@ namespace boost } -// Show the types of an integer template version +// Logging #if CONTROL_SHOW_TYPES -#define SHOW_TYPE(Template, Number, Type) ::std::cout << "Type \"" \ - #Template "<" #Number ">::" #Type "\" is \"" << typeid(Template < \ - Number > :: Type).name() << ".\"\n" +#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl #else -#define SHOW_TYPE(Template, Number, Type) +#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m ) #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) +// Custom types/templates, helper functions, and objects +namespace +{ -#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_EQUAL( 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 ) +// List the built-in integral types, excluding the ones that are strong-typedefs +// of a lower type. +typedef boost::mpl::vector< + unsigned char +#if USHRT_MAX > UCHAR_MAX + , unsigned short #endif +#if UINT_MAX > USHRT_MAX + , unsigned int +#endif +#if ULONG_MAX > UINT_MAX + , unsigned long +#endif +> distinct_unsigned_types; -#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( Template < (ULONG_MAX >> Number) > :: Type ( Value ) , Value ) +typedef boost::mpl::transform< + distinct_unsigned_types, + boost::make_signed< boost::mpl::_1 > +>::type distinct_signed_types; -#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 ) +// List the digit counts for each integral type +class dibc_helper +{ + template < typename T > + struct type_to_digit_count + : boost::mpl::integral_c< int, std::numeric_limits::digits > + {}; -#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( Template < (LONG_MAX >> Number) > :: Type ( Value ) , Value ) +public: + typedef boost::mpl::transform< + distinct_unsigned_types, + type_to_digit_count< boost::mpl::_1 > + >::type type; +}; -#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 ) +typedef dibc_helper::type distinct_integral_bit_counts; -#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK_EQUAL( Template < (LONG_MIN >> Number) > :: Type ( Value ) , Value ) +// Make list of bit counts between each offical point, plus CHAR_BIT/2 +typedef boost::mpl::transform_view< + boost::mpl::zip_view< + boost::mpl::vector< + boost::mpl::push_front< + boost::mpl::pop_back< distinct_integral_bit_counts >::type, + boost::mpl::integral_c< int, 0 > + >::type, + distinct_integral_bit_counts + > + >, + boost::mpl::unpack_args< + boost::mpl::divides< + boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >, + boost::mpl::integral_c< int, 2 > + > + > +> median_bit_counts; -#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 ) +// Maximum number of bits allowed +int const intmax_bits = boost::mpl::back::type::value; + // should be std::numeric_limits::digits + 1 +int const uintmax_bits = intmax_bits; + // should be std::numeric_limits::digits + +// Make master lists including an outlier beyond all valid bit counts +typedef boost::mpl::sort< + boost::mpl::copy< + boost::mpl::joint_view< + distinct_integral_bit_counts, + median_bit_counts + >, + boost::mpl::front_inserter< + boost::mpl::vector< + boost::mpl::integral_c + > + > + >::type +>::type bits_list; + +// Remove the outlier when all bits counts must be valid +typedef boost::mpl::pop_back::type valid_bits_list; + +// Replace the maximum bit count with one less, so left-shifting by a stored +// value doesn't give an invalid result +typedef boost::mpl::push_back< + boost::mpl::pop_back< valid_bits_list >::type, + boost::mpl::integral_c< int, uintmax_bits - 1 > +>::type valid_to_increase_ubits_list; + +// Do it again for signed types since they have one-less bit to use for the +// mantissa (don't want to shift into the sign bit) +typedef boost::mpl::push_back< + boost::mpl::pop_back< valid_bits_list >::type, + boost::mpl::integral_c< int, intmax_bits - 2 > +>::type valid_to_increase_sbits_list; + +} // unnamed namespace // Check if given types can support given size parameters BOOST_AUTO_TEST_SUITE( show_type_tests ) -// Check size parameters given by bit length -BOOST_AUTO_TEST_CASE( show_bit_length_type_test ) +// Check the specialization type status of given bit lengths +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, valid_bits_list ) { - SHOW_TYPES( boost::int_t, least ); - SHOW_TYPES( boost::int_t, fast ); - SHOW_TYPES( boost::uint_t, least ); - SHOW_TYPES( boost::uint_t, fast ); + // This test is supposed to replace the following printouts given in + // puesdo-code by: + // Routine: Template, Type + // for N := 32 downto 0 + // cout << "Type '" << Template << "<" N << ">::" << Type << "' is '" + // << typeid(Template::Type).name << ".'\n" + // end for + // end Routine + // with Template = {int_t, uint_t}; Type = {least, fast} + // But now we'll use template meta-programming instead of macros. The limit + // of type-lists is usually less than 32 (not to mention 64) elements, so we + // have to take selected values. The only interesting part is if the bit + // count is too large, and we can't check that yet. +#ifndef BOOST_NO_USING_TEMPLATE + using std::numeric_limits; + using boost::int_t; + using boost::uint_t; +#else + using namespace std; + using namespace boost; +#endif + + BOOST_MPL_ASSERT_RELATION( numeric_limits::least>::digits, >=, T::value - 1 ); + BOOST_MPL_ASSERT_RELATION( numeric_limits::fast>::digits, >=, T::value - 1 ); + BOOST_MPL_ASSERT_RELATION( numeric_limits::least>::digits, >=, T::value ); + BOOST_MPL_ASSERT_RELATION( numeric_limits::fast>::digits, >=, T::value ); } -// Check size parameters given by maximum or minimum (i.e. extreme) value -BOOST_AUTO_TEST_CASE( show_extreme_type_test ) +// Check size comparisons of given value support, unsigned +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T, + valid_to_increase_ubits_list ) { - SHOW_POS_SHIFTED_TYPES( boost::int_max_value_t, least ); - SHOW_POS_SHIFTED_TYPES( boost::int_max_value_t, fast ); + // This test is supposed to replace the following printouts given in + // puesdo-code by: + // Routine: Type + // for N := 30 downto 0 + // cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type + // << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n" + // end for + // end Routine + // with Type = {least, fast} + // But now we'll use template meta-programming instead of macros. The limit + // of type-lists is usually less than 32 (not to mention 64) elements, so we + // have to take selected values. The interesting parts are where N is the + // length of a integral type, so 1 << N would have to fit in the next larger + // type. (This is why N can't be more than bitlength(uintmax_t) - 1.) +#ifndef BOOST_NO_USING_TEMPLATE + using boost::is_same; + using boost::uint_value_t; + using boost::uint_t; +#else + using namespace boost; +#endif - SHOW_NEG_SHIFTED_TYPES( boost::int_min_value_t, least ); - SHOW_NEG_SHIFTED_TYPES( boost::int_min_value_t, fast ); + unsigned long const one = 1u; + int const count = T::value; - SHOW_SHIFTED_TYPES( boost::uint_value_t, least ); - SHOW_SHIFTED_TYPES( boost::uint_value_t, fast ); + BOOST_MPL_ASSERT( (is_same::least, typename uint_t::least>::value) ); + BOOST_MPL_ASSERT( (is_same::least, typename uint_t::least>::value) ); + BOOST_MPL_ASSERT( (is_same::least, + typename uint_t::least>::value) ); +} + +// Check size comparisons of given value support, signed +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T, + valid_to_increase_sbits_list ) +{ + // This test is supposed to replace the following printouts given in + // puesdo-code by: + // Routine: Type + // for N := 30 downto 0 + // cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" << + // Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name + // << ".'\n" + // cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" << + // Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name + // << ".'\n" + // end for + // end Routine + // with Type = {least, fast} + // But now we'll use template meta-programming instead of macros. The limit + // of type-lists is usually less than 32 (not to mention 64) elements, so we + // have to take selected values. The interesting parts are where N is the + // length of a integral type, so 1 << N would have to fit in the next larger + // type. (This is why N can't be more than bitlength(intmax_t) - 1. Note + // that bitlength(intmax_t) + 1 == bitlength(uintmax_t).) +#ifndef BOOST_NO_USING_TEMPLATE + using boost::is_same; + using boost::int_max_value_t; + using boost::int_t; + using boost::int_min_value_t; +#else + using namespace boost; +#endif + + long const one = 1; + int const count = T::value; + + BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + + BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + + BOOST_MPL_ASSERT( (is_same::least, + typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (is_same::least, + typename int_t::least>::value) ); } BOOST_AUTO_TEST_SUITE_END() @@ -278,41 +308,99 @@ BOOST_AUTO_TEST_SUITE_END() // Check if given constants can fit in given types BOOST_AUTO_TEST_SUITE( fit_type_tests ) -// Check against large initial value -BOOST_AUTO_TEST_CASE( show_bit_length_type_test ) +// Check if large value can fit its minimum required size, by size +BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, + valid_bits_list ) { + // This test is supposed to replace the following checks given in + // puesdo-code by: + // Routine: Template, Type + // for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 ) + // Confirm( static_cast::Type>(V) == V ); + // end for + // end Routine + // with Template = {int_t, uint_t}; Type = {least, fast}; + // Template:Max = { LONG_MAX for int_t, ULONG_MAX for uint_t } + // In other words, the selected type doesn't mask out any bits it's not + // supposed to. But now we'll use template meta-programming instead of + // macros. The limit of type-lists is usually less than 32 (not to mention + // 64) elements, so we have to take selected values. #ifndef BOOST_NO_USING_TEMPLATE - using boost::int_t; using boost::uint_t; + using boost::int_t; #else using namespace boost; #endif - 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 ); + int const count = T::value, shift = uintmax_bits - count; + unsigned long const value_u = ULONG_MAX >> shift; + long const value_s = LONG_MAX >> shift; + + BOOST_CHECK_EQUAL( typename uint_t::least(value_u), value_u ); + BOOST_CHECK_EQUAL( typename uint_t::least(value_u >> 1), value_u + >> 1 ); + BOOST_CHECK_EQUAL( typename uint_t::fast(value_u), value_u ); + BOOST_CHECK_EQUAL( typename uint_t::fast(value_u >> 1), value_u + >> 1 ); + + BOOST_CHECK_EQUAL( typename int_t::least(value_s), value_s ); + BOOST_CHECK_EQUAL( typename int_t::least(value_s >> 1), value_s + >> 1 ); + BOOST_CHECK_EQUAL( typename int_t::fast(value_s), value_s ); + BOOST_CHECK_EQUAL( typename int_t::fast(value_s >> 1), value_s >> + 1 ); } -// Check against (absolutely) large initial value -BOOST_AUTO_TEST_CASE( show_extreme_type_test ) +// Check if large value can fit its minimum required size, by value +BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_values_test, T, + valid_to_increase_ubits_list ) { + // This test is supposed to replace the following checks given in + // puesdo-code by: + // Routine: Template, Type + // for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 ) + // Confirm( static_cast::Type>(V) == V ); + // end for + // end Routine + // with Template = {uint_value_t, int_max_value_t, int_min_value_t}; Type = + // {least, fast}; Template:Extreme = { LONG_MIN for int_min_value_t, + // LONG_MAX for int_max_value_t, ULONG_MAX for uint_value_t } + // In other words, the selected type doesn't mask out any bits it's not + // supposed to. But now we'll use template meta-programming instead of + // macros. The limit of type-lists is usually less than 32 (not to mention + // 64) elements, so we have to take selected values. #ifndef BOOST_NO_USING_TEMPLATE + using boost::uint_value_t; using boost::int_max_value_t; using boost::int_min_value_t; - using boost::uint_value_t; #else using namespace boost; #endif - PRIVATE_POS_FIT_TESTS( int_max_value_t, least, long, LONG_MAX ); - PRIVATE_POS_FIT_TESTS( int_max_value_t, fast, long, LONG_MAX ); + int const shift = T::value; + unsigned long const max_u = ULONG_MAX >> shift; + long const max_s = LONG_MAX >> shift, min_s = LONG_MIN >> shift; - PRIVATE_NEG_FIT_TESTS( int_min_value_t, least, long, LONG_MIN ); - PRIVATE_NEG_FIT_TESTS( int_min_value_t, fast, long, LONG_MIN ); + BOOST_CHECK_EQUAL( typename uint_value_t::least(max_u), max_u ); + BOOST_CHECK_EQUAL( typename uint_value_t<(max_u >> 1)>::least(max_u >> 1), + max_u >> 1 ); + BOOST_CHECK_EQUAL( typename uint_value_t::fast(max_u), max_u ); + BOOST_CHECK_EQUAL( typename uint_value_t<(max_u >> 1)>::fast(max_u >> 1), + max_u >> 1 ); - PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, least, unsigned long, ULONG_MAX ); - PRIVATE_SHIFTED_FIT_TESTS( uint_value_t, fast, unsigned long, ULONG_MAX ); + BOOST_CHECK_EQUAL( typename int_max_value_t::least(max_s), max_s ); + BOOST_CHECK_EQUAL( typename int_max_value_t<(max_s >> 1)>::least(max_s >> + 1), max_s >> 1 ); + BOOST_CHECK_EQUAL( typename int_max_value_t::fast(max_s), max_s ); + BOOST_CHECK_EQUAL( typename int_max_value_t<(max_s >> 1)>::fast(max_s >> 1), + max_s >> 1 ); + + BOOST_CHECK_EQUAL( typename int_min_value_t::least(min_s), min_s ); + BOOST_CHECK_EQUAL( typename int_min_value_t<(min_s >> 1)>::least(min_s >> + 1), min_s >> 1 ); + BOOST_CHECK_EQUAL( typename int_min_value_t::fast(min_s), min_s ); + BOOST_CHECK_EQUAL( typename int_min_value_t<(min_s >> 1)>::fast(min_s >> 1), + min_s >> 1 ); } BOOST_AUTO_TEST_SUITE_END() From 2f91e69629c287b08b2cc5d4ecc86d28016186c5 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 13 Jul 2008 23:30:18 +0000 Subject: [PATCH 12/64] Re-did implementation [SVN r47408] --- include/boost/integer.hpp | 148 ++++++++++++++++++++++++++------------ 1 file changed, 102 insertions(+), 46 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index dc57dff..256fa27 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -7,6 +7,7 @@ // See http://www.boost.org/libs/integer for documentation. // Revision History +// 13 Jul 08 Redid implmentation. (Daryle Walker) // 22 Sep 01 Added value-based integer templates. (Daryle Walker) // 01 Apr 01 Modified to use new header. (John Maddock) // 30 Jul 00 Add typename syntax fix (Jens Maurer) @@ -17,33 +18,105 @@ #include // self include +#include // for BOOST_STATIC_CONSTANT #include // for boost::integer_traits #include // for std::numeric_limits namespace boost { - // Helper templates ------------------------------------------------------// + // integer template mapping a type to its processor-optimized analog -----// // 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 - // convert category to type - template< int Category > struct int_least_helper {}; // default is empty +namespace detail +{ - // 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; }; + // Helper templates ------------------------------------------------------// + + // convert integer category to type ; default is empty + template< int Rank, typename Signedness > struct int_least_helper {}; + + // specializatons: 1=(unsigned) long, 2=unsigned/int, 3=(unsigned) short, + // 4=(un)signed char + // no specializations for 0: requests for a type > (unsigned) long are in + // error + template<> struct int_least_helper<1, signed> { typedef long least; }; + template<> struct int_least_helper<1, unsigned> + { typedef unsigned long least; }; + template<> struct int_least_helper<2, signed> { typedef int least; }; + template<> struct int_least_helper<2, unsigned> + { typedef unsigned int least; }; + template<> struct int_least_helper<3, signed> { typedef short least; }; + template<> struct int_least_helper<3, unsigned> + { typedef unsigned short least; }; + template<> struct int_least_helper<4, signed> { typedef signed char least; }; + template<> struct int_least_helper<4, unsigned> + { typedef unsigned char least; }; + + // category bounds + enum + { + lowest_integral_rank = 1, + highest_integral_rank = 4 + }; + + // map a bit count to a category + template < int BitsIncludingSign > + struct int_rank_helper + { + BOOST_STATIC_CONSTANT( int, rank = + (BitsIncludingSign - 1 <= std::numeric_limits< long >::digits) + + (BitsIncludingSign - 1 <= std::numeric_limits< int >::digits) + + (BitsIncludingSign - 1 <= std::numeric_limits< short >::digits) + + (BitsIncludingSign - 1 <= std::numeric_limits< signed char >::digits) ); + }; + + template < int Bits > + struct uint_rank_helper + { + BOOST_STATIC_CONSTANT( int, rank = + (Bits <= std::numeric_limits< unsigned long >::digits) + + (Bits <= std::numeric_limits< unsigned int >::digits) + + (Bits <= std::numeric_limits< unsigned short >::digits) + + (Bits <= std::numeric_limits< unsigned char >::digits) ); + }; + + // map an extreme value to a category + template < long MaxValue > + struct int_max_rank_helper + { + BOOST_STATIC_CONSTANT( int, rank = + (MaxValue <= integer_traits< long >::const_max) + + (MaxValue <= integer_traits< int >::const_max) + + (MaxValue <= integer_traits< short >::const_max) + + (MaxValue <= integer_traits< signed char >::const_max) ); + }; + + template < long MinValue > + struct int_min_rank_helper + { + BOOST_STATIC_CONSTANT( int, rank = + (MinValue >= integer_traits< long >::const_min) + + (MinValue >= integer_traits< int >::const_min) + + (MinValue >= integer_traits< short >::const_min) + + (MinValue >= integer_traits< signed char >::const_min) ); + }; + + template < unsigned long Value > + struct uint_max_rank_helper + { + BOOST_STATIC_CONSTANT( int, rank = + (Value <= integer_traits< unsigned long >::const_max) + + (Value <= integer_traits< unsigned int >::const_max) + + (Value <= integer_traits< unsigned short >::const_max) + + (Value <= integer_traits< unsigned char >::const_max) ); + }; + +} // namespace detail // integer templates specifying number of bits ---------------------------// @@ -51,13 +124,10 @@ namespace boost template< int Bits > // bits (including sign) required struct int_t { - 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) - >::least least; + detail::int_rank_helper::rank, + signed>::least least; typedef typename int_fast_t::fast fast; }; @@ -65,14 +135,10 @@ namespace boost template< int Bits > // bits required struct uint_t { - typedef typename int_least_helper + 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) - >::least least; + detail::uint_rank_helper::rank, + unsigned>::least least; typedef typename int_fast_t::fast fast; // int_fast_t<> works correctly for unsigned too, in spite of the name. }; @@ -83,26 +149,20 @@ namespace boost template< long MaxValue > // maximum value to require support 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) - >::least least; + detail::int_max_rank_helper::rank, + signed>::least least; typedef typename int_fast_t::fast fast; }; template< long MinValue > // minimum value to require support struct int_min_value_t { - typedef typename int_least_helper + 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) - >::least least; + detail::int_min_rank_helper::rank, + signed>::least least; typedef typename int_fast_t::fast fast; }; @@ -110,14 +170,10 @@ namespace boost template< unsigned long Value > // maximum value to require support struct uint_value_t { - typedef typename int_least_helper + 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) - >::least least; + detail::uint_max_rank_helper::rank, + unsigned>::least least; typedef typename int_fast_t::fast fast; }; From 10e5587b9e2ae1417cbd831f937d194cf39f4b47 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 14 Jul 2008 04:25:31 +0000 Subject: [PATCH 13/64] Improved/added testing for the processor-optimized integer template [SVN r47413] --- test/integer_test.cpp | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index d296011..6772e56 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -8,6 +8,7 @@ // See http://www.boost.org/libs/integer for documentation. // Revision History +// 14 Jul 08 Improved testing of fast-integer template. (Daryle Walker) // 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker) // 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker) // 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker) @@ -49,6 +50,11 @@ #include // for std::type_info +// Control what the "fast" specialization of "short" is +#ifndef CONTROL_FAST_SHORT +#define CONTROL_FAST_SHORT long +#endif + // Control if the names of the types for each version // of the integer templates will be printed. #ifndef CONTROL_SHOW_TYPES @@ -57,13 +63,15 @@ // If specializations have not already been done, then we can confirm -// the effects of the "fast" types by making a specialization. +// the effects of the "fast" types by making a specialization. If there +// is a specialization for "short," make sure that CONTROL_FAST_SHORT +// is set to a type distinct from "short" and the default implementation. namespace boost { template < > struct int_fast_t< short > { - typedef long fast; + typedef CONTROL_FAST_SHORT fast; }; } @@ -177,6 +185,34 @@ typedef boost::mpl::push_back< } // unnamed namespace +// Check the processor-optimzed type system +BOOST_AUTO_TEST_SUITE( optimized_type_tests ) + +// Check the optimzed type override of a given type +BOOST_AUTO_TEST_CASE( fast_type_test ) +{ +#ifndef BOOST_NO_USING_TEMPLATE + using std::numeric_limits; +#else + using namespace std; +#endif + + typedef short least_type; + typedef boost::int_fast_t::fast fast_type; + typedef numeric_limits least_limits; + typedef numeric_limits fast_limits; + + BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), + ==, false ); + BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true ); + BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed && + fast_limits::is_bounded, ==, true ); + BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 ); + BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits ); +} + +BOOST_AUTO_TEST_SUITE_END() + // Check if given types can support given size parameters BOOST_AUTO_TEST_SUITE( show_type_tests ) @@ -404,3 +440,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_values_test, T, } BOOST_AUTO_TEST_SUITE_END() + +// Verification of bugs and their fixes +BOOST_AUTO_TEST_SUITE( bug_fix_tests ) + +BOOST_AUTO_TEST_SUITE_END() From 053be71261effcd8b0e9cf7be0d3e704f76a88a3 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 14 Jul 2008 06:28:54 +0000 Subject: [PATCH 14/64] Added extended-integer support, which fixes #653 (the main part; the secondary part is split off as #1225) [SVN r47414] --- include/boost/integer.hpp | 98 +++++++++++++++++++++++++++-------- include/boost/integer_fwd.hpp | 18 +++++-- integer.htm | 19 ++++--- test/integer_test.cpp | 57 ++++++++++++-------- 4 files changed, 135 insertions(+), 57 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 256fa27..cb285f8 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -7,6 +7,7 @@ // See http://www.boost.org/libs/integer for documentation. // Revision History +// 14 Jul 08 Added extended-integer support. (Daryle Walker) // 13 Jul 08 Redid implmentation. (Daryle Walker) // 22 Sep 01 Added value-based integer templates. (Daryle Walker) // 01 Apr 01 Modified to use new header. (John Maddock) @@ -18,7 +19,8 @@ #include // self include -#include // for BOOST_STATIC_CONSTANT +#include // for BOOST_STATIC_CONSTANT, etc. +#include // for boost::uintmax_t, intmax_t #include // for boost::integer_traits #include // for std::numeric_limits @@ -40,45 +42,74 @@ namespace detail // convert integer category to type ; default is empty template< int Rank, typename Signedness > struct int_least_helper {}; - // specializatons: 1=(unsigned) long, 2=unsigned/int, 3=(unsigned) short, - // 4=(un)signed char - // no specializations for 0: requests for a type > (unsigned) long are in - // error - template<> struct int_least_helper<1, signed> { typedef long least; }; + // specializatons: 1=(unsigned) __int64/long long, 2=(unsigned) long, + // 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char + // no specializations for 0: requests for a type > (unsigned) (long) long are + // in error +#ifdef BOOST_HAS_LONG_LONG + template<> struct int_least_helper<1, signed> + { typedef long_long_type least; }; template<> struct int_least_helper<1, unsigned> - { typedef unsigned long least; }; - template<> struct int_least_helper<2, signed> { typedef int least; }; + { typedef ulong_long_type least; }; +#elif defined(BOOST_HAS_MS_INT64) + template<> struct int_least_helper<1, signed> { typedef __int64 least; }; + template<> struct int_least_helper<1, unsigned> + { typedef unsigned __int64 least; }; +#endif + template<> struct int_least_helper<2, signed> { typedef long least; }; template<> struct int_least_helper<2, unsigned> - { typedef unsigned int least; }; - template<> struct int_least_helper<3, signed> { typedef short least; }; + { typedef unsigned long least; }; + template<> struct int_least_helper<3, signed> { typedef int least; }; template<> struct int_least_helper<3, unsigned> - { typedef unsigned short least; }; - template<> struct int_least_helper<4, signed> { typedef signed char least; }; + { typedef unsigned int least; }; + template<> struct int_least_helper<4, signed> { typedef short least; }; template<> struct int_least_helper<4, unsigned> + { typedef unsigned short least; }; + template<> struct int_least_helper<5, signed> { typedef signed char least; }; + template<> struct int_least_helper<5, unsigned> { typedef unsigned char least; }; // category bounds enum { +#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) lowest_integral_rank = 1, - highest_integral_rank = 4 +#else + lowest_integral_rank = 2, +#endif + highest_integral_rank = 5 }; // map a bit count to a category template < int BitsIncludingSign > struct int_rank_helper { + BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 ); BOOST_STATIC_CONSTANT( int, rank = - (BitsIncludingSign - 1 <= std::numeric_limits< long >::digits) + - (BitsIncludingSign - 1 <= std::numeric_limits< int >::digits) + - (BitsIncludingSign - 1 <= std::numeric_limits< short >::digits) + - (BitsIncludingSign - 1 <= std::numeric_limits< signed char >::digits) ); +#ifdef BOOST_HAS_LONG_LONG + (mantissa <= std::numeric_limits< long_long_type >::digits) + +#elif defined(BOOST_HAS_MS_INT64) + (mantissa <= std::numeric_limits< __int64 >::digits) + +#else + 1 + +#endif + (mantissa <= std::numeric_limits< long >::digits) + + (mantissa <= std::numeric_limits< int >::digits) + + (mantissa <= std::numeric_limits< short >::digits) + + (mantissa <= std::numeric_limits< signed char >::digits) ); }; template < int Bits > struct uint_rank_helper { BOOST_STATIC_CONSTANT( int, rank = +#ifdef BOOST_HAS_LONG_LONG + (Bits <= std::numeric_limits< ulong_long_type >::digits) + +#elif defined(BOOST_HAS_MS_INT64) + (Bits <= std::numeric_limits< unsigned __int64 >::digits) + +#else + 1 + +#endif (Bits <= std::numeric_limits< unsigned long >::digits) + (Bits <= std::numeric_limits< unsigned int >::digits) + (Bits <= std::numeric_limits< unsigned short >::digits) + @@ -86,30 +117,51 @@ namespace detail }; // map an extreme value to a category - template < long MaxValue > + template < intmax_t MaxValue > struct int_max_rank_helper { BOOST_STATIC_CONSTANT( int, rank = +#ifdef BOOST_HAS_LONG_LONG + (MaxValue <= integer_traits< long_long_type >::const_max) + +#elif defined(BOOST_HAS_MS_INT64) + (MaxValue <= integer_traits< __int64 >::const_max) + +#else + 1 + +#endif (MaxValue <= integer_traits< long >::const_max) + (MaxValue <= integer_traits< int >::const_max) + (MaxValue <= integer_traits< short >::const_max) + (MaxValue <= integer_traits< signed char >::const_max) ); }; - template < long MinValue > + template < intmax_t MinValue > struct int_min_rank_helper { BOOST_STATIC_CONSTANT( int, rank = +#ifdef BOOST_HAS_LONG_LONG + (MinValue >= integer_traits< long_long_type >::const_min) + +#elif defined(BOOST_HAS_MS_INT64) + (MinValue >= integer_traits< __int64 >::const_min) + +#else + 1 + +#endif (MinValue >= integer_traits< long >::const_min) + (MinValue >= integer_traits< int >::const_min) + (MinValue >= integer_traits< short >::const_min) + (MinValue >= integer_traits< signed char >::const_min) ); }; - template < unsigned long Value > + template < uintmax_t Value > struct uint_max_rank_helper { BOOST_STATIC_CONSTANT( int, rank = +#ifdef BOOST_HAS_LONG_LONG + (Value <= integer_traits< ulong_long_type >::const_max) + +#elif defined(BOOST_HAS_MS_INT64) + (Value <= integer_traits< unsigned __int64 >::const_max) + +#else + 1 + +#endif (Value <= integer_traits< unsigned long >::const_max) + (Value <= integer_traits< unsigned int >::const_max) + (Value <= integer_traits< unsigned short >::const_max) + @@ -146,7 +198,7 @@ namespace detail // integer templates specifying extreme value ----------------------------// // signed - template< long MaxValue > // maximum value to require support + template< intmax_t MaxValue > // maximum value to require support struct int_max_value_t { typedef typename detail::int_least_helper @@ -156,7 +208,7 @@ namespace detail typedef typename int_fast_t::fast fast; }; - template< long MinValue > // minimum value to require support + template< intmax_t MinValue > // minimum value to require support struct int_min_value_t { typedef typename detail::int_least_helper @@ -167,7 +219,7 @@ namespace detail }; // unsigned - template< unsigned long Value > // maximum value to require support + template< uintmax_t Value > // maximum value to require support struct uint_value_t { typedef typename detail::int_least_helper diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 33cfc99..312cd7b 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -12,8 +12,9 @@ #include // for UCHAR_MAX, etc. #include // for std::size_t -#include // for BOOST_NO_INTRINSIC_WCHAR_T -#include // for std::numeric_limits +#include // for BOOST_NO_INTRINSIC_WCHAR_T +#include // for boost::uintmax_t, intmax_t +#include // for std::numeric_limits namespace boost @@ -24,6 +25,13 @@ namespace boost // Only has typedefs or using statements, with #conditionals +// ALERT: the forward declarations of items in need items +// from this header. That means that cannot #include this +// forwarding header, to avoid infinite recursion! One day, maybe +// boost::uintmax_t and boost::intmax_t could be segregated into their own +// header file (which can't #include this header), will use +// that header, and could refer to . + // From -----------------------------------------// @@ -85,13 +93,13 @@ template< int Bits > template< int Bits > struct uint_t; -template< long MaxValue > +template< intmax_t MaxValue > struct int_max_value_t; -template< long MinValue > +template< intmax_t MinValue > struct int_min_value_t; -template< unsigned long Value > +template< uintmax_t Value > struct uint_value_t; diff --git a/integer.htm b/integer.htm index 3d3f9c5..11b2f5b 100644 --- a/integer.htm +++ b/integer.htm @@ -21,7 +21,7 @@ is particularly useful for solving generic programming problems.

-

The exact_integral class template provides an MPL-compatible -alternative. This alternative has the form:

+

The sized_integral, exact_integral, +maximum_signed_integral, minimum_signed_integral, and +maximum_unsigned_integral class templates provide MPL-compatible +alternatives. These alternatives generally have the form:

 template< SwitchType SwitchValue, typename Signedness >
@@ -299,6 +341,11 @@ struct name
 	
 
 
+

The exceptions are the extreme-value class templates +(maximum_signed_integral, minimum_signed_integral, and +maximum_unsigned_integral), which do not take a Signedness +template parameter because the meta-functions already inherently have signedness. +

The following table describes each template's criteria. The classic signed and unsigned equivalents are the sized-type class templates that each MPL-compatible class template emulates. (The setting of Signedness @@ -308,24 +355,66 @@ controls the appropriate emulation.)

Criteria for the MPL-Compatible Class Templates Class Template (all in name-space boost) - Parameter Type + Parameter Type (in name-space boost as needed) Parameter Member ID Classic Equivalent - Template Parameter Mapping (when type is defined) + Template Parameter Mapping (when type is defined) Signed Unsigned + + sized_integral + int + bit_count + int_t + uint_t + The smallest built-in integral type with at least + bit_count bits (including the sign bit when + Signedness is signed). Not present if no + type qualifies. + exact_integral int bit_count int_exact_t uint_exact_t - The smallest built-in integral type with exactly bit_count - bits (including the sign bit when Signedness is - signed). Not present if no type qualifies. + The smallest built-in integral type with exactly + bit_count bits (including the sign bit when + Signedness is signed). Not present if no + type qualifies. + + + maximum_signed_integral + intmax_t + bound + int_max_value_t + The smallest built-in integral type that can perserve the value in + bound. Not present if bound is non-positive. + It is possible for a type to be absent if + a platform supports really-extended integral types (beyond long + long or __int64), support for those types goes + into <boost/cstdint.hpp>, + but said support hadn't yet been added to <boost/integer.hpp> + + + minimum_signed_integral + intmax_t + bound + int_min_value_t + The smallest built-in integral type that can perserve the value in + bound. Not present if bound is non-negative. + + + maximum_unsigned_integral + uintmax_t + bound + uint_value_t + The smallest built-in integral type that can perserve the value in + bound. Should always be present. @@ -406,7 +495,7 @@ exact and value-based sized templates, and the MPL-compatible templates.


-

Revised July 15, 2008

+

Revised July 16, 2008

© Copyright Beman Dawes 1999. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file // for BOOST_MPL_ASSERT_RELATION, etc. #include // for boost::mpl::back #include // for boost::mpl::copy +#include // for boost::mpl::equal #include // for boost::mpl::front_inserter #include // for boost::mpl::integral_c #include // for boost::mpl::joint_view @@ -221,13 +223,53 @@ std::size_t const integral_type_count = sizeof(integral_bit_lengths) / // Use SFINAE to check if a particular bit-count is supported template < int Bits > bool -print_out_exact_signed( boost::mpl::integral_c const &x, int bits, - typename boost::exact_integral::type *unused = 0 ) +print_out_sized_signed( boost::mpl::integral_c const &x, int bits, + typename boost::sized_integral::type *unused = 0 ) { // Too bad the type-id expression couldn't use the compact form "*unused", // but type-ids of dereferenced null pointers throw by order of C++ 2003, // sect. 5.2.8, para. 2 (although the result is not conceptually needed). + PRIVATE_SHOW_MESSAGE( "There is a sized_integral<" << bits << + ", signed> specialization, with type '" << typeid(typename + boost::sized_integral::type).name() << "'." ); + return true; +} + +template < typename T > +bool +print_out_sized_signed( T const &x, int bits ) +{ + PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits << + ", signed> specialization." ); + return false; +} + +template < int Bits > +bool +print_out_sized_unsigned( boost::mpl::integral_c const &x, int bits, + typename boost::sized_integral::type *unused = 0 ) +{ + PRIVATE_SHOW_MESSAGE( "There is a sized_integral<" << bits << + ", unsigned> specialization, with type '" << typeid(typename + boost::sized_integral::type).name() << "'." ); + return true; +} + +template < typename T > +bool +print_out_sized_unsigned( T const &x, int bits ) +{ + PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits << + ", unsigned> specialization." ); + return false; +} + +template < int Bits > +bool +print_out_exact_signed( boost::mpl::integral_c const &x, int bits, + typename boost::exact_integral::type *unused = 0 ) +{ PRIVATE_SHOW_MESSAGE( "There is an exact_integral<" << bits << ", signed> specialization, with type '" << typeid(typename boost::exact_integral::type).name() << "'." ); @@ -263,6 +305,69 @@ print_out_exact_unsigned( T const &x, int bits ) return false; } +template < boost::intmax_t Value > +bool +print_out_maximum_signed( boost::maximum_signed_integral const &x, + boost::intmax_t value, typename boost::maximum_signed_integral::type + *unused = 0 ) +{ + PRIVATE_SHOW_MESSAGE( "There is a maximum_signed_integral<" << value << + "> specialization, with type '" << typeid(typename + boost::maximum_signed_integral::type).name() << "'." ); + return true; +} + +template < typename T > +bool +print_out_maximum_signed( T const &x, boost::intmax_t value ) +{ + PRIVATE_SHOW_MESSAGE( "There is no maximum_signed_integral<" << value << + "> specialization." ); + return false; +} + +template < boost::intmax_t Value > +bool +print_out_minimum_signed( boost::minimum_signed_integral const &x, + boost::intmax_t value, typename boost::minimum_signed_integral::type + *unused = 0 ) +{ + PRIVATE_SHOW_MESSAGE( "There is a minimum_signed_integral<" << value << + "> specialization, with type '" << typeid(typename + boost::minimum_signed_integral::type).name() << "'." ); + return true; +} + +template < typename T > +bool +print_out_minimum_signed( T const &x, boost::intmax_t value ) +{ + PRIVATE_SHOW_MESSAGE( "There is no minimum_signed_integral<" << value << + "> specialization." ); + return false; +} + +template < boost::uintmax_t Value > +bool +print_out_maximum_unsigned( boost::maximum_unsigned_integral const &x, + boost::uintmax_t value, typename boost::maximum_unsigned_integral::type + *unused = 0 ) +{ + PRIVATE_SHOW_MESSAGE( "There is a maximum_unsigned_integral<" << value << + "> specialization, with type '" << typeid(typename + boost::maximum_unsigned_integral::type).name() << "'." ); + return true; +} + +template < typename T > +bool +print_out_maximum_unsigned( T const &x, boost::uintmax_t value ) +{ + PRIVATE_SHOW_MESSAGE( "There is no maximum_unsigned_integral<" << value << + "> specialization." ); + return false; +} + } // unnamed namespace @@ -303,8 +408,18 @@ BOOST_AUTO_TEST_SUITE_END() // Check if given types can support given size parameters BOOST_AUTO_TEST_SUITE( show_type_tests ) -// Check the specialization type status of given bit lengths, exact or higher -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, valid_bits_list ) +// Check the specialization type status of given bit lengths, minimum +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list ) +{ + BOOST_CHECK_EQUAL( print_out_sized_signed(T(), T::value), T::value <= + intmax_bits ); + BOOST_CHECK_EQUAL( print_out_sized_unsigned(T(), T::value), T::value <= + uintmax_bits ); +} + +// Check the classic specialization type status of given bit lengths, minimum +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_test, T, + valid_bits_list ) { // This test is supposed to replace the following printouts given in // puesdo-code by: @@ -357,22 +472,23 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T, // length of a integral type, so 1 << N would have to fit in the next larger // type. (This is why N can't be more than bitlength(uintmax_t) - 1.) #ifndef BOOST_NO_USING_TEMPLATE - using boost::is_same; - using boost::uint_value_t; - using boost::uint_t; + using boost::mpl::equal; + using boost::maximum_unsigned_integral; + using boost::sized_integral; #else + using namespace boost::mpl; using namespace boost; #endif boost::uintmax_t const one = 1u; int const count = T::value; - BOOST_MPL_ASSERT( (is_same::least, typename uint_t::least>::value) ); - BOOST_MPL_ASSERT( (is_same::least, typename uint_t::least>::value) ); - BOOST_MPL_ASSERT( (is_same::least, - typename uint_t::least>::value) ); + BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 2))>, + sized_integral >) ); + BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 1))>, + sized_integral >) ); + BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << count)>, + sized_integral >) ); } // Check size comparisons of given value support, signed @@ -399,31 +515,32 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T, // type. (This is why N can't be more than bitlength(intmax_t) - 1. Note // that bitlength(intmax_t) + 1 == bitlength(uintmax_t).) #ifndef BOOST_NO_USING_TEMPLATE - using boost::is_same; - using boost::int_max_value_t; - using boost::int_t; - using boost::int_min_value_t; + using boost::mpl::equal; + using boost::maximum_signed_integral; + using boost::sized_integral; + using boost::minimum_signed_integral; #else + using namespace boost::mpl; using namespace boost; #endif boost::intmax_t const one = 1; int const count = T::value; - BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); - BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 2))>, + sized_integral >) ); + BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 2))>, + sized_integral >) ); - BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); - BOOST_MPL_ASSERT( (is_same::least, typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 1))>, + sized_integral >) ); + BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 1))>, + sized_integral >) ); - BOOST_MPL_ASSERT( (is_same::least, - typename int_t::least>::value) ); - BOOST_MPL_ASSERT( (is_same::least, - typename int_t::least>::value) ); + BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << count)>, + sized_integral >) ); + BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << count)>, + sized_integral >) ); } // Check the specialization type status of given bit lengths, exact only @@ -462,6 +579,88 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T, uint_exact_t::exact>::digits, ==, T::value ); } +// Check if MPL-compatible templates give bad returns for out-of-range values +BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test ) +{ +#ifndef BOOST_NO_USING_TEMPLATE + using boost::sized_integral; + using boost::mpl::integral_c; + using boost::exact_integral; + using boost::maximum_signed_integral; + using boost::minimum_signed_integral; + using boost::maximum_unsigned_integral; +#else + using namespace boost; + using namespace boost::mpl; +#endif + + typedef sized_integral< 3, signed> ssz3_type; + typedef sized_integral< 0, signed> ssz0_type; + typedef sized_integral<-3, signed> ssz3n_type; + + BOOST_CHECK( print_out_sized_signed(integral_c(), + ssz3_type::bit_count) ); + BOOST_CHECK( !print_out_sized_signed(integral_c(), + ssz0_type::bit_count) ); + BOOST_CHECK( !print_out_sized_signed(integral_c(), + ssz3n_type::bit_count) ); + + typedef sized_integral< 3, unsigned> usz3_type; + typedef sized_integral< 0, unsigned> usz0_type; + typedef sized_integral<-3, unsigned> usz3n_type; + + BOOST_CHECK( print_out_sized_unsigned(integral_c(), + usz3_type::bit_count) ); + BOOST_CHECK( print_out_sized_unsigned(integral_c(), + usz0_type::bit_count) ); + BOOST_CHECK( !print_out_sized_unsigned(integral_c(), + usz3n_type::bit_count) ); + + typedef exact_integral< 3, signed> se3_type; + typedef exact_integral< 0, signed> se0_type; + typedef exact_integral<-3, signed> se3n_type; + + BOOST_CHECK( !print_out_exact_signed(integral_c(), + se3_type::bit_count) ); + BOOST_CHECK( !print_out_exact_signed(integral_c(), + se0_type::bit_count) ); + BOOST_CHECK( !print_out_exact_signed(integral_c(), + se3n_type::bit_count) ); + + typedef exact_integral< 3, unsigned> ue3_type; + typedef exact_integral< 0, unsigned> ue0_type; + typedef exact_integral<-3, unsigned> ue3n_type; + + BOOST_CHECK( !print_out_exact_unsigned(integral_c(), + ue3_type::bit_count) ); + BOOST_CHECK( !print_out_exact_unsigned(integral_c(), + ue0_type::bit_count) ); + BOOST_CHECK( !print_out_exact_unsigned(integral_c(), + ue3n_type::bit_count) ); + + typedef maximum_signed_integral< 15> max15_type; + typedef maximum_signed_integral< 0> max0_type; + typedef maximum_signed_integral<-15> max15n_type; + + BOOST_CHECK( print_out_maximum_signed(max15_type(), max15_type::bound) ); + BOOST_CHECK( !print_out_maximum_signed(max0_type(), max0_type::bound) ); + BOOST_CHECK( !print_out_maximum_signed(max15n_type(), max15n_type::bound) ); + + typedef minimum_signed_integral< 15> min15_type; + typedef minimum_signed_integral< 0> min0_type; + typedef minimum_signed_integral<-15> min15n_type; + + BOOST_CHECK( !print_out_minimum_signed(min15_type(), min15_type::bound) ); + BOOST_CHECK( !print_out_minimum_signed(min0_type(), min0_type::bound) ); + BOOST_CHECK( print_out_minimum_signed(min15n_type(), min15n_type::bound) ); + + typedef maximum_unsigned_integral<15> umax15_type; + typedef maximum_unsigned_integral< 0> umax0_type; + + BOOST_CHECK( print_out_maximum_unsigned(umax15_type(), umax15_type::bound) ); + BOOST_CHECK( print_out_maximum_unsigned(umax0_type(), umax0_type::bound) ); +} + BOOST_AUTO_TEST_SUITE_END() // Check if given constants can fit in given types @@ -485,6 +684,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, // macros. The limit of type-lists is usually less than 32 (not to mention // 64) elements, so we have to take selected values. #ifndef BOOST_NO_USING_TEMPLATE + using boost::sized_integral; using boost::uint_t; using boost::int_t; #else @@ -497,7 +697,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, boost::intmax_t const value_s = intmax_limits::max BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift; - BOOST_CHECK_EQUAL( typename uint_t::least(value_u), value_u ); + BOOST_CHECK_EQUAL( (typename sized_integral::type(value_u)), + value_u ); BOOST_CHECK_EQUAL( typename uint_t::least(value_u >> 1), value_u >> 1 ); BOOST_CHECK_EQUAL( typename uint_t::fast(value_u), value_u ); @@ -505,8 +706,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, >> 1 ); BOOST_CHECK_EQUAL( typename int_t::least(value_s), value_s ); - BOOST_CHECK_EQUAL( typename int_t::least(value_s >> 1), value_s - >> 1 ); + BOOST_CHECK_EQUAL( (typename sized_integral::type(value_s + >> 1)), value_s >> 1 ); BOOST_CHECK_EQUAL( typename int_t::fast(value_s), value_s ); BOOST_CHECK_EQUAL( typename int_t::fast(value_s >> 1), value_s >> 1 ); From 203705fea6cf9da3d8dce7b92d56b256721ca293 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Wed, 23 Jul 2008 06:55:23 +0000 Subject: [PATCH 18/64] Moved preprocessor selection from within macro-function calls to surrounding whole macro calls (some compilers suspend preprocessor directives within a macro call) [SVN r47696] --- include/boost/integer.hpp | 50 +++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 5b8b6dc..1f7a750 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -103,14 +103,16 @@ namespace detail struct int_rank_helper { BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 ); - BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * ( #ifdef BOOST_HAS_LONG_LONG - (mantissa <= std::numeric_limits< long_long_type >::digits) + + BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits< + long_long_type >::digits) ); #elif defined(BOOST_HAS_MS_INT64) - (mantissa <= std::numeric_limits< __int64 >::digits) + + BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits< + __int64 >::digits) ); #else - 1 + + BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif + BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * (extended_ + (mantissa <= std::numeric_limits< long >::digits) + (mantissa <= std::numeric_limits< int >::digits) + (mantissa <= std::numeric_limits< short >::digits) + @@ -120,14 +122,16 @@ namespace detail template < int Bits > struct uint_rank_helper { - BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * ( #ifdef BOOST_HAS_LONG_LONG - (Bits <= std::numeric_limits< ulong_long_type >::digits) + + BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits< + ulong_long_type >::digits) ); #elif defined(BOOST_HAS_MS_INT64) - (Bits <= std::numeric_limits< unsigned __int64 >::digits) + + BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits< + unsigned __int64 >::digits) ); #else - 1 + + BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif + BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * (extended_ + (Bits <= std::numeric_limits< unsigned long >::digits) + (Bits <= std::numeric_limits< unsigned int >::digits) + (Bits <= std::numeric_limits< unsigned short >::digits) + @@ -177,14 +181,16 @@ namespace detail template < intmax_t MaxValue > struct int_max_rank_helper { - BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * ( #ifdef BOOST_HAS_LONG_LONG - (MaxValue <= integer_traits< long_long_type >::const_max) + + BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= integer_traits< + long_long_type >::const_max) ); #elif defined(BOOST_HAS_MS_INT64) - (MaxValue <= integer_traits< __int64 >::const_max) + + BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= integer_traits< + __int64 >::const_max) ); #else - 1 + + BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif + BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ + (MaxValue <= integer_traits< long >::const_max) + (MaxValue <= integer_traits< int >::const_max) + (MaxValue <= integer_traits< short >::const_max) + @@ -194,14 +200,16 @@ namespace detail template < intmax_t MinValue > struct int_min_rank_helper { - BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * ( #ifdef BOOST_HAS_LONG_LONG - (MinValue >= integer_traits< long_long_type >::const_min) + + BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= integer_traits< + long_long_type >::const_min) ); #elif defined(BOOST_HAS_MS_INT64) - (MinValue >= integer_traits< __int64 >::const_min) + + BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= integer_traits< + __int64 >::const_min) ); #else - 1 + + BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif + BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ + (MinValue >= integer_traits< long >::const_min) + (MinValue >= integer_traits< int >::const_min) + (MinValue >= integer_traits< short >::const_min) + @@ -211,14 +219,16 @@ namespace detail template < uintmax_t Value > struct uint_max_rank_helper { - BOOST_STATIC_CONSTANT( int, rank = #ifdef BOOST_HAS_LONG_LONG - (Value <= integer_traits< ulong_long_type >::const_max) + + BOOST_STATIC_CONSTANT( int, extended_ = (Value <= integer_traits< + ulong_long_type >::const_max) ); #elif defined(BOOST_HAS_MS_INT64) - (Value <= integer_traits< unsigned __int64 >::const_max) + + BOOST_STATIC_CONSTANT( int, extended_ = (Value <= integer_traits< unsigned + __int64 >::const_max) ); #else - 1 + + BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif + BOOST_STATIC_CONSTANT( int, rank = extended_ + (Value <= integer_traits< unsigned long >::const_max) + (Value <= integer_traits< unsigned int >::const_max) + (Value <= integer_traits< unsigned short >::const_max) + From 2b7ed6ebf73bbf92487bda93e69b2c4c917d1be4 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Wed, 23 Jul 2008 22:40:20 +0000 Subject: [PATCH 19/64] Resolved namespace conflict from unadorned call, which fixes #2134 [SVN r47742] --- include/boost/integer.hpp | 36 ++++++++++++++++++------------------ test/Jamfile.v2 | 1 + test/issue_2134.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 test/issue_2134.cpp diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 1f7a750..7e0b86c 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -182,57 +182,57 @@ namespace detail struct int_max_rank_helper { #ifdef BOOST_HAS_LONG_LONG - BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= integer_traits< + BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= boost::integer_traits< long_long_type >::const_max) ); #elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= integer_traits< + BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= boost::integer_traits< __int64 >::const_max) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ + - (MaxValue <= integer_traits< long >::const_max) + - (MaxValue <= integer_traits< int >::const_max) + - (MaxValue <= integer_traits< short >::const_max) + - (MaxValue <= integer_traits< signed char >::const_max)) ); + (MaxValue <= boost::integer_traits< long >::const_max) + + (MaxValue <= boost::integer_traits< int >::const_max) + + (MaxValue <= boost::integer_traits< short >::const_max) + + (MaxValue <= boost::integer_traits< signed char >::const_max)) ); }; template < intmax_t MinValue > struct int_min_rank_helper { #ifdef BOOST_HAS_LONG_LONG - BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= integer_traits< + BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= boost::integer_traits< long_long_type >::const_min) ); #elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= integer_traits< + BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= boost::integer_traits< __int64 >::const_min) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ + - (MinValue >= integer_traits< long >::const_min) + - (MinValue >= integer_traits< int >::const_min) + - (MinValue >= integer_traits< short >::const_min) + - (MinValue >= integer_traits< signed char >::const_min)) ); + (MinValue >= boost::integer_traits< long >::const_min) + + (MinValue >= boost::integer_traits< int >::const_min) + + (MinValue >= boost::integer_traits< short >::const_min) + + (MinValue >= boost::integer_traits< signed char >::const_min)) ); }; template < uintmax_t Value > struct uint_max_rank_helper { #ifdef BOOST_HAS_LONG_LONG - BOOST_STATIC_CONSTANT( int, extended_ = (Value <= integer_traits< + BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits< ulong_long_type >::const_max) ); #elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (Value <= integer_traits< unsigned + BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits< unsigned __int64 >::const_max) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif BOOST_STATIC_CONSTANT( int, rank = extended_ + - (Value <= integer_traits< unsigned long >::const_max) + - (Value <= integer_traits< unsigned int >::const_max) + - (Value <= integer_traits< unsigned short >::const_max) + - (Value <= integer_traits< unsigned char >::const_max) ); + (Value <= boost::integer_traits< unsigned long >::const_max) + + (Value <= boost::integer_traits< unsigned int >::const_max) + + (Value <= boost::integer_traits< unsigned short >::const_max) + + (Value <= boost::integer_traits< unsigned char >::const_max) ); }; // convert rank to type, Boost.MPL-style diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f85e614..a0b5b19 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,4 +16,5 @@ test-suite integer /boost/test//boost_test_exec_monitor/static ] [ run static_min_max_test.cpp /boost/test//boost_test_exec_monitor/static ] + [ compile issue_2134.cpp ] ; diff --git a/test/issue_2134.cpp b/test/issue_2134.cpp new file mode 100644 index 0000000..26f8962 --- /dev/null +++ b/test/issue_2134.cpp @@ -0,0 +1,33 @@ +// boost Issue #2134 test program ------------------------------------------// + +// Copyright Daryle Walker 2008. Distributed under the Boost +// Software License, Version 1.0. (See the accompanying file +// LICENSE_1_0.txt or a copy at .) + +// See for documentation. +// See for the issue involved. + +// Revision History +// 23 Jul 2008 Initial version + +// Control if the inclusion error is triggered +#ifndef CONTROL_INCLUDE_TRAITS +#define CONTROL_INCLUDE_TRAITS 1 +#endif + +#if CONTROL_INCLUDE_TRAITS +// This file defines boost::detail::integer_traits. +#include +#endif + +// This is the file with the issue. It has items within the boost::detail +// namespace that referenced an unadorned "integer_traits". This was meant to +// refer to boost::integer_traits. However, +// defines a boost::detail::integer_traits. If that header is #included before +// this one, then b.d.integer_traits (rightfully) took priority, which lead to a +// syntax error. +#include + + +// Main program, minimal (since this is a compile test) +int main() { return 0; } From 4af7660410961279895c8eb8909268b415c74c1d Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Thu, 24 Jul 2008 11:43:02 +0000 Subject: [PATCH 20/64] Encapsulated the mutually exclusive 'long long' and '__int64' type families into a single interface [SVN r47754] --- include/boost/detail/extended_integer.hpp | 177 ++++++++++++++++++++++ include/boost/integer.hpp | 64 +++----- include/boost/integer_fwd.hpp | 8 +- include/boost/integer_traits.hpp | 75 ++------- test/integer_test.cpp | 14 +- 5 files changed, 218 insertions(+), 120 deletions(-) create mode 100644 include/boost/detail/extended_integer.hpp diff --git a/include/boost/detail/extended_integer.hpp b/include/boost/detail/extended_integer.hpp new file mode 100644 index 0000000..c69636c --- /dev/null +++ b/include/boost/detail/extended_integer.hpp @@ -0,0 +1,177 @@ +// Boost detail/extended_integer.hpp header file ----------------------------// + +// (C) Copyright Daryle Walker 2008. Distributed under the Boost Software +// License, Version 1.0. (See the accompanying file LICENSE_1_0.txt or a copy +// at .) + +// Encapsulates the double-long and __int64 type families as a single family, +// as they are mutually exclusive. + +/** \file + \brief Common definition of extended integer types. + + Instead of other Boost headers making separate \#defines for the double-long + and __int64 type families, since they're mutually exclusive, make a single + set of types and macros for the family that exists (if either). + */ + +#ifndef BOOST_DETAIL_EXTENDED_INTEGER_HPP +#define BOOST_DETAIL_EXTENDED_INTEGER_HPP + +#include // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64 + +#include // for CHAR_BIT, etc. + + +namespace boost +{ +namespace detail +{ + + +// Extended integer type macro and alias definitions -----------------------// + +// (Unsigned) long long family +#ifdef BOOST_HAS_LONG_LONG + +// Existence +#define BOOST_HAS_XINT 1 + +// Extents +#ifdef ULLONG_MAX +#define BOOST_XINT_MAX LLONG_MAX +#define BOOST_XINT_MIN LLONG_MIN +#define BOOST_UXINT_MAX ULLONG_MAX +#elif defined(ULONG_LONG_MAX) +#define BOOST_XINT_MAX LONG_LONG_MAX +#define BOOST_XINT_MIN LONG_LONG_MIN +#define BOOST_UXINT_MAX ULONG_LONG_MAX +#elif defined(ULONGLONG_MAX) +#define BOOST_XINT_MAX LONGLONG_MAX +#define BOOST_XINT_MIN LONGLONG_MIN +#define BOOST_UXINT_MAX ULONGLONG_MAX +#elif defined(_LLONG_MAX) && defined(_C2) +#define BOOST_XINT_MAX _LLONG_MAX +#define BOOST_XINT_MIN (-_LLONG_MAX - _C2) +#define BOOST_UXINT_MAX _ULLONG_MAX +#else // guess +// Sometimes we get the double-long types without the corresponding constants, +// e.g. GCC in "-ansi" mode. In this case, we'll just have to work out the +// values ourselves. (Here we assume a two's complement representation.) +#define BOOST_XINT_MIN (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1)) +#define BOOST_XINT_MAX (~ BOOST_XINT_MIN) +#define BOOST_UXINT_MAX (~ 0uLL) +#endif + +// Types +typedef ::boost:: long_long_type xint_t; +typedef ::boost::ulong_long_type uxint_t; + +// (Unsigned) __int64 family +#elif defined(BOOST_HAS_MS_INT64) + +// Existence +#define BOOST_HAS_XINT 1 + +// Extents +#ifdef _UI64_MAX +#define BOOST_XINT_MAX _I64_MAX +#define BOOST_XINT_MIN _I64_MIN +#define BOOST_UXINT_MAX _UI64_MAX +#else // guess +// The types are exactly 2's-compl. 64-bit, so we'll enter the values directly. +#define BOOST_XINT_MAX 0x7FFFFFFFFFFFFFFFi64 +#define BOOST_XINT_MIN 0x8000000000000000i64 +#define BOOST_UXINT_MAX 0xFFFFFFFFFFFFFFFFui64 +#endif + +// Types +typedef __int64 xint_t; +typedef unsigned __int64 uxint_t; + +// Neither +#else + +// Non-existence +#define BOOST_HAS_XINT 0 + +// Dummy extents +#define BOOST_XINT_MAX LONG_MAX +#define BOOST_XINT_MIN LONG_MIN +#define BOOST_UXINT_MAX ULONG_MAX + +// Dummy types +typedef signed long xint_t; +typedef unsigned long uxint_t; + +#endif // defined(BOOST_HAS_LONG_LONG)/defined(BOOST_HAS_MS_INT64)/else + +/** \def BOOST_HAS_XINT + + \brief Flag for extended integer types. + + Indicates the presence of one of the two common extended integer type + families, either (unsigned) long long or + (unsigned) __int64. \c BOOST_HAS_XINT is \c 1 if + either type family is defined, and \c 0 if neither is. + */ + +/** \def BOOST_XINT_MAX + + \brief Maximum value for the signed extended integer type. + + \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1. + + Macro constant representing the largest value the signed extended integer + type supports. Its composition may be another macro, an expression, or a + literal. Defaulted to \c LONG_MAX if \c BOOST_HAS_XINT is zero. + */ +/** \def BOOST_XINT_MIN + + \brief Minimum value for the signed extended integer type. + + \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1. + + Macro constant representing the smallest value the signed extended integer + type supports. Its composition may be another macro, an expression, or a + literal. Defaulted to \c LONG_MIN if \c BOOST_HAS_XINT is zero. + */ +/** \def BOOST_UXINT_MAX + + \brief Maximum value for the unsigned extended integer type. + + \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1. + + Macro constant representing the largest value the unsigned extended integer + type supports. Its composition may be another macro, an expression, or a + literal. Defaulted to \c ULONG_MAX if \c BOOST_HAS_XINT is zero. (Use + \c 0u for the type's minimum value.) + */ + +/** \typedef signed long boost::detail::xint_t + + \brief Alias for the signed extended integer type. + + \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1. + + Alias representing the signed extended integer type, no matter which type + family it came from. Defaulted to signed long if + \c BOOST_HAS_XINT is zero. + */ +/** \typedef unsigned long ::boost::detail::uxint_t + + \brief Alias for the signed extended integer type. + + \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1. + + Alias representing the unsigned extended integer type, no matter which type + family it came from. Defaulted to unsigned long if + \c BOOST_HAS_XINT is zero. + */ + + +} // namespace detail +} // namespace boost + + +#endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 7e0b86c..531b405 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -29,6 +29,8 @@ #include // for std::numeric_limits #include // for boost::enable_if_c +#include // for BOOST_HAS_XINT, etc. + #include // for UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, etc. namespace boost @@ -64,15 +66,9 @@ namespace detail // 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char // no specializations for 0: requests for a type > (unsigned) (long) long are // in error -#ifdef BOOST_HAS_LONG_LONG - template<> struct int_least_helper<1, signed> - { typedef long_long_type least; }; - template<> struct int_least_helper<1, unsigned> - { typedef ulong_long_type least; }; -#elif defined(BOOST_HAS_MS_INT64) - template<> struct int_least_helper<1, signed> { typedef __int64 least; }; - template<> struct int_least_helper<1, unsigned> - { typedef unsigned __int64 least; }; +#if BOOST_HAS_XINT + template<> struct int_least_helper<1, signed> { typedef xint_t least; }; + template<> struct int_least_helper<1, unsigned> { typedef uxint_t least; }; #endif template<> struct int_least_helper<2, signed> { typedef long least; }; template<> struct int_least_helper<2, unsigned> @@ -90,7 +86,7 @@ namespace detail // category bounds enum { -#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) +#if BOOST_HAS_XINT lowest_integral_rank = 1, #else lowest_integral_rank = 2, @@ -103,12 +99,9 @@ namespace detail struct int_rank_helper { BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 ); -#ifdef BOOST_HAS_LONG_LONG +#if BOOST_HAS_XINT BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits< - long_long_type >::digits) ); -#elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits< - __int64 >::digits) ); + xint_t >::digits) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif @@ -122,12 +115,9 @@ namespace detail template < int Bits > struct uint_rank_helper { -#ifdef BOOST_HAS_LONG_LONG +#if BOOST_HAS_XINT BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits< - ulong_long_type >::digits) ); -#elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits< - unsigned __int64 >::digits) ); + uxint_t >::digits) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif @@ -152,12 +142,9 @@ namespace detail struct uint_exact_rank_helper::digits> \ { BOOST_STATIC_CONSTANT( int, rank = Rank ); } -#if defined(BOOST_HAS_LONG_LONG) && ((ULLONG_MAX > ULONG_MAX) || (ULONGLONG_MAX > ULONG_MAX)) - BOOST_PRIVATE_INT_EXACT_BUILDER( long_long_type, 1 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( ulong_long_type, 1 ); -#elif defined(BOOST_HAS_MS_INT64) && (0xFFFFFFFFFFFFFFFFui64 > ULONG_MAX) - BOOST_PRIVATE_INT_EXACT_BUILDER( __int64, 1 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned __int64, 1 ); +#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) + BOOST_PRIVATE_INT_EXACT_BUILDER( xint_t, 1 ); + BOOST_PRIVATE_UINT_EXACT_BUILDER( uxint_t, 1 ); #endif #if ULONG_MAX > UINT_MAX BOOST_PRIVATE_INT_EXACT_BUILDER( long, 2 ); @@ -181,12 +168,9 @@ namespace detail template < intmax_t MaxValue > struct int_max_rank_helper { -#ifdef BOOST_HAS_LONG_LONG - BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= boost::integer_traits< - long_long_type >::const_max) ); -#elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= boost::integer_traits< - __int64 >::const_max) ); +#if BOOST_HAS_XINT + BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= + boost::integer_traits< xint_t >::const_max) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif @@ -200,12 +184,9 @@ namespace detail template < intmax_t MinValue > struct int_min_rank_helper { -#ifdef BOOST_HAS_LONG_LONG - BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= boost::integer_traits< - long_long_type >::const_min) ); -#elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= boost::integer_traits< - __int64 >::const_min) ); +#if BOOST_HAS_XINT + BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= + boost::integer_traits< xint_t >::const_min) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif @@ -219,12 +200,9 @@ namespace detail template < uintmax_t Value > struct uint_max_rank_helper { -#ifdef BOOST_HAS_LONG_LONG +#if BOOST_HAS_XINT BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits< - ulong_long_type >::const_max) ); -#elif defined(BOOST_HAS_MS_INT64) - BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits< unsigned - __int64 >::const_max) ); + uxint_t >::const_max) ); #else BOOST_STATIC_CONSTANT( int, extended_ = 1 ); #endif diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 1cc1ce1..446ad66 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -16,6 +16,8 @@ #include // for boost::uintmax_t, intmax_t #include // for std::numeric_limits +#include // for BOOST_HAS_XINT, etc. + namespace boost { @@ -73,12 +75,12 @@ template < > template < > class integer_traits< unsigned long >; -#ifdef ULLONG_MAX +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT template < > - class integer_traits< ::boost::long_long_type>; + class integer_traits< ::boost::detail::xint_t >; template < > - class integer_traits< ::boost::ulong_long_type >; + class integer_traits< ::boost::detail::uxint_t >; #endif diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 96b3526..4cdc817 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -27,6 +27,8 @@ #include #endif +#include // for BOOST_HAS_XINT, etc. + namespace boost { template @@ -155,77 +157,18 @@ class integer_traits public detail::integer_traits_base { }; -#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) -#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG) - +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT template<> -class integer_traits< ::boost::long_long_type> - : public std::numeric_limits< ::boost::long_long_type>, - public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX> +class integer_traits< detail::xint_t > + : public std::numeric_limits< detail::xint_t >, + public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX > { }; template<> -class integer_traits< ::boost::ulong_long_type> - : public std::numeric_limits< ::boost::ulong_long_type>, - public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX> +class integer_traits< detail::uxint_t > + : public std::numeric_limits< detail::uxint_t >, + public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX > { }; - -#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG) - -template<> -class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ }; -template<> -class integer_traits< ::boost::ulong_long_type> - : public std::numeric_limits< ::boost::ulong_long_type>, - public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX> -{ }; - -#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG) - -template<> -class integer_traits< ::boost::long_long_type> - : public std::numeric_limits< ::boost::long_long_type>, - public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX> -{ }; - -template<> -class integer_traits< ::boost::ulong_long_type> - : public std::numeric_limits< ::boost::ulong_long_type>, - public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX> -{ }; - -#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG) - -template<> -class integer_traits< ::boost::long_long_type> - : public std::numeric_limits< ::boost::long_long_type>, - public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX> -{ }; - -template<> -class integer_traits< ::boost::ulong_long_type> - : public std::numeric_limits< ::boost::ulong_long_type>, - public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX> -{ }; - -#elif defined(BOOST_HAS_LONG_LONG) -// -// we have long long but no constants, this happens for example with gcc in -ansi mode, -// we'll just have to work out the values for ourselves (assumes 2's compliment representation): -// -template<> -class integer_traits< ::boost::long_long_type> - : public std::numeric_limits< ::boost::long_long_type>, - public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))> -{ }; - -template<> -class integer_traits< ::boost::ulong_long_type> - : public std::numeric_limits< ::boost::ulong_long_type>, - public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL> -{ }; - -#endif #endif } // namespace boost diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 4e32cc1..63bb4ff 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -30,6 +30,8 @@ #include // for boost::integer_traits #include // for std::numeric_limits +#include // for BOOST_HAS_XINT, etc. + #include // for boost::mpl::plus, divides #include // for BOOST_MPL_ASSERT_RELATION, etc. #include // for boost::mpl::back @@ -110,10 +112,8 @@ typedef boost::mpl::vector< #if ULONG_MAX > UINT_MAX , unsigned long #endif -#if defined(BOOST_HAS_LONG_LONG) && ((ULLONG_MAX > ULONG_MAX) || (ULONGLONG_MAX > ULONG_MAX)) - , boost::ulong_long_type -#elif defined(BOOST_HAS_MS_INT64) && (0xFFFFFFFFFFFFFFFFui64 > ULONG_MAX) - , unsigned __int64 +#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) + , boost::detail::uxint_t #endif > distinct_unsigned_types; @@ -210,10 +210,8 @@ int const integral_bit_lengths[] = { #if ULONG_MAX > UINT_MAX , std::numeric_limits< unsigned long >::digits #endif -#if defined(BOOST_HAS_LONG_LONG) && ((ULLONG_MAX > ULONG_MAX) || (ULONGLONG_MAX > ULONG_MAX)) - , std::numeric_limits< boost::ulong_long_type >::digits -#elif defined(BOOST_HAS_MS_INT64) && (0xFFFFFFFFFFFFFFFFui64 > ULONG_MAX) - , std::numeric_limits< unsigned __int64 >::digits +#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) + , std::numeric_limits< boost::detail::uxint_t >::digits #endif }; From 2fcbc31b77bfa9704f1f3db7f6add866c14c7002 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Fri, 25 Jul 2008 12:39:06 +0000 Subject: [PATCH 21/64] Tightened up code; number of bit-counts sampled is now comprehensive instead of representative (with a preprocessor switch for the old behavior since the new behavior greatly increases compile times) [SVN r47801] --- test/integer_test.cpp | 618 ++++++++++++++++-------------------------- 1 file changed, 230 insertions(+), 388 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 63bb4ff..4b34d40 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -21,16 +21,15 @@ #define BOOST_TEST_MODULE "Integer size-selection tests" -#include // unit testing framework -#include +#include // unit testing framework -#include // for BOOST_NO_USING_TEMPLATE, etc. +#include // for BOOST_NO_SFINAE #include // for boost::uintmax_t, intmax_t #include // for boost::int_t, boost::uint_t, etc. #include // for boost::integer_traits #include // for std::numeric_limits -#include // for BOOST_HAS_XINT, etc. +#include // BOOST_HAS_XINT, BOOST_UXINT_MAX #include // for boost::mpl::plus, divides #include // for BOOST_MPL_ASSERT_RELATION, etc. @@ -38,11 +37,13 @@ #include // for boost::mpl::copy #include // for boost::mpl::equal #include // for boost::mpl::front_inserter +#include // for boost::mpl::int_ #include // for boost::mpl::integral_c #include // for boost::mpl::joint_view #include // for boost::mpl::pop_back #include // for boost::mpl::push_back #include // for boost::mpl::push_front +#include // for boost::mpl::range_c #include // for boost::mpl::sort #include // for boost::mpl::transform #include // for boost::mpl::transform_view @@ -72,6 +73,12 @@ #define CONTROL_SHOW_TYPES 0 #endif +// Control if every potential bit-count is used, or only a selection +// For me, full counts increase compile time from 90 seconds to 20 minutes! +#ifndef CONTROL_FULL_COUNTS +#define CONTROL_FULL_COUNTS 1 +#endif + // If specializations have not already been done, then we can confirm // the effects of the fast types by making a specialization. If there @@ -123,21 +130,16 @@ typedef boost::mpl::transform< >::type distinct_signed_types; // List the digit counts for each integral type -class dibc_helper +template < typename T > +struct digits_of + : boost::mpl::int_< std::numeric_limits::digits > { - template < typename T > - struct type_to_digit_count - : boost::mpl::integral_c< int, std::numeric_limits::digits > - {}; - -public: - typedef boost::mpl::transform< - distinct_unsigned_types, - type_to_digit_count< boost::mpl::_1 > - >::type type; }; -typedef dibc_helper::type distinct_integral_bit_counts; +typedef boost::mpl::transform< + distinct_unsigned_types, + digits_of< boost::mpl::_1 > +>::type distinct_integral_bit_counts; // Make list of bit counts between each offical point, plus CHAR_BIT/2 typedef boost::mpl::transform_view< @@ -166,6 +168,9 @@ int const intmax_bits = intmax_limits::digits + 1; int const uintmax_bits = uintmax_limits::digits; // Make master lists including an outlier beyond all valid bit counts +#if CONTROL_FULL_COUNTS +typedef boost::mpl::range_c bits_list; +#else typedef boost::mpl::sort< boost::mpl::copy< boost::mpl::joint_view< @@ -179,23 +184,46 @@ typedef boost::mpl::sort< > >::type >::type bits_list; +#endif // Remove the outlier when all bits counts must be valid +#if CONTROL_FULL_COUNTS +typedef boost::mpl::range_c valid_bits_list; +#else typedef boost::mpl::pop_back::type valid_bits_list; +#endif + +// Replace the minimum bit count with one more, so right-shifting by a stored +// value doesn't give an invalid result +#if CONTROL_FULL_COUNTS +typedef boost::mpl::range_c + valid_to_decrease_bits_list; +#else +typedef valid_bits_list valid_to_decrease_bits_list; +#endif // Replace the maximum bit count with one less, so left-shifting by a stored // value doesn't give an invalid result +#if CONTROL_FULL_COUNTS +typedef boost::mpl::range_c valid_to_increase_ubits_list; +#else typedef boost::mpl::push_back< boost::mpl::pop_back< valid_bits_list >::type, boost::mpl::integral_c< int, uintmax_bits - 1 > >::type valid_to_increase_ubits_list; +#endif // Do it again for signed types since they have one-less bit to use for the // mantissa (don't want to shift into the sign bit) +#if CONTROL_FULL_COUNTS +typedef boost::mpl::range_c + valid_to_increase_sbits_list; +#else typedef boost::mpl::push_back< boost::mpl::pop_back< valid_bits_list >::type, boost::mpl::integral_c< int, intmax_bits - 3 > >::type valid_to_increase_sbits_list; +#endif // List the digit counts for each integral type, this time as an object, an // array working as a sorted list @@ -218,153 +246,49 @@ int const integral_bit_lengths[] = { std::size_t const integral_type_count = sizeof(integral_bit_lengths) / sizeof(integral_bit_lengths[0]); -// Use SFINAE to check if a particular bit-count is supported +// "Template-typedefs" to reduce two-argument templates to single-argument. +// This way, all the MPL-compatible templates have the same form, for below. template < int Bits > +struct signed_sized_integral : boost::sized_integral {}; + +template < int Bits > +struct unsigned_sized_integral : boost::sized_integral {}; + +template < int Bits > +struct signed_exact_integral : boost::exact_integral {}; + +template < int Bits > +struct unsigned_exact_integral : boost::exact_integral {}; + +// Use SFINAE to check if a particular parameter is supported +#ifndef BOOST_NO_SFINAE +template < typename ValueT, template class Tmpl, ValueT Value > bool -print_out_sized_signed( boost::mpl::integral_c const &x, int bits, - typename boost::sized_integral::type *unused = 0 ) +print_out_template( Tmpl const &, ValueT setting, char const + *template_pre_name, char const *template_post_name, typename Tmpl::type + *unused = 0 ) { // Too bad the type-id expression couldn't use the compact form "*unused", // but type-ids of dereferenced null pointers throw by order of C++ 2003, // sect. 5.2.8, para. 2 (although the result is not conceptually needed). - - PRIVATE_SHOW_MESSAGE( "There is a sized_integral<" << bits << - ", signed> specialization, with type '" << typeid(typename - boost::sized_integral::type).name() << "'." ); + PRIVATE_SHOW_MESSAGE( "This is " << template_pre_name << setting + << template_post_name << " specialization, with type '" << typeid(typename + Tmpl::type).name() << "'." ); return true; } -template < typename T > +template < typename ValueT, typename T > bool -print_out_sized_signed( T const &x, int bits ) +print_out_template( T const &, ValueT setting, char const *template_pre_name, + char const *template_post_name ) { - PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits << - ", signed> specialization." ); - return false; -} - -template < int Bits > -bool -print_out_sized_unsigned( boost::mpl::integral_c const &x, int bits, - typename boost::sized_integral::type *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is a sized_integral<" << bits << - ", unsigned> specialization, with type '" << typeid(typename - boost::sized_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_sized_unsigned( T const &x, int bits ) -{ - PRIVATE_SHOW_MESSAGE( "There is no sized_integral<" << bits << - ", unsigned> specialization." ); - return false; -} - -template < int Bits > -bool -print_out_exact_signed( boost::mpl::integral_c const &x, int bits, - typename boost::exact_integral::type *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is an exact_integral<" << bits << - ", signed> specialization, with type '" << typeid(typename - boost::exact_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_exact_signed( T const &x, int bits ) -{ - PRIVATE_SHOW_MESSAGE( "There is no exact_integral<" << bits << - ", signed> specialization." ); - return false; -} - -template < int Bits > -bool -print_out_exact_unsigned( boost::mpl::integral_c const &x, int bits, - typename boost::exact_integral::type *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is an exact_integral<" << bits << - ", unsigned> specialization, with type '" << typeid(typename - boost::exact_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_exact_unsigned( T const &x, int bits ) -{ - PRIVATE_SHOW_MESSAGE( "There is no exact_integral<" << bits << - ", unsigned> specialization." ); - return false; -} - -template < boost::intmax_t Value > -bool -print_out_maximum_signed( boost::maximum_signed_integral const &x, - boost::intmax_t value, typename boost::maximum_signed_integral::type - *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is a maximum_signed_integral<" << value << - "> specialization, with type '" << typeid(typename - boost::maximum_signed_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_maximum_signed( T const &x, boost::intmax_t value ) -{ - PRIVATE_SHOW_MESSAGE( "There is no maximum_signed_integral<" << value << - "> specialization." ); - return false; -} - -template < boost::intmax_t Value > -bool -print_out_minimum_signed( boost::minimum_signed_integral const &x, - boost::intmax_t value, typename boost::minimum_signed_integral::type - *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is a minimum_signed_integral<" << value << - "> specialization, with type '" << typeid(typename - boost::minimum_signed_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_minimum_signed( T const &x, boost::intmax_t value ) -{ - PRIVATE_SHOW_MESSAGE( "There is no minimum_signed_integral<" << value << - "> specialization." ); - return false; -} - -template < boost::uintmax_t Value > -bool -print_out_maximum_unsigned( boost::maximum_unsigned_integral const &x, - boost::uintmax_t value, typename boost::maximum_unsigned_integral::type - *unused = 0 ) -{ - PRIVATE_SHOW_MESSAGE( "There is a maximum_unsigned_integral<" << value << - "> specialization, with type '" << typeid(typename - boost::maximum_unsigned_integral::type).name() << "'." ); - return true; -} - -template < typename T > -bool -print_out_maximum_unsigned( T const &x, boost::uintmax_t value ) -{ - PRIVATE_SHOW_MESSAGE( "There is no maximum_unsigned_integral<" << value << - "> specialization." ); + PRIVATE_SHOW_MESSAGE( "Looking for " << template_pre_name << setting + << template_post_name << " specialization? It doesn't exist." ); return false; } +#else +#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error" +#endif } // unnamed namespace @@ -375,25 +299,17 @@ BOOST_AUTO_TEST_SUITE( optimized_type_tests ) // Check the optimzed type override of a given type BOOST_AUTO_TEST_CASE( fast_type_test ) { -#ifndef BOOST_NO_USING_TEMPLATE - using std::numeric_limits; - using boost::is_same; -#else - using namespace std; - using namespace boost; -#endif - typedef short least_type; typedef boost::int_fast_t::fast fast_type; - typedef numeric_limits least_limits; - typedef numeric_limits fast_limits; + typedef std::numeric_limits least_limits; + typedef std::numeric_limits fast_limits; typedef boost::fast_integral::type real_fast_type; - BOOST_MPL_ASSERT_RELATION( (is_same::value), ==, - false ); - BOOST_MPL_ASSERT_RELATION( (is_same::value), ==, - true ); + BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), + ==, false ); + BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), ==, true ); BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true ); BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed && fast_limits::is_bounded, ==, true ); @@ -409,14 +325,16 @@ BOOST_AUTO_TEST_SUITE( show_type_tests ) // Check the specialization type status of given bit lengths, minimum BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list ) { - BOOST_CHECK_EQUAL( print_out_sized_signed(T(), T::value), T::value <= - intmax_bits ); - BOOST_CHECK_EQUAL( print_out_sized_unsigned(T(), T::value), T::value <= - uintmax_bits ); + BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral(), + T::value, "a sized_integral<", ", signed>"), T::value && (T::value <= + intmax_bits) ); + BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral(), + T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits ); } -// Check the classic specialization type status of given bit lengths, minimum -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_test, T, +// Check the classic specialization type status of given bit lengths, minimum, +// unsigned +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T, valid_bits_list ) { // This test is supposed to replace the following printouts given in @@ -432,23 +350,21 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_test, T, // of type-lists is usually less than 32 (not to mention 64) elements, so we // have to take selected values. The only interesting part is if the bit // count is too large, and we can't check that yet. -#ifndef BOOST_NO_USING_TEMPLATE - using std::numeric_limits; - using boost::int_t; - using boost::uint_t; -#else - using namespace std; - using namespace boost; -#endif + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value ); + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value ); +} - BOOST_MPL_ASSERT_RELATION( numeric_limits::least>::digits, >=, T::value - 1 ); - BOOST_MPL_ASSERT_RELATION( numeric_limits::fast>::digits, >=, T::value - 1 ); - BOOST_MPL_ASSERT_RELATION( numeric_limits::least>::digits, >=, T::value ); - BOOST_MPL_ASSERT_RELATION( numeric_limits::fast>::digits, >=, T::value ); +// Check the classic specialization type status of given bit lengths, minimum, +// signed +BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T, + valid_to_decrease_bits_list ) +{ + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value - 1 ); + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value - 1 ); } // Check size comparisons of given value support, unsigned @@ -469,24 +385,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T, // have to take selected values. The interesting parts are where N is the // length of a integral type, so 1 << N would have to fit in the next larger // type. (This is why N can't be more than bitlength(uintmax_t) - 1.) -#ifndef BOOST_NO_USING_TEMPLATE - using boost::mpl::equal; - using boost::maximum_unsigned_integral; - using boost::sized_integral; -#else - using namespace boost::mpl; - using namespace boost; -#endif - boost::uintmax_t const one = 1u; - int const count = T::value; - BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 2))>, - sized_integral >) ); - BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << (count - 1))>, - sized_integral >) ); - BOOST_MPL_ASSERT( (equal< maximum_unsigned_integral<(one << count)>, - sized_integral >) ); + BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one + << T::value)>, unsigned_sized_integral >) ); } // Check size comparisons of given value support, signed @@ -512,151 +414,124 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T, // length of a integral type, so 1 << N would have to fit in the next larger // type. (This is why N can't be more than bitlength(intmax_t) - 1. Note // that bitlength(intmax_t) + 1 == bitlength(uintmax_t).) -#ifndef BOOST_NO_USING_TEMPLATE - using boost::mpl::equal; - using boost::maximum_signed_integral; - using boost::sized_integral; - using boost::minimum_signed_integral; -#else - using namespace boost::mpl; - using namespace boost; -#endif + static boost::intmax_t const one = 1; - boost::intmax_t const one = 1; - int const count = T::value; - - BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 2))>, - sized_integral >) ); - BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 2))>, - sized_integral >) ); - - BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << (count - 1))>, - sized_integral >) ); - BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << (count - 1))>, - sized_integral >) ); - - BOOST_MPL_ASSERT( (equal< maximum_signed_integral<+(one << count)>, - sized_integral >) ); - BOOST_MPL_ASSERT( (equal< minimum_signed_integral<-(one << count)>, - sized_integral >) ); + BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one + << T::value)>, signed_sized_integral >) ); + BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one + << T::value)>, signed_sized_integral >) ); } // Check the specialization type status of given bit lengths, exact only BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list ) { -#ifndef BOOST_NO_USING_TEMPLATE - using std::binary_search; -#else - using namespace std; -#endif + bool const is_exact_length = std::binary_search( integral_bit_lengths, + integral_bit_lengths + integral_type_count, T::value ); - BOOST_CHECK_EQUAL( print_out_exact_signed(T(), T::value), - binary_search(integral_bit_lengths, integral_bit_lengths + - integral_type_count, T::value) ); - BOOST_CHECK_EQUAL( print_out_exact_unsigned(T(), T::value), - binary_search(integral_bit_lengths, integral_bit_lengths + - integral_type_count, T::value) ); + BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral(), + T::value, "an exact_integral<", ", signed>"), is_exact_length ); + BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral(), + T::value, "an exact_integral<", ", unsigned>"), is_exact_length ); } // Check the classic specialization type status of given bit lengths, exact only BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T, distinct_integral_bit_counts ) { -#ifndef BOOST_NO_USING_TEMPLATE - using std::numeric_limits; - using boost::int_exact_t; - using boost::uint_exact_t; -#else - using namespace std; - using namespace boost; -#endif - - BOOST_MPL_ASSERT_RELATION( numeric_limits::exact>::digits, ==, T::value - 1 ); - BOOST_MPL_ASSERT_RELATION( numeric_limits::exact>::digits, ==, T::value ); + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value - 1 ); + BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value ); } // Check if MPL-compatible templates give bad returns for out-of-range values BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test ) { -#ifndef BOOST_NO_USING_TEMPLATE - using boost::sized_integral; - using boost::mpl::integral_c; - using boost::exact_integral; - using boost::maximum_signed_integral; - using boost::minimum_signed_integral; - using boost::maximum_unsigned_integral; -#else - using namespace boost; - using namespace boost::mpl; -#endif + typedef signed_sized_integral< 3> ssz3_type; + typedef signed_sized_integral< 0> ssz0_type; + typedef signed_sized_integral<-3> ssz3n_type; - typedef sized_integral< 3, signed> ssz3_type; - typedef sized_integral< 0, signed> ssz0_type; - typedef sized_integral<-3, signed> ssz3n_type; + BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count, + "a sized_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count, + "a sized_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count, + "a sized_integral<", ", signed>") ); - BOOST_CHECK( print_out_sized_signed(integral_c(), - ssz3_type::bit_count) ); - BOOST_CHECK( !print_out_sized_signed(integral_c(), - ssz0_type::bit_count) ); - BOOST_CHECK( !print_out_sized_signed(integral_c(), - ssz3n_type::bit_count) ); + typedef unsigned_sized_integral< 3> usz3_type; + typedef unsigned_sized_integral< 0> usz0_type; + typedef unsigned_sized_integral<-3> usz3n_type; - typedef sized_integral< 3, unsigned> usz3_type; - typedef sized_integral< 0, unsigned> usz0_type; - typedef sized_integral<-3, unsigned> usz3n_type; + BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count, + "a sized_integral<", ", unsigned>") ); + BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count, + "a sized_integral<", ", unsigned>") ); + BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count, + "a sized_integral<", ", unsigned>") ); - BOOST_CHECK( print_out_sized_unsigned(integral_c(), - usz3_type::bit_count) ); - BOOST_CHECK( print_out_sized_unsigned(integral_c(), - usz0_type::bit_count) ); - BOOST_CHECK( !print_out_sized_unsigned(integral_c(), - usz3n_type::bit_count) ); + typedef signed_exact_integral< CHAR_BIT > se8_type; + typedef signed_exact_integral< 3> se3_type; + typedef signed_exact_integral< 0> se0_type; + typedef signed_exact_integral<-3> se3n_type; + typedef signed_exact_integral< - CHAR_BIT > se8n_type; - typedef exact_integral< 3, signed> se3_type; - typedef exact_integral< 0, signed> se0_type; - typedef exact_integral<-3, signed> se3n_type; + BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count, + "an exact_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count, + "an exact_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count, + "an exact_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count, + "an exact_integral<", ", signed>") ); + BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count, + "an exact_integral<", ", signed>") ); - BOOST_CHECK( !print_out_exact_signed(integral_c(), - se3_type::bit_count) ); - BOOST_CHECK( !print_out_exact_signed(integral_c(), - se0_type::bit_count) ); - BOOST_CHECK( !print_out_exact_signed(integral_c(), - se3n_type::bit_count) ); + typedef unsigned_exact_integral< CHAR_BIT > ue8_type; + typedef unsigned_exact_integral< 3> ue3_type; + typedef unsigned_exact_integral< 0> ue0_type; + typedef unsigned_exact_integral<-3> ue3n_type; + typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type; - typedef exact_integral< 3, unsigned> ue3_type; - typedef exact_integral< 0, unsigned> ue0_type; - typedef exact_integral<-3, unsigned> ue3n_type; + BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count, + "an exact_integral<", ", unsigned>") ); + BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count, + "an exact_integral<", ", unsigned>") ); + BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count, + "an exact_integral<", ", unsigned>") ); + BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count, + "an exact_integral<", ", unsigned>") ); + BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count, + "an exact_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_exact_unsigned(integral_c(), - ue3_type::bit_count) ); - BOOST_CHECK( !print_out_exact_unsigned(integral_c(), - ue0_type::bit_count) ); - BOOST_CHECK( !print_out_exact_unsigned(integral_c(), - ue3n_type::bit_count) ); + typedef boost::maximum_signed_integral< 15> max15_type; + typedef boost::maximum_signed_integral< 0> max0_type; + typedef boost::maximum_signed_integral<-15> max15n_type; - typedef maximum_signed_integral< 15> max15_type; - typedef maximum_signed_integral< 0> max0_type; - typedef maximum_signed_integral<-15> max15n_type; + BOOST_CHECK( print_out_template(max15_type(), max15_type::bound, + "a maximum_signed_integral<", ">") ); + BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound, + "a maximum_signed_integral<", ">") ); + BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound, + "a maximum_signed_integral<", ">") ); - BOOST_CHECK( print_out_maximum_signed(max15_type(), max15_type::bound) ); - BOOST_CHECK( !print_out_maximum_signed(max0_type(), max0_type::bound) ); - BOOST_CHECK( !print_out_maximum_signed(max15n_type(), max15n_type::bound) ); + typedef boost::minimum_signed_integral< 15> min15_type; + typedef boost::minimum_signed_integral< 0> min0_type; + typedef boost::minimum_signed_integral<-15> min15n_type; - typedef minimum_signed_integral< 15> min15_type; - typedef minimum_signed_integral< 0> min0_type; - typedef minimum_signed_integral<-15> min15n_type; + BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound, + "a minimum_signed_integral<", ">") ); + BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound, + "a minimum_signed_integral<", ">") ); + BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound, + "a minimum_signed_integral<", ">") ); - BOOST_CHECK( !print_out_minimum_signed(min15_type(), min15_type::bound) ); - BOOST_CHECK( !print_out_minimum_signed(min0_type(), min0_type::bound) ); - BOOST_CHECK( print_out_minimum_signed(min15n_type(), min15n_type::bound) ); + typedef boost::maximum_unsigned_integral<15> umax15_type; + typedef boost::maximum_unsigned_integral< 0> umax0_type; - typedef maximum_unsigned_integral<15> umax15_type; - typedef maximum_unsigned_integral< 0> umax0_type; - - BOOST_CHECK( print_out_maximum_unsigned(umax15_type(), umax15_type::bound) ); - BOOST_CHECK( print_out_maximum_unsigned(umax0_type(), umax0_type::bound) ); + BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound, + "a maximum_unsigned_integral<", ">") ); + BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound, + "a maximum_unsigned_integral<", ">") ); } BOOST_AUTO_TEST_SUITE_END() @@ -666,7 +541,7 @@ BOOST_AUTO_TEST_SUITE( fit_type_tests ) // Check if large value can fit its minimum required size, by size BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, - valid_bits_list ) + valid_to_decrease_bits_list ) { // This test is supposed to replace the following checks given in // puesdo-code by: @@ -681,58 +556,42 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, // supposed to. But now we'll use template meta-programming instead of // macros. The limit of type-lists is usually less than 32 (not to mention // 64) elements, so we have to take selected values. -#ifndef BOOST_NO_USING_TEMPLATE - using boost::sized_integral; - using boost::uint_t; - using boost::int_t; -#else - using namespace boost; -#endif - - int const count = T::value, shift = uintmax_bits - count; + static int const count = T::value; + int const shift = uintmax_bits - count; boost::uintmax_t const value_u = uintmax_limits::max BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift; boost::intmax_t const value_s = intmax_limits::max BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift; - BOOST_CHECK_EQUAL( (typename sized_integral::type(value_u)), - value_u ); - BOOST_CHECK_EQUAL( typename uint_t::least(value_u >> 1), value_u - >> 1 ); - BOOST_CHECK_EQUAL( typename uint_t::fast(value_u), value_u ); - BOOST_CHECK_EQUAL( typename uint_t::fast(value_u >> 1), value_u - >> 1 ); + BOOST_CHECK_EQUAL( static_cast::type>(value_u), value_u ); + BOOST_CHECK_EQUAL( static_cast::least>(value_u), value_u ); + BOOST_CHECK_EQUAL( static_cast::fast>(value_u), value_u ); - BOOST_CHECK_EQUAL( typename int_t::least(value_s), value_s ); - BOOST_CHECK_EQUAL( (typename sized_integral::type(value_s - >> 1)), value_s >> 1 ); - BOOST_CHECK_EQUAL( typename int_t::fast(value_s), value_s ); - BOOST_CHECK_EQUAL( typename int_t::fast(value_s >> 1), value_s >> - 1 ); + BOOST_CHECK_EQUAL( static_cast::type>(value_s), value_s ); + BOOST_CHECK_EQUAL( static_cast::least>(value_s), value_s ); + BOOST_CHECK_EQUAL( static_cast::fast>(value_s), value_s ); } // Check if a large value can only fit of its exact bit length BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T, distinct_integral_bit_counts ) { -#ifndef BOOST_NO_USING_TEMPLATE - using boost::exact_integral; -#else - using namespace boost; -#endif - - typedef typename exact_integral::type uexact_type; - typedef typename exact_integral::type sexact_type; - - uexact_type const one_u( 1u ), high_bit_u( one_u << (T::value - 1) ), - repeated_bits_u( (high_bit_u << 1) | high_bit_u ); + typename boost::exact_integral::type const one_u( 1u ), + high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) | + high_bit_u ); BOOST_CHECK( high_bit_u ); BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u ); - sexact_type const one_s( 1 ), high_bit_s( one_s << (T::value - 2) ), - repeated_bits_s( (high_bit_s << 1) | high_bit_s ), - repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s ); + typename boost::exact_integral::type const one_s( 1 ), + high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) | + high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s ); BOOST_CHECK( high_bit_s > 0 ); BOOST_CHECK( repeated_bits_s < 0 ); @@ -757,21 +616,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T, // macros. The limit of type-lists is usually less than 32 (not to mention // 64) elements, so we have to take selected values. using boost::uintmax_t; -#ifndef BOOST_NO_USING_TEMPLATE - using boost::uint_value_t; -#else - using namespace boost; -#endif - uintmax_t const max_u = boost::integer_traits::const_max >> - T::value; + static uintmax_t const maxi = boost::integer_traits::const_max + >> T::value; - BOOST_CHECK_EQUAL( typename uint_value_t::least(max_u), max_u ); - BOOST_CHECK_EQUAL( typename uint_value_t<(max_u >> 1)>::least(max_u >> 1), - max_u >> 1 ); - BOOST_CHECK_EQUAL( typename uint_value_t::fast(max_u), max_u ); - BOOST_CHECK_EQUAL( typename uint_value_t<(max_u >> 1)>::fast(max_u >> 1), - max_u >> 1 ); + BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); } // Check if large value can fit its minimum required size, by value, signed @@ -793,31 +645,21 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T, // macros. The limit of type-lists is usually less than 32 (not to mention // 64) elements, so we have to take selected values. using boost::intmax_t; -#ifndef BOOST_NO_USING_TEMPLATE - using boost::integer_traits; - using boost::int_max_value_t; - using boost::int_min_value_t; -#else - using namespace boost; -#endif - int const shift = T::value; - intmax_t const max_s = integer_traits::const_max >> shift, - min_s = integer_traits::const_min >> shift; + typedef boost::integer_traits intmax_traits; - BOOST_CHECK_EQUAL( typename int_max_value_t::least(max_s), max_s ); - BOOST_CHECK_EQUAL( typename int_max_value_t<(max_s >> 1)>::least(max_s >> - 1), max_s >> 1 ); - BOOST_CHECK_EQUAL( typename int_max_value_t::fast(max_s), max_s ); - BOOST_CHECK_EQUAL( typename int_max_value_t<(max_s >> 1)>::fast(max_s >> 1), - max_s >> 1 ); + static intmax_t const maxi = intmax_traits::const_max >> T::value, + mini = intmax_traits::const_min >> T::value; - BOOST_CHECK_EQUAL( typename int_min_value_t::least(min_s), min_s ); - BOOST_CHECK_EQUAL( typename int_min_value_t<(min_s >> 1)>::least(min_s >> - 1), min_s >> 1 ); - BOOST_CHECK_EQUAL( typename int_min_value_t::fast(min_s), min_s ); - BOOST_CHECK_EQUAL( typename int_min_value_t<(min_s >> 1)>::fast(min_s >> 1), - min_s >> 1 ); + BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); + + BOOST_CHECK_EQUAL( static_cast::least>(mini), mini ); + BOOST_CHECK_EQUAL( static_cast::fast>(mini), mini ); } BOOST_AUTO_TEST_SUITE_END() From 2ae867bcf8c1812ab04ed5b135bdcbba35946bc5 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 27 Jul 2008 09:00:54 +0000 Subject: [PATCH 22/64] Corrected link to corresponding test files [SVN r47838] --- cstdint.htm | 2 +- integer.htm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cstdint.htm b/cstdint.htm index 9492827..0c2f893 100644 --- a/cstdint.htm +++ b/cstdint.htm @@ -18,7 +18,7 @@ writing portable code that requires certain integer widths. All typedef's are i header <stdint.h>.  The 64-bit types required by the C standard are not required in the boost header, and may not be supplied in all implementations, because long long is not [yet] included in the C++ standard.

-

See cstdint_test.cpp for a test program.

+

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 diff --git a/integer.htm b/integer.htm index e563bc1..0130d7a 100644 --- a/integer.htm +++ b/integer.htm @@ -462,7 +462,7 @@ int main()

Demonstration Program

-

The program integer_test.cpp is a +

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

From 188cef05a9986feca195f6926640f9f15314fe06 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 27 Jul 2008 16:34:38 +0000 Subject: [PATCH 23/64] Changed the Integer-mask test to use the unit-test system [SVN r47841] --- test/Jamfile.v2 | 2 +- test/integer_mask_test.cpp | 139 +++++++++++++------------------------ 2 files changed, 51 insertions(+), 90 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a0b5b19..50fceee 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,7 +11,7 @@ test-suite integer [ run integer_traits_test.cpp /boost/test//boost_test_exec_monitor/static ] [ run integer_mask_test.cpp - /boost/test//boost_test_exec_monitor/static ] + /boost/test//boost_unit_test_framework ] [ run static_log2_test.cpp /boost/test//boost_test_exec_monitor/static ] [ run static_min_max_test.cpp diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 6146ddf..4444801 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -8,104 +8,65 @@ // See http://www.boost.org for most recent version including documentation. // Revision History +// 27 Jul 2008 Changed tests to use the unit-test system (Daryle Walker) // 23 Sep 2001 Initial version (Daryle Walker) -#define BOOST_INCLUDE_MAIN -#include // for main +#define BOOST_TEST_MODULE "Integer mask tests" +#include // unit testing framework -#include // for boost::exit_success +#include // for boost::uintmax_t #include // for boost::high_bit_mask_t, etc. +#include // for BOOST_MPL_ASSERT_RELATION +#include // for boost::mpl::range_c -#include // for std::cout (std::endl indirectly) +#include // for std::size_t -#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ - (v) >::high_bit == (1ul << (v)) ); -#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ - (v) >::high_bit_fast == (1ul << (v)) ); -#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ - PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) - -#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ - PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) - - -int test_main( int, char*[] ) +// Custom types/templates, helper functions, and objects +namespace { - 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 ); +// A big one +boost::uintmax_t const one = 1u; - cout << "Doing low_bits_mask_t tests." << endl; - PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops! - PRIVATE_LOW_BITS_TEST( 31 ); - PRIVATE_LOW_BITS_TEST( 30 ); - PRIVATE_LOW_BITS_TEST( 29 ); - PRIVATE_LOW_BITS_TEST( 28 ); - PRIVATE_LOW_BITS_TEST( 27 ); - PRIVATE_LOW_BITS_TEST( 26 ); - PRIVATE_LOW_BITS_TEST( 25 ); - PRIVATE_LOW_BITS_TEST( 24 ); - PRIVATE_LOW_BITS_TEST( 23 ); - PRIVATE_LOW_BITS_TEST( 22 ); - PRIVATE_LOW_BITS_TEST( 21 ); - PRIVATE_LOW_BITS_TEST( 20 ); - PRIVATE_LOW_BITS_TEST( 19 ); - PRIVATE_LOW_BITS_TEST( 18 ); - PRIVATE_LOW_BITS_TEST( 17 ); - PRIVATE_LOW_BITS_TEST( 16 ); - PRIVATE_LOW_BITS_TEST( 15 ); - PRIVATE_LOW_BITS_TEST( 14 ); - PRIVATE_LOW_BITS_TEST( 13 ); - PRIVATE_LOW_BITS_TEST( 12 ); - PRIVATE_LOW_BITS_TEST( 11 ); - PRIVATE_LOW_BITS_TEST( 10 ); - PRIVATE_LOW_BITS_TEST( 9 ); - PRIVATE_LOW_BITS_TEST( 8 ); - PRIVATE_LOW_BITS_TEST( 7 ); - PRIVATE_LOW_BITS_TEST( 6 ); - PRIVATE_LOW_BITS_TEST( 5 ); - PRIVATE_LOW_BITS_TEST( 4 ); - PRIVATE_LOW_BITS_TEST( 3 ); - PRIVATE_LOW_BITS_TEST( 2 ); - PRIVATE_LOW_BITS_TEST( 1 ); +// List the ranges of template parameters tests (ranges are half-open) +typedef boost::mpl::range_c high_bit_offsets; +typedef boost::mpl::range_c low_bit_lengths; - return boost::exit_success; +} // unnamed namespace + + +// Check the various integer-valued bit-masks +BOOST_AUTO_TEST_SUITE( integer_mask_tests ) + +// Check the bit-masks of one offset bit +BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets ) +{ + BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit, ==, + (one << T::value) ); + BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit_fast, + ==, (one << T::value) ); } + +// Check the bit-masks of a block of low-valued bits +BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, low_bit_lengths ) +{ + // One can express (2^x - 1) in two ways + // 1. (1 << x) - 1 + // 2. (1 << (x-1)) | ((1 << (x-1)) - 1) + // Since unsigneds have modulo arithmetic, [1] gives the right answer even + // when x is the number of bits in the register. However, that last case + // gives warnings about the sole bit flowing past the register. Applying + // distributive property backwards gives [2], which works without overflow. + BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits, ==, + (one << ( T::value - 1u )) | (( one << (T::value - 1u) ) - 1u) ); + BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits_fast, + ==, (one << ( T::value - 1u )) | (( one << (T::value - 1u) ) - 1u) ); +} + +BOOST_AUTO_TEST_SUITE_END() + +// Verification of bugs and their fixes +BOOST_AUTO_TEST_SUITE( bug_fix_tests ) + +BOOST_AUTO_TEST_SUITE_END() From f041dc0f0a3f63cc710e8ed78f64e9076b0e4a80 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sun, 27 Jul 2008 17:08:51 +0000 Subject: [PATCH 24/64] Added extended-integer support [SVN r47842] --- include/boost/integer/integer_mask.hpp | 6 ++++++ include/boost/integer_fwd.hpp | 6 ++++++ test/integer_mask_test.cpp | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp index 0a092d3..65ee5d5 100644 --- a/include/boost/integer/integer_mask.hpp +++ b/include/boost/integer/integer_mask.hpp @@ -15,6 +15,8 @@ #include // for BOOST_STATIC_CONSTANT #include // for boost::uint_t +#include // for BOOST_HAS_XINT, etc. + #include // for UCHAR_MAX, etc. #include // for std::size_t @@ -84,6 +86,10 @@ BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); #endif +#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) +BOOST_LOW_BITS_MASK_SPECIALIZE( ::boost::detail::uxint_t ); +#endif + #undef BOOST_LOW_BITS_MASK_SPECIALIZE diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 446ad66..e15385a 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -155,6 +155,12 @@ template < > struct low_bits_mask_t< ::std::numeric_limits::digits >; #endif +#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) +template < > + struct low_bits_mask_t< ::std::numeric_limits< ::boost::detail::uxint_t + >::digits >; +#endif + // From ------------------------------------// diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 4444801..99a22b0 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -8,7 +8,8 @@ // See http://www.boost.org for most recent version including documentation. // Revision History -// 27 Jul 2008 Changed tests to use the unit-test system (Daryle Walker) +// 27 Jul 2008 Changed tests to use the unit-test system; added +// extended-integer support. (Daryle Walker) // 23 Sep 2001 Initial version (Daryle Walker) #define BOOST_TEST_MODULE "Integer mask tests" @@ -16,6 +17,7 @@ #include // for boost::uintmax_t #include // for boost::high_bit_mask_t, etc. +#include // for std::numeric_limits #include // for BOOST_MPL_ASSERT_RELATION #include // for boost::mpl::range_c @@ -30,8 +32,10 @@ namespace boost::uintmax_t const one = 1u; // List the ranges of template parameters tests (ranges are half-open) -typedef boost::mpl::range_c high_bit_offsets; -typedef boost::mpl::range_c low_bit_lengths; +int const max_offset = std::numeric_limits::digits; + +typedef boost::mpl::range_c high_bit_offsets; +typedef boost::mpl::range_c low_bit_lengths; } // unnamed namespace From 2fd0675a21a35ee0d1f6aa7c2f7fa6873aa45a5c Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 28 Jul 2008 14:41:00 +0000 Subject: [PATCH 25/64] Hopefully made compile-time constants suitable for more compilers [SVN r47852] --- test/integer_test.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 4b34d40..8f5c834 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -44,6 +44,7 @@ #include // for boost::mpl::push_back #include // for boost::mpl::push_front #include // for boost::mpl::range_c +#include // for boost::mpl::shift_right #include // for boost::mpl::sort #include // for boost::mpl::transform #include // for boost::mpl::transform_view @@ -290,6 +291,19 @@ print_out_template( T const &, ValueT setting, char const *template_pre_name, #error "These tests cannot work without Substitution-Failure-Is-Not-An-Error" #endif +// Get the extreme values for each integral type +template < typename T > +struct minimum_of + : boost::mpl::integral_c< T, boost::integer_traits::const_min > +{ +}; + +template < typename T > +struct maximum_of + : boost::mpl::integral_c< T, boost::integer_traits::const_max > +{ +}; + } // unnamed namespace @@ -617,13 +631,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T, // 64) elements, so we have to take selected values. using boost::uintmax_t; - static uintmax_t const maxi = boost::integer_traits::const_max - >> T::value; + typedef boost::mpl::shift_right, T> maxi_type; + + uintmax_t const maxi = maxi_type::value; BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + boost::uint_value_t::least>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); + boost::uint_value_t::fast>(maxi), maxi ); } // Check if large value can fit its minimum required size, by value, signed @@ -646,20 +661,20 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T, // 64) elements, so we have to take selected values. using boost::intmax_t; - typedef boost::integer_traits intmax_traits; + typedef boost::mpl::shift_right, T> mini_type; + typedef boost::mpl::shift_right, T> maxi_type; - static intmax_t const maxi = intmax_traits::const_max >> T::value, - mini = intmax_traits::const_min >> T::value; + intmax_t const maxi = maxi_type::value, mini = mini_type::value; BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); + boost::int_max_value_t::least>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); + boost::int_max_value_t::fast>(maxi), maxi ); BOOST_CHECK_EQUAL( static_cast::least>(mini), mini ); + boost::int_min_value_t::least>(mini), mini ); BOOST_CHECK_EQUAL( static_cast::fast>(mini), mini ); + boost::int_min_value_t::fast>(mini), mini ); } BOOST_AUTO_TEST_SUITE_END() From 2d259a4f3e44879d2dccfbc0eef006b532a5bcaf Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Tue, 29 Jul 2008 19:33:20 +0000 Subject: [PATCH 26/64] Added MPL-compatible variants of the integer-mask class templates (and finally make the lowest-bit-group metafunctions work for zero-length bit-groups) [SVN r47869] --- doc/integer_mask.html | 211 ++++++++++++++++++++++--- include/boost/integer/integer_mask.hpp | 207 ++++++++++++++++++------ include/boost/integer_fwd.hpp | 38 ++--- test/integer_mask_test.cpp | 119 ++++++++++++-- 4 files changed, 461 insertions(+), 114 deletions(-) diff --git a/doc/integer_mask.html b/doc/integer_mask.html index 5bc7301..6dba489 100644 --- a/doc/integer_mask.html +++ b/doc/integer_mask.html @@ -8,7 +8,11 @@

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.

+

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

@@ -17,6 +21,7 @@ align="middle" width="277" height="86">Integer Bit Mask Templates
  • Synopsis
  • Single Bit-Mask Class Template
  • Group Bit-Mask Class Template
  • +
  • MPL-Compatible Variants
  • Example
  • Demonstration Program
  • Rationale
  • @@ -26,39 +31,68 @@ align="middle" width="277" height="86">Integer Bit Mask Templates

    Synopsis

    -#include <cstddef>  // for std::size_t
    +#include <boost/integer_fwd.hpp>  // forwarding header
    +#include <boost/integer.hpp>      // for boost::int_fast_t
    +#include <cstddef>                // for std::size_t
     
     namespace boost
     {
     
    -template < std::size_t Bit >
    -struct high_bit_mask_t
    +// MPL-compatible
    +template < int Offset >
    +struct integer_hi_mask
     {
    -    typedef implementation_supplied  least;
    -    typedef implementation_supplied   fast;
    +    static  bool const  is_specialized = implementation_supplied;
    +    static  int const   bit_offset = Offset;
     
    -    static const least  high_bit = implementation_defined;
    -    static const fast   high_bit_fast = implementation_defined;
    +    typedef implementation_supplied  type;
    +    typedef implementation_supplied  value_type;
    +    static  value_type const  value = implementation_supplied;
    +    // There are other (optional) operations....
    +};
    +
    +template < int Length >
    +struct integer_lo_mask
    +{
    +    static  bool const  is_specialized = implementation_supplied;
    +    static  int const   bit_count = Length;
    +
    +    typedef implementation_supplied  type;
    +    typedef implementation_supplied  value_type;
    +    static  value_type const  value = implementation_supplied;
    +    // There are other (optional) operations....
    +};
    +
    +// single
    +template < std::size_t Bit >
    +class high_bit_mask_t
    +{
    +public:
    +    typedef typename integer_hi_mask<Bit>::value_type  least;
    +    typedef int_fast_t<least>::fast                     fast;
    +
    +    static const least  high_bit = integer_hi_mask<Bit>::value;
    +    static const fast   high_bit_fast = high_bit;
     
         static const std::size_t  bit_position = Bit;
     
     };
     
    +// group
     template < std::size_t Bits >
    -struct low_bits_mask_t
    +class low_bits_mask_t
     {
    -    typedef implementation_supplied  least;
    -    typedef implementation_supplied   fast;
    +public:
    +    typedef typename integer_lo_mask<Bits>::value_type  least;
    +    typedef int_fast_t<least>::fast                      fast;
     
    -    static const least  sig_bits = implementation_defined;
    -    static const fast   sig_bits_fast = implementation_defined;
    +    static const least  sig_bits = integer_lo_mask<Bits>::value;
    +    static const fast   sig_bits_fast = sig_bits;
     
         static const std::size_t  bit_count = Bits;
     
     };
     
    -// Specializations for low_bits_mask_t exist for certain bit counts.
    -
     }  // namespace boost
     
    @@ -149,16 +183,149 @@ describes the members of an instantiation of -

    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.

    +

    MPL-Compatible Variants

    + +

    The single and group bit-mask class templates have several drawbacks:

    + +
      +
    • You must know the valid bit-lengths in advance.
    • +
    • Using an inappropriate parameter value results in a compiler + diagnostic.
    • +
    • The type names used are inconsistent with other transformations in + Boost, like in MPL.
    • +
    • The above two facts make use of the regular bit-mask class templates + incompatible with template meta-programming techniques.
    • +
    + +

    The integer_hi_mask and integer_lo_mask class +templates provide MPL-compatible alternatives. These alternatives have the +form:

    + +
    +template< int Size >
    +struct name
    +{
    +    static  bool const  is_specialized = implementation_supplied;
    +    static  int const   switch_id = Size;
    +
    +    typedef implementation_supplied  type;
    +    typedef implementation_supplied  value_type;
    +    static  value_type const  value = implementation_supplied;
    +    // with other operations...
    +};
    +
    + +

    Only some of the members are always present. The presence of other members +and operations is flagged by the (always-present) is_specialized.

    + + + + + + + + + + + + + + + +
    Permanent Members of the MPL-Compatible Masking Class Template + Types
    Class Template MemberMeaning
    is_specializedFlag indicating when a particular template class instantiation is a + valid meta-function (true) or not (false).
    switch_id (Actual name is template-specific.)The value of the main control parameter, accessible even if the + template class instantiation is aliased.
    + +

    The optional members are based from inheriting from a MPL-style Integral +Constant type, but only if is_specialized is true.

    + + + + + + + + + + + + + + + + + + + +
    Optional Members of the MPL-Compatible Masking Types
    Class Template MemberMeaning
    valueThe actual bit mask.
    value_typeThe type of the bit mask value.
    typeThe Integral Constant implementation type, which should be + boost::mpl:: + integral_c< value_type, value + >.
    + +

    The Integral Constant prototype also adds the following operations:

    + + + + + + + + + + + + + + + + + + + +
    Optional Operations of the MPL-Compatible Masking Types
    Operation (with n as a masking type)Meaning
    boost::mpl::next< n >::typeboost::mpl::next< n::type >::type, i.e. + boost::mpl::integral_c< n::value_type, n::value + 1 + >.
    boost::mpl::prior< n >::typeboost::mpl::prior< n::type >::type, i.e. + boost::mpl::integral_c< n::value_type, n::value - 1 + >.
    n::value_type const c = n();c is set to n::value.
    + +

    The specifics for each masking class template are:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Criteria for the MPL-Compatible Masking Types
    + (Everything besides the parameter ID is in name-space + boost except where indicated.)
    Class TemplateParameter Member IDClassic EquivalentValue TypeValueValid Range
    integer_hi_maskbit_offsethigh_bit_mask_tsized_integral < bit_offset + 1, unsigned >2bit_offset0 <= bit_offset < std::numeric_limits< uintmax_t >::digits
    integer_lo_maskbit_countlow_bits_mask_tsized_integral < bit_count, unsigned >2bit_offset - 10 <= bit_count <= std::numeric_limits< uintmax_t >::digits

    Example

    -#include <boost/integer/integer_mask.hpp>
    +#include <boost/integer/integer_mask.hpp>
     
     //...
     
    @@ -200,7 +367,7 @@ href="http://www.boost.org/people/daryle_walker.html">Daryle Walker.


    -

    Revised September 23, 2001

    +

    Revised July 29, 2008

    © Copyright Daryle Walker 2001. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file // self include -#include // for BOOST_STATIC_CONSTANT -#include // for boost::uint_t +#include // for BOOST_STATIC_CONSTANT +#include // for boost::uintmax_t +#include // for boost::sized_integral +#include // for std::numeric_limits +#include // for boost::mpl::and_ +#include // for boost::mpl::bitor_, shift_left +#include // for boost::mpl::true_ +#include // for boost::mpl::greater_equal, etc. +#include // for boost::mpl::empty_base +#include // for boost::mpl::if_ +#include // for boost::mpl::int_ +#include // for boost::integral_c +#include // for boost::mpl::next, prior +#include // for boost::enable_if -#include // for BOOST_HAS_XINT, etc. - -#include // for UCHAR_MAX, etc. #include // for std::size_t -#include // for std::numeric_limits - namespace boost { +namespace detail +{ + +// Helper templates --------------------------------------------------------// + +template < int Bits > +struct hi_integer_mask_builder1 +{ + typedef boost::mpl::int_ bit_count_type; + + typedef typename boost::mpl::next::type + mask_length_type; + typedef boost::sized_integral + mask_type; + + typedef boost::mpl::integral_c one_type; + typedef boost::mpl::shift_left result_type; +}; + +template < int Bits > +struct hi_integer_mask_builder2 +{ + typedef boost::mpl::int_ bit_count_type; + + typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> > + lo_bound_type; + typedef boost::mpl::less< bit_count_type, + boost::mpl::int_::digits> > + hi_bound_type; + typedef boost::mpl::and_ count_valid_type; +}; + +template < int Bits, class Enable = void > +struct hi_integer_mask_builder3 +{ + BOOST_STATIC_CONSTANT( bool, is_specialized = false ); +}; + +template < int Bits > +struct hi_integer_mask_builder3< Bits, typename boost::enable_if::count_valid_type>::type > + : hi_integer_mask_builder1::result_type +{ + BOOST_STATIC_CONSTANT( bool, is_specialized = true ); +}; + +template < int Bits > +struct lo_integer_mask_builder1 +{ + typedef boost::mpl::int_ bit_count_type; + + typedef typename boost::mpl::prior::type + shift_length_type; + typedef boost::sized_integral + mask_type; + + typedef boost::mpl::integral_c one_type; + typedef boost::mpl::shift_left + high_bit_type; + typedef typename boost::mpl::prior::type low_bits_type; + typedef boost::mpl::bitor_ result_type; +}; + +template < > +struct lo_integer_mask_builder1< 0 > +{ + // Let's not deal with negative interim values.... + typedef boost::mpl::integral_c result_type; +}; + +template < int Bits > +struct lo_integer_mask_builder2 +{ + typedef boost::mpl::int_ bit_count_type; + + typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> > + lo_bound_type; + typedef boost::mpl::less_equal< bit_count_type, + boost::mpl::int_::digits> > + hi_bound_type; + typedef boost::mpl::and_ count_valid_type; +}; + +template < > +struct lo_integer_mask_builder2< 0 > +{ + typedef boost::mpl::true_ count_valid_type; +}; + +template < int Bits, class Enable = void > +struct lo_integer_mask_builder3 +{ + BOOST_STATIC_CONSTANT( bool, is_specialized = false ); + // No MPL Integral Constant to inherit from +}; + +template < int Bits > +struct lo_integer_mask_builder3< Bits, typename enable_if::count_valid_type>::type > + : lo_integer_mask_builder1::result_type +{ + BOOST_STATIC_CONSTANT( bool, is_specialized = true ); +}; + +} // namespace detail + + +// MPL-compatible integer mask class templates -----------------------------// + +// Displaced single-bit mask, 1 << Offset, 0 <= Offset < BitLengthOf(uintmax_t) +template < int Offset > +struct integer_hi_mask + : detail::hi_integer_mask_builder3 +{ + BOOST_STATIC_CONSTANT( int, bit_offset = Offset ); +}; + +// Lowest bit-group mask, 2**Length - 1, 0 <= Length <= BitLengthOf(uintmax_t) +template < int Length > +struct integer_lo_mask + : detail::lo_integer_mask_builder3 +{ + BOOST_STATIC_CONSTANT( int, bit_count = Length ); +}; // Specified single-bit mask class declaration -----------------------------// // (Lowest bit starts counting at 0.) template < std::size_t Bit > -struct high_bit_mask_t +class high_bit_mask_t { - typedef typename uint_t<(Bit + 1)>::least least; - typedef typename uint_t<(Bit + 1)>::fast fast; + typedef integer_hi_mask impl_type; - BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) ); - BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) ); +public: + typedef typename impl_type::value_type least; + typedef typename int_fast_t::fast fast; - BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit ); + BOOST_STATIC_CONSTANT( least, high_bit = impl_type::value ); + BOOST_STATIC_CONSTANT( fast, high_bit_fast = impl_type::value ); + + BOOST_STATIC_CONSTANT( std::size_t, bit_position = impl_type::bit_offset ); }; // boost::high_bit_mask_t // Specified bit-block mask class declaration ------------------------------// // Makes masks for the lowest N bits -// (Specializations are needed when N fills up a type.) template < std::size_t Bits > -struct low_bits_mask_t +class low_bits_mask_t { - typedef typename uint_t::least least; - typedef typename uint_t::fast fast; + typedef integer_lo_mask impl_type; - BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) ); - BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); +public: + typedef typename impl_type::value_type least; + typedef typename int_fast_t::fast fast; - BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits ); + BOOST_STATIC_CONSTANT( least, sig_bits = impl_type::value ); + BOOST_STATIC_CONSTANT( fast, sig_bits_fast = impl_type::value ); + + BOOST_STATIC_CONSTANT( std::size_t, bit_count = impl_type::bit_count ); }; // boost::low_bits_mask_t -#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \ - template < > struct low_bits_mask_t< std::numeric_limits::digits > { \ - typedef std::numeric_limits limits_type; \ - typedef uint_t::least least; \ - typedef uint_t::fast fast; \ - BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \ - BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \ - BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ - } - -BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); - -#if USHRT_MAX > UCHAR_MAX -BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short ); -#endif - -#if UINT_MAX > USHRT_MAX -BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); -#endif - -#if ULONG_MAX > UINT_MAX -BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); -#endif - -#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) -BOOST_LOW_BITS_MASK_SPECIALIZE( ::boost::detail::uxint_t ); -#endif - -#undef BOOST_LOW_BITS_MASK_SPECIALIZE - - } // namespace boost diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index e15385a..3ece2e3 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -9,12 +9,10 @@ #ifndef BOOST_INTEGER_FWD_HPP #define BOOST_INTEGER_FWD_HPP -#include // for UCHAR_MAX, etc. #include // for std::size_t -#include // for BOOST_NO_INTRINSIC_WCHAR_T +#include // for BOOST_NO_INTRINSIC_WCHAR_T, etc. #include // for boost::uintmax_t, intmax_t -#include // for std::numeric_limits #include // for BOOST_HAS_XINT, etc. @@ -131,35 +129,17 @@ template< uintmax_t Value > // From -----------------------------------// +template < int Offset > + struct integer_hi_mask; + +template < int Length > + struct integer_lo_mask; + template < std::size_t Bit > - struct high_bit_mask_t; + class high_bit_mask_t; template < std::size_t Bits > - struct low_bits_mask_t; - -template < > - struct low_bits_mask_t< ::std::numeric_limits::digits >; - -#if USHRT_MAX > UCHAR_MAX -template < > - struct low_bits_mask_t< ::std::numeric_limits::digits >; -#endif - -#if UINT_MAX > USHRT_MAX -template < > - struct low_bits_mask_t< ::std::numeric_limits::digits >; -#endif - -#if ULONG_MAX > UINT_MAX -template < > - struct low_bits_mask_t< ::std::numeric_limits::digits >; -#endif - -#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) -template < > - struct low_bits_mask_t< ::std::numeric_limits< ::boost::detail::uxint_t - >::digits >; -#endif + class low_bits_mask_t; // From ------------------------------------// diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 99a22b0..65b6fc2 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -8,6 +8,8 @@ // See http://www.boost.org for most recent version including documentation. // Revision History +// 29 Jul 2008 Added MPL-compatible variants of the integer-mask templates. +// (Daryle Walker) // 27 Jul 2008 Changed tests to use the unit-test system; added // extended-integer support. (Daryle Walker) // 23 Sep 2001 Initial version (Daryle Walker) @@ -18,24 +20,72 @@ #include // for boost::uintmax_t #include // for boost::high_bit_mask_t, etc. #include // for std::numeric_limits -#include // for BOOST_MPL_ASSERT_RELATION +#include // for BOOST_MPL_ASSERT_RELATION,etc. +#include // for boost::mpl::bool_ +#include // for boost::mpl::bitor_, shift_left +#include // for boost::mpl::equal_to +#include // for boost::mpl::int_ +#include // for boost::mpl::integral_c +#include // for boost::mpl::prior #include // for boost::mpl::range_c #include // for std::size_t +#include // for std::hex +#include // for std::cout +#include // for std::endl + + +// Control if events will be printed conventionally, or just logged. +#ifndef CONTROL_SHOW_TYPES +#define CONTROL_SHOW_TYPES 0 +#endif + +// Logging +#if CONTROL_SHOW_TYPES +#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl +#else +#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m ) +#endif // Custom types/templates, helper functions, and objects namespace { -// A big one -boost::uintmax_t const one = 1u; - // List the ranges of template parameters tests (ranges are half-open) int const max_offset = std::numeric_limits::digits; -typedef boost::mpl::range_c high_bit_offsets; -typedef boost::mpl::range_c low_bit_lengths; +typedef boost::mpl::range_c high_bit_offsets; +typedef boost::mpl::range_c low_bit_lengths; +typedef boost::mpl::range_c special_low_bit_lengths; + +// List a range with out-of-service values +typedef boost::mpl::range_c wild_bit_lengths; + +// Use SFINAE to check if a particular parameter is supported +template < typename ValueT, template class Tmpl, ValueT Value > +bool +print_out_template( Tmpl const &, ValueT setting, char const + *template_name, typename Tmpl::type *unused = 0 ) +{ + // Too bad the type-id expression couldn't use the compact form "*unused", + // but type-ids of dereferenced null pointers throw by order of C++ 2003, + // sect. 5.2.8, para. 2 (although the result is not conceptually needed). + PRIVATE_SHOW_MESSAGE( "There is an " << template_name << "<" << setting << + "> specialization with type '" << typeid(typename + Tmpl::value_type).name() << "' and value '" << std::hex << + Tmpl::value << "'." ); + return true; +} + +template < typename ValueT, typename T > +bool +print_out_template( T const &, ValueT setting, char const *template_name ) +{ + PRIVATE_SHOW_MESSAGE( "There is no " << template_name << "<" << setting << + "> specialization." ); + return false; +} } // unnamed namespace @@ -46,14 +96,18 @@ BOOST_AUTO_TEST_SUITE( integer_mask_tests ) // Check the bit-masks of one offset bit BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets ) { + typedef boost::mpl::integral_c::least, 1u> one_type; + typedef boost::mpl::shift_left result_type; + BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit, ==, - (one << T::value) ); + result_type::value ); BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit_fast, - ==, (one << T::value) ); + ==, result_type::value ); } -// Check the bit-masks of a block of low-valued bits -BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, low_bit_lengths ) +// Check the bit-masks of a block of low-valued bits, non-zero block-lengths +BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, special_low_bit_lengths ) { // One can express (2^x - 1) in two ways // 1. (1 << x) - 1 @@ -62,10 +116,51 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, low_bit_lengths ) // when x is the number of bits in the register. However, that last case // gives warnings about the sole bit flowing past the register. Applying // distributive property backwards gives [2], which works without overflow. + typedef typename boost::mpl::prior::type shift_type; + typedef boost::mpl::integral_c::least, 1u> one_type; + typedef boost::mpl::shift_left high_bit_type; + typedef typename boost::mpl::prior::type low_bits_type; + typedef boost::mpl::bitor_ result_type; + BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits, ==, - (one << ( T::value - 1u )) | (( one << (T::value - 1u) ) - 1u) ); + result_type::value ); BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits_fast, - ==, (one << ( T::value - 1u )) | (( one << (T::value - 1u) ) - 1u) ); + ==, result_type::value ); +} + +// Check the bit-masks of a block of low-valued bits, zero block-length +BOOST_AUTO_TEST_CASE( special_low_bits_mask_test ) +{ + // Just like "low_bits_mask_test" above, except that the shifts are negative + // when the bit-count is zero. That causes a lot of warnings and errors, so + // special-case that bit-count. + BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<0u>::sig_bits, ==, 0 ); + BOOST_MPL_ASSERT_RELATION(boost::low_bits_mask_t<0u>::sig_bits_fast, ==, 0); +} + +// Check the specialization type status of given bit-offsets/lengths +BOOST_AUTO_TEST_CASE_TEMPLATE( confirm_bounds_test, T, wild_bit_lengths ) +{ + typedef boost::integer_hi_mask hi_type; + typedef boost::mpl::int_ hi_offset_type; + typedef boost::mpl::bool_ special_hi_type; + + BOOST_MPL_ASSERT( (boost::mpl::equal_to< hi_offset_type, T >) ); + BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_hi_type, + boost::mpl::bool_<(T::value >= 0) && (T::value < max_offset)> >) ); + BOOST_CHECK_EQUAL( print_out_template(hi_type(), hi_offset_type::value, + "integer_hi_mask"), special_hi_type::value ); + + typedef boost::integer_lo_mask lo_type; + typedef boost::mpl::int_ lo_length_type; + typedef boost::mpl::bool_ special_lo_type; + + BOOST_MPL_ASSERT( (boost::mpl::equal_to< lo_length_type, T >) ); + BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_lo_type, + boost::mpl::bool_<(T::value >= 0) && (T::value <= max_offset)> >) ); + BOOST_CHECK_EQUAL( print_out_template(lo_type(), lo_length_type::value, + "integer_lo_mask"), special_lo_type::value ); } BOOST_AUTO_TEST_SUITE_END() From c7e9da65513d7f86adf1659a33bc6e7aed167d36 Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Sat, 1 Nov 2008 13:15:41 +0000 Subject: [PATCH 27/64] Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor [SVN r49510] --- CMakeLists.txt | 25 +++++++++++++++++++++++++ test/CMakeLists.txt | 8 ++++++++ 2 files changed, 33 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2241512 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +#---------------------------------------------------------------------------- +# This file was automatically generated from the original CMakeLists.txt file +# Add a variable to hold the headers for the library +set (lib_headers + integer.hpp + integer_fwd.hpp + integer_traits.hpp + integer +) + +# Add a library target to the build system +boost_library_project( + integer + # SRCDIRS + TESTDIRS test + HEADERS ${lib_headers} + # DOCDIRS + DESCRIPTION "The organization of boost integer headers and classes is designed to take advantage of types from the 1999 C standard without resorting to 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." + MODULARIZED + AUTHORS "Beman Dawes " + "Daryle Walker " + # MAINTAINERS +) + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..e332eb1 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +boost_test_run(cstdint_test cstdint_test.cpp) +boost_test_run(integer_mask_test integer_mask_test.cpp) +boost_test_run(integer_test integer_test.cpp) +boost_test_run(integer_traits_test integer_traits_test.cpp + DEPENDS boost_test_exec_monitor) +boost_test_run(issue_2134 issue_2134.cpp) +boost_test_run(static_log2_test static_log2_test.cpp) +boost_test_run(static_min_max_test static_min_max_test.cpp) From 768023af1ad3aad4c5336977fa6f992ee325642f Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:02:56 +0000 Subject: [PATCH 28/64] Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use. [SVN r49627] --- test/CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e332eb1..eca38ae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,9 @@ +boost_additional_test_dependencies(integer BOOST_DEPENDS test) + boost_test_run(cstdint_test cstdint_test.cpp) -boost_test_run(integer_mask_test integer_mask_test.cpp) -boost_test_run(integer_test integer_test.cpp) -boost_test_run(integer_traits_test integer_traits_test.cpp - DEPENDS boost_test_exec_monitor) +boost_test_run(integer_mask_test integer_mask_test.cpp DEPENDS boost_test_exec_monitor) +boost_test_run(integer_test integer_test.cpp DEPENDS boost_test_exec_monitor) +boost_test_run(integer_traits_test integer_traits_test.cpp DEPENDS boost_test_exec_monitor) boost_test_run(issue_2134 issue_2134.cpp) -boost_test_run(static_log2_test static_log2_test.cpp) -boost_test_run(static_min_max_test static_min_max_test.cpp) +boost_test_run(static_log2_test static_log2_test.cpp DEPENDS boost_test_exec_monitor) +boost_test_run(static_min_max_test static_min_max_test.cpp DEPENDS boost_test_exec_monitor) From a8f7c90aff24fd7cfbd5772d40fff7b4660329cb Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:05:27 +0000 Subject: [PATCH 29/64] Updating dependency information for modularized libraries. [SVN r49628] --- module.cmake | 1 + 1 file changed, 1 insertion(+) create mode 100644 module.cmake diff --git a/module.cmake b/module.cmake new file mode 100644 index 0000000..d0c4293 --- /dev/null +++ b/module.cmake @@ -0,0 +1 @@ +boost_module(integer DEPENDS utility) \ No newline at end of file From ec8ede3378530d43b13a141eb6db80c210e2535e Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Sat, 29 Nov 2008 07:45:02 +0000 Subject: [PATCH 30/64] Changed control of extra messages to be determined solely by the Boost.Test messaging controls [SVN r50009] --- test/integer_mask_test.cpp | 19 ++----------------- test/integer_test.cpp | 20 ++------------------ 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 65b6fc2..c3a0854 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -31,21 +31,6 @@ #include // for std::size_t #include // for std::hex -#include // for std::cout -#include // for std::endl - - -// Control if events will be printed conventionally, or just logged. -#ifndef CONTROL_SHOW_TYPES -#define CONTROL_SHOW_TYPES 0 -#endif - -// Logging -#if CONTROL_SHOW_TYPES -#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl -#else -#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m ) -#endif // Custom types/templates, helper functions, and objects @@ -71,7 +56,7 @@ print_out_template( Tmpl const &, ValueT setting, char const // Too bad the type-id expression couldn't use the compact form "*unused", // but type-ids of dereferenced null pointers throw by order of C++ 2003, // sect. 5.2.8, para. 2 (although the result is not conceptually needed). - PRIVATE_SHOW_MESSAGE( "There is an " << template_name << "<" << setting << + BOOST_TEST_MESSAGE( "There is an " << template_name << "<" << setting << "> specialization with type '" << typeid(typename Tmpl::value_type).name() << "' and value '" << std::hex << Tmpl::value << "'." ); @@ -82,7 +67,7 @@ template < typename ValueT, typename T > bool print_out_template( T const &, ValueT setting, char const *template_name ) { - PRIVATE_SHOW_MESSAGE( "There is no " << template_name << "<" << setting << + BOOST_TEST_MESSAGE( "There is no " << template_name << "<" << setting << "> specialization." ); return false; } diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 8f5c834..3749183 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -58,8 +58,6 @@ #include // for std::binary_search #include // for ULONG_MAX, LONG_MAX, LONG_MIN, etc. #include // for std::size_t -#include // for std::cout -#include // for std::endl #include // for std::type_info @@ -68,12 +66,6 @@ #define CONTROL_FAST_SHORT long #endif -// Control if the names of the types for each version -// of the integer templates will be printed. -#ifndef CONTROL_SHOW_TYPES -#define CONTROL_SHOW_TYPES 0 -#endif - // Control if every potential bit-count is used, or only a selection // For me, full counts increase compile time from 90 seconds to 20 minutes! #ifndef CONTROL_FULL_COUNTS @@ -95,14 +87,6 @@ namespace boost } -// Logging -#if CONTROL_SHOW_TYPES -#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl -#else -#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m ) -#endif - - // Custom types/templates, helper functions, and objects namespace { @@ -272,7 +256,7 @@ print_out_template( Tmpl const &, ValueT setting, char const // Too bad the type-id expression couldn't use the compact form "*unused", // but type-ids of dereferenced null pointers throw by order of C++ 2003, // sect. 5.2.8, para. 2 (although the result is not conceptually needed). - PRIVATE_SHOW_MESSAGE( "This is " << template_pre_name << setting + BOOST_TEST_MESSAGE( "This is " << template_pre_name << setting << template_post_name << " specialization, with type '" << typeid(typename Tmpl::type).name() << "'." ); return true; @@ -283,7 +267,7 @@ bool print_out_template( T const &, ValueT setting, char const *template_pre_name, char const *template_post_name ) { - PRIVATE_SHOW_MESSAGE( "Looking for " << template_pre_name << setting + BOOST_TEST_MESSAGE( "Looking for " << template_pre_name << setting << template_post_name << " specialization? It doesn't exist." ); return false; } From 3706ee7bd94fba1f9c24e96b2bf2237086f57de4 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 14 Jan 2009 10:17:25 +0000 Subject: [PATCH 31/64] Fixes #2654. [SVN r50572] --- include/boost/cstdint.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/cstdint.hpp b/include/boost/cstdint.hpp index 31a432a..d55a484 100644 --- a/include/boost/cstdint.hpp +++ b/include/boost/cstdint.hpp @@ -36,7 +36,7 @@ // this is triggered with GCC, because it defines __cplusplus < 199707L # define BOOST_NO_INT64_T # endif -# elif defined(__FreeBSD__) || defined(__IBMCPP__) +# elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX) # include # else # include From edd638ec918a3a00724eb6339d5325f98669074c Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 8 Jul 2009 21:27:05 +0000 Subject: [PATCH 32/64] Use BOOST_STATIC_CONSTANT in static_log2, as g++ 4.0 has problems with enum. [SVN r54811] --- include/boost/integer/static_log2.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/integer/static_log2.hpp b/include/boost/integer/static_log2.hpp index 19e048b..219a48e 100644 --- a/include/boost/integer/static_log2.hpp +++ b/include/boost/integer/static_log2.hpp @@ -48,7 +48,7 @@ namespace boost { template struct choose_initial_n { - enum { c = (argument_type(1) << n << n) != 0 }; + BOOST_STATIC_CONSTANT(bool, c = (argument_type(1) << n << n) != 0); BOOST_STATIC_CONSTANT( result_type, value = !c*n + choose_initial_n<2*c*n>::value @@ -85,7 +85,7 @@ namespace boost { template struct static_log2_impl { - enum { c = (x >> n) > 0 }; // x >= 2**n ? + BOOST_STATIC_CONSTANT(bool, c = (x >> n) > 0); // x >= 2**n ? BOOST_STATIC_CONSTANT( result_type, value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value) From 9fd48f6a5650fb47c2fcc7e42609a8c23761e2e9 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sun, 26 Jul 2009 00:49:56 +0000 Subject: [PATCH 33/64] Copyrights on CMakeLists.txt to keep them from clogging up the inspect reports. This is essentially the same commit as r55095 on the release branch. [SVN r55159] --- CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2241512..c952ed0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# #---------------------------------------------------------------------------- # This file was automatically generated from the original CMakeLists.txt file # Add a variable to hold the headers for the library diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eca38ae..5b6a21d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# boost_additional_test_dependencies(integer BOOST_DEPENDS test) boost_test_run(cstdint_test cstdint_test.cpp) From f9561fec20fea84ab867f2317d1c411d317cf465 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sat, 17 Oct 2009 02:07:38 +0000 Subject: [PATCH 34/64] rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back [SVN r56942] --- CMakeLists.txt | 31 ------------------------------- module.cmake | 1 - test/CMakeLists.txt | 15 --------------- 3 files changed, 47 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 module.cmake delete mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index c952ed0..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -#---------------------------------------------------------------------------- -# This file was automatically generated from the original CMakeLists.txt file -# Add a variable to hold the headers for the library -set (lib_headers - integer.hpp - integer_fwd.hpp - integer_traits.hpp - integer -) - -# Add a library target to the build system -boost_library_project( - integer - # SRCDIRS - TESTDIRS test - HEADERS ${lib_headers} - # DOCDIRS - DESCRIPTION "The organization of boost integer headers and classes is designed to take advantage of types from the 1999 C standard without resorting to 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." - MODULARIZED - AUTHORS "Beman Dawes " - "Daryle Walker " - # MAINTAINERS -) - - diff --git a/module.cmake b/module.cmake deleted file mode 100644 index d0c4293..0000000 --- a/module.cmake +++ /dev/null @@ -1 +0,0 @@ -boost_module(integer DEPENDS utility) \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 5b6a21d..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -boost_additional_test_dependencies(integer BOOST_DEPENDS test) - -boost_test_run(cstdint_test cstdint_test.cpp) -boost_test_run(integer_mask_test integer_mask_test.cpp DEPENDS boost_test_exec_monitor) -boost_test_run(integer_test integer_test.cpp DEPENDS boost_test_exec_monitor) -boost_test_run(integer_traits_test integer_traits_test.cpp DEPENDS boost_test_exec_monitor) -boost_test_run(issue_2134 issue_2134.cpp) -boost_test_run(static_log2_test static_log2_test.cpp DEPENDS boost_test_exec_monitor) -boost_test_run(static_min_max_test static_min_max_test.cpp DEPENDS boost_test_exec_monitor) From fd0a8f8c2c4478e0c053b0810bb3116e6d11c4dd Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 27 Oct 2009 09:58:40 +0000 Subject: [PATCH 35/64] Suppress gcc warnings: for bug report #1451. [SVN r57170] --- include/boost/integer_traits.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 4cdc817..9be25ce 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -158,6 +158,16 @@ class integer_traits { }; #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT + +#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3))) +// +// The following code emits warnings when built with -pedantic, and there appears +// to be no other way of suppressing these warnings as use of __extension__ has no +// effect, so declare the rest of this header a system header. +// +# pragma GCC system_header +#endif + template<> class integer_traits< detail::xint_t > : public std::numeric_limits< detail::xint_t >, From eecbd5276fd6fb19ef54974723183de9377ffdae Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 11 Nov 2009 18:57:24 +0000 Subject: [PATCH 36/64] Reverted Integer back to Release branch state - as per devel-list discussions. [SVN r57580] --- cstdint.htm | 2 +- doc/integer_mask.html | 209 +----- include/boost/integer.hpp | 383 ++--------- include/boost/integer/integer_mask.hpp | 201 ++---- include/boost/integer_fwd.hpp | 78 +-- include/boost/integer_traits.hpp | 89 ++- integer.htm | 391 ++--------- integer_traits.html | 2 +- test/Jamfile.v2 | 2 +- test/integer_mask_test.cpp | 222 +++---- test/integer_test.cpp | 882 +++++++------------------ test/issue_2134.cpp | 33 - 12 files changed, 619 insertions(+), 1875 deletions(-) delete mode 100644 test/issue_2134.cpp diff --git a/cstdint.htm b/cstdint.htm index 0c2f893..9492827 100644 --- a/cstdint.htm +++ b/cstdint.htm @@ -18,7 +18,7 @@ writing portable code that requires certain integer widths. All typedef's are i header <stdint.h>.  The 64-bit types required by the C standard are not required in the boost header, and may not be supplied in all implementations, because long long is not [yet] included in the C++ standard.

    -

    See cstdint_test.cpp for a test program.

    +

    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 diff --git a/doc/integer_mask.html b/doc/integer_mask.html index 6dba489..5bc7301 100644 --- a/doc/integer_mask.html +++ b/doc/integer_mask.html @@ -8,11 +8,7 @@

    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.

    +

    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

    @@ -21,7 +17,6 @@ href="../integer.htm">integer type selection templates header.

  • Synopsis
  • Single Bit-Mask Class Template
  • Group Bit-Mask Class Template
  • -
  • MPL-Compatible Variants
  • Example
  • Demonstration Program
  • Rationale
  • @@ -31,68 +26,39 @@ href="../integer.htm">integer type selection templates header.

    Synopsis

    -#include <boost/integer_fwd.hpp>  // forwarding header
    -#include <boost/integer.hpp>      // for boost::int_fast_t
    -#include <cstddef>                // for std::size_t
    +#include <cstddef>  // for std::size_t
     
     namespace boost
     {
     
    -// MPL-compatible
    -template < int Offset >
    -struct integer_hi_mask
    -{
    -    static  bool const  is_specialized = implementation_supplied;
    -    static  int const   bit_offset = Offset;
    -
    -    typedef implementation_supplied  type;
    -    typedef implementation_supplied  value_type;
    -    static  value_type const  value = implementation_supplied;
    -    // There are other (optional) operations....
    -};
    -
    -template < int Length >
    -struct integer_lo_mask
    -{
    -    static  bool const  is_specialized = implementation_supplied;
    -    static  int const   bit_count = Length;
    -
    -    typedef implementation_supplied  type;
    -    typedef implementation_supplied  value_type;
    -    static  value_type const  value = implementation_supplied;
    -    // There are other (optional) operations....
    -};
    -
    -// single
     template < std::size_t Bit >
    -class high_bit_mask_t
    +struct high_bit_mask_t
     {
    -public:
    -    typedef typename integer_hi_mask<Bit>::value_type  least;
    -    typedef int_fast_t<least>::fast                     fast;
    +    typedef implementation_supplied  least;
    +    typedef implementation_supplied   fast;
     
    -    static const least  high_bit = integer_hi_mask<Bit>::value;
    -    static const fast   high_bit_fast = high_bit;
    +    static const least  high_bit = implementation_defined;
    +    static const fast   high_bit_fast = implementation_defined;
     
         static const std::size_t  bit_position = Bit;
     
     };
     
    -// group
     template < std::size_t Bits >
    -class low_bits_mask_t
    +struct low_bits_mask_t
     {
    -public:
    -    typedef typename integer_lo_mask<Bits>::value_type  least;
    -    typedef int_fast_t<least>::fast                      fast;
    +    typedef implementation_supplied  least;
    +    typedef implementation_supplied   fast;
     
    -    static const least  sig_bits = integer_lo_mask<Bits>::value;
    -    static const fast   sig_bits_fast = sig_bits;
    +    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
     
    @@ -183,149 +149,16 @@ describes the members of an instantiation of -

    MPL-Compatible Variants

    - -

    The single and group bit-mask class templates have several drawbacks:

    - -
      -
    • You must know the valid bit-lengths in advance.
    • -
    • Using an inappropriate parameter value results in a compiler - diagnostic.
    • -
    • The type names used are inconsistent with other transformations in - Boost, like in MPL.
    • -
    • The above two facts make use of the regular bit-mask class templates - incompatible with template meta-programming techniques.
    • -
    - -

    The integer_hi_mask and integer_lo_mask class -templates provide MPL-compatible alternatives. These alternatives have the -form:

    - -
    -template< int Size >
    -struct name
    -{
    -    static  bool const  is_specialized = implementation_supplied;
    -    static  int const   switch_id = Size;
    -
    -    typedef implementation_supplied  type;
    -    typedef implementation_supplied  value_type;
    -    static  value_type const  value = implementation_supplied;
    -    // with other operations...
    -};
    -
    - -

    Only some of the members are always present. The presence of other members -and operations is flagged by the (always-present) is_specialized.

    - - - - - - - - - - - - - - - -
    Permanent Members of the MPL-Compatible Masking Class Template - Types
    Class Template MemberMeaning
    is_specializedFlag indicating when a particular template class instantiation is a - valid meta-function (true) or not (false).
    switch_id (Actual name is template-specific.)The value of the main control parameter, accessible even if the - template class instantiation is aliased.
    - -

    The optional members are based from inheriting from a MPL-style Integral -Constant type, but only if is_specialized is true.

    - - - - - - - - - - - - - - - - - - - -
    Optional Members of the MPL-Compatible Masking Types
    Class Template MemberMeaning
    valueThe actual bit mask.
    value_typeThe type of the bit mask value.
    typeThe Integral Constant implementation type, which should be - boost::mpl:: - integral_c< value_type, value - >.
    - -

    The Integral Constant prototype also adds the following operations:

    - - - - - - - - - - - - - - - - - - - -
    Optional Operations of the MPL-Compatible Masking Types
    Operation (with n as a masking type)Meaning
    boost::mpl::next< n >::typeboost::mpl::next< n::type >::type, i.e. - boost::mpl::integral_c< n::value_type, n::value + 1 - >.
    boost::mpl::prior< n >::typeboost::mpl::prior< n::type >::type, i.e. - boost::mpl::integral_c< n::value_type, n::value - 1 - >.
    n::value_type const c = n();c is set to n::value.
    - -

    The specifics for each masking class template are:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Criteria for the MPL-Compatible Masking Types
    - (Everything besides the parameter ID is in name-space - boost except where indicated.)
    Class TemplateParameter Member IDClassic EquivalentValue TypeValueValid Range
    integer_hi_maskbit_offsethigh_bit_mask_tsized_integral < bit_offset + 1, unsigned >2bit_offset0 <= bit_offset < std::numeric_limits< uintmax_t >::digits
    integer_lo_maskbit_countlow_bits_mask_tsized_integral < bit_count, unsigned >2bit_offset - 10 <= bit_count <= std::numeric_limits< uintmax_t >::digits
    +

    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>
    +#include <boost/integer/integer_mask.hpp>
     
     //...
     
    @@ -367,7 +200,7 @@ href="http://www.boost.org/people/daryle_walker.html">Daryle Walker.


    -

    Revised July 29, 2008

    +

    Revised September 23, 2001

    © Copyright Daryle Walker 2001. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file header. (John Maddock) // 30 Jul 00 Add typename syntax fix (Jens Maurer) @@ -23,357 +17,108 @@ #include // self include -#include // for BOOST_STATIC_CONSTANT, etc. -#include // for boost::uintmax_t, intmax_t -#include // for boost::integer_traits -#include // for std::numeric_limits -#include // for boost::enable_if_c - -#include // for BOOST_HAS_XINT, etc. - -#include // for UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, etc. +#include // for boost::integer_traits +#include // for std::numeric_limits namespace boost { - // integer template mapping a type to its processor-optimized analog -----// - - // Some types can be handled better by the processor than others. This - // template metafunction should map various built-in integral types to - // the processor's perferred type for the given type's value range - template < typename BaseInt > - struct fast_integral - { - typedef BaseInt type; - }; - - // Platform-specific specializations should go here. + // Helper templates ------------------------------------------------------// // fast integers from least integers // int_fast_t<> works correctly for unsigned too, in spite of the name. template< typename LeastInt > - struct int_fast_t { typedef typename fast_integral::type fast; }; + struct int_fast_t { typedef LeastInt fast; }; // imps may specialize -namespace detail -{ + // convert category to type + template< int Category > struct int_least_helper {}; // default is empty - // Helper templates ------------------------------------------------------// - - // convert integer category to type ; default is empty - template< int Rank, typename Signedness > struct int_least_helper {}; - - // specializatons: 1=(unsigned) __int64/long long, 2=(unsigned) long, - // 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char - // no specializations for 0: requests for a type > (unsigned) (long) long are - // in error -#if BOOST_HAS_XINT - template<> struct int_least_helper<1, signed> { typedef xint_t least; }; - template<> struct int_least_helper<1, unsigned> { typedef uxint_t least; }; -#endif - template<> struct int_least_helper<2, signed> { typedef long least; }; - template<> struct int_least_helper<2, unsigned> - { typedef unsigned long least; }; - template<> struct int_least_helper<3, signed> { typedef int least; }; - template<> struct int_least_helper<3, unsigned> - { typedef unsigned int least; }; - template<> struct int_least_helper<4, signed> { typedef short least; }; - template<> struct int_least_helper<4, unsigned> - { typedef unsigned short least; }; - template<> struct int_least_helper<5, signed> { typedef signed char least; }; - template<> struct int_least_helper<5, unsigned> - { typedef unsigned char least; }; - - // category bounds - enum - { -#if BOOST_HAS_XINT - lowest_integral_rank = 1, -#else - lowest_integral_rank = 2, -#endif - highest_integral_rank = 5 - }; - - // map a bit count to a category - template < int BitsIncludingSign > - struct int_rank_helper - { - BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 ); -#if BOOST_HAS_XINT - BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits< - xint_t >::digits) ); -#else - BOOST_STATIC_CONSTANT( int, extended_ = 1 ); -#endif - BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * (extended_ + - (mantissa <= std::numeric_limits< long >::digits) + - (mantissa <= std::numeric_limits< int >::digits) + - (mantissa <= std::numeric_limits< short >::digits) + - (mantissa <= std::numeric_limits< signed char >::digits)) ); - }; - - template < int Bits > - struct uint_rank_helper - { -#if BOOST_HAS_XINT - BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits< - uxint_t >::digits) ); -#else - BOOST_STATIC_CONSTANT( int, extended_ = 1 ); -#endif - BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * (extended_ + - (Bits <= std::numeric_limits< unsigned long >::digits) + - (Bits <= std::numeric_limits< unsigned int >::digits) + - (Bits <= std::numeric_limits< unsigned short >::digits) + - (Bits <= std::numeric_limits< unsigned char >::digits)) ); - }; - - template < int BitsIncludingSign > - struct int_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); }; - template < int Bits > - struct uint_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); }; - -#define BOOST_PRIVATE_INT_EXACT_BUILDER(Type, Rank) \ - template < > \ - struct int_exact_rank_helper::digits + 1> \ - { BOOST_STATIC_CONSTANT( int, rank = Rank ); } -#define BOOST_PRIVATE_UINT_EXACT_BUILDER(Type, Rank) \ - template < > \ - struct uint_exact_rank_helper::digits> \ - { BOOST_STATIC_CONSTANT( int, rank = Rank ); } - -#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) - BOOST_PRIVATE_INT_EXACT_BUILDER( xint_t, 1 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( uxint_t, 1 ); -#endif -#if ULONG_MAX > UINT_MAX - BOOST_PRIVATE_INT_EXACT_BUILDER( long, 2 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned long, 2 ); -#endif -#if UINT_MAX > USHRT_MAX - BOOST_PRIVATE_INT_EXACT_BUILDER( int, 3 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned, 3 ); -#endif -#if USHRT_MAX > UCHAR_MAX - BOOST_PRIVATE_INT_EXACT_BUILDER( short, 4 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned short, 4 ); -#endif - BOOST_PRIVATE_INT_EXACT_BUILDER( signed char, 5 ); - BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned char, 5 ); - -#undef BOOST_PRIVATE_INT_EXACT_BUILDER -#undef BOOST_PRIVATE_UINT_EXACT_BUILDER - - // map an extreme value to a category - template < intmax_t MaxValue > - struct int_max_rank_helper - { -#if BOOST_HAS_XINT - BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <= - boost::integer_traits< xint_t >::const_max) ); -#else - BOOST_STATIC_CONSTANT( int, extended_ = 1 ); -#endif - BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ + - (MaxValue <= boost::integer_traits< long >::const_max) + - (MaxValue <= boost::integer_traits< int >::const_max) + - (MaxValue <= boost::integer_traits< short >::const_max) + - (MaxValue <= boost::integer_traits< signed char >::const_max)) ); - }; - - template < intmax_t MinValue > - struct int_min_rank_helper - { -#if BOOST_HAS_XINT - BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >= - boost::integer_traits< xint_t >::const_min) ); -#else - BOOST_STATIC_CONSTANT( int, extended_ = 1 ); -#endif - BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ + - (MinValue >= boost::integer_traits< long >::const_min) + - (MinValue >= boost::integer_traits< int >::const_min) + - (MinValue >= boost::integer_traits< short >::const_min) + - (MinValue >= boost::integer_traits< signed char >::const_min)) ); - }; - - template < uintmax_t Value > - struct uint_max_rank_helper - { -#if BOOST_HAS_XINT - BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits< - uxint_t >::const_max) ); -#else - BOOST_STATIC_CONSTANT( int, extended_ = 1 ); -#endif - BOOST_STATIC_CONSTANT( int, rank = extended_ + - (Value <= boost::integer_traits< unsigned long >::const_max) + - (Value <= boost::integer_traits< unsigned int >::const_max) + - (Value <= boost::integer_traits< unsigned short >::const_max) + - (Value <= boost::integer_traits< unsigned char >::const_max) ); - }; - - // convert rank to type, Boost.MPL-style - template < int Rank, typename Signedness, class Enable = void > - struct integral_rank_to_type - { - BOOST_STATIC_CONSTANT( bool, is_specialized = false ); - // No "signed" nor "type" here - }; - - template < int Rank > - struct integral_rank_to_type< Rank, signed, typename - enable_if_c<(lowest_integral_rank <= Rank) && (Rank <= - highest_integral_rank)>::type > - { - BOOST_STATIC_CONSTANT( bool, is_specialized = true ); - BOOST_STATIC_CONSTANT( bool, is_signed = true ); - typedef typename int_least_helper< Rank, signed >::least type; - }; - - template < int Rank > - struct integral_rank_to_type< Rank, unsigned, typename - enable_if_c<(lowest_integral_rank <= Rank) && (Rank <= - highest_integral_rank)>::type > - { - BOOST_STATIC_CONSTANT( bool, is_specialized = true ); - BOOST_STATIC_CONSTANT( bool, is_signed = false ); - typedef typename int_least_helper< Rank, unsigned >::least type; - }; - -} // namespace detail - - // MPL-compatible integer-mapping class templates ------------------------// - - // minimum number of bits - template < int Bits, typename Signedness > - struct sized_integral - { - BOOST_STATIC_CONSTANT( bool, is_specialized = false ); - BOOST_STATIC_CONSTANT( int, bit_count = Bits ); - }; - - template < int BitsIncludingSign > - struct sized_integral< BitsIncludingSign, signed > - : detail::integral_rank_to_type< - detail::int_rank_helper::rank, signed > - { - BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign ); - }; - - template < int Bits > - struct sized_integral< Bits, unsigned > - : detail::integral_rank_to_type< - detail::uint_rank_helper::rank, unsigned > - { - BOOST_STATIC_CONSTANT( int, bit_count = Bits ); - }; - - // exact number of bits - template < int Bits, typename Signedness > - struct exact_integral - { - BOOST_STATIC_CONSTANT( bool, is_specialized = false ); - BOOST_STATIC_CONSTANT( int, bit_count = Bits ); - }; - - template < int BitsIncludingSign > - struct exact_integral< BitsIncludingSign, signed > - : detail::integral_rank_to_type< - detail::int_exact_rank_helper::rank, signed > - { - BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign ); - }; - - template < int Bits > - struct exact_integral< Bits, unsigned > - : detail::integral_rank_to_type< - detail::uint_exact_rank_helper::rank, unsigned > - { - BOOST_STATIC_CONSTANT( int, bit_count = Bits ); - }; - - // maximum supported (positive) value, signed - template < intmax_t MaxValue > - struct maximum_signed_integral - : detail::integral_rank_to_type< - detail::int_max_rank_helper::rank, signed > - { - BOOST_STATIC_CONSTANT( intmax_t, bound = MaxValue ); - }; - - // minimum supported (negative) value - template < intmax_t MinValue > - struct minimum_signed_integral - : detail::integral_rank_to_type< - detail::int_min_rank_helper::rank, signed > - { - BOOST_STATIC_CONSTANT( intmax_t, bound = MinValue ); - }; - - // maximum supported (nonnegative) value, unsigned - template < uintmax_t Value > - struct maximum_unsigned_integral - : detail::integral_rank_to_type< - detail::uint_max_rank_helper::rank, unsigned > - { - BOOST_STATIC_CONSTANT( uintmax_t, bound = Value ); - }; + // specializatons: 1=long, 2=int, 3=short, 4=signed char, + // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char + // no specializations for 0 and 5: requests for a type > long are in error + template<> struct int_least_helper<1> { typedef long least; }; + template<> struct int_least_helper<2> { typedef int least; }; + template<> struct int_least_helper<3> { typedef short least; }; + template<> struct int_least_helper<4> { typedef signed char least; }; + template<> struct int_least_helper<6> { typedef unsigned long least; }; + template<> struct int_least_helper<7> { typedef unsigned int least; }; + template<> struct int_least_helper<8> { typedef unsigned short least; }; + template<> struct int_least_helper<9> { typedef unsigned char least; }; // integer templates specifying number of bits ---------------------------// // signed - template< int Bits > // minimum bits (including sign) required + template< int Bits > // bits (including sign) required struct int_t { - typedef typename sized_integral::type least; - typedef typename int_fast_t::fast fast; - }; - - template< int Bits > // exact bits (including sign) desired - struct int_exact_t - { - typedef typename exact_integral::type exact; + typedef typename int_least_helper + < + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + >::least least; + typedef typename int_fast_t::fast fast; }; // unsigned - template< int Bits > // minimum bits required + template< int Bits > // bits required struct uint_t { - typedef typename sized_integral::type least; - typedef typename int_fast_t::fast fast; + typedef typename int_least_helper + < + 5 + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + >::least least; + typedef typename int_fast_t::fast fast; // int_fast_t<> works correctly for unsigned too, in spite of the name. }; - template< int Bits > // exact bits desired - struct uint_exact_t - { - typedef typename exact_integral::type exact; - }; - // integer templates specifying extreme value ----------------------------// // signed - template< intmax_t MaxValue > // maximum value to require support + template< long MaxValue > // maximum value to require support struct int_max_value_t { - typedef typename maximum_signed_integral::type least; - typedef typename int_fast_t::fast fast; + typedef typename int_least_helper + < + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + >::least least; + typedef typename int_fast_t::fast fast; }; - template< intmax_t MinValue > // minimum value to require support + template< long MinValue > // minimum value to require support struct int_min_value_t { - typedef typename minimum_signed_integral::type least; - typedef typename int_fast_t::fast fast; + typedef typename int_least_helper + < + (MinValue >= integer_traits::const_min) + + (MinValue >= integer_traits::const_min) + + (MinValue >= integer_traits::const_min) + + (MinValue >= integer_traits::const_min) + >::least least; + typedef typename int_fast_t::fast fast; }; // unsigned - template< uintmax_t Value > // maximum value to require support + template< unsigned long Value > // maximum value to require support struct uint_value_t { - typedef typename maximum_unsigned_integral::type least; - typedef typename int_fast_t::fast fast; + typedef typename int_least_helper + < + 5 + + (Value <= integer_traits::const_max) + + (Value <= integer_traits::const_max) + + (Value <= integer_traits::const_max) + + (Value <= integer_traits::const_max) + >::least least; + typedef typename int_fast_t::fast fast; }; diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp index a334d64..0a092d3 100644 --- a/include/boost/integer/integer_mask.hpp +++ b/include/boost/integer/integer_mask.hpp @@ -12,192 +12,81 @@ #include // self include -#include // for BOOST_STATIC_CONSTANT -#include // for boost::uintmax_t -#include // for boost::sized_integral -#include // for std::numeric_limits -#include // for boost::mpl::and_ -#include // for boost::mpl::bitor_, shift_left -#include // for boost::mpl::true_ -#include // for boost::mpl::greater_equal, etc. -#include // for boost::mpl::empty_base -#include // for boost::mpl::if_ -#include // for boost::mpl::int_ -#include // for boost::integral_c -#include // for boost::mpl::next, prior -#include // for boost::enable_if +#include // for BOOST_STATIC_CONSTANT +#include // for boost::uint_t +#include // for UCHAR_MAX, etc. #include // for std::size_t +#include // for std::numeric_limits + namespace boost { -namespace detail -{ - -// Helper templates --------------------------------------------------------// - -template < int Bits > -struct hi_integer_mask_builder1 -{ - typedef boost::mpl::int_ bit_count_type; - - typedef typename boost::mpl::next::type - mask_length_type; - typedef boost::sized_integral - mask_type; - - typedef boost::mpl::integral_c one_type; - typedef boost::mpl::shift_left result_type; -}; - -template < int Bits > -struct hi_integer_mask_builder2 -{ - typedef boost::mpl::int_ bit_count_type; - - typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> > - lo_bound_type; - typedef boost::mpl::less< bit_count_type, - boost::mpl::int_::digits> > - hi_bound_type; - typedef boost::mpl::and_ count_valid_type; -}; - -template < int Bits, class Enable = void > -struct hi_integer_mask_builder3 -{ - BOOST_STATIC_CONSTANT( bool, is_specialized = false ); -}; - -template < int Bits > -struct hi_integer_mask_builder3< Bits, typename boost::enable_if::count_valid_type>::type > - : hi_integer_mask_builder1::result_type -{ - BOOST_STATIC_CONSTANT( bool, is_specialized = true ); -}; - -template < int Bits > -struct lo_integer_mask_builder1 -{ - typedef boost::mpl::int_ bit_count_type; - - typedef typename boost::mpl::prior::type - shift_length_type; - typedef boost::sized_integral - mask_type; - - typedef boost::mpl::integral_c one_type; - typedef boost::mpl::shift_left - high_bit_type; - typedef typename boost::mpl::prior::type low_bits_type; - typedef boost::mpl::bitor_ result_type; -}; - -template < > -struct lo_integer_mask_builder1< 0 > -{ - // Let's not deal with negative interim values.... - typedef boost::mpl::integral_c result_type; -}; - -template < int Bits > -struct lo_integer_mask_builder2 -{ - typedef boost::mpl::int_ bit_count_type; - - typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> > - lo_bound_type; - typedef boost::mpl::less_equal< bit_count_type, - boost::mpl::int_::digits> > - hi_bound_type; - typedef boost::mpl::and_ count_valid_type; -}; - -template < > -struct lo_integer_mask_builder2< 0 > -{ - typedef boost::mpl::true_ count_valid_type; -}; - -template < int Bits, class Enable = void > -struct lo_integer_mask_builder3 -{ - BOOST_STATIC_CONSTANT( bool, is_specialized = false ); - // No MPL Integral Constant to inherit from -}; - -template < int Bits > -struct lo_integer_mask_builder3< Bits, typename enable_if::count_valid_type>::type > - : lo_integer_mask_builder1::result_type -{ - BOOST_STATIC_CONSTANT( bool, is_specialized = true ); -}; - -} // namespace detail - - -// MPL-compatible integer mask class templates -----------------------------// - -// Displaced single-bit mask, 1 << Offset, 0 <= Offset < BitLengthOf(uintmax_t) -template < int Offset > -struct integer_hi_mask - : detail::hi_integer_mask_builder3 -{ - BOOST_STATIC_CONSTANT( int, bit_offset = Offset ); -}; - -// Lowest bit-group mask, 2**Length - 1, 0 <= Length <= BitLengthOf(uintmax_t) -template < int Length > -struct integer_lo_mask - : detail::lo_integer_mask_builder3 -{ - BOOST_STATIC_CONSTANT( int, bit_count = Length ); -}; // Specified single-bit mask class declaration -----------------------------// // (Lowest bit starts counting at 0.) template < std::size_t Bit > -class high_bit_mask_t +struct high_bit_mask_t { - typedef integer_hi_mask impl_type; + typedef typename uint_t<(Bit + 1)>::least least; + typedef typename uint_t<(Bit + 1)>::fast fast; -public: - typedef typename impl_type::value_type least; - typedef typename int_fast_t::fast fast; + BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) ); + BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) ); - BOOST_STATIC_CONSTANT( least, high_bit = impl_type::value ); - BOOST_STATIC_CONSTANT( fast, high_bit_fast = impl_type::value ); - - BOOST_STATIC_CONSTANT( std::size_t, bit_position = impl_type::bit_offset ); + BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit ); }; // boost::high_bit_mask_t // Specified bit-block mask class declaration ------------------------------// // Makes masks for the lowest N bits +// (Specializations are needed when N fills up a type.) template < std::size_t Bits > -class low_bits_mask_t +struct low_bits_mask_t { - typedef integer_lo_mask impl_type; + typedef typename uint_t::least least; + typedef typename uint_t::fast fast; -public: - typedef typename impl_type::value_type least; - typedef typename int_fast_t::fast fast; + BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) ); + BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); - BOOST_STATIC_CONSTANT( least, sig_bits = impl_type::value ); - BOOST_STATIC_CONSTANT( fast, sig_bits_fast = impl_type::value ); - - BOOST_STATIC_CONSTANT( std::size_t, bit_count = impl_type::bit_count ); + BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits ); }; // boost::low_bits_mask_t +#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \ + template < > struct low_bits_mask_t< std::numeric_limits::digits > { \ + typedef std::numeric_limits limits_type; \ + typedef uint_t::least least; \ + typedef uint_t::fast fast; \ + BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \ + BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \ + BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ + } + +BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); + +#if USHRT_MAX > UCHAR_MAX +BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short ); +#endif + +#if UINT_MAX > USHRT_MAX +BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); +#endif + +#if ULONG_MAX > UINT_MAX +BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); +#endif + +#undef BOOST_LOW_BITS_MASK_SPECIALIZE + + } // namespace boost diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 3ece2e3..33cfc99 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -9,12 +9,11 @@ #ifndef BOOST_INTEGER_FWD_HPP #define BOOST_INTEGER_FWD_HPP +#include // for UCHAR_MAX, etc. #include // for std::size_t -#include // for BOOST_NO_INTRINSIC_WCHAR_T, etc. -#include // for boost::uintmax_t, intmax_t - -#include // for BOOST_HAS_XINT, etc. +#include // for BOOST_NO_INTRINSIC_WCHAR_T +#include // for std::numeric_limits namespace boost @@ -25,13 +24,6 @@ namespace boost // Only has typedefs or using statements, with #conditionals -// ALERT: the forward declarations of items in need items -// from this header. That means that cannot #include this -// forwarding header, to avoid infinite recursion! One day, maybe -// boost::uintmax_t and boost::intmax_t could be segregated into their own -// header file (which can't #include this header), will use -// that header, and could refer to . - // From -----------------------------------------// @@ -73,73 +65,61 @@ template < > template < > class integer_traits< unsigned long >; -#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT +#ifdef ULLONG_MAX template < > - class integer_traits< ::boost::detail::xint_t >; + class integer_traits< ::boost::long_long_type>; template < > - class integer_traits< ::boost::detail::uxint_t >; + class integer_traits< ::boost::ulong_long_type >; #endif // From ------------------------------------------------// -template < typename BaseInt > - struct fast_integral; - template < typename LeastInt > struct int_fast_t; -template < int Bits, typename Signedness > - struct sized_integral; - -template < int Bits, typename Signedness > - struct exact_integral; - -template < intmax_t MaxValue > - struct maximum_signed_integral; - -template < intmax_t MinValue > - struct minimum_signed_integral; - -template < uintmax_t Value > - struct maximum_unsigned_integral; - template< int Bits > struct int_t; -template< int Bits > - struct int_exact_t; - template< int Bits > struct uint_t; -template< int Bits > - struct uint_exact_t; - -template< intmax_t MaxValue > +template< long MaxValue > struct int_max_value_t; -template< intmax_t MinValue > +template< long MinValue > struct int_min_value_t; -template< uintmax_t Value > +template< unsigned long Value > struct uint_value_t; // From -----------------------------------// -template < int Offset > - struct integer_hi_mask; - -template < int Length > - struct integer_lo_mask; - template < std::size_t Bit > - class high_bit_mask_t; + struct high_bit_mask_t; template < std::size_t Bits > - class low_bits_mask_t; + struct low_bits_mask_t; + +template < > + struct low_bits_mask_t< ::std::numeric_limits::digits >; + +#if USHRT_MAX > UCHAR_MAX +template < > + struct low_bits_mask_t< ::std::numeric_limits::digits >; +#endif + +#if UINT_MAX > USHRT_MAX +template < > + struct low_bits_mask_t< ::std::numeric_limits::digits >; +#endif + +#if ULONG_MAX > UINT_MAX +template < > + struct low_bits_mask_t< ::std::numeric_limits::digits >; +#endif // From ------------------------------------// diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 9be25ce..96b3526 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -27,8 +27,6 @@ #include #endif -#include // for BOOST_HAS_XINT, etc. - namespace boost { template @@ -157,28 +155,77 @@ class integer_traits public detail::integer_traits_base { }; -#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) +#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG) -#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3))) -// -// The following code emits warnings when built with -pedantic, and there appears -// to be no other way of suppressing these warnings as use of __extension__ has no -// effect, so declare the rest of this header a system header. +template<> +class integer_traits< ::boost::long_long_type> + : public std::numeric_limits< ::boost::long_long_type>, + public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX> +{ }; + +template<> +class integer_traits< ::boost::ulong_long_type> + : public std::numeric_limits< ::boost::ulong_long_type>, + public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX> +{ }; + +#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG) + +template<> +class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ }; +template<> +class integer_traits< ::boost::ulong_long_type> + : public std::numeric_limits< ::boost::ulong_long_type>, + public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX> +{ }; + +#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG) + +template<> +class integer_traits< ::boost::long_long_type> + : public std::numeric_limits< ::boost::long_long_type>, + public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX> +{ }; + +template<> +class integer_traits< ::boost::ulong_long_type> + : public std::numeric_limits< ::boost::ulong_long_type>, + public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX> +{ }; + +#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG) + +template<> +class integer_traits< ::boost::long_long_type> + : public std::numeric_limits< ::boost::long_long_type>, + public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX> +{ }; + +template<> +class integer_traits< ::boost::ulong_long_type> + : public std::numeric_limits< ::boost::ulong_long_type>, + public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX> +{ }; + +#elif defined(BOOST_HAS_LONG_LONG) // -# pragma GCC system_header +// we have long long but no constants, this happens for example with gcc in -ansi mode, +// we'll just have to work out the values for ourselves (assumes 2's compliment representation): +// +template<> +class integer_traits< ::boost::long_long_type> + : public std::numeric_limits< ::boost::long_long_type>, + public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))> +{ }; + +template<> +class integer_traits< ::boost::ulong_long_type> + : public std::numeric_limits< ::boost::ulong_long_type>, + public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL> +{ }; + #endif - -template<> -class integer_traits< detail::xint_t > - : public std::numeric_limits< detail::xint_t >, - public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX > -{ }; - -template<> -class integer_traits< detail::uxint_t > - : public std::numeric_limits< detail::uxint_t >, - public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX > -{ }; #endif } // namespace boost diff --git a/integer.htm b/integer.htm index 0130d7a..3d3f9c5 100644 --- a/integer.htm +++ b/integer.htm @@ -21,9 +21,8 @@ is particularly useful for solving generic programming problems.

    • Contents
    • Synopsis
    • -
    • Processor-Optimized Types
    • +
    • Easiest-to-Manipulate Types
    • Sized Types
    • -
    • MPL-Compatible Variants
    • Example
    • Demonstration Program
    • Rationale
    • @@ -33,145 +32,67 @@ is particularly useful for solving generic programming problems.

      Synopsis

      -
      -#include <boost/integer_fwd.hpp>  // forwarding header
      -#include <boost/cstdint.hpp>      // for boost::uintmax_t, intmax_t
      -
      -namespace boost
      +
      namespace boost
       {
         //  fast integers from least integers
      -  template< typename BaseInt >
      -  struct fast_integral
      -  {
      -      typedef implementation_supplied  type;
      -  };
      -
         template< typename LeastInt >
         struct int_fast_t
         {
      -      typedef typename fast_integral<LeastInt>::type  fast;
      -  };
      -
      -  //  MPL-compatible
      -  template< int Bits, typename Signedness >
      -  struct sized_integral
      -  {
      -      static  bool const  is_specialized = implementation_supplied;
      -      static  bool const  is_signed = implementation_supplied;
      -      static  int const   bit_count = Bits;
      -
      -      typedef implementation_supplied  type;
      -  };
      -
      -  template< int Bits, typename Signedness >
      -  struct exact_integral
      -  {
      -      static  bool const  is_specialized = implementation_supplied;
      -      static  bool const  is_signed = implementation_supplied;
      -      static  int const   bit_count = Bits;
      -
      -      typedef implementation_supplied  type;
      -  };
      -
      -  template< intmax_t MaxValue >
      -  struct maximum_signed_integral
      -  {
      -      static  bool const      is_specialized = implementation_supplied;
      -      static  bool const      is_signed = true;
      -      static  intmax_t const  bound = MaxValue;
      -
      -      typedef implementation_supplied  type;
      -  };
      -
      -  template< intmax_t MinValue >
      -  struct minimum_signed_integral
      -  {
      -      static  bool const      is_specialized = implementation_supplied;
      -      static  bool const      is_signed = true;
      -      static  intmax_t const  bound = MinValue;
      -
      -      typedef implementation_supplied  type;
      -  };
      -
      -  template< uintmax_t Value >
      -  struct maximum_unsigned_integral
      -  {
      -      static  bool const       is_specialized = implementation_supplied;
      -      static  bool const       is_signed = false;
      -      static  uintmax_t const  bound = Value;
      -
      -      typedef implementation_supplied  type;
      +      typedef implementation_supplied  fast;
         };
       
         //  signed
         template< int Bits >
         struct int_t 
         {
      -      typedef typename sized_integral<Bits, signed>::type  least;
      -      typedef int_fast_t<least>::fast                      fast;
      -  };
      -
      -  template< int Bits >
      -  struct int_exact_t
      -  {
      -      typedef typename exact_integral<Bits, signed>::type  exact;
      +      typedef implementation_supplied  least;
      +      typedef int_fast_t<least>::fast  fast;
         };
       
         //  unsigned
         template< int Bits >
         struct uint_t 
         {
      -      typedef typename sized_integral<Bits, unsigned>::type  least;
      -      typedef int_fast_t<least>::fast                        fast;
      -  };
      -
      -  template< int Bits >
      -  struct uint_exact_t
      -  {
      -      typedef typename exact_integral<Bits, unsigned>::type  exact;
      +      typedef implementation_supplied  least;
      +      typedef int_fast_t<least>::fast  fast;
         };
       
         //  signed
      -  template< intmax_t MaxValue >
      +  template< long MaxValue >
         struct int_max_value_t 
         {
      -      typedef typename maximum_signed_integral<MaxValue>::type  least;
      -      typedef int_fast_t<least>::fast                           fast;
      +      typedef implementation_supplied  least;
      +      typedef int_fast_t<least>::fast  fast;
         };
       
      -  template< intmax_t MinValue >
      +  template< long MinValue >
         struct int_min_value_t 
         {
      -      typedef typename minimum_signed_integral<MinValue>::type  least;
      -      typedef int_fast_t<least>::fast                           fast;
      +      typedef implementation_supplied  least;
      +      typedef int_fast_t<least>::fast  fast;
         };
       
         //  unsigned
      -  template< uintmax_t Value >
      +  template< unsigned long Value >
         struct uint_value_t 
         {
      -      typedef typename maximum_unsigned_integral<Value>::type  least;
      -      typedef int_fast_t<least>::fast                          fast;
      +      typedef implementation_supplied  least;
      +      typedef int_fast_t<least>::fast  fast;
         };
       } // namespace boost
       
      -

      Processor-Optimized Types

      +

      Easiest-to-Manipulate Types

      -

      The fast_integral class template maps its input type to the +

      The int_fast_t class template maps its input type to the next-largest type that the processor can manipulate the easiest, or to itself if the input type is already an easy-to-manipulate type. For instance, processing a bunch of char objects may go faster if they were converted to int objects before processing. -The input type, passed as the only template parameter, can be any built-in -integral type besides bool. The output type is given as the class -member type.

      - -

      The int_fast_t class template is the classic meta-function for -this operation. Despite the name, it works for unsigned integral types just -like it works for the signed integral types. The output type is given as the -class member fast, defined to be the same as the corresponding -result from the fast_integral meta-function.

      +The input type, passed as the only template parameter, must be a +built-in integral type, except bool. Unsigned integral +types can be used, as well as signed integral types, despite the name. +The output type is given as the class member fast.

      Implementation Notes
      By default, the output type is identical to the input type. Eventually, @@ -183,286 +104,72 @@ type.

      Sized Types

      -

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

      +

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

      - +
      - + - + + long. - - - - - + + 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. - - - - - + - + - +
      Criteria for the Sized Type Class Templates
      Class Template (all in name-space boost)Class Template Template Parameter Mapping
      int_tboost::int_t The smallest built-in signed integral type with at least the given number of bits, including the sign bit. The parameter - must be a positive number. A compile-time error results if + should be a positive number. A compile-time error results if the parameter is larger than the number of bits in a - boost::intmax_t.
      int_exact_tThe smallest built-in signed integral type with exactly the - given number of bits, including the sign bit. A compile-time error - results if no qualifying type exists.
      uint_tboost::uint_t The smallest built-in unsigned integral type with at least - the given number of bits. The parameter must be a - non-negative number. A compile-time error results if the parameter - is larger than the number of bits in a - boost::uintmax_t.
      uint_exact_tThe smallest built-in unsigned integral type with exactly the given - number of bits. A compile-time error results if no qualifying type - exists.
      int_max_value_tboost::int_max_value_t The smallest built-in signed integral type that supports the - given value as a maximum. The parameter must be a + given value as a maximum. The parameter should be a positive number.
      int_min_value_tboost::int_min_value_t The smallest built-in signed integral type that supports the - given value as a minimum. The parameter must be a + given value as a minimum. The parameter should be a negative number.
      uint_value_tboost::uint_value_t The smallest built-in unsigned integral type that supports the given value as a maximum. The parameter should be a positive number.
      -

      MPL-Compatible Variants

      - -

      The bit-length sized-type class templates have several drawbacks:

      - -
        -
      • You must know the valid bit-lengths in advance.
      • -
      • There is no way to inspect the parameter used after a size-type template - class is aliased.
      • -
      • Using an inappropriate parameter value results in a compiler - diagnostic.
      • -
      • The type names used are inconsistent with other transformations in - Boost, like in MPL.
      • -
      • The above two facts make use of the size-type class templates - incompatible with template meta-programming techniques.
      • -
      - -

      The sized_integral, exact_integral, -maximum_signed_integral, minimum_signed_integral, and -maximum_unsigned_integral class templates provide MPL-compatible -alternatives. These alternatives generally have the form:

      - -
      -template< SwitchType SwitchValue, typename Signedness >
      -struct name
      -{
      -    static  bool const         is_specialized = implementation_supplied;
      -    static  bool const         is_signed = implementation_supplied;
      -    static  SwitchType const   switch_id = SwitchValue;
      -
      -    typedef implementation_supplied  type;
      -};
      -
      - -

      Each member, if present, is defined by:

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Members in MPL-Compatible Class Templates
      Class Template MemberWhen DefinedMeaning
      is_specializedAlwaysFlag indicating when a particular template class instantiation is a - valid meta-function (true) or not (false).
      is_signedis_specialized == trueFlag indicating whether the signed-variant (true) or - the unsigned-variant (false) of the meta-function is - used. This is controlled by the Signedness template - parameter: - - - - - - - - - - - - - - - - - - -
      Effect of Signedness Setting
      Signedness Typeis_signed
      signedtrue
      unsignedfalse
      anything elsenot defined
      - The type used is a programmer mnemonic; the compiler cannot prevent - someone from using int or signed int - instead of signed, or unsigned int instead - of unsigned.
      switch_id (Actual name is template-specific.)AlwaysThe value of the main control parameter, accessible even if the - template class instantiation is aliased.
      typeis_specialized == trueThe meta-function's result. It appears only if the input parameters - satisfy the template's requirements. Its presence, or lack thereof, - enables "Substitution Failure Is Not An Error" (SFINAE) - techniques, instead of a hard compiler diagnostic.
      - -

      The exceptions are the extreme-value class templates -(maximum_signed_integral, minimum_signed_integral, and -maximum_unsigned_integral), which do not take a Signedness -template parameter because the meta-functions already inherently have signedness. - -

      The following table describes each template's criteria. The classic signed -and unsigned equivalents are the sized-type class templates that each -MPL-compatible class template emulates. (The setting of Signedness -controls the appropriate emulation.)

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Criteria for the MPL-Compatible Class Templates
      Class Template (all in name-space boost)Parameter Type (in name-space boost as needed)Parameter Member IDClassic EquivalentTemplate Parameter Mapping (when type is defined)
      SignedUnsigned
      sized_integralintbit_countint_tuint_tThe smallest built-in integral type with at least - bit_count bits (including the sign bit when - Signedness is signed). Not present if no - type qualifies.
      exact_integralintbit_countint_exact_tuint_exact_tThe smallest built-in integral type with exactly - bit_count bits (including the sign bit when - Signedness is signed). Not present if no - type qualifies.
      maximum_signed_integralintmax_tboundint_max_value_tThe smallest built-in integral type that can perserve the value in - bound. Not present if bound is non-positive.It is possible for a type to be absent if - a platform supports really-extended integral types (beyond long - long or __int64), support for those types goes - into <boost/cstdint.hpp>, - but said support hadn't yet been added to <boost/integer.hpp>
      minimum_signed_integralintmax_tboundint_min_value_tThe smallest built-in integral type that can perserve the value in - bound. Not present if bound is non-negative.
      maximum_unsigned_integraluintmax_tbounduint_value_tThe smallest built-in integral type that can perserve the value in - bound. Should always be present.
      -

      Example

      -
      -#include <boost/integer.hpp>
      -#include <boost/mpl/int.hpp>
      -#include <iostream>
      -#include <ostream>
      -
      -//...
      -
      -template < int Bits >
      -bool
      -fit_exactly( boost::mpl::int_<Bits> const &x,
      - typename boost::exact_integral<Bits, signed>::type *unused = 0 )
      -{
      -    return true;
      -}
      -
      -template < typename T >
      -bool
      -fit_exactly( T const &x )
      -{
      -    return false;
      -}
      +
      #include <boost/integer.hpp>
       
       //...
       
       int main()
       {
      -    typedef boost::mpl::int_<24>  twenty_four;
      -
      -    boost::int_t<twenty_four::value>::least my_var;
      -
      -    //...
      -
      -    std::cout << "my_var " << ( fit_exactly(twenty_four()) ? "does" :
      -     "does not" ) << " fit its type exactly." << std::endl;
      -
      +    boost::int_t<24>::least my_var;
           //...
       }
       

      Demonstration Program

      -

      The program integer_test.cpp is a +

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

      @@ -491,11 +198,11 @@ to Valentin Bonnard and Kevlin Henney for sharing their designs for similar templates. Daryle Walker designed the -exact and value-based sized templates, and the MPL-compatible templates.

      +value-based sized templates.


      -

      Revised July 16, 2008

      +

      Revised May 20, 2001

      © Copyright Beman Dawes 1999. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file

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

      Acknowledgements

      diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 50fceee..1609bf5 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,5 +16,5 @@ test-suite integer /boost/test//boost_test_exec_monitor/static ] [ run static_min_max_test.cpp /boost/test//boost_test_exec_monitor/static ] - [ compile issue_2134.cpp ] +# [ compile issue_2134.cpp ] ; diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index c3a0854..38f5211 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -8,149 +8,103 @@ // See http://www.boost.org for most recent version including documentation. // Revision History -// 29 Jul 2008 Added MPL-compatible variants of the integer-mask templates. -// (Daryle Walker) -// 27 Jul 2008 Changed tests to use the unit-test system; added -// extended-integer support. (Daryle Walker) // 23 Sep 2001 Initial version (Daryle Walker) -#define BOOST_TEST_MODULE "Integer mask tests" -#include // unit testing framework +#include // for main -#include // for boost::uintmax_t +#include // for boost::exit_success #include // for boost::high_bit_mask_t, etc. -#include // for std::numeric_limits -#include // for BOOST_MPL_ASSERT_RELATION,etc. -#include // for boost::mpl::bool_ -#include // for boost::mpl::bitor_, shift_left -#include // for boost::mpl::equal_to -#include // for boost::mpl::int_ -#include // for boost::mpl::integral_c -#include // for boost::mpl::prior -#include // for boost::mpl::range_c -#include // for std::size_t -#include // for std::hex +#include // for std::cout (std::endl indirectly) -// Custom types/templates, helper functions, and objects -namespace +#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ + (v) >::high_bit == (1ul << (v)) ); +#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ + (v) >::high_bit_fast == (1ul << (v)) ); +#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ + PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) + +#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ + (v) >::sig_bits == ((1ul << (v)) - 1) ); +#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ + (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); +#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ + PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) + + +int test_main( int, char*[] ) { + using std::cout; + using std::endl; -// List the ranges of template parameters tests (ranges are half-open) -int const max_offset = std::numeric_limits::digits; + cout << "Doing high_bit_mask_t tests." << endl; + PRIVATE_HIGH_BIT_TEST( 31 ); + PRIVATE_HIGH_BIT_TEST( 30 ); + PRIVATE_HIGH_BIT_TEST( 29 ); + PRIVATE_HIGH_BIT_TEST( 28 ); + PRIVATE_HIGH_BIT_TEST( 27 ); + PRIVATE_HIGH_BIT_TEST( 26 ); + PRIVATE_HIGH_BIT_TEST( 25 ); + PRIVATE_HIGH_BIT_TEST( 24 ); + PRIVATE_HIGH_BIT_TEST( 23 ); + PRIVATE_HIGH_BIT_TEST( 22 ); + PRIVATE_HIGH_BIT_TEST( 21 ); + PRIVATE_HIGH_BIT_TEST( 20 ); + PRIVATE_HIGH_BIT_TEST( 19 ); + PRIVATE_HIGH_BIT_TEST( 18 ); + PRIVATE_HIGH_BIT_TEST( 17 ); + PRIVATE_HIGH_BIT_TEST( 16 ); + PRIVATE_HIGH_BIT_TEST( 15 ); + PRIVATE_HIGH_BIT_TEST( 14 ); + PRIVATE_HIGH_BIT_TEST( 13 ); + PRIVATE_HIGH_BIT_TEST( 12 ); + PRIVATE_HIGH_BIT_TEST( 11 ); + PRIVATE_HIGH_BIT_TEST( 10 ); + PRIVATE_HIGH_BIT_TEST( 9 ); + PRIVATE_HIGH_BIT_TEST( 8 ); + PRIVATE_HIGH_BIT_TEST( 7 ); + PRIVATE_HIGH_BIT_TEST( 6 ); + PRIVATE_HIGH_BIT_TEST( 5 ); + PRIVATE_HIGH_BIT_TEST( 4 ); + PRIVATE_HIGH_BIT_TEST( 3 ); + PRIVATE_HIGH_BIT_TEST( 2 ); + PRIVATE_HIGH_BIT_TEST( 1 ); + PRIVATE_HIGH_BIT_TEST( 0 ); -typedef boost::mpl::range_c high_bit_offsets; -typedef boost::mpl::range_c low_bit_lengths; -typedef boost::mpl::range_c special_low_bit_lengths; + cout << "Doing low_bits_mask_t tests." << endl; + PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops! + PRIVATE_LOW_BITS_TEST( 31 ); + PRIVATE_LOW_BITS_TEST( 30 ); + PRIVATE_LOW_BITS_TEST( 29 ); + PRIVATE_LOW_BITS_TEST( 28 ); + PRIVATE_LOW_BITS_TEST( 27 ); + PRIVATE_LOW_BITS_TEST( 26 ); + PRIVATE_LOW_BITS_TEST( 25 ); + PRIVATE_LOW_BITS_TEST( 24 ); + PRIVATE_LOW_BITS_TEST( 23 ); + PRIVATE_LOW_BITS_TEST( 22 ); + PRIVATE_LOW_BITS_TEST( 21 ); + PRIVATE_LOW_BITS_TEST( 20 ); + PRIVATE_LOW_BITS_TEST( 19 ); + PRIVATE_LOW_BITS_TEST( 18 ); + PRIVATE_LOW_BITS_TEST( 17 ); + PRIVATE_LOW_BITS_TEST( 16 ); + PRIVATE_LOW_BITS_TEST( 15 ); + PRIVATE_LOW_BITS_TEST( 14 ); + PRIVATE_LOW_BITS_TEST( 13 ); + PRIVATE_LOW_BITS_TEST( 12 ); + PRIVATE_LOW_BITS_TEST( 11 ); + PRIVATE_LOW_BITS_TEST( 10 ); + PRIVATE_LOW_BITS_TEST( 9 ); + PRIVATE_LOW_BITS_TEST( 8 ); + PRIVATE_LOW_BITS_TEST( 7 ); + PRIVATE_LOW_BITS_TEST( 6 ); + PRIVATE_LOW_BITS_TEST( 5 ); + PRIVATE_LOW_BITS_TEST( 4 ); + PRIVATE_LOW_BITS_TEST( 3 ); + PRIVATE_LOW_BITS_TEST( 2 ); + PRIVATE_LOW_BITS_TEST( 1 ); -// List a range with out-of-service values -typedef boost::mpl::range_c wild_bit_lengths; - -// Use SFINAE to check if a particular parameter is supported -template < typename ValueT, template class Tmpl, ValueT Value > -bool -print_out_template( Tmpl const &, ValueT setting, char const - *template_name, typename Tmpl::type *unused = 0 ) -{ - // Too bad the type-id expression couldn't use the compact form "*unused", - // but type-ids of dereferenced null pointers throw by order of C++ 2003, - // sect. 5.2.8, para. 2 (although the result is not conceptually needed). - BOOST_TEST_MESSAGE( "There is an " << template_name << "<" << setting << - "> specialization with type '" << typeid(typename - Tmpl::value_type).name() << "' and value '" << std::hex << - Tmpl::value << "'." ); - return true; + return boost::exit_success; } - -template < typename ValueT, typename T > -bool -print_out_template( T const &, ValueT setting, char const *template_name ) -{ - BOOST_TEST_MESSAGE( "There is no " << template_name << "<" << setting << - "> specialization." ); - return false; -} - -} // unnamed namespace - - -// Check the various integer-valued bit-masks -BOOST_AUTO_TEST_SUITE( integer_mask_tests ) - -// Check the bit-masks of one offset bit -BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets ) -{ - typedef boost::mpl::integral_c::least, 1u> one_type; - typedef boost::mpl::shift_left result_type; - - BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit, ==, - result_type::value ); - BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t::high_bit_fast, - ==, result_type::value ); -} - -// Check the bit-masks of a block of low-valued bits, non-zero block-lengths -BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, special_low_bit_lengths ) -{ - // One can express (2^x - 1) in two ways - // 1. (1 << x) - 1 - // 2. (1 << (x-1)) | ((1 << (x-1)) - 1) - // Since unsigneds have modulo arithmetic, [1] gives the right answer even - // when x is the number of bits in the register. However, that last case - // gives warnings about the sole bit flowing past the register. Applying - // distributive property backwards gives [2], which works without overflow. - typedef typename boost::mpl::prior::type shift_type; - typedef boost::mpl::integral_c::least, 1u> one_type; - typedef boost::mpl::shift_left high_bit_type; - typedef typename boost::mpl::prior::type low_bits_type; - typedef boost::mpl::bitor_ result_type; - - BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits, ==, - result_type::value ); - BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t::sig_bits_fast, - ==, result_type::value ); -} - -// Check the bit-masks of a block of low-valued bits, zero block-length -BOOST_AUTO_TEST_CASE( special_low_bits_mask_test ) -{ - // Just like "low_bits_mask_test" above, except that the shifts are negative - // when the bit-count is zero. That causes a lot of warnings and errors, so - // special-case that bit-count. - BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<0u>::sig_bits, ==, 0 ); - BOOST_MPL_ASSERT_RELATION(boost::low_bits_mask_t<0u>::sig_bits_fast, ==, 0); -} - -// Check the specialization type status of given bit-offsets/lengths -BOOST_AUTO_TEST_CASE_TEMPLATE( confirm_bounds_test, T, wild_bit_lengths ) -{ - typedef boost::integer_hi_mask hi_type; - typedef boost::mpl::int_ hi_offset_type; - typedef boost::mpl::bool_ special_hi_type; - - BOOST_MPL_ASSERT( (boost::mpl::equal_to< hi_offset_type, T >) ); - BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_hi_type, - boost::mpl::bool_<(T::value >= 0) && (T::value < max_offset)> >) ); - BOOST_CHECK_EQUAL( print_out_template(hi_type(), hi_offset_type::value, - "integer_hi_mask"), special_hi_type::value ); - - typedef boost::integer_lo_mask lo_type; - typedef boost::mpl::int_ lo_length_type; - typedef boost::mpl::bool_ special_lo_type; - - BOOST_MPL_ASSERT( (boost::mpl::equal_to< lo_length_type, T >) ); - BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_lo_type, - boost::mpl::bool_<(T::value >= 0) && (T::value <= max_offset)> >) ); - BOOST_CHECK_EQUAL( print_out_template(lo_type(), lo_length_type::value, - "integer_lo_mask"), special_lo_type::value ); -} - -BOOST_AUTO_TEST_SUITE_END() - -// Verification of bugs and their fixes -BOOST_AUTO_TEST_SUITE( bug_fix_tests ) - -BOOST_AUTO_TEST_SUITE_END() diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 3749183..6bfff11 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -4,666 +4,288 @@ // 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 -// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value- -// based integer templates. (Daryle Walker) -// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of -// processor-optimized integer template. (Daryle Walker) -// 14 Jul 08 Improved testing of processor-optimized integer template; added -// extended-integer support. (Daryle Walker) -// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker) -// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker) // 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 -#define BOOST_TEST_MODULE "Integer size-selection tests" +#include // for main, BOOST_CHECK -#include // unit testing framework +#include // for BOOST_NO_USING_TEMPLATE +#include // for boost::exit_success +#include // for boost::int_t, boost::uint_t -#include // for BOOST_NO_SFINAE -#include // for boost::uintmax_t, intmax_t -#include // for boost::int_t, boost::uint_t, etc. -#include // for boost::integer_traits -#include // for std::numeric_limits - -#include // BOOST_HAS_XINT, BOOST_UXINT_MAX - -#include // for boost::mpl::plus, divides -#include // for BOOST_MPL_ASSERT_RELATION, etc. -#include // for boost::mpl::back -#include // for boost::mpl::copy -#include // for boost::mpl::equal -#include // for boost::mpl::front_inserter -#include // for boost::mpl::int_ -#include // for boost::mpl::integral_c -#include // for boost::mpl::joint_view -#include // for boost::mpl::pop_back -#include // for boost::mpl::push_back -#include // for boost::mpl::push_front -#include // for boost::mpl::range_c -#include // for boost::mpl::shift_right -#include // for boost::mpl::sort -#include // for boost::mpl::transform -#include // for boost::mpl::transform_view -#include // for boost::mpl::unpack_args -#include // for boost::mpl::vector -#include // for boost::mpl::zip_view - -#include // for boost::is_same -#include // for boost::make_signed - -#include // for std::binary_search -#include // for ULONG_MAX, LONG_MAX, LONG_MIN, etc. -#include // for std::size_t -#include // for std::type_info +#include // for ULONG_MAX, LONG_MAX, LONG_MIN +#include // for std::cout (std::endl indirectly) +#include // for std::type_info -// Control what the "fast" specialization of "short" is -#ifndef CONTROL_FAST_SHORT -#define CONTROL_FAST_SHORT long -#endif - -// Control if every potential bit-count is used, or only a selection -// For me, full counts increase compile time from 90 seconds to 20 minutes! -#ifndef CONTROL_FULL_COUNTS -#define CONTROL_FULL_COUNTS 1 +// 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. If there -// is a specialization for "short," make sure that CONTROL_FAST_SHORT -// is set to a type distinct from "short" and the default implementation. +// the effects of the "fast" types by making a specialization. namespace boost { template < > - struct fast_integral< short > + struct int_fast_t< short > { - typedef CONTROL_FAST_SHORT type; + typedef long fast; }; } -// Custom types/templates, helper functions, and objects -namespace -{ - -// List the built-in integral types, excluding the ones that are strong-typedefs -// of a lower type. -typedef boost::mpl::vector< - unsigned char -#if USHRT_MAX > UCHAR_MAX - , unsigned short -#endif -#if UINT_MAX > USHRT_MAX - , unsigned int -#endif -#if ULONG_MAX > UINT_MAX - , unsigned long -#endif -#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) - , boost::detail::uxint_t -#endif -> distinct_unsigned_types; - -typedef boost::mpl::transform< - distinct_unsigned_types, - boost::make_signed< boost::mpl::_1 > ->::type distinct_signed_types; - -// List the digit counts for each integral type -template < typename T > -struct digits_of - : boost::mpl::int_< std::numeric_limits::digits > -{ -}; - -typedef boost::mpl::transform< - distinct_unsigned_types, - digits_of< boost::mpl::_1 > ->::type distinct_integral_bit_counts; - -// Make list of bit counts between each offical point, plus CHAR_BIT/2 -typedef boost::mpl::transform_view< - boost::mpl::zip_view< - boost::mpl::vector< - boost::mpl::push_front< - boost::mpl::pop_back< distinct_integral_bit_counts >::type, - boost::mpl::integral_c< int, 0 > - >::type, - distinct_integral_bit_counts - > - >, - boost::mpl::unpack_args< - boost::mpl::divides< - boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >, - boost::mpl::integral_c< int, 2 > - > - > -> median_bit_counts; - -// Maximum number of bits allowed -typedef std::numeric_limits intmax_limits; -typedef std::numeric_limits uintmax_limits; - -int const intmax_bits = intmax_limits::digits + 1; -int const uintmax_bits = uintmax_limits::digits; - -// Make master lists including an outlier beyond all valid bit counts -#if CONTROL_FULL_COUNTS -typedef boost::mpl::range_c bits_list; +// 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 -typedef boost::mpl::sort< - boost::mpl::copy< - boost::mpl::joint_view< - distinct_integral_bit_counts, - median_bit_counts - >, - boost::mpl::front_inserter< - boost::mpl::vector< - boost::mpl::integral_c - > - > - >::type ->::type bits_list; +#define SHOW_TYPE(Template, Number, Type) #endif -// Remove the outlier when all bits counts must be valid -#if CONTROL_FULL_COUNTS -typedef boost::mpl::range_c valid_bits_list; +#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 -typedef boost::mpl::pop_back::type valid_bits_list; +#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 -// Replace the minimum bit count with one more, so right-shifting by a stored -// value doesn't give an invalid result -#if CONTROL_FULL_COUNTS -typedef boost::mpl::range_c - valid_to_decrease_bits_list; +#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 -typedef valid_bits_list valid_to_decrease_bits_list; + using namespace boost; #endif -// Replace the maximum bit count with one less, so left-shifting by a stored -// value doesn't give an invalid result -#if CONTROL_FULL_COUNTS -typedef boost::mpl::range_c valid_to_increase_ubits_list; -#else -typedef boost::mpl::push_back< - boost::mpl::pop_back< valid_bits_list >::type, - boost::mpl::integral_c< int, uintmax_bits - 1 > ->::type valid_to_increase_ubits_list; -#endif - -// Do it again for signed types since they have one-less bit to use for the -// mantissa (don't want to shift into the sign bit) -#if CONTROL_FULL_COUNTS -typedef boost::mpl::range_c - valid_to_increase_sbits_list; -#else -typedef boost::mpl::push_back< - boost::mpl::pop_back< valid_bits_list >::type, - boost::mpl::integral_c< int, intmax_bits - 3 > ->::type valid_to_increase_sbits_list; -#endif - -// List the digit counts for each integral type, this time as an object, an -// array working as a sorted list -int const integral_bit_lengths[] = { - std::numeric_limits< unsigned char >::digits -#if USHRT_MAX > UCHAR_MAX - , std::numeric_limits< unsigned short >::digits -#endif -#if UINT_MAX > USHRT_MAX - , std::numeric_limits< unsigned int >::digits -#endif -#if ULONG_MAX > UINT_MAX - , std::numeric_limits< unsigned long >::digits -#endif -#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX) - , std::numeric_limits< boost::detail::uxint_t >::digits -#endif -}; - -std::size_t const integral_type_count = sizeof(integral_bit_lengths) / - sizeof(integral_bit_lengths[0]); - -// "Template-typedefs" to reduce two-argument templates to single-argument. -// This way, all the MPL-compatible templates have the same form, for below. -template < int Bits > -struct signed_sized_integral : boost::sized_integral {}; - -template < int Bits > -struct unsigned_sized_integral : boost::sized_integral {}; - -template < int Bits > -struct signed_exact_integral : boost::exact_integral {}; - -template < int Bits > -struct unsigned_exact_integral : boost::exact_integral {}; - -// Use SFINAE to check if a particular parameter is supported -#ifndef BOOST_NO_SFINAE -template < typename ValueT, template class Tmpl, ValueT Value > -bool -print_out_template( Tmpl const &, ValueT setting, char const - *template_pre_name, char const *template_post_name, typename Tmpl::type - *unused = 0 ) -{ - // Too bad the type-id expression couldn't use the compact form "*unused", - // but type-ids of dereferenced null pointers throw by order of C++ 2003, - // sect. 5.2.8, para. 2 (although the result is not conceptually needed). - BOOST_TEST_MESSAGE( "This is " << template_pre_name << setting - << template_post_name << " specialization, with type '" << typeid(typename - Tmpl::type).name() << "'." ); - return true; + 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; } - -template < typename ValueT, typename T > -bool -print_out_template( T const &, ValueT setting, char const *template_pre_name, - char const *template_post_name ) -{ - BOOST_TEST_MESSAGE( "Looking for " << template_pre_name << setting - << template_post_name << " specialization? It doesn't exist." ); - return false; -} -#else -#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error" -#endif - -// Get the extreme values for each integral type -template < typename T > -struct minimum_of - : boost::mpl::integral_c< T, boost::integer_traits::const_min > -{ -}; - -template < typename T > -struct maximum_of - : boost::mpl::integral_c< T, boost::integer_traits::const_max > -{ -}; - -} // unnamed namespace - - -// Check the processor-optimzed type system -BOOST_AUTO_TEST_SUITE( optimized_type_tests ) - -// Check the optimzed type override of a given type -BOOST_AUTO_TEST_CASE( fast_type_test ) -{ - typedef short least_type; - typedef boost::int_fast_t::fast fast_type; - typedef std::numeric_limits least_limits; - typedef std::numeric_limits fast_limits; - - typedef boost::fast_integral::type real_fast_type; - - BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), - ==, false ); - BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), ==, true ); - BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true ); - BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed && - fast_limits::is_bounded, ==, true ); - BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 ); - BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits ); -} - -BOOST_AUTO_TEST_SUITE_END() - -// Check if given types can support given size parameters -BOOST_AUTO_TEST_SUITE( show_type_tests ) - -// Check the specialization type status of given bit lengths, minimum -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list ) -{ - BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral(), - T::value, "a sized_integral<", ", signed>"), T::value && (T::value <= - intmax_bits) ); - BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral(), - T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits ); -} - -// Check the classic specialization type status of given bit lengths, minimum, -// unsigned -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T, - valid_bits_list ) -{ - // This test is supposed to replace the following printouts given in - // puesdo-code by: - // Routine: Template, Type - // for N := 32 downto 0 - // cout << "Type '" << Template << "<" N << ">::" << Type << "' is '" - // << typeid(Template::Type).name << ".'\n" - // end for - // end Routine - // with Template = {int_t, uint_t}; Type = {least, fast} - // But now we'll use template meta-programming instead of macros. The limit - // of type-lists is usually less than 32 (not to mention 64) elements, so we - // have to take selected values. The only interesting part is if the bit - // count is too large, and we can't check that yet. - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value ); - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value ); -} - -// Check the classic specialization type status of given bit lengths, minimum, -// signed -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T, - valid_to_decrease_bits_list ) -{ - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::least>::digits, >=, T::value - 1 ); - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::fast>::digits, >=, T::value - 1 ); -} - -// Check size comparisons of given value support, unsigned -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T, - valid_to_increase_ubits_list ) -{ - // This test is supposed to replace the following printouts given in - // puesdo-code by: - // Routine: Type - // for N := 30 downto 0 - // cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type - // << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n" - // end for - // end Routine - // with Type = {least, fast} - // But now we'll use template meta-programming instead of macros. The limit - // of type-lists is usually less than 32 (not to mention 64) elements, so we - // have to take selected values. The interesting parts are where N is the - // length of a integral type, so 1 << N would have to fit in the next larger - // type. (This is why N can't be more than bitlength(uintmax_t) - 1.) - boost::uintmax_t const one = 1u; - - BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one - << T::value)>, unsigned_sized_integral >) ); -} - -// Check size comparisons of given value support, signed -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T, - valid_to_increase_sbits_list ) -{ - // This test is supposed to replace the following printouts given in - // puesdo-code by: - // Routine: Type - // for N := 30 downto 0 - // cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" << - // Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name - // << ".'\n" - // cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" << - // Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name - // << ".'\n" - // end for - // end Routine - // with Type = {least, fast} - // But now we'll use template meta-programming instead of macros. The limit - // of type-lists is usually less than 32 (not to mention 64) elements, so we - // have to take selected values. The interesting parts are where N is the - // length of a integral type, so 1 << N would have to fit in the next larger - // type. (This is why N can't be more than bitlength(intmax_t) - 1. Note - // that bitlength(intmax_t) + 1 == bitlength(uintmax_t).) - static boost::intmax_t const one = 1; - - BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one - << T::value)>, signed_sized_integral >) ); - BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one - << T::value)>, signed_sized_integral >) ); -} - -// Check the specialization type status of given bit lengths, exact only -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list ) -{ - bool const is_exact_length = std::binary_search( integral_bit_lengths, - integral_bit_lengths + integral_type_count, T::value ); - - BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral(), - T::value, "an exact_integral<", ", signed>"), is_exact_length ); - BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral(), - T::value, "an exact_integral<", ", unsigned>"), is_exact_length ); -} - -// Check the classic specialization type status of given bit lengths, exact only -BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T, - distinct_integral_bit_counts ) -{ - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value - 1 ); - BOOST_MPL_ASSERT_RELATION( std::numeric_limits::exact>::digits, ==, T::value ); -} - -// Check if MPL-compatible templates give bad returns for out-of-range values -BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test ) -{ - typedef signed_sized_integral< 3> ssz3_type; - typedef signed_sized_integral< 0> ssz0_type; - typedef signed_sized_integral<-3> ssz3n_type; - - BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count, - "a sized_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count, - "a sized_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count, - "a sized_integral<", ", signed>") ); - - typedef unsigned_sized_integral< 3> usz3_type; - typedef unsigned_sized_integral< 0> usz0_type; - typedef unsigned_sized_integral<-3> usz3n_type; - - BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count, - "a sized_integral<", ", unsigned>") ); - BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count, - "a sized_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count, - "a sized_integral<", ", unsigned>") ); - - typedef signed_exact_integral< CHAR_BIT > se8_type; - typedef signed_exact_integral< 3> se3_type; - typedef signed_exact_integral< 0> se0_type; - typedef signed_exact_integral<-3> se3n_type; - typedef signed_exact_integral< - CHAR_BIT > se8n_type; - - BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count, - "an exact_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count, - "an exact_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count, - "an exact_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count, - "an exact_integral<", ", signed>") ); - BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count, - "an exact_integral<", ", signed>") ); - - typedef unsigned_exact_integral< CHAR_BIT > ue8_type; - typedef unsigned_exact_integral< 3> ue3_type; - typedef unsigned_exact_integral< 0> ue0_type; - typedef unsigned_exact_integral<-3> ue3n_type; - typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type; - - BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count, - "an exact_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count, - "an exact_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count, - "an exact_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count, - "an exact_integral<", ", unsigned>") ); - BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count, - "an exact_integral<", ", unsigned>") ); - - typedef boost::maximum_signed_integral< 15> max15_type; - typedef boost::maximum_signed_integral< 0> max0_type; - typedef boost::maximum_signed_integral<-15> max15n_type; - - BOOST_CHECK( print_out_template(max15_type(), max15_type::bound, - "a maximum_signed_integral<", ">") ); - BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound, - "a maximum_signed_integral<", ">") ); - BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound, - "a maximum_signed_integral<", ">") ); - - typedef boost::minimum_signed_integral< 15> min15_type; - typedef boost::minimum_signed_integral< 0> min0_type; - typedef boost::minimum_signed_integral<-15> min15n_type; - - BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound, - "a minimum_signed_integral<", ">") ); - BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound, - "a minimum_signed_integral<", ">") ); - BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound, - "a minimum_signed_integral<", ">") ); - - typedef boost::maximum_unsigned_integral<15> umax15_type; - typedef boost::maximum_unsigned_integral< 0> umax0_type; - - BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound, - "a maximum_unsigned_integral<", ">") ); - BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound, - "a maximum_unsigned_integral<", ">") ); -} - -BOOST_AUTO_TEST_SUITE_END() - -// Check if given constants can fit in given types -BOOST_AUTO_TEST_SUITE( fit_type_tests ) - -// Check if large value can fit its minimum required size, by size -BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T, - valid_to_decrease_bits_list ) -{ - // This test is supposed to replace the following checks given in - // puesdo-code by: - // Routine: Template, Type - // for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 ) - // Confirm( static_cast::Type>(V) == V ); - // end for - // end Routine - // with Template = {int_t, uint_t}; Type = {least, fast}; - // Template:Max = { intmax_t.Max for int_t, uintmax_t.Max for uint_t } - // In other words, the selected type doesn't mask out any bits it's not - // supposed to. But now we'll use template meta-programming instead of - // macros. The limit of type-lists is usually less than 32 (not to mention - // 64) elements, so we have to take selected values. - static int const count = T::value; - int const shift = uintmax_bits - count; - boost::uintmax_t const value_u = uintmax_limits::max - BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift; - boost::intmax_t const value_s = intmax_limits::max - BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift; - - BOOST_CHECK_EQUAL( static_cast::type>(value_u), value_u ); - BOOST_CHECK_EQUAL( static_cast::least>(value_u), value_u ); - BOOST_CHECK_EQUAL( static_cast::fast>(value_u), value_u ); - - BOOST_CHECK_EQUAL( static_cast::type>(value_s), value_s ); - BOOST_CHECK_EQUAL( static_cast::least>(value_s), value_s ); - BOOST_CHECK_EQUAL( static_cast::fast>(value_s), value_s ); -} - -// Check if a large value can only fit of its exact bit length -BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T, - distinct_integral_bit_counts ) -{ - typename boost::exact_integral::type const one_u( 1u ), - high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) | - high_bit_u ); - - BOOST_CHECK( high_bit_u ); - BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u ); - - typename boost::exact_integral::type const one_s( 1 ), - high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) | - high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s ); - - BOOST_CHECK( high_bit_s > 0 ); - BOOST_CHECK( repeated_bits_s < 0 ); - BOOST_CHECK_EQUAL( repeated_bits_s, repeated_2bits_s ); -} - -// Check if large value can fit its minimum required size, by value, unsigned -BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T, - valid_to_increase_ubits_list ) -{ - // This test is supposed to replace the following checks given in - // puesdo-code by: - // Routine: Template, Type - // for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 ) - // Confirm( static_cast::Type>(V) == V ); - // end for - // end Routine - // with Template = {uint_value_t}; Type = {least, fast}; Template:Extreme = - // {uintmax_t.Max for uint_value_t} - // In other words, the selected type doesn't mask out any bits it's not - // supposed to. But now we'll use template meta-programming instead of - // macros. The limit of type-lists is usually less than 32 (not to mention - // 64) elements, so we have to take selected values. - using boost::uintmax_t; - - typedef boost::mpl::shift_right, T> maxi_type; - - uintmax_t const maxi = maxi_type::value; - - BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); - BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); -} - -// Check if large value can fit its minimum required size, by value, signed -BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T, - valid_to_increase_sbits_list ) -{ - // This test is supposed to replace the following checks given in - // puesdo-code by: - // Routine: Template, Type - // for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 ) - // Confirm( static_cast::Type>(V) == V ); - // end for - // end Routine - // with Template = {int_max_value_t, int_min_value_t}; Type = {least, fast}; - // Template:Extreme = {intmax_t.Min for int_min_value_t, intmax_t.Max - // for int_max_value_t} - // In other words, the selected type doesn't mask out any bits it's not - // supposed to. But now we'll use template meta-programming instead of - // macros. The limit of type-lists is usually less than 32 (not to mention - // 64) elements, so we have to take selected values. - using boost::intmax_t; - - typedef boost::mpl::shift_right, T> mini_type; - typedef boost::mpl::shift_right, T> maxi_type; - - intmax_t const maxi = maxi_type::value, mini = mini_type::value; - - BOOST_CHECK_EQUAL( static_cast::least>(maxi), maxi ); - BOOST_CHECK_EQUAL( static_cast::fast>(maxi), maxi ); - - BOOST_CHECK_EQUAL( static_cast::least>(mini), mini ); - BOOST_CHECK_EQUAL( static_cast::fast>(mini), mini ); -} - -BOOST_AUTO_TEST_SUITE_END() - -// Verification of bugs and their fixes -BOOST_AUTO_TEST_SUITE( bug_fix_tests ) - -BOOST_AUTO_TEST_SUITE_END() diff --git a/test/issue_2134.cpp b/test/issue_2134.cpp deleted file mode 100644 index 26f8962..0000000 --- a/test/issue_2134.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// boost Issue #2134 test program ------------------------------------------// - -// Copyright Daryle Walker 2008. Distributed under the Boost -// Software License, Version 1.0. (See the accompanying file -// LICENSE_1_0.txt or a copy at .) - -// See for documentation. -// See for the issue involved. - -// Revision History -// 23 Jul 2008 Initial version - -// Control if the inclusion error is triggered -#ifndef CONTROL_INCLUDE_TRAITS -#define CONTROL_INCLUDE_TRAITS 1 -#endif - -#if CONTROL_INCLUDE_TRAITS -// This file defines boost::detail::integer_traits. -#include -#endif - -// This is the file with the issue. It has items within the boost::detail -// namespace that referenced an unadorned "integer_traits". This was meant to -// refer to boost::integer_traits. However, -// defines a boost::detail::integer_traits. If that header is #included before -// this one, then b.d.integer_traits (rightfully) took priority, which lead to a -// syntax error. -#include - - -// Main program, minimal (since this is a compile test) -int main() { return 0; } From dd1194afa4d2a2a2f049a0a20b6845cb2932e6e0 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 22 Nov 2009 16:38:05 +0000 Subject: [PATCH 37/64] Fix preprocessor logic for long long support. Fixes #3657. Fixes #3568. [SVN r57843] --- include/boost/integer_fwd.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 33cfc99..34183d8 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -65,7 +65,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) template < > class integer_traits< ::boost::long_long_type>; From 9ff5c9d3b60f4bb231ab85865a6270f784986f8b Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 22 Nov 2009 17:12:57 +0000 Subject: [PATCH 38/64] Fixes #3180. [SVN r57845] --- include/boost/cstdint.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/boost/cstdint.hpp b/include/boost/cstdint.hpp index d55a484..fbce18d 100644 --- a/include/boost/cstdint.hpp +++ b/include/boost/cstdint.hpp @@ -220,6 +220,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 +255,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 From 8cab32a0dd1fab19fb4befe9aaaf639a31a23fd4 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 09:51:23 +0000 Subject: [PATCH 39/64] Fix for Comeau compiler - does not define __GLIBC_HAVE_LONG_LONG which in turn causes GLIBC's stdint.h to misbehave. Fixes #3548. [SVN r57858] --- include/boost/cstdint.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/boost/cstdint.hpp b/include/boost/cstdint.hpp index fbce18d..030995f 100644 --- a/include/boost/cstdint.hpp +++ b/include/boost/cstdint.hpp @@ -25,8 +25,13 @@ #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 From 285048504c96a34e42347c1582054d85786c5d07 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 10:43:00 +0000 Subject: [PATCH 40/64] Suppress and/or fix warnings - in particular avoid undefined behaviour in the test cases! [SVN r57859] --- include/boost/integer/integer_mask.hpp | 9 +++++++++ include/boost/integer_traits.hpp | 11 +++++++++++ test/integer_mask_test.cpp | 23 ++++++++++++++++++----- test/integer_test.cpp | 4 ++++ 4 files changed, 42 insertions(+), 5 deletions(-) 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_traits.hpp b/include/boost/integer_traits.hpp index 96b3526..8011618 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 diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 38f5211..8e0c11a 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -17,6 +17,9 @@ #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< \ (v) >::high_bit == (1ul << (v)) ); @@ -25,10 +28,20 @@ #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_CHECK( ::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_CHECK( ::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) @@ -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 ); diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 6bfff11..ba6a4bb 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -22,6 +22,10 @@ #include // for std::cout (std::endl indirectly) #include // for std::type_info +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif + // Control if the names of the types for each version // of the integer templates will be printed. From 4c23c47ebea5940ef634d4de23aa5c71f1f4c74d Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 13:23:15 +0000 Subject: [PATCH 41/64] Add support for MS style __int64 when long long is not available. Fixes #3084. [SVN r57863] --- include/boost/integer_fwd.hpp | 2 +- include/boost/integer_traits.hpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 34183d8..ae3d0f1 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -65,7 +65,7 @@ template < > template < > class integer_traits< unsigned long >; -#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG) +#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>; diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 8011618..34b3570 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -236,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 From 44c3831e0598190f07db8dda4ecf8c7d61964ce1 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 16:39:45 +0000 Subject: [PATCH 42/64] Fix Jamfile and Boost.Test usage. [SVN r57866] --- test/Jamfile.v2 | 12 ++++++------ test/integer_traits_test.cpp | 1 - test/static_log2_test.cpp | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1609bf5..6111059 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -6,15 +6,15 @@ import testing ; test-suite integer : [ run cstdint_test.cpp ] - [ run integer_test.cpp - /boost/test//boost_unit_test_framework ] + [ run integer_test.cpp + /boost/test//minimal ] [ run integer_traits_test.cpp - /boost/test//boost_test_exec_monitor/static ] + /boost/test//boost_test_exec_monitor ] [ run integer_mask_test.cpp - /boost/test//boost_unit_test_framework ] + /boost/test//minimal ] [ run static_log2_test.cpp - /boost/test//boost_test_exec_monitor/static ] + /boost/test//boost_test_exec_monitor ] [ run static_min_max_test.cpp - /boost/test//boost_test_exec_monitor/static ] + /boost/test//boost_test_exec_monitor ] # [ compile issue_2134.cpp ] ; diff --git a/test/integer_traits_test.cpp b/test/integer_traits_test.cpp index e3de239..065f90a 100644 --- a/test/integer_traits_test.cpp +++ b/test/integer_traits_test.cpp @@ -17,7 +17,6 @@ // use int64_t instead of long long for better portability #include -#define BOOST_INCLUDE_MAIN #include /* diff --git a/test/static_log2_test.cpp b/test/static_log2_test.cpp index 68628f6..00446e3 100644 --- a/test/static_log2_test.cpp +++ b/test/static_log2_test.cpp @@ -10,7 +10,6 @@ // Revision History // 01 Oct 2001 Initial version (Daryle Walker) -#define BOOST_INCLUDE_MAIN #include // for main #include // for boost::exit_success From e07b49c95510ae2e87fd1728e7a08f5d3f5e09a0 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 16:45:21 +0000 Subject: [PATCH 43/64] remove reference to dead test (no longer relevant) [SVN r57867] --- test/Jamfile.v2 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6111059..03adbd9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,5 +16,4 @@ test-suite integer /boost/test//boost_test_exec_monitor ] [ run static_min_max_test.cpp /boost/test//boost_test_exec_monitor ] -# [ compile issue_2134.cpp ] ; From ddb6a13f29da4d994fa0d078a2d5e29f2f16e560 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 23 Nov 2009 18:51:33 +0000 Subject: [PATCH 44/64] Add support for long long throughout. Fixes #653. [SVN r57873] --- include/boost/integer.hpp | 70 ++++++++++++++++++++++++++++------- include/boost/integer_fwd.hpp | 18 +++++++-- test/integer_test.cpp | 2 +- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index dc57dff..b39e300 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -19,6 +19,7 @@ #include // for boost::integer_traits #include // for std::numeric_limits +#include // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T namespace boost { @@ -36,14 +37,20 @@ 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; }; // integer templates specifying number of bits ---------------------------// @@ -53,6 +60,11 @@ namespace boost { typedef typename int_least_helper < +#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) + @@ -68,6 +80,11 @@ namespace boost typedef typename int_least_helper < 5 + +#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) + @@ -80,11 +97,20 @@ namespace boost // 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 < +#ifdef BOOST_HAS_LONG_LONG + (MaxValue <= integer_traits::const_max) + +#else + 1 + +#endif (MaxValue <= integer_traits::const_max) + (MaxValue <= integer_traits::const_max) + (MaxValue <= integer_traits::const_max) + @@ -93,11 +119,20 @@ namespace boost typedef typename int_fast_t::fast 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 < +#ifdef BOOST_HAS_LONG_LONG + (MinValue >= integer_traits::const_min) + +#else + 1 + +#endif (MinValue >= integer_traits::const_min) + (MinValue >= integer_traits::const_min) + (MinValue >= integer_traits::const_min) + @@ -107,16 +142,25 @@ namespace boost }; // 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< long MaxValue > // minimum value to require support +#endif struct uint_value_t { typedef typename int_least_helper < 5 + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) + - (Value <= integer_traits::const_max) +#ifdef BOOST_HAS_LONG_LONG + (MaxValue <= integer_traits::const_max) + +#else + 1 + +#endif + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) + + (MaxValue <= integer_traits::const_max) >::least least; typedef typename int_fast_t::fast fast; }; diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index ae3d0f1..cd213b6 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -85,13 +85,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< long MaxValue > // maximum value to require support +#endif struct uint_value_t; diff --git a/test/integer_test.cpp b/test/integer_test.cpp index ba6a4bb..c6c3e8a 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -134,7 +134,7 @@ namespace boost // 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 +#if (ULONG_MAX > 0xFFFFFFFFL) || !defined(BOOST_NO_INTEGRAL_INT64_T) #define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \ PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \ From 0248ecb71ba7fde4397f1a409740f4e48751042c Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 24 Nov 2009 10:07:45 +0000 Subject: [PATCH 45/64] Add history/revision log. [SVN r57883] --- index.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 1f0f83c..f94148a 100644 --- a/index.html +++ b/index.html @@ -119,12 +119,26 @@ the global namespace to users of <boost/cstdint.hpp>. interface. Use the respective names in namespace boost instead.

      -
      +

      + History +

      + +

      + Reverted Trunk to release branch state (i.e. a "known good state"), Nov 2009. Then fixed issues: + 653, + 3084, + 3177, + 3180, + 3568, + 3657, +

      + +

      Revised: 06 Nov 2007

      -

      © Copyright Beman Dawes 2003

      +

      © Copyright Beman Dawes 2003

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

      From 09ee5872ba49d0017d14f5a1b4dc26fbb63a29b9 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 24 Nov 2009 10:12:29 +0000 Subject: [PATCH 46/64] Tidied up namespace usage, fixes #2134. [SVN r57884] --- include/boost/integer.hpp | 64 +++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index b39e300..559d2f1 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -17,8 +17,8 @@ #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 namespace boost @@ -31,6 +31,8 @@ namespace boost template< typename LeastInt > struct int_fast_t { typedef LeastInt fast; }; // imps may specialize + namespace detail{ + // convert category to type template< int Category > struct int_least_helper {}; // default is empty @@ -52,23 +54,25 @@ namespace boost template<> struct int_least_helper<9> { typedef unsigned short least; }; template<> struct int_least_helper<10> { typedef unsigned char least; }; + } // namespace detail + // integer templates specifying number of bits ---------------------------// // signed template< int Bits > // bits (including sign) required struct int_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < #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) + (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; }; @@ -77,7 +81,7 @@ namespace boost template< int Bits > // bits required struct uint_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < 5 + #ifdef BOOST_HAS_LONG_LONG @@ -85,10 +89,10 @@ namespace boost #else 1 + #endif - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) + - (Bits <= std::numeric_limits::digits) + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) + + (Bits <= ::std::numeric_limits::digits) >::least least; typedef typename int_fast_t::fast fast; // int_fast_t<> works correctly for unsigned too, in spite of the name. @@ -104,17 +108,17 @@ namespace boost #endif struct int_max_value_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < #ifdef BOOST_HAS_LONG_LONG - (MaxValue <= integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + #else 1 + #endif - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= 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) >::least least; typedef typename int_fast_t::fast fast; }; @@ -126,17 +130,17 @@ namespace boost #endif struct int_min_value_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < #ifdef BOOST_HAS_LONG_LONG - (MinValue >= integer_traits::const_min) + + (MinValue >= ::boost::integer_traits::const_min) + #else 1 + #endif - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) + - (MinValue >= integer_traits::const_min) + (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; }; @@ -149,18 +153,18 @@ namespace boost #endif struct uint_value_t { - typedef typename int_least_helper + typedef typename detail::int_least_helper < 5 + #ifdef BOOST_HAS_LONG_LONG - (MaxValue <= integer_traits::const_max) + + (MaxValue <= ::boost::integer_traits::const_max) + #else 1 + #endif - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= integer_traits::const_max) + - (MaxValue <= 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) >::least least; typedef typename int_fast_t::fast fast; }; From cf359129a3edf0836397ffd491eed6dff4a13ea4 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 24 Nov 2009 10:14:43 +0000 Subject: [PATCH 47/64] Bring docs into line with code. [SVN r57885] --- index.html | 1 + integer.htm | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index f94148a..6aa0bb8 100644 --- a/index.html +++ b/index.html @@ -131,6 +131,7 @@ instead.

      3180, 3568, 3657, + 2134,


      diff --git a/integer.htm b/integer.htm index 3d3f9c5..68767b4 100644 --- a/integer.htm +++ b/integer.htm @@ -58,14 +58,14 @@ is particularly useful for solving generic programming problems.

      }; // signed - template< long MaxValue > + template< long long MaxValue > struct int_max_value_t { typedef implementation_supplied least; typedef int_fast_t<least>::fast fast; }; - template< long MinValue > + template< long long MinValue > struct int_min_value_t { typedef implementation_supplied least; @@ -73,7 +73,7 @@ is particularly useful for solving generic programming problems.

      }; // unsigned - template< unsigned long Value > + template< unsigned long long Value > struct uint_value_t { typedef implementation_supplied least; From db267e22f808fc0ed32b77dfd83bfad69cf78ce8 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 24 Nov 2009 21:24:20 +0000 Subject: [PATCH 48/64] Integer: fixed search&replace gone mad [SVN r57908] --- include/boost/integer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 559d2f1..2d339ae 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -17,7 +17,7 @@ #include // self include -#include // for boost::::boost::integer_traits +#include // for ::boost::integer_traits #include // for ::std::numeric_limits #include // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T From ca84baa55db80d55245ff1b740e7bf4678ac7070 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 25 Nov 2009 12:38:09 +0000 Subject: [PATCH 49/64] Update Boost.Integer meta-programming classes to work with intmax_t where possible - ie to be 64-bit clean. Added quickbook based docs - updated as necessary. Removed old html docs. [SVN r57926] --- cstdint.htm | 81 --- doc/Jamfile.v2 | 59 ++ doc/html/boost_integer/cstdint.html | 235 +++++++ doc/html/boost_integer/history.html | 82 +++ doc/html/boost_integer/integer.html | 323 +++++++++ doc/html/boost_integer/log2.html | 184 ++++++ doc/html/boost_integer/mask.html | 376 +++++++++++ doc/html/boost_integer/minmax.html | 160 +++++ doc/html/boost_integer/traits.html | 214 ++++++ doc/html/index.html | 238 +++++++ doc/integer.qbk | 801 +++++++++++++++++++++++ doc/integer_mask.html | 210 ------ doc/static_log2.html | 215 ------ doc/static_min_max.html | 120 ---- include/boost/integer.hpp | 2 +- include/boost/integer/static_log2.hpp | 11 +- include/boost/integer/static_min_max.hpp | 20 +- include/boost/integer_fwd.hpp | 26 +- index.html | 156 +---- integer.htm | 212 ------ integer_traits.html | 94 --- 21 files changed, 2714 insertions(+), 1105 deletions(-) delete mode 100644 cstdint.htm create mode 100644 doc/Jamfile.v2 create mode 100644 doc/html/boost_integer/cstdint.html create mode 100644 doc/html/boost_integer/history.html create mode 100644 doc/html/boost_integer/integer.html create mode 100644 doc/html/boost_integer/log2.html create mode 100644 doc/html/boost_integer/mask.html create mode 100644 doc/html/boost_integer/minmax.html create mode 100644 doc/html/boost_integer/traits.html create mode 100644 doc/html/index.html create mode 100644 doc/integer.qbk delete mode 100644 doc/integer_mask.html delete mode 100644 doc/static_log2.html delete mode 100644 doc/static_min_max.html delete mode 100644 integer.htm delete mode 100644 integer_traits.html 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:

      -
        -
      • int_least8_t
      • -
      • int_least16_t
      • -
      • int_least32_t
      • -
      • uint_least8_t
      • -
      • uint_least16_t
      • -
      • uint_least32_t
      • -
      -

      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:

      -
        -
      • int_fast8_t
      • -
      • int_fast16_t
      • -
      • int_fast32_t
      • -
      • uint_fast8_t
      • -
      • uint_fast16_t
      • -
      • uint_fast32_t
      • -
      -

      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..fca043b --- /dev/null +++ b/doc/html/boost_integer/cstdint.html @@ -0,0 +1,235 @@ + + + +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 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. +

      +
      +
      + +

      + The organization of the 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. +

      +
      +
      + +

      + 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 an implementation provides integer + types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding + typedef names. +

      +

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

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

      + The types: +

      +
        +
      • int_least64_t
      • +
      • uint_least64_t
      • +
      +

      + Are available only if, after inclusion of <boost/cstdint.hpp> + the macro BOOST_NO_INT64_T + is not defined. +

      +

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

      +

      + Required fastest minimum-width integer types: +

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

      + The types: +

      +
        +
      • int_fast64_t
      • +
      • uint_fast64_t
      • +
      +

      + Are available only if, after inclusion of <boost/cstdint.hpp> + the macro BOOST_NO_INT64_T + is not defined. +

      +

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

      +
      +
      + + + +
      +
      +
      +PrevUpHomeNext +
      + + diff --git a/doc/html/boost_integer/history.html b/doc/html/boost_integer/history.html new file mode 100644 index 0000000..fb7fc8a --- /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..8772326 --- /dev/null +++ b/doc/html/boost_integer/integer.html @@ -0,0 +1,323 @@ + + + +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  fast;
      +  };
      +
      +  //  signed
      +  template<int Bits>
      +  struct int_t 
      +  {
      +      typedef implementation-defined-type  least;
      +      typedef int_fast_t<least>::fast      fast;
      +  };
      +
      +  //  unsigned
      +  template<int Bits>
      +  struct uint_t 
      +  {
      +      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, 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. +

      +
      +
      + +

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

      +
      +

      Table 1. Criteria for the Sized Type Class Templates

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

      + Class Template +

      +
      +

      + Template Parameter Mapping +

      +
      +

      + boost::int_t<N> +

      +
      +

      + The smallest built-in signed integral type with at least N + bits, including the sign bit. The parameter should be a positive number. + A compile-time error results if the parameter is larger than the number + of bits in the largest integer type. +

      +
      +

      + boost::uint_t<N> +

      +
      +

      + The smallest built-in unsigned integral type with at least N + bits. The parameter should be a positive number. A compile-time error + results if the parameter is larger than the number of bits in the largest + integer type. +

      +
      +

      + boost::int_max_value_t<V> +

      +
      +

      + 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_min_value_t<V> +

      +
      +

      + 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::uint_value_t<V> +

      +
      +

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

      +
      +
      +
      +
      +
      + +
      #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, it's 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..2d5f4d0 --- /dev/null +++ b/doc/html/boost_integer/log2.html @@ -0,0 +1,184 @@ + + + +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). +
      • +
      +
      +
      + +
      #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>();
      +    //...
      +}
      +
      +
      +
      + +

      + 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 statically (i.e. at compile-time) available. +

      +
      +
      + +

      + 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..e8ca8e2 --- /dev/null +++ b/doc/html/boost_integer/mask.html @@ -0,0 +1,376 @@ + + + +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 quick-to-manipulate analog of least. +

      +
      +

      + high_bit +

      +
      +

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

      +
      +

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

      +
      +

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

      +
      +
      + +

      + 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..c25e4fc --- /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..c6dbe6c --- /dev/null +++ b/doc/html/boost_integer/traits.html @@ -0,0 +1,214 @@ + + + +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>
      +  {
      +     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. + 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: +

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

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

      +
      +
      + +

      + 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..69f0579 --- /dev/null +++ b/doc/html/index.html @@ -0,0 +1,238 @@ + + + +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 consists of the following components: +

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

      + 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: November 25, 2009 at 12:02:32 GMT

      +
      +
      Next
      + + diff --git a/doc/integer.qbk b/doc/integer.qbk new file mode 100644 index 0000000..403b010 --- /dev/null +++ b/doc/integer.qbk @@ -0,0 +1,801 @@ +[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 consists of the following components: + +[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 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 in all implementations, 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 resorting to 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]. As always, 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 an implementation provides integer types with widths of 8, 16, 32, or 64 bits, +it shall define the corresponding typedef names. + +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 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: + +* [^int_least8_t] +* [^int_least16_t] +* [^int_least32_t] +* [^uint_least8_t] +* [^uint_least16_t] +* [^uint_least32_t] + +The types: + +* [^int_least64_t] +* [^uint_least64_t] + +Are available only if, after inclusion of [^] the macro `BOOST_NO_INT64_T` is ['[*not defined]]. + +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. + +Required fastest minimum-width integer types: + +* [^int_fast8_t] +* [^int_fast16_t] +* [^int_fast32_t] +* [^uint_fast8_t] +* [^uint_fast16_t] +* [^uint_fast32_t] + +The types: + +* [^int_fast64_t] +* [^uint_fast64_t] + +Are available only if, after inclusion of [^] the macro `BOOST_NO_INT64_T` is ['[*not defined]]. + +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 required. + +[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 + { + 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]. 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: + +[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: 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. + +[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]`` fast; + }; + + // signed + template + struct int_t + { + typedef ``['implementation-defined-type]`` least; + typedef int_fast_t::fast fast; + }; + + // unsigned + template + struct uint_t + { + 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, 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. + +[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 +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. + +[table Criteria for the Sized Type Class Templates + [ + [Class Template][Template Parameter Mapping] + ] + [ + [[^boost::int_t]] + [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::uint_t]] + [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::int_max_value_t]] + [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_min_value_t]] + [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::uint_value_t]] + [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.] + ] +] + +[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, it's 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 quick-to-manipulate analog of [^least].]] + [[[^high_bit]][A [^least] constant of the desired bit-masking value.]] + [[[^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 representing the lowest +bits of a certain amount. The masks are equivalent to the value (2[super Bits] - 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]. + +[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 quick-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 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. + +[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 Example] + + #include "boost/integer/static_log2.hpp" + + + template < boost::static_log2_argument_type value > + bool is_it_what() + { + typedef boost::static_log2 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>(); + //... + } + +[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 statically (['i.e.] at compile-time) available. + +[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/integer.hpp b/include/boost/integer.hpp index 2d339ae..86cc3a5 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -17,7 +17,7 @@ #include // self include -#include // for ::boost::integer_traits +#include // for boost::::boost::integer_traits #include // for ::std::numeric_limits #include // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T 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 cd213b6..ab39561 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 ------------------------------------------------// @@ -136,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/index.html b/index.html index 6aa0bb8..dfc23cc 100644 --- a/index.html +++ b/index.html @@ -1,148 +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.

      - -

      - History -

      - -

      - Reverted Trunk to release branch state (i.e. a "known good state"), Nov 2009. Then fixed issues: - 653, - 3084, - 3177, - 3180, - 3568, - 3657, - 2134, -

      - -
      - -

      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 68767b4..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 long MaxValue >
      -  struct int_max_value_t 
      -  {
      -      typedef implementation_supplied  least;
      -      typedef int_fast_t<least>::fast  fast;
      -  };
      -
      -  template< long long MinValue >
      -  struct int_min_value_t 
      -  {
      -      typedef implementation_supplied  least;
      -      typedef int_fast_t<least>::fast  fast;
      -  };
      -
      -  //  unsigned
      -  template< unsigned long 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

      - From ac155d3843a6d89e54d30a6ddc260b4cb6c9eedb Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 26 Nov 2009 11:08:27 +0000 Subject: [PATCH 50/64] Added support for exact width integer type to int_t and uint_t Updated docs to match. Fixes #1225. [SVN r57941] --- doc/html/boost_integer/history.html | 4 +- doc/html/boost_integer/integer.html | 14 +- doc/html/boost_integer/mask.html | 4 +- doc/html/index.html | 4 +- doc/integer.qbk | 11 +- include/boost/integer.hpp | 45 ++- test/Jamfile.v2 | 6 +- test/cstdint_test.cpp | 120 ++++--- test/integer_test.cpp | 468 +++++++++++++--------------- 9 files changed, 338 insertions(+), 338 deletions(-) diff --git a/doc/html/boost_integer/history.html b/doc/html/boost_integer/history.html index fb7fc8a..6d4b878 100644 --- a/doc/html/boost_integer/history.html +++ b/doc/html/boost_integer/history.html @@ -26,7 +26,7 @@ History
      - + 1.42.0
        @@ -55,7 +55,7 @@
      - + 1.32.0
      • diff --git a/doc/html/boost_integer/integer.html b/doc/html/boost_integer/integer.html index 8772326..50d58d9 100644 --- a/doc/html/boost_integer/integer.html +++ b/doc/html/boost_integer/integer.html @@ -61,6 +61,8 @@ template<int Bits> struct int_t { + /* Member exact may or may not be defined depending upon Bits */ + typedef implementation-defined-type exact; typedef implementation-defined-type least; typedef int_fast_t<least>::fast fast; }; @@ -69,6 +71,8 @@ template<int Bits> struct uint_t { + /* Member exact may or may not be defined depending upon Bits */ + typedef implementation-defined-type exact; typedef implementation-defined-type least; typedef int_fast_t<least>::fast fast; }; @@ -136,7 +140,7 @@ fast. The following table describes each template's criteria.

        -

        Table 1. Criteria for the Sized Type Class Templates

        +

        Table 1. Criteria for the Sized Type Class Templates

        @@ -166,7 +170,9 @@ 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. + of bits in the largest integer type. Note that the member exact + is defined only if there is a type + with exactly N bits.

        @@ -181,7 +187,9 @@ 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. + integer type. Note that the member exact is defined + only if there is a type with exactly + N bits.

        diff --git a/doc/html/boost_integer/mask.html b/doc/html/boost_integer/mask.html index e8ca8e2..9aee7d0 100644 --- a/doc/html/boost_integer/mask.html +++ b/doc/html/boost_integer/mask.html @@ -105,7 +105,7 @@ of high_bit_mask_t.

        -

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

        +

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

        @@ -205,7 +205,7 @@ the members of an instantiation of low_bits_mask_t.

        -

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

        +

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

        diff --git a/doc/html/index.html b/doc/html/index.html index 69f0579..dab3f7c 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -40,7 +40,7 @@
        -

        +

        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)

        @@ -229,7 +229,7 @@
        - +

        Last revised: November 25, 2009 at 12:02:32 GMT

        Last revised: November 26, 2009 at 11:06:43 GMT


        diff --git a/doc/integer.qbk b/doc/integer.qbk index 403b010..36f9a1b 100644 --- a/doc/integer.qbk +++ b/doc/integer.qbk @@ -282,6 +282,8 @@ This facility is particularly useful for solving generic programming problems. 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; }; @@ -290,6 +292,8 @@ This facility is particularly useful for solving generic programming problems. 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; }; @@ -351,13 +355,16 @@ The following table describes each template's criteria. [[^boost::int_t]] [The smallest built-in signed integral type with at least /N/ bits, including the sign bit. The parameter should be a positive number. A compile-time error results if the parameter is - larger than the number of bits in the largest integer type.] + larger than the number of bits in the largest integer type. Note that the member /exact/ is defined + [*only] if there is a type with exactly N bits.] ] [ [[^boost::uint_t]] [The smallest built-in unsigned integral type with at least /N/ bits. The parameter should be a positive number. A compile-time error results if the - parameter is larger than the number of bits in the largest integer type.] + parameter is larger than the number of bits in the largest integer type. + Note that the member /exact/ is defined + [*only] if there is a type with exactly N bits.] ] [ [[^boost::int_max_value_t]] diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp index 86cc3a5..7125ca6 100644 --- a/include/boost/integer.hpp +++ b/include/boost/integer.hpp @@ -21,6 +21,18 @@ #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 { @@ -54,13 +66,42 @@ namespace boost 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 long long exact; }; + template <> struct exact_unsigned_base_helper { typedef unsigned long long exact; }; +#endif + + } // namespace detail // integer templates specifying number of bits ---------------------------// // signed template< int Bits > // bits (including sign) required - struct int_t + struct int_t : public detail::exact_signed_base_helper { typedef typename detail::int_least_helper < @@ -79,7 +120,7 @@ namespace boost // unsigned template< int Bits > // bits required - struct uint_t + struct uint_t : public detail::exact_unsigned_base_helper { typedef typename detail::int_least_helper < diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 03adbd9..9104efc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -5,11 +5,11 @@ import testing ; test-suite integer - : [ run cstdint_test.cpp ] - [ run integer_test.cpp - /boost/test//minimal ] + : [ run cstdint_test.cpp /boost/test//minimal ] [ run integer_traits_test.cpp /boost/test//boost_test_exec_monitor ] + [ run integer_test.cpp + /boost/test//minimal ] [ run integer_mask_test.cpp /boost/test//minimal ] [ run static_log2_test.cpp diff --git a/test/cstdint_test.cpp b/test/cstdint_test.cpp index 88422de..6d26b91 100644 --- a/test/cstdint_test.cpp +++ b/test/cstdint_test.cpp @@ -13,17 +13,10 @@ // 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock). // 28 Jun 00 Initial version #define __STDC_CONSTANT_MACROS -#include #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 // @@ -62,24 +55,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_CHECK( int8 == -127 ); + BOOST_CHECK( int_least8 == -127 ); + BOOST_CHECK( int_fast8 == -127 ); + BOOST_CHECK( uint8 == 255u ); + BOOST_CHECK( uint_least8 == 255u ); + BOOST_CHECK( uint_fast8 == 255u ); + BOOST_CHECK( int16 == -32767 ); + BOOST_CHECK( int_least16 == -32767 ); + BOOST_CHECK( int_fast16 == -32767 ); + BOOST_CHECK( uint16 == 65535u ); + BOOST_CHECK( uint_least16 == 65535u ); + BOOST_CHECK( uint_fast16 == 65535u ); + BOOST_CHECK( int32 == -2147483647 ); + BOOST_CHECK( int_least32 == -2147483647 ); + BOOST_CHECK( int_fast32 == -2147483647 ); + BOOST_CHECK( uint32 == 4294967295u ); + BOOST_CHECK( uint_least32 == 4294967295u ); + BOOST_CHECK( uint_fast32 == 4294967295u ); } #endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION @@ -108,10 +101,10 @@ 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_CHECK(sizeof(T1) <= sizeof(T2)); #else - assert(sizeof(T1) == sizeof(T2)); - assert(t1 == t2); + BOOST_CHECK(sizeof(T1) == sizeof(T2)); + BOOST_CHECK(t1 == t2); #endif #if defined(BOOST_HAS_STDINT_H) // native headers are permitted to promote small @@ -119,22 +112,22 @@ void integral_constant_type_check(T1, T2) if(sizeof(T1) >= sizeof(int)) { if(t1 > 0) - assert(t2 > 0); + BOOST_CHECK(t2 > 0); else - assert(!(t2 > 0)); + BOOST_CHECK(!(t2 > 0)); } else if(t1 < 0) - assert(!(t2 > 0)); + BOOST_CHECK(!(t2 > 0)); #else if(t1 > 0) - assert(t2 > 0); + BOOST_CHECK(t2 > 0); else - assert(!(t2 > 0)); + BOOST_CHECK(!(t2 > 0)); #endif } -int main() +int test_main(int, char*[]) { #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION integral_constant_checker::check(); @@ -193,41 +186,40 @@ 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_CHECK( int8 == -127 ); + BOOST_CHECK( int_least8 == -127 ); + BOOST_CHECK( int_fast8 == -127 ); + BOOST_CHECK( uint8 == 255u ); + BOOST_CHECK( uint_least8 == 255u ); + BOOST_CHECK( uint_fast8 == 255u ); + BOOST_CHECK( int16 == -32767 ); + BOOST_CHECK( int_least16 == -32767 ); + BOOST_CHECK( int_fast16 == -32767 ); + BOOST_CHECK( uint16 == 65535u ); + BOOST_CHECK( uint_least16 == 65535u ); + BOOST_CHECK( uint_fast16 == 65535u ); + BOOST_CHECK( int32 == -2147483647 ); + BOOST_CHECK( int_least32 == -2147483647 ); + BOOST_CHECK( int_fast32 == -2147483647 ); + BOOST_CHECK( uint32 == 4294967295u ); + BOOST_CHECK( uint_least32 == 4294967295u ); + BOOST_CHECK( uint_fast32 == 4294967295u ); #ifndef BOOST_NO_INT64_T - assert( int64 == INT64_C(-9223372036854775807) ); - assert( int_least64 == INT64_C(-9223372036854775807) ); - assert( int_fast64 == INT64_C(-9223372036854775807) ); - assert( uint64 == UINT64_C(18446744073709551615) ); - assert( uint_least64 == UINT64_C(18446744073709551615) ); - assert( uint_fast64 == UINT64_C(18446744073709551615) ); - assert( intmax == INT64_C(-9223372036854775807) ); - assert( uintmax == UINT64_C(18446744073709551615) ); + BOOST_CHECK( int64 == INT64_C(-9223372036854775807) ); + BOOST_CHECK( int_least64 == INT64_C(-9223372036854775807) ); + BOOST_CHECK( int_fast64 == INT64_C(-9223372036854775807) ); + BOOST_CHECK( uint64 == UINT64_C(18446744073709551615) ); + BOOST_CHECK( uint_least64 == UINT64_C(18446744073709551615) ); + BOOST_CHECK( uint_fast64 == UINT64_C(18446744073709551615) ); + BOOST_CHECK( intmax == INT64_C(-9223372036854775807) ); + BOOST_CHECK( uintmax == UINT64_C(18446744073709551615) ); #else - assert( intmax == -2147483647 ); - assert( uintmax == 4294967295u ); + BOOST_CHECK( intmax == -2147483647 ); + BOOST_CHECK( uintmax == 4294967295u ); #endif std::cout << "OK\n"; return 0; } -#endif diff --git a/test/integer_test.cpp b/test/integer_test.cpp index c6c3e8a..e70ac86 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) @@ -13,10 +16,8 @@ // 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 #include // for ULONG_MAX, LONG_MAX, LONG_MIN #include // for std::cout (std::endl indirectly) @@ -25,271 +26,222 @@ #ifdef BOOST_MSVC #pragma warning(disable:4127) // conditional expression is constant #endif - - -// Control if the names of the types for each version -// of the integer templates will be printed. -#ifndef CONTROL_SHOW_TYPES -#define CONTROL_SHOW_TYPES 0 +// +// Keep track of error count, so we can print out detailed +// info only if we need it: +// +unsigned last_error_count = 0; +// +// Helpers to print out the name of a type, +// we use these as typeid(X).name() doesn't always +// return a human readable string: +// +template const char* get_name_of_type(T){ return typeid(T).name(); } +const char* get_name_of_type(signed char){ return "signed char"; } +const char* get_name_of_type(unsigned char){ return "unsigned char"; } +const char* get_name_of_type(short){ return "short"; } +const char* get_name_of_type(unsigned short){ return "unsigned short"; } +const char* get_name_of_type(int){ return "int"; } +const char* get_name_of_type(unsigned int){ return "unsigned int"; } +const char* get_name_of_type(long){ return "long"; } +const char* get_name_of_type(unsigned long){ return "unsigned long"; } +#ifdef BOOST_HAS_LONG_LONG +const char* get_name_of_type(long long){ return "long long"; } +const char* get_name_of_type(unsigned long long){ return "unsigned long long"; } #endif - -// 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_CHECK((boost::is_same::value)); + BOOST_CHECK((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(unsigned long long) * 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_CHECK(std::numeric_limits::digits + 1 >= Bits); + } + if(std::numeric_limits::is_specialized) + { + BOOST_CHECK(std::numeric_limits::digits >= Bits); + } + BOOST_CHECK(sizeof(least_int) * CHAR_BIT >= Bits); + BOOST_CHECK(sizeof(least_uint) * CHAR_BIT >= Bits); + BOOST_CHECK(sizeof(fast_int) >= sizeof(least_int)); + BOOST_CHECK(sizeof(fast_uint) >= sizeof(least_uint)); + // + // There should be no type smaller than least_* that also has enough bits: + // + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + } + } + } + } + // And again, but unsigned: + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + if(!boost::is_same::value) + { + BOOST_CHECK(std::numeric_limits::digits < Bits); + } + } + } + } -#define SHOW_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, (1UL << Number), Type) - -#define SHOW_SHIFTED_TYPES(Template, Type) SHOW_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_SHIFTED_TYPE(Template, 29, Type); SHOW_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_SHIFTED_TYPE(Template, 27, Type); SHOW_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_SHIFTED_TYPE(Template, 25, Type); SHOW_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_SHIFTED_TYPE(Template, 23, Type); SHOW_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_SHIFTED_TYPE(Template, 21, Type); SHOW_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_SHIFTED_TYPE(Template, 19, Type); SHOW_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_SHIFTED_TYPE(Template, 17, Type); SHOW_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_SHIFTED_TYPE(Template, 15, Type); SHOW_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_SHIFTED_TYPE(Template, 13, Type); SHOW_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_SHIFTED_TYPE(Template, 11, Type); SHOW_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_SHIFTED_TYPE(Template, 9, Type); SHOW_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_SHIFTED_TYPE(Template, 7, Type); SHOW_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_SHIFTED_TYPE(Template, 5, Type); SHOW_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_SHIFTED_TYPE(Template, 3, Type); SHOW_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_SHIFTED_TYPE(Template, 1, Type); SHOW_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_POS_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, +(1L << Number), Type) - -#define SHOW_POS_SHIFTED_TYPES(Template, Type) SHOW_POS_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 29, Type); SHOW_POS_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 27, Type); SHOW_POS_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 25, Type); SHOW_POS_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 23, Type); SHOW_POS_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 21, Type); SHOW_POS_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 19, Type); SHOW_POS_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 17, Type); SHOW_POS_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 15, Type); SHOW_POS_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 13, Type); SHOW_POS_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 11, Type); SHOW_POS_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 9, Type); SHOW_POS_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 7, Type); SHOW_POS_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 5, Type); SHOW_POS_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 3, Type); SHOW_POS_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_POS_SHIFTED_TYPE(Template, 1, Type); SHOW_POS_SHIFTED_TYPE(Template, 0, Type) - -#define SHOW_NEG_SHIFTED_TYPE(Template, Number, Type) SHOW_TYPE(Template, -(1L << Number), Type) - -#define SHOW_NEG_SHIFTED_TYPES(Template, Type) SHOW_NEG_SHIFTED_TYPE(Template, 30, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 29, Type); SHOW_NEG_SHIFTED_TYPE(Template, 28, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 27, Type); SHOW_NEG_SHIFTED_TYPE(Template, 26, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 25, Type); SHOW_NEG_SHIFTED_TYPE(Template, 24, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 23, Type); SHOW_NEG_SHIFTED_TYPE(Template, 22, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 21, Type); SHOW_NEG_SHIFTED_TYPE(Template, 20, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 19, Type); SHOW_NEG_SHIFTED_TYPE(Template, 18, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 17, Type); SHOW_NEG_SHIFTED_TYPE(Template, 16, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 15, Type); SHOW_NEG_SHIFTED_TYPE(Template, 14, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 13, Type); SHOW_NEG_SHIFTED_TYPE(Template, 12, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 11, Type); SHOW_NEG_SHIFTED_TYPE(Template, 10, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 9, Type); SHOW_NEG_SHIFTED_TYPE(Template, 8, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 7, Type); SHOW_NEG_SHIFTED_TYPE(Template, 6, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 5, Type); SHOW_NEG_SHIFTED_TYPE(Template, 4, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 3, Type); SHOW_NEG_SHIFTED_TYPE(Template, 2, Type); \ - SHOW_NEG_SHIFTED_TYPE(Template, 1, Type); SHOW_NEG_SHIFTED_TYPE(Template, 0, Type) - - -// Test if a constant can fit within a certain type -#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value ) - -#if (ULONG_MAX > 0xFFFFFFFFL) || !defined(BOOST_NO_INTEGRAL_INT64_T) -#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ - PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false ) -#else -#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \ - PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \ - PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false ) -#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 ) + if(boost::minimal_test::errors_counter() != last_error_count) + { + last_error_count = boost::minimal_test::errors_counter(); + std::cout << "Errors occured while testing with bit count = " << Bits << std::endl; + std::cout << "Type int_t<" << Bits << ">::least was " << get_name_of_type(least_int(0)) << std::endl; + std::cout << "Type int_t<" << Bits << ">::fast was " << get_name_of_type(fast_int(0)) << std::endl; + std::cout << "Type uint_t<" << Bits << ">::least was " << get_name_of_type(least_uint(0)) << std::endl; + std::cout << "Type uint_t<" << Bits << ">::fast was " << get_name_of_type(fast_uint(0)) << std::endl; + } +} +template <> +void do_test_bits<-1>() +{ + // Nothing to do here!! +} +template +void test_min_max_type(Expected val) +{ + typedef typename Traits::least least_type; + typedef typename Traits::fast fast_type; + BOOST_CHECK((boost::is_same::value)); + BOOST_CHECK(sizeof(fast_type) >= sizeof(least_type)); + BOOST_CHECK((std::numeric_limits::min)() <= val); + BOOST_CHECK((std::numeric_limits::max)() >= val); +} // Test program -int -test_main -( - int, - char*[] -) +int test_main(int, char*[]) { -#ifndef BOOST_NO_USING_TEMPLATE - using boost::int_t; - using boost::uint_t; - using boost::int_max_value_t; - using boost::int_min_value_t; - using boost::uint_value_t; -#else - using namespace boost; -#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 +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) + test_min_max_type, long long>(LONG_MAX+1LL); + test_min_max_type, long long>(LONG_MIN-1LL); + test_min_max_type, unsigned long long>(ULONG_MAX+1uLL); + test_min_max_type, long long>(LLONG_MAX); + test_min_max_type, long long>(LLONG_MIN); + test_min_max_type, unsigned long long>(ULLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) + test_min_max_type, long long>(LONG_MAX+1LL); + test_min_max_type, long long>(LONG_MIN-1LL); + test_min_max_type, unsigned long long>(ULONG_MAX+1uLL); + test_min_max_type, long long>(LONG_LONG_MAX); + test_min_max_type, long long>(LONG_LONG_MIN); + test_min_max_type, unsigned long long>(ULONG_LONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) + test_min_max_type, long long>(LONG_MAX+1LL); + test_min_max_type, long long>(LONG_MIN-1LL); + test_min_max_type, unsigned long long>(ULONG_MAX+1uLL); + test_min_max_type, long long>(LONGLONG_MAX); + test_min_max_type, long long>(LONGLONG_MAX); + test_min_max_type, unsigned long long>(ULONGLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(_ULLONG_MAX) && defined(_LLONG_MIN) && (_ULLONG_MAX != ULONG_MAX)) + test_min_max_type, long long>(LONG_MAX+1LL); + test_min_max_type, long long>(LONG_MIN-1LL); + test_min_max_type, unsigned long long>(ULONG_MAX+1uLL); + test_min_max_type, long long>(_LLONG_MAX); + test_min_max_type, long long>(_LLONG_MIN); + test_min_max_type, unsigned long long>(_ULLONG_MAX); +#endif + return 0; } From b83327861c98c7c18e4822a0ca68cc33833aa259 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 26 Nov 2009 12:59:39 +0000 Subject: [PATCH 51/64] Changed to use the lightweight test framework - we can now test with a much wider range of compilers. [SVN r57942] --- test/Jamfile.v2 | 17 ++---- test/cstdint_test.cpp | 113 +++++++++++++++++------------------ test/integer_mask_test.cpp | 12 ++-- test/integer_test.cpp | 54 +++++++++-------- test/integer_traits_test.cpp | 18 +++--- test/static_log2_test.cpp | 6 +- test/static_min_max_test.cpp | 73 +++++++++++----------- 7 files changed, 145 insertions(+), 148 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9104efc..7220a36 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -5,15 +5,10 @@ import testing ; test-suite integer - : [ run cstdint_test.cpp /boost/test//minimal ] - [ run integer_traits_test.cpp - /boost/test//boost_test_exec_monitor ] - [ run integer_test.cpp - /boost/test//minimal ] - [ run integer_mask_test.cpp - /boost/test//minimal ] - [ run static_log2_test.cpp - /boost/test//boost_test_exec_monitor ] - [ run static_min_max_test.cpp - /boost/test//boost_test_exec_monitor ] + : [ run cstdint_test.cpp ] + [ run integer_traits_test.cpp ] + [ run integer_test.cpp ] + [ run integer_mask_test.cpp ] + [ run static_log2_test.cpp ] + [ run static_min_max_test.cpp ] ; diff --git a/test/cstdint_test.cpp b/test/cstdint_test.cpp index 6d26b91..2ee450a 100644 --- a/test/cstdint_test.cpp +++ b/test/cstdint_test.cpp @@ -15,8 +15,7 @@ #define __STDC_CONSTANT_MACROS #include #include -#include - +#include #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION // @@ -55,24 +54,24 @@ struct integral_constant_checker void integral_constant_checker::check() { - BOOST_CHECK( int8 == -127 ); - BOOST_CHECK( int_least8 == -127 ); - BOOST_CHECK( int_fast8 == -127 ); - BOOST_CHECK( uint8 == 255u ); - BOOST_CHECK( uint_least8 == 255u ); - BOOST_CHECK( uint_fast8 == 255u ); - BOOST_CHECK( int16 == -32767 ); - BOOST_CHECK( int_least16 == -32767 ); - BOOST_CHECK( int_fast16 == -32767 ); - BOOST_CHECK( uint16 == 65535u ); - BOOST_CHECK( uint_least16 == 65535u ); - BOOST_CHECK( uint_fast16 == 65535u ); - BOOST_CHECK( int32 == -2147483647 ); - BOOST_CHECK( int_least32 == -2147483647 ); - BOOST_CHECK( int_fast32 == -2147483647 ); - BOOST_CHECK( uint32 == 4294967295u ); - BOOST_CHECK( uint_least32 == 4294967295u ); - BOOST_CHECK( uint_fast32 == 4294967295u ); + 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 @@ -101,10 +100,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: - BOOST_CHECK(sizeof(T1) <= sizeof(T2)); + BOOST_TEST(sizeof(T1) <= sizeof(T2)); #else - BOOST_CHECK(sizeof(T1) == sizeof(T2)); - BOOST_CHECK(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 @@ -112,22 +111,22 @@ void integral_constant_type_check(T1, T2) if(sizeof(T1) >= sizeof(int)) { if(t1 > 0) - BOOST_CHECK(t2 > 0); + BOOST_TEST(t2 > 0); else - BOOST_CHECK(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); } else if(t1 < 0) - BOOST_CHECK(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); #else if(t1 > 0) - BOOST_CHECK(t2 > 0); + BOOST_TEST(t2 > 0); else - BOOST_CHECK(!(t2 > 0)); + BOOST_TEST(!(t2 > 0)); #endif } -int test_main(int, char*[]) +int main(int, char*[]) { #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION integral_constant_checker::check(); @@ -186,37 +185,37 @@ int test_main(int, char*[]) boost::uintmax_t uintmax = UINTMAX_C(4294967295); #endif - BOOST_CHECK( int8 == -127 ); - BOOST_CHECK( int_least8 == -127 ); - BOOST_CHECK( int_fast8 == -127 ); - BOOST_CHECK( uint8 == 255u ); - BOOST_CHECK( uint_least8 == 255u ); - BOOST_CHECK( uint_fast8 == 255u ); - BOOST_CHECK( int16 == -32767 ); - BOOST_CHECK( int_least16 == -32767 ); - BOOST_CHECK( int_fast16 == -32767 ); - BOOST_CHECK( uint16 == 65535u ); - BOOST_CHECK( uint_least16 == 65535u ); - BOOST_CHECK( uint_fast16 == 65535u ); - BOOST_CHECK( int32 == -2147483647 ); - BOOST_CHECK( int_least32 == -2147483647 ); - BOOST_CHECK( int_fast32 == -2147483647 ); - BOOST_CHECK( uint32 == 4294967295u ); - BOOST_CHECK( uint_least32 == 4294967295u ); - BOOST_CHECK( uint_fast32 == 4294967295u ); + 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_CHECK( int64 == INT64_C(-9223372036854775807) ); - BOOST_CHECK( int_least64 == INT64_C(-9223372036854775807) ); - BOOST_CHECK( int_fast64 == INT64_C(-9223372036854775807) ); - BOOST_CHECK( uint64 == UINT64_C(18446744073709551615) ); - BOOST_CHECK( uint_least64 == UINT64_C(18446744073709551615) ); - BOOST_CHECK( uint_fast64 == UINT64_C(18446744073709551615) ); - BOOST_CHECK( intmax == INT64_C(-9223372036854775807) ); - BOOST_CHECK( uintmax == UINT64_C(18446744073709551615) ); + 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_CHECK( intmax == -2147483647 ); - BOOST_CHECK( uintmax == 4294967295u ); + BOOST_TEST( intmax == -2147483647 ); + BOOST_TEST( uintmax == 4294967295u ); #endif diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 8e0c11a..e54c031 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -10,7 +10,7 @@ // 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. @@ -21,9 +21,9 @@ #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) @@ -33,20 +33,20 @@ unsigned long mask = 0;\ if(v > 0)\ { mask = ((1ul << (v-1)) - 1); mask <<= 1; mask |= 1; }\ - BOOST_CHECK( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \ + 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_CHECK( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\ + 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; diff --git a/test/integer_test.cpp b/test/integer_test.cpp index e70ac86..c709282 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -15,7 +15,7 @@ // 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) // 31 Aug 99 Initial version -#include // for main, BOOST_CHECK +#include // for main, BOOST_TEST #include // for boost::int_t, boost::uint_t #include @@ -26,11 +26,15 @@ #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: // -unsigned last_error_count = 0; +int last_error_count = 0; // // Helpers to print out the name of a type, // we use these as typeid(X).name() doesn't always @@ -59,8 +63,8 @@ void do_test_exact(boost::mpl::true_ const&) typedef typename boost::int_t::least least_int; typedef typename boost::uint_t::least least_uint; - BOOST_CHECK((boost::is_same::value)); - BOOST_CHECK((boost::is_same::value)); + BOOST_TEST((boost::is_same::value)); + BOOST_TEST((boost::is_same::value)); } template void do_test_exact(boost::mpl::false_ const&) @@ -98,31 +102,31 @@ void do_test_bits() if(std::numeric_limits::is_specialized) { - BOOST_CHECK(std::numeric_limits::digits + 1 >= Bits); + BOOST_TEST(std::numeric_limits::digits + 1 >= Bits); } if(std::numeric_limits::is_specialized) { - BOOST_CHECK(std::numeric_limits::digits >= Bits); + BOOST_TEST(std::numeric_limits::digits >= Bits); } - BOOST_CHECK(sizeof(least_int) * CHAR_BIT >= Bits); - BOOST_CHECK(sizeof(least_uint) * CHAR_BIT >= Bits); - BOOST_CHECK(sizeof(fast_int) >= sizeof(least_int)); - BOOST_CHECK(sizeof(fast_uint) >= sizeof(least_uint)); + 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_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); } } } @@ -130,24 +134,24 @@ void do_test_bits() // And again, but unsigned: if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); if(!boost::is_same::value) { - BOOST_CHECK(std::numeric_limits::digits < Bits); + BOOST_TEST(std::numeric_limits::digits < Bits); } } } } - if(boost::minimal_test::errors_counter() != last_error_count) + if(boost::detail::test_errors() != last_error_count) { - last_error_count = boost::minimal_test::errors_counter(); + 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; @@ -166,14 +170,14 @@ void test_min_max_type(Expected val) { typedef typename Traits::least least_type; typedef typename Traits::fast fast_type; - BOOST_CHECK((boost::is_same::value)); - BOOST_CHECK(sizeof(fast_type) >= sizeof(least_type)); - BOOST_CHECK((std::numeric_limits::min)() <= val); - BOOST_CHECK((std::numeric_limits::max)() >= val); + 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); } // Test program -int test_main(int, char*[]) +int main(int, char*[]) { // Test int_t and unint_t first: if(std::numeric_limits::is_specialized) diff --git a/test/integer_traits_test.cpp b/test/integer_traits_test.cpp index 065f90a..701764b 100644 --- a/test/integer_traits_test.cpp +++ b/test/integer_traits_test.cpp @@ -17,7 +17,7 @@ // use int64_t instead of long long for better portability #include -#include +#include /* * General portability note: @@ -52,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()); diff --git a/test/static_log2_test.cpp b/test/static_log2_test.cpp index 00446e3..5dba689 100644 --- a/test/static_log2_test.cpp +++ b/test/static_log2_test.cpp @@ -10,7 +10,7 @@ // Revision History // 01 Oct 2001 Initial version (Daryle Walker) -#include // for main +#include // for main #include // for boost::exit_success #include // for boost::static_log2 @@ -19,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 @@ -34,7 +34,7 @@ // Main testing function int -test_main +main ( int , // "argc" is unused char * [] // "argv" is unused diff --git a/test/static_min_max_test.cpp b/test/static_min_max_test.cpp index ed081f7..37ea6bd 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; } From fad95e3d1f30d7580e41ae90456e235bb73765b2 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 26 Nov 2009 13:35:03 +0000 Subject: [PATCH 52/64] Oops, tests should return the error code is any. [SVN r57943] --- test/cstdint_test.cpp | 2 +- test/integer_mask_test.cpp | 2 +- test/integer_test.cpp | 2 +- test/integer_traits_test.cpp | 2 +- test/static_log2_test.cpp | 2 +- test/static_min_max_test.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cstdint_test.cpp b/test/cstdint_test.cpp index 2ee450a..9c40d3d 100644 --- a/test/cstdint_test.cpp +++ b/test/cstdint_test.cpp @@ -220,5 +220,5 @@ int main(int, char*[]) std::cout << "OK\n"; - return 0; + return boost::report_errors(); } diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index e54c031..4c1bb4b 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -119,5 +119,5 @@ int 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 c709282..e7dbbe4 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -247,5 +247,5 @@ int main(int, char*[]) test_min_max_type, long long>(_LLONG_MIN); test_min_max_type, unsigned long long>(_ULLONG_MAX); #endif - return 0; + return boost::report_errors(); } diff --git a/test/integer_traits_test.cpp b/test/integer_traits_test.cpp index 701764b..9c5fcd0 100644 --- a/test/integer_traits_test.cpp +++ b/test/integer_traits_test.cpp @@ -96,6 +96,6 @@ int 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_test.cpp b/test/static_log2_test.cpp index 5dba689..f92d801 100644 --- a/test/static_log2_test.cpp +++ b/test/static_log2_test.cpp @@ -145,5 +145,5 @@ 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_test.cpp b/test/static_min_max_test.cpp index 37ea6bd..124e137 100644 --- a/test/static_min_max_test.cpp +++ b/test/static_min_max_test.cpp @@ -88,5 +88,5 @@ main 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(); } From 154b9ce992a37a7c17ac38212baf259fc5e6bc3d Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 26 Nov 2009 15:43:32 +0000 Subject: [PATCH 53/64] Fix some typos. [SVN r57946] --- doc/html/boost_integer/history.html | 4 ++-- doc/html/boost_integer/integer.html | 4 ++-- doc/html/boost_integer/mask.html | 8 ++++---- doc/html/index.html | 4 ++-- doc/integer.qbk | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/html/boost_integer/history.html b/doc/html/boost_integer/history.html index 6d4b878..105ac89 100644 --- a/doc/html/boost_integer/history.html +++ b/doc/html/boost_integer/history.html @@ -26,7 +26,7 @@ History
      - + 1.42.0
        @@ -55,7 +55,7 @@
      - + 1.32.0
      • diff --git a/doc/html/boost_integer/integer.html b/doc/html/boost_integer/integer.html index 50d58d9..1b45764 100644 --- a/doc/html/boost_integer/integer.html +++ b/doc/html/boost_integer/integer.html @@ -140,7 +140,7 @@ fast. The following table describes each template's criteria.

        -

        Table 1. Criteria for the Sized Type Class Templates

        +

        Table 1. Criteria for the Sized Type Class Templates

        @@ -256,7 +256,7 @@ boost::int_max_value_t<1000>::leastmy1000=1000;//... // This one is guarenteed not to be truncated, and as fast -// to manipulate as possible, it's size may be greater than +// to manipulate as possible, its size may be greater than // that of my1000: boost::int_max_value_t<1000>::fastmy_fast1000=1000;} diff --git a/doc/html/boost_integer/mask.html b/doc/html/boost_integer/mask.html index 9aee7d0..9fab512 100644 --- a/doc/html/boost_integer/mask.html +++ b/doc/html/boost_integer/mask.html @@ -105,7 +105,7 @@ of high_bit_mask_t.

        -

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

        +

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

        @@ -205,7 +205,7 @@ the members of an instantiation of low_bits_mask_t.

        -

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

        +

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

        @@ -344,9 +344,9 @@

        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 + 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 contaimination of values by the higher, unused bits. + bits. This prevents contamination of values by the higher, unused bits.

        diff --git a/doc/html/index.html b/doc/html/index.html index dab3f7c..58077eb 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -40,7 +40,7 @@
        -

        +

        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)

        @@ -229,7 +229,7 @@
        - +

        Last revised: November 26, 2009 at 11:06:43 GMT

        Last revised: November 26, 2009 at 15:42:57 GMT


        diff --git a/doc/integer.qbk b/doc/integer.qbk index 36f9a1b..5417d3c 100644 --- a/doc/integer.qbk +++ b/doc/integer.qbk @@ -399,7 +399,7 @@ The following table describes each template's criteria. boost::int_max_value_t<1000>::least my1000 = 1000; //... // This one is guarenteed not to be truncated, and as fast - // to manipulate as possible, it's size may be greater than + // to manipulate as possible, its size may be greater than // that of my1000: boost::int_max_value_t<1000>::fast my_fast1000 = 1000; } @@ -568,9 +568,9 @@ results from instantiating various examples of the bit mask class templates. [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 convienent masks to use when extracting the +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 contaimination of values by the higher, unused bits. +This prevents contamination of values by the higher, unused bits. [endsect] From 98b57c1f3b6612894af65fd6985c3234d65aa126 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 26 Nov 2009 18:06:10 +0000 Subject: [PATCH 54/64] Get the tests warning free with gcc, and add conceptual-header-inclusion tests. [SVN r57948] --- test/Jamfile.v2 | 13 +++++- test/cstdint_include_test.cpp | 69 ++++++++++++++++++++++++++++ test/integer_fwd_include_test.cpp | 22 +++++++++ test/integer_include_test.cpp | 36 +++++++++++++++ test/integer_mask_include_test.cpp | 18 ++++++++ test/integer_traits_include_test.cpp | 37 +++++++++++++++ test/static_log2_include_test.cpp | 14 ++++++ test/static_min_max_include_test.cpp | 14 ++++++ 8 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 test/cstdint_include_test.cpp create mode 100644 test/integer_fwd_include_test.cpp create mode 100644 test/integer_include_test.cpp create mode 100644 test/integer_mask_include_test.cpp create mode 100644 test/integer_traits_include_test.cpp create mode 100644 test/static_log2_include_test.cpp create mode 100644 test/static_min_max_include_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7220a36..0732774 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -4,11 +4,20 @@ import testing ; +project : requirements all gcc:-Wextra ; + test-suite integer - : [ run cstdint_test.cpp ] + : [ run cstdint_test.cpp : : : gcc:-Wno-long-long gcc:-Wno-type-limits ] [ run integer_traits_test.cpp ] - [ run integer_test.cpp ] + [ run integer_test.cpp : : : gcc:-Wno-long-long ] [ 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/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_traits_include_test.cpp b/test/integer_traits_include_test.cpp new file mode 100644 index 0000000..ddbe070 --- /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(); +#ifdef BOOST_HAS_LONG_LONG + check(); + check(); +#endif +} 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_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; +} From 6a497ee263a87672d2c75aeaaa29bc2c935aeba1 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 27 Nov 2009 11:13:02 +0000 Subject: [PATCH 55/64] Regenerate with new stylesheets. [SVN r57968] --- doc/html/boost_integer/cstdint.html | 4 ++-- doc/html/boost_integer/history.html | 8 ++++---- doc/html/boost_integer/integer.html | 6 +++--- doc/html/boost_integer/log2.html | 4 ++-- doc/html/boost_integer/mask.html | 8 ++++---- doc/html/boost_integer/minmax.html | 4 ++-- doc/html/boost_integer/traits.html | 4 ++-- doc/html/index.html | 8 ++++---- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/html/boost_integer/cstdint.html b/doc/html/boost_integer/cstdint.html index fca043b..ce7bcf1 100644 --- a/doc/html/boost_integer/cstdint.html +++ b/doc/html/boost_integer/cstdint.html @@ -1,6 +1,6 @@ - + Standard Integer Types @@ -220,7 +220,7 @@
        -
        - + 1.42.0
          @@ -55,7 +55,7 @@
        - + 1.32.0
        • @@ -67,7 +67,7 @@
        -