1 /* boost integer_traits.hpp header file
3 * Copyright Jens Maurer 2000
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
10 * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
13 // See http://www.boost.org/libs/integer for documentation.
16 #ifndef BOOST_INTEGER_TRAITS_HPP
17 #define BOOST_INTEGER_TRAITS_HPP
19 #include <boost/config.hpp>
20 #include <boost/limits.hpp>
22 // These are an implementation detail and not part of the interface
24 // we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
25 // and some may have <wchar.h> but not <cwchar> ...
26 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__))
30 #include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
35 class integer_traits
: public std::numeric_limits
<T
>
38 BOOST_STATIC_CONSTANT(bool, is_integral
= false);
42 template<class T
, T min_val
, T max_val
>
43 class integer_traits_base
46 BOOST_STATIC_CONSTANT(bool, is_integral
= true);
47 BOOST_STATIC_CONSTANT(T
, const_min
= min_val
);
48 BOOST_STATIC_CONSTANT(T
, const_max
= max_val
);
51 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
52 // A definition is required even for integral static constants
53 template<class T
, T min_val
, T max_val
>
54 const bool integer_traits_base
<T
, min_val
, max_val
>::is_integral
;
56 template<class T
, T min_val
, T max_val
>
57 const T integer_traits_base
<T
, min_val
, max_val
>::const_min
;
59 template<class T
, T min_val
, T max_val
>
60 const T integer_traits_base
<T
, min_val
, max_val
>::const_max
;
66 class integer_traits
<bool>
67 : public std::numeric_limits
<bool>,
68 public detail::integer_traits_base
<bool, false, true>
72 class integer_traits
<char>
73 : public std::numeric_limits
<char>,
74 public detail::integer_traits_base
<char, CHAR_MIN
, CHAR_MAX
>
78 class integer_traits
<signed char>
79 : public std::numeric_limits
<signed char>,
80 public detail::integer_traits_base
<signed char, SCHAR_MIN
, SCHAR_MAX
>
84 class integer_traits
<unsigned char>
85 : public std::numeric_limits
<unsigned char>,
86 public detail::integer_traits_base
<unsigned char, 0, UCHAR_MAX
>
89 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
91 class integer_traits
<wchar_t>
92 : public std::numeric_limits
<wchar_t>,
93 // Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native
94 // library: they are wrong!
95 #if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
96 public detail::integer_traits_base
<wchar_t, WCHAR_MIN
, WCHAR_MAX
>
97 #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
98 // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
99 public detail::integer_traits_base
<wchar_t, 0, 0xffff>
100 #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\
101 || (defined __APPLE__)\
102 || (defined(__OpenBSD__) && defined(__GNUC__))\
103 || (defined(__NetBSD__) && defined(__GNUC__))\
104 || (defined(__FreeBSD__) && defined(__GNUC__))\
105 || (defined(__DragonFly__) && defined(__GNUC__))\
106 || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
107 // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
108 // - SGI MIPSpro with native library
109 // - gcc 3.x on HP-UX
110 // - Mac OS X with native library
111 // - gcc on FreeBSD, OpenBSD and NetBSD
112 public detail::integer_traits_base
<wchar_t, INT_MIN
, INT_MAX
>
113 #elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
114 // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
115 // - gcc 2.95.x on HP-UX
116 // (also, std::numeric_limits<wchar_t> appears to return the wrong values).
117 public detail::integer_traits_base
<wchar_t, 0, UINT_MAX
>
119 #error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
122 #endif // BOOST_NO_INTRINSIC_WCHAR_T
125 class integer_traits
<short>
126 : public std::numeric_limits
<short>,
127 public detail::integer_traits_base
<short, SHRT_MIN
, SHRT_MAX
>
131 class integer_traits
<unsigned short>
132 : public std::numeric_limits
<unsigned short>,
133 public detail::integer_traits_base
<unsigned short, 0, USHRT_MAX
>
137 class integer_traits
<int>
138 : public std::numeric_limits
<int>,
139 public detail::integer_traits_base
<int, INT_MIN
, INT_MAX
>
143 class integer_traits
<unsigned int>
144 : public std::numeric_limits
<unsigned int>,
145 public detail::integer_traits_base
<unsigned int, 0, UINT_MAX
>
149 class integer_traits
<long>
150 : public std::numeric_limits
<long>,
151 public detail::integer_traits_base
<long, LONG_MIN
, LONG_MAX
>
155 class integer_traits
<unsigned long>
156 : public std::numeric_limits
<unsigned long>,
157 public detail::integer_traits_base
<unsigned long, 0, ULONG_MAX
>
160 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
162 class integer_traits
< detail::xint_t
>
163 : public std::numeric_limits
< detail::xint_t
>,
164 public detail::integer_traits_base
< detail::xint_t
, BOOST_XINT_MIN
, BOOST_XINT_MAX
>
168 class integer_traits
< detail::uxint_t
>
169 : public std::numeric_limits
< detail::uxint_t
>,
170 public detail::integer_traits_base
< detail::uxint_t
, 0u, BOOST_UXINT_MAX
>
176 #endif /* BOOST_INTEGER_TRAITS_HPP */