]> git.lyx.org Git - lyx.git/blob - boost/boost/integer_traits.hpp
update
[lyx.git] / boost / boost / integer_traits.hpp
1 /* boost integer_traits.hpp header file
2  *
3  * Copyright Jens Maurer 2000
4  * Permission to use, copy, modify, sell, and distribute this software
5  * is hereby granted without fee provided that the above copyright notice
6  * appears in all copies and that both that copyright notice and this
7  * permission notice appear in supporting documentation,
8  *
9  * Jens Maurer makes no representations about the suitability of this
10  * software for any purpose. It is provided "as is" without express or
11  * implied warranty.
12  *
13  * $Id: integer_traits.hpp,v 1.3 2002/06/16 13:12:16 lyx Exp $
14  *
15  * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
16  */
17
18 #ifndef BOOST_INTEGER_TRAITS_HPP
19 #define BOOST_INTEGER_TRAITS_HPP
20
21 #include <boost/config.hpp>
22 #include <boost/limits.hpp>
23
24 // These are an implementation detail and not part of the interface
25 #include <limits.h>
26 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
27 #include <wchar.h>
28 #endif
29
30
31 namespace boost {
32 template<class T>
33 class integer_traits : public std::numeric_limits<T>
34 {
35 public:
36   BOOST_STATIC_CONSTANT(bool, is_integral = false);
37 };
38
39 namespace detail {
40 template<class T, T min_val, T max_val>
41 class integer_traits_base
42 {
43 public:
44   BOOST_STATIC_CONSTANT(bool, is_integral = true);
45   BOOST_STATIC_CONSTANT(T, const_min = min_val);
46   BOOST_STATIC_CONSTANT(T, const_max = max_val);
47 };
48
49 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
50 //  A definition is required even for integral static constants
51 template<class T, T min_val, T max_val>
52 const bool integer_traits_base<T, min_val, max_val>::is_integral;
53
54 template<class T, T min_val, T max_val>
55 const T integer_traits_base<T, min_val, max_val>::const_min;
56
57 template<class T, T min_val, T max_val>
58 const T integer_traits_base<T, min_val, max_val>::const_max;
59 #endif
60
61 } // namespace detail
62
63 template<>
64 class integer_traits<bool>
65   : public std::numeric_limits<bool>,
66     public detail::integer_traits_base<bool, false, true>
67 { };
68
69 template<>
70 class integer_traits<char>
71   : public std::numeric_limits<char>,
72     public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
73 { };
74
75 template<>
76 class integer_traits<signed char>
77   : public std::numeric_limits<signed char>,
78     public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
79 { };
80
81 template<>
82 class integer_traits<unsigned char>
83   : public std::numeric_limits<unsigned char>,
84     public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
85 { };
86
87 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
88 template<>
89 class integer_traits<wchar_t>
90   : public std::numeric_limits<wchar_t>,
91 #if defined(WCHAR_MIN) && defined(WCHAR_MAX)
92     public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
93 #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
94     // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
95     public detail::integer_traits_base<wchar_t, 0, 0xffff>
96 #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) || (defined __APPLE__) || (defined(__FreeBSD__) && defined(__GNUC__)) || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
97     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
98     //  - SGI MIPSpro with native library
99     //  - gcc 3.x on HP-UX
100     //  - Mac OS X with native library
101     //  - gcc on FreeBSD
102     public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
103 #elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
104     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
105     //  - gcc 2.95.x on HP-UX
106     // (also, std::numeric_limits<wchar_t> appears to return the wrong values).
107     public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
108 #else
109 #error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
110 #endif
111 { };
112 #endif // BOOST_NO_INTRINSIC_WCHAR_T
113
114 template<>
115 class integer_traits<short>
116   : public std::numeric_limits<short>,
117     public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
118 { };
119
120 template<>
121 class integer_traits<unsigned short>
122   : public std::numeric_limits<unsigned short>,
123     public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
124 { };
125
126 template<>
127 class integer_traits<int>
128   : public std::numeric_limits<int>,
129     public detail::integer_traits_base<int, INT_MIN, INT_MAX>
130 { };
131
132 template<>
133 class integer_traits<unsigned int>
134   : public std::numeric_limits<unsigned int>,
135     public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
136 { };
137
138 template<>
139 class integer_traits<long>
140   : public std::numeric_limits<long>,
141     public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
142 { };
143
144 template<>
145 class integer_traits<unsigned long>
146   : public std::numeric_limits<unsigned long>,
147     public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
148 { };
149
150 #if defined(ULLONG_MAX) && !defined(__SUNPRO_CC)
151 template<>
152 class integer_traits<long long>
153   : public std::numeric_limits<long long>,
154     public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX>
155 { };
156 template<>
157 class integer_traits<unsigned long long>
158   : public std::numeric_limits<unsigned long long>,
159     public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX>
160 { };
161 #elif defined(ULONG_LONG_MAX)
162 template<>
163 class integer_traits<long long>
164   : public std::numeric_limits<long long>,
165     public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>
166 { };
167 template<>
168 class integer_traits<unsigned long long>
169   : public std::numeric_limits<unsigned long long>,
170     public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
171 { };
172 #elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
173 template<>
174 class integer_traits<long long>
175   : public std::numeric_limits<long long>,
176     public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
177 { };
178 template<>
179 class integer_traits<unsigned long long>
180   : public std::numeric_limits<unsigned long long>,
181     public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
182 { };
183 #endif
184
185 } // namespace boost
186
187 #endif /* BOOST_INTEGER_TRAITS_HPP */
188