Compare commits

...

34 Commits

Author SHA1 Message Date
229056d7bc bcbboost branch rebased on current release
[SVN r49389]
2008-10-19 14:43:01 +00:00
648ff2fe0c Patches for Codegear C++ Builder 2009
[SVN r48981]
2008-09-27 08:59:20 +00:00
2d259a4f3e 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]
2008-07-29 19:33:20 +00:00
2fd0675a21 Hopefully made compile-time constants suitable for more compilers
[SVN r47852]
2008-07-28 14:41:00 +00:00
f041dc0f0a Added extended-integer support
[SVN r47842]
2008-07-27 17:08:51 +00:00
188cef05a9 Changed the Integer-mask test to use the unit-test system
[SVN r47841]
2008-07-27 16:34:38 +00:00
2ae867bcf8 Corrected link to corresponding test files
[SVN r47838]
2008-07-27 09:00:54 +00:00
2fcbc31b77 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]
2008-07-25 12:39:06 +00:00
4af7660410 Encapsulated the mutually exclusive 'long long' and '__int64' type families into a single interface
[SVN r47754]
2008-07-24 11:43:02 +00:00
2b7ed6ebf7 Resolved namespace conflict from unadorned call, which fixes #2134
[SVN r47742]
2008-07-23 22:40:20 +00:00
203705fea6 Moved preprocessor selection from within macro-function calls to surrounding whole macro calls (some compilers suspend preprocessor directives within a macro call)
[SVN r47696]
2008-07-23 06:55:23 +00:00
ed80575830 Added MPL-compatible variants of the minimum-size and value-based integer templates, which fixes #1224
[SVN r47470]
2008-07-16 09:55:31 +00:00
f27ad7b337 Added MPL-compatible variant of the processor-optimized integer template
[SVN r47452]
2008-07-15 18:56:59 +00:00
55e1796c7a Added exact-integer templates, which fixes #1225 (and completes #653)
[SVN r47434]
2008-07-15 09:59:19 +00:00
053be71261 Added extended-integer support, which fixes #653 (the main part; the secondary part is split off as #1225)
[SVN r47414]
2008-07-14 06:28:54 +00:00
10e5587b9e Improved/added testing for the processor-optimized integer template
[SVN r47413]
2008-07-14 04:25:31 +00:00
2f91e69629 Re-did implementation
[SVN r47408]
2008-07-13 23:30:18 +00:00
422ef1ebe6 Replaced comprehensive macros with focused templates
[SVN r47404]
2008-07-13 21:08:16 +00:00
edfaeb6c0e Changed the Integer-selection test to use the unit-test system
[SVN r47200]
2008-07-07 23:13:43 +00:00
3c7910fad3 Added entries for the forgotten tests
[SVN r47123]
2008-07-06 00:58:34 +00:00
600801670e Move integer tests into canonical test subdir structure.
[SVN r44384]
2008-04-13 23:00:19 +00:00
85e4d3e23d Merged revisions 43206,43208-43213 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix some broken links.
........
  r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Link to people pages on the website, as they've been removed from the download.
........
  r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Point links to the pages that used to be in 'more' to the site.
........
  r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix links on the home page as well.
........
  r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Generated documentation which is no longer generated.
........


[SVN r43214]
2008-02-10 16:39:38 +00:00
4e2c8440b5 Point links to the pages that used to be in 'more' to the site.
[SVN r43210]
2008-02-10 15:02:17 +00:00
94ace80618 Link to people pages on the website, as they've been removed from the download.
[SVN r43209]
2008-02-10 14:56:22 +00:00
550fe9d89f Merged revisions 43129,43131,43137,43139-43140,43142,43144,43146,43149,43151,43153,43158,43160-43164,43167-43170,43172-43174,43178,43180-43193 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43129 | danieljames | 2008-02-06 19:02:38 +0000 (Wed, 06 Feb 2008) | 2 lines
  
  In the boostbook navbar, link FAQ and people to the website.
........
  r43188 | danieljames | 2008-02-09 12:29:02 +0000 (Sat, 09 Feb 2008) | 2 lines
  
  Fix a link in the intrusive redirect.
........
  r43189 | danieljames | 2008-02-09 12:37:00 +0000 (Sat, 09 Feb 2008) | 1 line
  
  Fix another redirect link.
........
  r43190 | danieljames | 2008-02-09 12:38:19 +0000 (Sat, 09 Feb 2008) | 1 line
  
  Update link to Jamfile, to link to the version 2 jamfile.
........
  r43191 | danieljames | 2008-02-09 12:39:06 +0000 (Sat, 09 Feb 2008) | 1 line
  
  Fix a link.
........
  r43192 | danieljames | 2008-02-09 12:45:32 +0000 (Sat, 09 Feb 2008) | 2 lines
  
  Add a forwarding header for hash/custom.html as Boost.Bimap links to it.
........
  r43193 | danieljames | 2008-02-09 13:02:45 +0000 (Sat, 09 Feb 2008) | 1 line
  
  Fix the link to the license.
........


[SVN r43194]
2008-02-09 13:27:00 +00:00
cd6a9565ff Fix the link to the license.
[SVN r43193]
2008-02-09 13:02:45 +00:00
19ed0e48e0 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
559b44c259 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
b162db6b72 Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
f17447cd24 Branch for CodeGear (Borland) specific fixes
[SVN r39356]
2007-09-17 20:28:43 +00:00
4935afbcd4 This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

[SVN r38286]
2007-07-24 19:28:14 +00:00
167961aba1 Correct testing bugs:
either changing assert(...) or BOOST_ASSERT(...) to BOOST_TEST
    (in my code only)

    or adding "return boost::report_errors();" where it was clearly
    missing (and a pure bug, in anyone's code).

    or changing BOOST_TEST to BOOST_CHECK where the integer library
    was clearly using Boost.Test and not returning report_errors().


[SVN r37063]
2007-02-25 15:28:02 +00:00
7ce7ba6bfd Changed test to reflect changes made to C99 in the TC.
[SVN r35333]
2006-09-26 09:04:05 +00:00
c8cb2b24a1 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
11 changed files with 1260 additions and 10 deletions

View File

@ -196,7 +196,7 @@ contaimination of values by the higher, unused bits.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of the Boost bit mask class templates is <a
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
<hr>

View File

@ -186,7 +186,7 @@ code (and update old code as soon as possible).
<p>The original version of the Boost binary logarithm class template was
written by <a href="../../../people/daryle_walker.html">Daryle Walker</a>
written by <a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>
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

View File

@ -106,7 +106,7 @@ class template.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of the Boost compile-time extrema class templates is <a
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
<hr>

View File

@ -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 <http://www.boost.org/LICENSE_1_0.txt>.)
// 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 <boost/config.hpp> // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64
#include <climits> // 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 (<code>unsigned</code>) <code>long long</code> or
(<code>unsigned</code>) <code>__int64</code>. \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 <code>signed long</code> 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 <code>unsigned long</code> if
\c BOOST_HAS_XINT is zero.
*/
} // namespace detail
} // namespace boost
#endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP

View File

@ -10,8 +10,8 @@
<td bgcolor="white"><img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
<td><a href="../../people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
<td><a href="../../more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
</tr>
</table>

View File

@ -193,11 +193,11 @@ href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;</a></cite>.</p>
<h2><a name="credits">Credits</a></h2>
<p>The author of most of the Boost integer type choosing templates is <a
href="../../people/beman_dawes.html">Beman Dawes</a>. He gives thanks
href="http://www.boost.org/people/beman_dawes.html">Beman Dawes</a>. He gives thanks
to Valentin Bonnard and
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
<a href="http://www.boost.org/people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
their designs for similar templates. <a
href="../../people/daryle_walker.html">Daryle Walker</a> designed the
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a> designed the
value-based sized templates.</p>
<hr>
@ -206,7 +206,7 @@ value-based sized templates.</p>
<p>&copy; Copyright Beman Dawes 1999. Use, modification, and distribution are
subject to the Boost Software License, Version 1.0. (See accompanying file <a
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at &lt;<a
href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at &lt;<a
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)</p>
</body>
</html>
</html>

20
test/Jamfile.v2 Normal file
View File

@ -0,0 +1,20 @@
#~ 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
/boost/test//boost_unit_test_framework ]
[ run integer_traits_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ run integer_mask_test.cpp
/boost/test//boost_unit_test_framework ]
[ run static_log2_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ run static_min_max_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ compile issue_2134.cpp ]
;

233
test/cstdint_test.cpp Normal file
View File

@ -0,0 +1,233 @@
// boost cstdint.hpp test program ------------------------------------------//
// Copyright Beman Dawes 2000. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
// 28 Jun 00 Initial version
#define __STDC_CONSTANT_MACROS
#include <cassert>
#include <iostream>
#include <boost/cstdint.hpp>
#ifdef NDEBUG
int main()
{
std::cout << "This test makes no sense with NDEBUG defined.\n";
return 0;
}
#else
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following class is designed to verify
// that the various INTXX_C macros can be used
// in integral constant expressions:
//
struct integral_constant_checker
{
static const boost::int8_t int8 = INT8_C(-127);
static const boost::int_least8_t int_least8 = INT8_C(-127);
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
static const boost::uint8_t uint8 = UINT8_C(255);
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
static const boost::int16_t int16 = INT16_C(-32767);
static const boost::int_least16_t int_least16 = INT16_C(-32767);
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
static const boost::uint16_t uint16 = UINT16_C(65535);
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
static const boost::int32_t int32 = INT32_C(-2147483647);
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
static const boost::uint32_t uint32 = UINT32_C(4294967295);
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
static void check();
};
void integral_constant_checker::check()
{
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
}
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following function simply verifies that the type
// of an integral constant is correctly defined:
//
#ifdef __BORLANDC__
#pragma option -w-8008
#pragma option -w-8066
#endif
template <class T1, class T2>
void integral_constant_type_check(T1, T2)
{
//
// the types T1 and T2 may not be exactly
// the same type, but they should be the
// same size and signedness. We could use
// numeric_limits to verify this, but
// numeric_limits implementations currently
// vary too much, or are incomplete or missing.
//
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
T2 t2 = static_cast<T2>(-1); // ditto
#if defined(BOOST_HAS_STDINT_H)
// if we have a native stdint.h
// then the INTXX_C macros may define
// a type that's wider than required:
assert(sizeof(T1) <= sizeof(T2));
#else
assert(sizeof(T1) == sizeof(T2));
assert(t1 == t2);
#endif
#if 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
}
int main()
{
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
integral_constant_checker::check();
#endif
//
// verify the types of the integral constants:
//
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
#ifndef BOOST_NO_INT64_T
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
#endif
//
boost::int8_t int8 = INT8_C(-127);
boost::int_least8_t int_least8 = INT8_C(-127);
boost::int_fast8_t int_fast8 = INT8_C(-127);
boost::uint8_t uint8 = UINT8_C(255);
boost::uint_least8_t uint_least8 = UINT8_C(255);
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
boost::int16_t int16 = INT16_C(-32767);
boost::int_least16_t int_least16 = INT16_C(-32767);
boost::int_fast16_t int_fast16 = INT16_C(-32767);
boost::uint16_t uint16 = UINT16_C(65535);
boost::uint_least16_t uint_least16 = UINT16_C(65535);
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
boost::int32_t int32 = INT32_C(-2147483647);
boost::int_least32_t int_least32 = INT32_C(-2147483647);
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
boost::uint32_t uint32 = UINT32_C(4294967295);
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
#ifndef BOOST_NO_INT64_T
boost::int64_t int64 = INT64_C(-9223372036854775807);
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
#else
boost::intmax_t intmax = INTMAX_C(-2147483647);
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
#endif
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
#ifndef BOOST_NO_INT64_T
assert( int64 == INT64_C(-9223372036854775807) );
assert( int_least64 == INT64_C(-9223372036854775807) );
assert( int_fast64 == INT64_C(-9223372036854775807) );
assert( uint64 == UINT64_C(18446744073709551615) );
assert( uint_least64 == UINT64_C(18446744073709551615) );
assert( uint_fast64 == UINT64_C(18446744073709551615) );
assert( intmax == INT64_C(-9223372036854775807) );
assert( uintmax == UINT64_C(18446744073709551615) );
#else
assert( intmax == -2147483647 );
assert( uintmax == 4294967295u );
#endif
std::cout << "OK\n";
return 0;
}
#endif

685
test/integer_test.cpp Normal file
View File

@ -0,0 +1,685 @@
// boost integer.hpp test program ------------------------------------------//
// Copyright Beman Dawes 1999. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 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 <boost/test/unit_test.hpp> // unit testing framework
#include <boost/config.hpp> // for BOOST_NO_SFINAE
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t, etc.
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
#include <boost/detail/extended_integer.hpp> // BOOST_HAS_XINT, BOOST_UXINT_MAX
#include <boost/mpl/arithmetic.hpp> // for boost::mpl::plus, divides
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION, etc.
#include <boost/mpl/back.hpp> // for boost::mpl::back
#include <boost/mpl/copy.hpp> // for boost::mpl::copy
#include <boost/mpl/equal.hpp> // for boost::mpl::equal
#include <boost/mpl/front_inserter.hpp> // for boost::mpl::front_inserter
#include <boost/mpl/int.hpp> // for boost::mpl::int_
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
#include <boost/mpl/joint_view.hpp> // for boost::mpl::joint_view
#include <boost/mpl/pop_back.hpp> // for boost::mpl::pop_back
#include <boost/mpl/push_back.hpp> // for boost::mpl::push_back
#include <boost/mpl/push_front.hpp> // for boost::mpl::push_front
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
#include <boost/mpl/shift_right.hpp> // for boost::mpl::shift_right
#include <boost/mpl/sort.hpp> // for boost::mpl::sort
#include <boost/mpl/transform.hpp> // for boost::mpl::transform
#include <boost/mpl/transform_view.hpp> // for boost::mpl::transform_view
#include <boost/mpl/unpack_args.hpp> // for boost::mpl::unpack_args
#include <boost/mpl/vector.hpp> // for boost::mpl::vector
#include <boost/mpl/zip_view.hpp> // for boost::mpl::zip_view
#include <boost/type_traits/is_same.hpp> // for boost::is_same
#include <boost/type_traits/make_signed.hpp> // for boost::make_signed
#include <algorithm> // for std::binary_search
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN, etc.
#include <cstddef> // for std::size_t
#include <iostream> // for std::cout
#include <ostream> // for std::endl
#include <typeinfo> // 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
#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
// 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 fast_integral< short >
{
typedef CONTROL_FAST_SHORT type;
};
}
// 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
{
// 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<T>::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<boost:: intmax_t> intmax_limits;
typedef std::numeric_limits<boost::uintmax_t> 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<int, 0, uintmax_bits + 2> bits_list;
#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<int, uintmax_bits + 1>
>
>
>::type
>::type bits_list;
#endif
// Remove the outlier when all bits counts must be valid
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 0, uintmax_bits + 1> valid_bits_list;
#else
typedef boost::mpl::pop_back<bits_list>::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<int, 1, uintmax_bits + 1>
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<int, 0, uintmax_bits> 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<int, 0, intmax_bits - 2>
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<Bits, signed> {};
template < int Bits >
struct unsigned_sized_integral : boost::sized_integral<Bits, unsigned> {};
template < int Bits >
struct signed_exact_integral : boost::exact_integral<Bits, signed> {};
template < int Bits >
struct unsigned_exact_integral : boost::exact_integral<Bits, unsigned> {};
// Use SFINAE to check if a particular parameter is supported
#ifndef BOOST_NO_SFINAE
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
bool
print_out_template( Tmpl<Value> const &, ValueT setting, char const
*template_pre_name, char const *template_post_name, typename Tmpl<Value>::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( "This is " << template_pre_name << setting
<< template_post_name << " specialization, with type '" << typeid(typename
Tmpl<Value>::type).name() << "'." );
return true;
}
template < typename ValueT, typename T >
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
<< 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<T>::const_min >
{
};
template < typename T >
struct maximum_of
: boost::mpl::integral_c< T, boost::integer_traits<T>::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<least_type>::fast fast_type;
typedef std::numeric_limits<least_type> least_limits;
typedef std::numeric_limits<fast_type> fast_limits;
typedef boost::fast_integral<least_type>::type real_fast_type;
BOOST_MPL_ASSERT_RELATION( (boost::is_same<least_type, fast_type>::value),
==, false );
BOOST_MPL_ASSERT_RELATION( (boost::is_same<fast_type,
real_fast_type>::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>(),
T::value, "a sized_integral<", ", signed>"), T::value && (T::value <=
intmax_bits) );
BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral<T::value>(),
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<N>::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<typename
boost::uint_t<T::value>::least>::digits, >=, T::value );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::uint_t<T::value>::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<typename
boost::int_t<T::value>::least>::digits, >=, T::value - 1 );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::int_t<T::value>::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<T::value + 1> >) );
}
// 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<T::value + 1> >) );
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one
<< T::value)>, signed_sized_integral<T::value + 1> >) );
}
// 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>(),
T::value, "an exact_integral<", ", signed>"), is_exact_length );
BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral<T::value>(),
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<typename
boost::int_exact_t<T::value>::exact>::digits, ==, T::value - 1 );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::uint_exact_t<T::value>::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<typename Template<N>::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<typename
unsigned_sized_integral<count>::type>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_t<count>::least>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_t<count>::fast>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
signed_sized_integral<count>::type>(value_s), value_s );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_t<count>::least>(value_s), value_s );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_t<count>::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<T::value, unsigned>::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<T::value, signed>::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<typename Template<V>::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<maximum_of<uintmax_t>, T> maxi_type;
uintmax_t const maxi = maxi_type::value;
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_value_t<maxi_type::value>::least>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_value_t<maxi_type::value>::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<typename Template<V>::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<minimum_of<intmax_t>, T> mini_type;
typedef boost::mpl::shift_right<maximum_of<intmax_t>, T> maxi_type;
intmax_t const maxi = maxi_type::value, mini = mini_type::value;
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_max_value_t<maxi_type::value>::least>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_max_value_t<maxi_type::value>::fast>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_min_value_t<mini_type::value>::least>(mini), mini );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_min_value_t<mini_type::value>::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()

View File

@ -0,0 +1,102 @@
/* boost integer_traits.hpp tests
*
* Copyright Jens Maurer 2000
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id$
*
* Revision history
* 2000-02-22 Small improvements by Beman Dawes
* 2000-06-27 Rework for better MSVC and BCC co-operation
*/
#include <iostream>
#include <boost/integer_traits.hpp>
// use int64_t instead of long long for better portability
#include <boost/cstdint.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
/*
* General portability note:
* MSVC mis-compiles explicit function template instantiations.
* For example, f<A>() and f<B>() are both compiled to call f<A>().
* BCC is unable to implicitly convert a "const char *" to a std::string
* when using explicit function template instantiations.
*
* Therefore, avoid explicit function template instantiations.
*/
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
namespace fix{
inline int make_char_numeric_for_streaming(char c) { return c; }
inline int make_char_numeric_for_streaming(signed char c) { return c; }
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
}
using namespace fix;
#else
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
inline int make_char_numeric_for_streaming(char c) { return c; }
inline int make_char_numeric_for_streaming(signed char c) { return c; }
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
#endif
template<class T>
void runtest(const char * type, T)
{
typedef boost::integer_traits<T> traits;
std::cout << "Checking " << type
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
<< std::endl;
BOOST_CHECK(traits::is_specialized);
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
// generates different symbol names with a very long common prefix:
// the dummy "&& true" disambiguates between the symbols generated by this
// BOOST_CHECK instantiation and the preceding one.
BOOST_CHECK(traits::is_integer && true);
#else
BOOST_CHECK(traits::is_integer);
#endif
BOOST_CHECK(traits::is_integral == true);
BOOST_CHECK(traits::const_min == (traits::min)());
BOOST_CHECK(traits::const_max == (traits::max)());
}
int test_main(int, char*[])
{
runtest("bool", bool());
runtest("char", char());
typedef signed char signed_char;
runtest("signed char", signed_char());
typedef unsigned char unsigned_char;
runtest("unsigned char", unsigned_char());
runtest("wchar_t", wchar_t());
runtest("short", short());
typedef unsigned short unsigned_short;
runtest("unsigned short", unsigned_short());
runtest("int", int());
typedef unsigned int unsigned_int;
runtest("unsigned int", unsigned_int());
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_long());
#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
//
// MS/Borland compilers can't support 64-bit member constants
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
runtest("int64_t (possibly long long)", boost::int64_t());
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
#else
std::cout << "Skipped int64_t and uint64_t" << std::endl;
#endif
// Some compilers don't pay attention to std:3.6.1/5 and issue a
// warning here if "return 0;" is omitted.
return 0;
}

33
test/issue_2134.cpp Normal file
View File

@ -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 <http://www.boost.org/LICENSE_1_0.txt>.)
// See <http://www.boost.org/libs/integer> for documentation.
// See <http://svn.boost.org/trac/boost/ticket/2134> 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 <boost/detail/numeric_traits.hpp>
#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, <boost/detail/numeric_traits.hpp>
// 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 <boost/integer.hpp>
// Main program, minimal (since this is a compile test)
int main() { return 0; }