forked from boostorg/integer
Compare commits
17 Commits
boost-1.21
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
bb212b7276 | |||
c6f3dce91a | |||
3e2b929118 | |||
645f809379 | |||
28ec7fa76c | |||
07505c76f8 | |||
fda46f9780 | |||
125bf3351f | |||
e3702f3abc | |||
c54da75efb | |||
2dd1bee693 | |||
949134726f | |||
b3f587b9f7 | |||
215b4d8ee7 | |||
976c5e6572 | |||
0424bb266e | |||
33abcf7250 |
@ -26,7 +26,17 @@
|
||||
|
||||
#ifdef BOOST_SYSTEM_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
|
||||
{
|
||||
@ -134,7 +144,9 @@ namespace boost
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)
|
||||
# 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;
|
||||
@ -254,8 +266,10 @@ Added 23rd September (John Maddock).
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# 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) && ULONG_LONG_MAX == 18446744073709551615U) || (defined(ULONGLONG_MAX) && ULONGLONG_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.
|
||||
|
||||
|
||||
|
@ -21,8 +21,11 @@
|
||||
#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,7 +159,7 @@ 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)
|
||||
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
template<>
|
||||
class integer_traits<long long>
|
||||
: public std::numeric_limits<long long>,
|
||||
@ -156,3 +175,4 @@ class integer_traits<unsigned long long>
|
||||
} // namespace boost
|
||||
|
||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||
|
||||
|
@ -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());
|
||||
@ -76,6 +74,8 @@ int main()
|
||||
// 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.
|
||||
|
Reference in New Issue
Block a user