mirror of
https://github.com/boostorg/integer.git
synced 2025-07-01 15:01:06 +02:00
Compare commits
28 Commits
boost-1.20
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
b3b5b039f7 | |||
0462a811f6 | |||
c6f3dce91a | |||
3e2b929118 | |||
645f809379 | |||
28ec7fa76c | |||
07505c76f8 | |||
fda46f9780 | |||
125bf3351f | |||
e3702f3abc | |||
c54da75efb | |||
2dd1bee693 | |||
949134726f | |||
b3f587b9f7 | |||
215b4d8ee7 | |||
976c5e6572 | |||
0424bb266e | |||
33abcf7250 | |||
b519841b7f | |||
d1781f09d2 | |||
c1c099c845 | |||
f4c38bdf51 | |||
53005cadc8 | |||
ea4963031a | |||
873879d5ac | |||
d39c7cd327 | |||
37eb749c49 | |||
8084359fda |
@ -69,7 +69,7 @@ representing any value of any signed integer type.</p>
|
||||
capable of representing any value of any unsigned integer type.</p>
|
||||
<p>These types are required.</p>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
||||
</p>
|
||||
<p> </p>
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
|
||||
// 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
|
||||
// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
|
||||
// 23 Sep 00 Added INTXX_C macro support (John Maddock).
|
||||
@ -23,9 +24,19 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
|
||||
# include <stdint.h> // implementation artifact; not part of interface
|
||||
// The following #include is an implementation artifact; not part of interface.
|
||||
# ifdef __hpux
|
||||
// HP-UX has a nice <stdint.h> in a non-standard location
|
||||
# include <sys/_inttypes.h>
|
||||
# ifdef __STDC_32_MODE__
|
||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||
# define BOOST_NO_INT64_T
|
||||
# endif
|
||||
# else
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -68,7 +79,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#else // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
@ -133,9 +144,10 @@ namespace boost
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U)
|
||||
# if !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
|
||||
(!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
# if (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
@ -183,7 +195,7 @@ namespace boost
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
#endif // BOOST_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
@ -253,9 +265,11 @@ Added 23rd September (John Maddock).
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
# if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# if (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
|
||||
(defined(ULONG_LONG_MAX) && (defined(__hpux) || ULONG_LONG_MAX == 18446744073709551615U)) || \
|
||||
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
@ -299,3 +313,4 @@ Added 23rd September (John Maddock).
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||
|
||||
|
||||
|
@ -9,13 +9,14 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
|
||||
// 28 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_INTEGER_HPP
|
||||
#define BOOST_INTEGER_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -23,6 +24,7 @@ namespace boost
|
||||
// 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 LeastInt fast; }; // imps may specialize
|
||||
|
||||
@ -70,6 +72,7 @@ namespace boost
|
||||
(Bits <= std::numeric_limits<unsigned char>::digits)
|
||||
>::least least;
|
||||
typedef typename int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
};
|
||||
|
||||
// The same dispatching technique can be used to select types based on
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without free provided that the above copyright notice
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
@ -18,11 +18,14 @@
|
||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||
#define BOOST_INTEGER_TRAITS_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
// This is an implementation detail and not part of the interface
|
||||
// These are an implementation detail and not part of the interface
|
||||
#include <limits.h>
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
@ -30,11 +33,7 @@ template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = false;
|
||||
#else
|
||||
enum { is_integral = false };
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = false);
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@ -42,18 +41,20 @@ template<class T, T min_val, T max_val>
|
||||
class integer_traits_base
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
static const bool is_integral = true;
|
||||
static const T const_min = min_val;
|
||||
static const T const_max = max_val;
|
||||
#else
|
||||
enum {
|
||||
is_integral = true,
|
||||
const_min = min_val,
|
||||
const_max = max_val
|
||||
};
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = true);
|
||||
BOOST_STATIC_CONSTANT(T, const_min = min_val);
|
||||
BOOST_STATIC_CONSTANT(T, const_max = max_val);
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
// The definition is required even for integral static constants
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_min;
|
||||
|
||||
template<class T, T min_val, T max_val>
|
||||
const T integer_traits_base<T, min_val, max_val>::const_max;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<>
|
||||
@ -80,7 +81,25 @@ class integer_traits<unsigned char>
|
||||
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
|
||||
{ };
|
||||
|
||||
// What about wchar_t ?
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template<>
|
||||
class integer_traits<wchar_t>
|
||||
: public std::numeric_limits<wchar_t>,
|
||||
#if defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
||||
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
||||
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
||||
#elif defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)
|
||||
// SGI MIPSpro with native library doesn't have them, either
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && !defined(__SGI_STL_PORT)
|
||||
// GCC 2.95.2 doesn't have them on HP-UX, either
|
||||
// (also, std::numeric_limits<wchar_t> appears to return the wrong values)
|
||||
public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
|
||||
#else
|
||||
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
||||
#endif
|
||||
{ };
|
||||
#endif // BOOST_NO_INTRINSIC_WCHAR_T
|
||||
|
||||
template<>
|
||||
class integer_traits<short>
|
||||
@ -140,8 +159,20 @@ class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
|
||||
{ };
|
||||
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
|
||||
{ };
|
||||
template<>
|
||||
class integer_traits<unsigned long long>
|
||||
: public std::numeric_limits<unsigned long long>,
|
||||
public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
|
||||
{ };
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
@ -14,11 +14,11 @@
|
||||
|
||||
// NOTE OF OBSOLESCENCE: In general, this header file cannot detect
|
||||
// whether the current translation unit somewhere includes ISO C99
|
||||
// <stdint.h> or not. For example, in case BOOST_SYSTEM_HAS_STDINT_H
|
||||
// <stdint.h> or not. For example, in case BOOST_HAS_STDINT_H
|
||||
// is not defined and ISO C99 <stdint.h> has been included before,
|
||||
// this file will re-define ISO C99 reserved file-scope identifiers
|
||||
// such as int8_t (see ISO C99 7.1.3 and 7.18). Defining the macro
|
||||
// BOOST_SYSTEM_HAS_STDINT_H is not sufficient in general, in
|
||||
// BOOST_HAS_STDINT_H is not sufficient in general, in
|
||||
// particular if a partly conformant <stdint.h> header is available
|
||||
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
|
||||
//
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
#include <stdint.h>
|
||||
|
||||
#else
|
||||
@ -150,7 +150,7 @@
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
||||
|
||||
/****************************************************
|
||||
|
@ -90,7 +90,7 @@ instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->18 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15249" -->
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->10 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
@ -34,6 +34,7 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
|
||||
<pre>namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt > // Required: LeastInt is integral type, not bool
|
||||
struct int_fast_t { typedef LeastInt fast; }; // implementations may specialize
|
||||
|
||||
@ -51,6 +52,7 @@ appropriate to use the types supplied in <code><a href="../../boost/cstdint.hpp"
|
||||
{
|
||||
typedef <i>implementation-supplied</i> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
};
|
||||
} // namespace boost
|
||||
</pre>
|
||||
|
153
integer_test.cpp
153
integer_test.cpp
@ -9,14 +9,15 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||
// 31 Aug 99 Initial version
|
||||
|
||||
// This program is misnamed in that it is really a demonstration rather than
|
||||
// a test. It doesn't detect failure, so isn't worthy of the name "test".
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void test( long ) { std::cout << "long\n"; }
|
||||
@ -35,10 +36,12 @@ namespace boost
|
||||
template<> struct int_fast_t<short> { typedef long fast; };
|
||||
}
|
||||
|
||||
int main()
|
||||
int test_main(int,char**)
|
||||
{
|
||||
using boost::int_t;
|
||||
using boost::uint_t;
|
||||
|
||||
#ifdef BOOST_SHOW_TYPES
|
||||
std::cout << 32 << ' '; test( int_t<32>::least() );
|
||||
std::cout << 31 << ' '; test( int_t<31>::least() );
|
||||
std::cout << 30 << ' '; test( int_t<30>::least() );
|
||||
@ -170,7 +173,145 @@ int main()
|
||||
std::cout << 3 << ' '; test( uint_t<3>::fast() );
|
||||
std::cout << 2 << ' '; test( uint_t<2>::fast() );
|
||||
std::cout << 1 << ' '; test( uint_t<1>::fast() );
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
#endif
|
||||
|
||||
long v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::least(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::least(v) == v );
|
||||
v = 0x7FFFFFFF;
|
||||
BOOST_TEST( int_t<32>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<31>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<30>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<29>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<28>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<27>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<26>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<25>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<24>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<23>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<22>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<21>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<20>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<19>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<18>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<17>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<16>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<15>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<14>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<13>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<12>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<11>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<10>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<9>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<8>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<7>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<6>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<5>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<4>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<3>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<2>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<1>::fast(v) == v ); v >>= 1;
|
||||
BOOST_TEST( int_t<0>::fast(v) == v );
|
||||
unsigned long u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::least(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::least(u) == u );
|
||||
u = 0xFFFFFFFF;
|
||||
BOOST_TEST( uint_t<32>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<31>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<30>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<29>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<28>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<27>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<26>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<25>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<24>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<23>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<22>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<21>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<20>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<19>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<18>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<17>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<16>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<15>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<14>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<13>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<12>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<11>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<10>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<9>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<8>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<7>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<6>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<5>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<4>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<3>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<2>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<1>::fast(u) == u ); u >>= 1;
|
||||
BOOST_TEST( uint_t<0>::fast(u) == u );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Permission to use, copy, modify, sell, and distribute this software
|
||||
* is hereby granted without free provided that the above copyright notice
|
||||
* is hereby granted without fee provided that the above copyright notice
|
||||
* appears in all copies and that both that copyright notice and this
|
||||
* permission notice appear in supporting documentation,
|
||||
*
|
||||
@ -18,15 +18,12 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/integer_traits.hpp>
|
||||
// use int64_t instead of long long for better portability
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test relies on assert() and thus makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
@ -46,14 +43,14 @@ void runtest(const char * type, T)
|
||||
<< "; min is " << traits::min()
|
||||
<< ", max is " << traits::max()
|
||||
<< std::endl;
|
||||
assert(traits::is_specialized);
|
||||
assert(traits::is_integer);
|
||||
assert(traits::is_integral);
|
||||
assert(traits::const_min == traits::min());
|
||||
assert(traits::const_max == traits::max());
|
||||
BOOST_TEST(traits::is_specialized);
|
||||
BOOST_TEST(traits::is_integer);
|
||||
BOOST_TEST(traits::is_integral);
|
||||
BOOST_TEST(traits::const_min == traits::min());
|
||||
BOOST_TEST(traits::const_max == traits::max());
|
||||
}
|
||||
|
||||
int main()
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
runtest("bool", bool());
|
||||
runtest("char", char());
|
||||
@ -61,6 +58,7 @@ int main()
|
||||
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());
|
||||
@ -70,13 +68,17 @@ int main()
|
||||
runtest("long", long());
|
||||
typedef unsigned long unsigned_long;
|
||||
runtest("unsigned long", unsigned_long());
|
||||
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user