Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | // The -*- C++ -*- type traits classes for internal use in libstdc++ |
2 | |||
3 | // Copyright (C) 2000-2001 Free Software Foundation, Inc. |
||
4 | // |
||
5 | // This file is part of the GNU ISO C++ Library. This library is free |
||
6 | // software; you can redistribute it and/or modify it under the |
||
7 | // terms of the GNU General Public License as published by the |
||
8 | // Free Software Foundation; either version 2, or (at your option) |
||
9 | // any later version. |
||
10 | |||
11 | // This library is distributed in the hope that it will be useful, |
||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | // GNU General Public License for more details. |
||
15 | |||
16 | // You should have received a copy of the GNU General Public License along |
||
17 | // with this library; see the file COPYING. If not, write to the Free |
||
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
||
19 | // USA. |
||
20 | |||
21 | // As a special exception, you may use this file as part of a free software |
||
22 | // library without restriction. Specifically, if other files instantiate |
||
23 | // templates or use macros or inline functions from this file, or you compile |
||
24 | // this file and link it with other files to produce an executable, this |
||
25 | // file does not by itself cause the resulting executable to be covered by |
||
26 | // the GNU General Public License. This exception does not however |
||
27 | // invalidate any other reasons why the executable file might be covered by |
||
28 | // the GNU General Public License. |
||
29 | |||
30 | // Written by Gabriel Dos Reis |
||
31 | |||
32 | #ifndef _CPP_BITS_CPP_TYPE_TRAITS_H |
||
33 | #define _CPP_BITS_CPP_TYPE_TRAITS_H 1 |
||
34 | |||
35 | #pragma GCC system_header |
||
36 | |||
37 | // |
||
38 | // This file provides some compile-time information about various types. |
||
39 | // These representations were designed, on purpose, to be constant-expressions |
||
40 | // and not types as found in |
||
41 | // can be used in control structures and the optimizer hopefully will do |
||
42 | // the obvious thing. |
||
43 | // |
||
44 | // Why integral expressions, and not functions nor types? |
||
45 | // Firstly, these compile-time entities are used as template-arguments |
||
46 | // so function return values won't work: We need compile-time entities. |
||
47 | // We're left with types and constant integral expressions. |
||
48 | // Secondly, from the point of view of ease of use, type-based compile-time |
||
49 | // information is -not- *that* convenient. On has to write lots of |
||
50 | // overloaded functions and to hope that the compiler will select the right |
||
51 | // one. As a net effect, the overall structure isn't very clear at first |
||
52 | // glance. |
||
53 | // Thirdly, partial ordering and overload resolution (of function templates) |
||
54 | // is highly costly in terms of compiler-resource. It is a Good Thing to |
||
55 | // keep these resource consumption as least as possible. |
||
56 | // |
||
57 | // See valarray_array.h for a case use. |
||
58 | // |
||
59 | // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06. |
||
60 | // |
||
61 | |||
62 | namespace std |
||
63 | { |
||
64 | template |
||
65 | struct __is_void |
||
66 | { |
||
67 | enum |
||
68 | { |
||
69 | _M_type = 0 |
||
70 | }; |
||
71 | }; |
||
72 | |||
73 | template<> |
||
74 | struct __is_void |
||
75 | { |
||
76 | enum |
||
77 | { |
||
78 | _M_type = 1 |
||
79 | }; |
||
80 | }; |
||
81 | |||
82 | // |
||
83 | // Integer types |
||
84 | // |
||
85 | template |
||
86 | struct __is_integer |
||
87 | { |
||
88 | enum |
||
89 | { |
||
90 | _M_type = 0 |
||
91 | }; |
||
92 | }; |
||
93 | |||
94 | // Thirteen specializations (yes there are eleven standard integer |
||
95 | // types; 'long long' and 'unsigned long long' are supported as |
||
96 | // extensions) |
||
97 | template<> |
||
98 | struct __is_integer |
||
99 | { |
||
100 | enum |
||
101 | { |
||
102 | _M_type = 1 |
||
103 | }; |
||
104 | }; |
||
105 | |||
106 | template<> |
||
107 | struct __is_integer |
||
108 | { |
||
109 | enum |
||
110 | { |
||
111 | _M_type = 1 |
||
112 | }; |
||
113 | }; |
||
114 | |||
115 | template<> |
||
116 | struct __is_integer |
||
117 | { |
||
118 | enum |
||
119 | { |
||
120 | _M_type = 1 |
||
121 | }; |
||
122 | }; |
||
123 | |||
124 | template<> |
||
125 | struct __is_integer |
||
126 | { |
||
127 | enum |
||
128 | { |
||
129 | _M_type = 1 |
||
130 | }; |
||
131 | }; |
||
132 | |||
133 | # ifdef _GLIBCPP_USE_WCHAR_T |
||
134 | template<> |
||
135 | struct __is_integer |
||
136 | { |
||
137 | enum |
||
138 | { |
||
139 | _M_type = 1 |
||
140 | }; |
||
141 | }; |
||
142 | # endif |
||
143 | |||
144 | template<> |
||
145 | struct __is_integer |
||
146 | { |
||
147 | enum |
||
148 | { |
||
149 | _M_type = 1 |
||
150 | }; |
||
151 | }; |
||
152 | |||
153 | template<> |
||
154 | struct __is_integer |
||
155 | { |
||
156 | enum |
||
157 | { |
||
158 | _M_type = 1 |
||
159 | }; |
||
160 | }; |
||
161 | |||
162 | template<> |
||
163 | struct __is_integer |
||
164 | { |
||
165 | enum |
||
166 | { |
||
167 | _M_type = 1 |
||
168 | }; |
||
169 | }; |
||
170 | |||
171 | template<> |
||
172 | struct __is_integer |
||
173 | { |
||
174 | enum |
||
175 | { |
||
176 | _M_type = 1 |
||
177 | }; |
||
178 | }; |
||
179 | |||
180 | template<> |
||
181 | struct __is_integer |
||
182 | { |
||
183 | enum |
||
184 | { |
||
185 | _M_type = 1 |
||
186 | }; |
||
187 | }; |
||
188 | |||
189 | template<> |
||
190 | struct __is_integer |
||
191 | { |
||
192 | enum |
||
193 | { |
||
194 | _M_type = 1 |
||
195 | }; |
||
196 | }; |
||
197 | |||
198 | # ifdef _GLIBCPP_USE_LONG_LONG |
||
199 | template<> |
||
200 | struct __is_integer |
||
201 | { |
||
202 | enum |
||
203 | { |
||
204 | _M_type = 1 |
||
205 | }; |
||
206 | }; |
||
207 | |||
208 | template<> |
||
209 | struct __is_integer |
||
210 | { |
||
211 | enum |
||
212 | { |
||
213 | _M_type = 1 |
||
214 | }; |
||
215 | }; |
||
216 | # endif |
||
217 | |||
218 | // |
||
219 | // Floating point types |
||
220 | // |
||
221 | template |
||
222 | struct __is_floating |
||
223 | { |
||
224 | enum |
||
225 | { |
||
226 | _M_type = 0 |
||
227 | }; |
||
228 | }; |
||
229 | |||
230 | // three specializations (float, double and 'long double') |
||
231 | template<> |
||
232 | struct __is_floating |
||
233 | { |
||
234 | enum |
||
235 | { |
||
236 | _M_type = 1 |
||
237 | }; |
||
238 | }; |
||
239 | |||
240 | template<> |
||
241 | struct __is_floating |
||
242 | { |
||
243 | enum |
||
244 | { |
||
245 | _M_type = 1 |
||
246 | }; |
||
247 | }; |
||
248 | |||
249 | template<> |
||
250 | struct __is_floating |
||
251 | { |
||
252 | enum |
||
253 | { |
||
254 | _M_type = 1 |
||
255 | }; |
||
256 | }; |
||
257 | |||
258 | // |
||
259 | // An arithmetic type is an integer type or a floating point type |
||
260 | // |
||
261 | template |
||
262 | struct __is_arithmetic |
||
263 | { |
||
264 | enum |
||
265 | { |
||
266 | _M_type = __is_integer<_Tp>::_M_type || __is_floating<_Tp>::_M_type |
||
267 | }; |
||
268 | }; |
||
269 | |||
270 | // |
||
271 | // A fundamental type is `void' or and arithmetic type |
||
272 | // |
||
273 | template |
||
274 | struct __is_fundamental |
||
275 | { |
||
276 | enum |
||
277 | { |
||
278 | _M_type = __is_void<_Tp>::_M_type || __is_arithmetic<_Tp>::_M_type |
||
279 | }; |
||
280 | }; |
||
281 | |||
282 | // |
||
283 | // For the immediate use, the following is a good approximation |
||
284 | // |
||
285 | template |
||
286 | struct __is_pod |
||
287 | { |
||
288 | enum |
||
289 | { |
||
290 | _M_type = __is_fundamental<_Tp>::_M_type |
||
291 | }; |
||
292 | }; |
||
293 | |||
294 | } // namespace std |
||
295 | |||
296 | |||
297 | #endif //_CPP_BITS_CPP_TYPE_TRAITS_H>>>>>>>>>>>>>>>>> |