os/ossrv/ossrv_pub/boost_apis/boost/integer_traits.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* boost integer_traits.hpp header file
sl@0
     2
 *
sl@0
     3
 * Copyright Jens Maurer 2000
sl@0
     4
 * Distributed under the Boost Software License, Version 1.0. (See
sl@0
     5
 * accompanying file LICENSE_1_0.txt or copy at
sl@0
     6
 * http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
 *
sl@0
     8
 * $Id: integer_traits.hpp,v 1.30 2006/02/05 10:19:42 johnmaddock Exp $
sl@0
     9
 *
sl@0
    10
 * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
sl@0
    11
 */
sl@0
    12
sl@0
    13
//  See http://www.boost.org/libs/integer for documentation.
sl@0
    14
sl@0
    15
sl@0
    16
#ifndef BOOST_INTEGER_TRAITS_HPP
sl@0
    17
#define BOOST_INTEGER_TRAITS_HPP
sl@0
    18
sl@0
    19
#include <boost/config.hpp>
sl@0
    20
#include <boost/limits.hpp>
sl@0
    21
sl@0
    22
// These are an implementation detail and not part of the interface
sl@0
    23
#include <limits.h>
sl@0
    24
// we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
sl@0
    25
// and some may have <wchar.h> but not <cwchar> ...
sl@0
    26
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__))
sl@0
    27
#include <wchar.h>
sl@0
    28
#endif
sl@0
    29
sl@0
    30
sl@0
    31
namespace boost {
sl@0
    32
template<class T>
sl@0
    33
class integer_traits : public std::numeric_limits<T>
sl@0
    34
{
sl@0
    35
public:
sl@0
    36
  BOOST_STATIC_CONSTANT(bool, is_integral = false);
sl@0
    37
};
sl@0
    38
sl@0
    39
namespace detail {
sl@0
    40
template<class T, T min_val, T max_val>
sl@0
    41
class integer_traits_base
sl@0
    42
{
sl@0
    43
public:
sl@0
    44
  BOOST_STATIC_CONSTANT(bool, is_integral = true);
sl@0
    45
  BOOST_STATIC_CONSTANT(T, const_min = min_val);
sl@0
    46
  BOOST_STATIC_CONSTANT(T, const_max = max_val);
sl@0
    47
};
sl@0
    48
sl@0
    49
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
sl@0
    50
//  A definition is required even for integral static constants
sl@0
    51
template<class T, T min_val, T max_val>
sl@0
    52
const bool integer_traits_base<T, min_val, max_val>::is_integral;
sl@0
    53
sl@0
    54
template<class T, T min_val, T max_val>
sl@0
    55
const T integer_traits_base<T, min_val, max_val>::const_min;
sl@0
    56
sl@0
    57
template<class T, T min_val, T max_val>
sl@0
    58
const T integer_traits_base<T, min_val, max_val>::const_max;
sl@0
    59
#endif
sl@0
    60
sl@0
    61
} // namespace detail
sl@0
    62
sl@0
    63
template<>
sl@0
    64
class integer_traits<bool>
sl@0
    65
  : public std::numeric_limits<bool>,
sl@0
    66
    public detail::integer_traits_base<bool, false, true>
sl@0
    67
{ };
sl@0
    68
sl@0
    69
template<>
sl@0
    70
class integer_traits<char>
sl@0
    71
  : public std::numeric_limits<char>,
sl@0
    72
    public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
sl@0
    73
{ };
sl@0
    74
sl@0
    75
template<>
sl@0
    76
class integer_traits<signed char>
sl@0
    77
  : public std::numeric_limits<signed char>,
sl@0
    78
    public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
sl@0
    79
{ };
sl@0
    80
sl@0
    81
template<>
sl@0
    82
class integer_traits<unsigned char>
sl@0
    83
  : public std::numeric_limits<unsigned char>,
sl@0
    84
    public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
sl@0
    85
{ };
sl@0
    86
sl@0
    87
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
sl@0
    88
template<>
sl@0
    89
class integer_traits<wchar_t>
sl@0
    90
  : public std::numeric_limits<wchar_t>,
sl@0
    91
    // Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native
sl@0
    92
    // library: they are wrong!
sl@0
    93
#if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
sl@0
    94
    public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
sl@0
    95
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
sl@0
    96
    // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
sl@0
    97
    public detail::integer_traits_base<wchar_t, 0, 0xffff>
sl@0
    98
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\
sl@0
    99
    || (defined __APPLE__)\
sl@0
   100
    || (defined(__OpenBSD__) && defined(__GNUC__))\
sl@0
   101
    || (defined(__NetBSD__) && defined(__GNUC__))\
sl@0
   102
    || (defined(__FreeBSD__) && defined(__GNUC__))\
sl@0
   103
    || (defined(__DragonFly__) && defined(__GNUC__))\
sl@0
   104
    || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
sl@0
   105
    // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
sl@0
   106
    //  - SGI MIPSpro with native library
sl@0
   107
    //  - gcc 3.x on HP-UX
sl@0
   108
    //  - Mac OS X with native library
sl@0
   109
    //  - gcc on FreeBSD, OpenBSD and NetBSD
sl@0
   110
    public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
sl@0
   111
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
sl@0
   112
    // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
sl@0
   113
    //  - gcc 2.95.x on HP-UX
sl@0
   114
    // (also, std::numeric_limits<wchar_t> appears to return the wrong values).
sl@0
   115
    public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
sl@0
   116
#else
sl@0
   117
#error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
sl@0
   118
#endif
sl@0
   119
{ };
sl@0
   120
#endif // BOOST_NO_INTRINSIC_WCHAR_T
sl@0
   121
sl@0
   122
template<>
sl@0
   123
class integer_traits<short>
sl@0
   124
  : public std::numeric_limits<short>,
sl@0
   125
    public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
sl@0
   126
{ };
sl@0
   127
sl@0
   128
template<>
sl@0
   129
class integer_traits<unsigned short>
sl@0
   130
  : public std::numeric_limits<unsigned short>,
sl@0
   131
    public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
sl@0
   132
{ };
sl@0
   133
sl@0
   134
template<>
sl@0
   135
class integer_traits<int>
sl@0
   136
  : public std::numeric_limits<int>,
sl@0
   137
    public detail::integer_traits_base<int, INT_MIN, INT_MAX>
sl@0
   138
{ };
sl@0
   139
sl@0
   140
template<>
sl@0
   141
class integer_traits<unsigned int>
sl@0
   142
  : public std::numeric_limits<unsigned int>,
sl@0
   143
    public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
sl@0
   144
{ };
sl@0
   145
sl@0
   146
template<>
sl@0
   147
class integer_traits<long>
sl@0
   148
  : public std::numeric_limits<long>,
sl@0
   149
    public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
sl@0
   150
{ };
sl@0
   151
sl@0
   152
template<>
sl@0
   153
class integer_traits<unsigned long>
sl@0
   154
  : public std::numeric_limits<unsigned long>,
sl@0
   155
    public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
sl@0
   156
{ };
sl@0
   157
sl@0
   158
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
sl@0
   159
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
sl@0
   160
sl@0
   161
template<>
sl@0
   162
class integer_traits< ::boost::long_long_type>
sl@0
   163
  : public std::numeric_limits< ::boost::long_long_type>,
sl@0
   164
    public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
sl@0
   165
{ };
sl@0
   166
sl@0
   167
template<>
sl@0
   168
class integer_traits< ::boost::ulong_long_type>
sl@0
   169
  : public std::numeric_limits< ::boost::ulong_long_type>,
sl@0
   170
    public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
sl@0
   171
{ };
sl@0
   172
sl@0
   173
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
sl@0
   174
sl@0
   175
template<>
sl@0
   176
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>{ };
sl@0
   177
template<>
sl@0
   178
class integer_traits< ::boost::ulong_long_type>
sl@0
   179
  : public std::numeric_limits< ::boost::ulong_long_type>,
sl@0
   180
    public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
sl@0
   181
{ };
sl@0
   182
sl@0
   183
#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
sl@0
   184
sl@0
   185
template<>
sl@0
   186
class integer_traits< ::boost::long_long_type>
sl@0
   187
  : public std::numeric_limits< ::boost::long_long_type>,
sl@0
   188
    public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
sl@0
   189
{ };
sl@0
   190
sl@0
   191
template<>
sl@0
   192
class integer_traits< ::boost::ulong_long_type>
sl@0
   193
  : public std::numeric_limits< ::boost::ulong_long_type>,
sl@0
   194
    public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
sl@0
   195
{ };
sl@0
   196
sl@0
   197
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
sl@0
   198
sl@0
   199
template<>
sl@0
   200
class integer_traits< ::boost::long_long_type>
sl@0
   201
  : public std::numeric_limits< ::boost::long_long_type>,
sl@0
   202
    public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
sl@0
   203
{ };
sl@0
   204
sl@0
   205
template<>
sl@0
   206
class integer_traits< ::boost::ulong_long_type>
sl@0
   207
  : public std::numeric_limits< ::boost::ulong_long_type>,
sl@0
   208
    public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
sl@0
   209
{ };
sl@0
   210
sl@0
   211
#elif defined(BOOST_HAS_LONG_LONG)
sl@0
   212
//
sl@0
   213
// we have long long but no constants, this happens for example with gcc in -ansi mode,
sl@0
   214
// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
sl@0
   215
//
sl@0
   216
template<>
sl@0
   217
class integer_traits< ::boost::long_long_type>
sl@0
   218
  : public std::numeric_limits< ::boost::long_long_type>,
sl@0
   219
    public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
sl@0
   220
{ };
sl@0
   221
sl@0
   222
template<>
sl@0
   223
class integer_traits< ::boost::ulong_long_type>
sl@0
   224
  : public std::numeric_limits< ::boost::ulong_long_type>,
sl@0
   225
    public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
sl@0
   226
{ };
sl@0
   227
sl@0
   228
#endif
sl@0
   229
#endif
sl@0
   230
sl@0
   231
} // namespace boost
sl@0
   232
sl@0
   233
#endif /* BOOST_INTEGER_TRAITS_HPP */
sl@0
   234
sl@0
   235
sl@0
   236