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