]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/bits/cpp_type_traits.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / bits / cpp_type_traits.h
1 // The  -*- C++ -*- type traits classes for internal use in libstdc++
2
3 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 /** @file cpp_type_traits.h
32  *  This is an internal header file, included by other library headers.
33  *  You should not attempt to use it directly.
34  */
35
36 // Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
37
38 #ifndef _CPP_TYPE_TRAITS_H
39 #define _CPP_TYPE_TRAITS_H 1
40
41 #pragma GCC system_header
42
43 #include <bits/c++config.h>
44
45 //
46 // This file provides some compile-time information about various types.
47 // These representations were designed, on purpose, to be constant-expressions
48 // and not types as found in <bits/type_traits.h>.  In particular, they
49 // can be used in control structures and the optimizer hopefully will do
50 // the obvious thing.
51 //
52 // Why integral expressions, and not functions nor types?
53 // Firstly, these compile-time entities are used as template-arguments
54 // so function return values won't work:  We need compile-time entities.
55 // We're left with types and constant  integral expressions.
56 // Secondly, from the point of view of ease of use, type-based compile-time
57 // information is -not- *that* convenient.  On has to write lots of
58 // overloaded functions and to hope that the compiler will select the right
59 // one. As a net effect, the overall structure isn't very clear at first
60 // glance.
61 // Thirdly, partial ordering and overload resolution (of function templates)
62 // is highly costly in terms of compiler-resource.  It is a Good Thing to
63 // keep these resource consumption as least as possible.
64 //
65 // See valarray_array.h for a case use.
66 //
67 // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06.
68 //
69 // Update 2005: types are also provided and <bits/type_traits.h> has been
70 // removed.
71 //
72
73 // Forward declaration hack, should really include this from somewhere.
74 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
75
76   template<typename _Iterator, typename _Container>
77     class __normal_iterator;
78
79 _GLIBCXX_END_NAMESPACE
80
81 _GLIBCXX_BEGIN_NAMESPACE(std)
82
83   struct __true_type { };
84   struct __false_type { };
85
86   template<bool>
87     struct __truth_type
88     { typedef __false_type __type; };
89
90   template<>
91     struct __truth_type<true>
92     { typedef __true_type __type; };
93
94   // N.B. The conversions to bool are needed due to the issue
95   // explained in c++/19404.
96   template<class _Sp, class _Tp>
97     struct __traitor
98     {
99       enum { __value = bool(_Sp::__value) || bool(_Tp::__value) };
100       typedef typename __truth_type<__value>::__type __type;
101     };
102
103   // N.B. The conversions to bool are needed due to the issue
104   // explained in c++/19404.
105   template<class _Sp, class _Tp>
106     struct __traitand
107     {
108       enum { __value = bool(_Sp::__value) && bool(_Tp::__value) };
109       typedef typename __truth_type<__value>::__type __type;
110     };
111
112   // Compare for equality of types.
113   template<typename, typename>
114     struct __are_same
115     {
116       enum { __value = 0 };
117       typedef __false_type __type;
118     };
119
120   template<typename _Tp>
121     struct __are_same<_Tp, _Tp>
122     {
123       enum { __value = 1 };
124       typedef __true_type __type;
125     };
126
127   // Holds if the template-argument is a void type.
128   template<typename _Tp>
129     struct __is_void
130     {
131       enum { __value = 0 };
132       typedef __false_type __type;
133     };
134
135   template<>
136     struct __is_void<void>
137     {
138       enum { __value = 1 };
139       typedef __true_type __type;
140     };
141
142   //
143   // Integer types
144   //
145   template<typename _Tp>
146     struct __is_integer
147     {
148       enum { __value = 0 };
149       typedef __false_type __type;
150     };
151
152   // Thirteen specializations (yes there are eleven standard integer
153   // types; 'long long' and 'unsigned long long' are supported as
154   // extensions)
155   template<>
156     struct __is_integer<bool>
157     {
158       enum { __value = 1 };
159       typedef __true_type __type;
160     };
161
162   template<>
163     struct __is_integer<char>
164     {
165       enum { __value = 1 };
166       typedef __true_type __type;
167     };
168
169   template<>
170     struct __is_integer<signed char>
171     {
172       enum { __value = 1 };
173       typedef __true_type __type;
174     };
175
176   template<>
177     struct __is_integer<unsigned char>
178     {
179       enum { __value = 1 };
180       typedef __true_type __type;
181     };
182
183 # ifdef _GLIBCXX_USE_WCHAR_T
184   template<>
185     struct __is_integer<wchar_t>
186     {
187       enum { __value = 1 };
188       typedef __true_type __type;
189     };
190 # endif
191
192   template<>
193     struct __is_integer<short>
194     {
195       enum { __value = 1 };
196       typedef __true_type __type;
197     };
198
199   template<>
200     struct __is_integer<unsigned short>
201     {
202       enum { __value = 1 };
203       typedef __true_type __type;
204     };
205
206   template<>
207     struct __is_integer<int>
208     {
209       enum { __value = 1 };
210       typedef __true_type __type;
211     };
212
213   template<>
214     struct __is_integer<unsigned int>
215     {
216       enum { __value = 1 };
217       typedef __true_type __type;
218     };
219
220   template<>
221     struct __is_integer<long>
222     {
223       enum { __value = 1 };
224       typedef __true_type __type;
225     };
226
227   template<>
228     struct __is_integer<unsigned long>
229     {
230       enum { __value = 1 };
231       typedef __true_type __type;
232     };
233
234   template<>
235     struct __is_integer<long long>
236     {
237       enum { __value = 1 };
238       typedef __true_type __type;
239     };
240
241   template<>
242     struct __is_integer<unsigned long long>
243     {
244       enum { __value = 1 };
245       typedef __true_type __type;
246     };
247
248   //
249   // Floating point types
250   //
251   template<typename _Tp>
252     struct __is_floating
253     {
254       enum { __value = 0 };
255       typedef __false_type __type;
256     };
257
258   // three specializations (float, double and 'long double')
259   template<>
260     struct __is_floating<float>
261     {
262       enum { __value = 1 };
263       typedef __true_type __type;
264     };
265
266   template<>
267     struct __is_floating<double>
268     {
269       enum { __value = 1 };
270       typedef __true_type __type;
271     };
272
273   template<>
274     struct __is_floating<long double>
275     {
276       enum { __value = 1 };
277       typedef __true_type __type;
278     };
279
280   //
281   // Pointer types
282   //
283   template<typename _Tp>
284     struct __is_pointer
285     {
286       enum { __value = 0 };
287       typedef __false_type __type;
288     };
289
290   template<typename _Tp>
291     struct __is_pointer<_Tp*>
292     {
293       enum { __value = 1 };
294       typedef __true_type __type;
295     };
296
297   //
298   // Normal iterator type
299   //
300   template<typename _Tp>
301     struct __is_normal_iterator
302     {
303       enum { __value = 0 };
304       typedef __false_type __type;
305     };
306
307   template<typename _Iterator, typename _Container>
308     struct __is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator,
309                                                               _Container> >
310     {
311       enum { __value = 1 };
312       typedef __true_type __type;
313     };
314
315   //
316   // An arithmetic type is an integer type or a floating point type
317   //
318   template<typename _Tp>
319     struct __is_arithmetic
320     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
321     { };
322
323   //
324   // A fundamental type is `void' or and arithmetic type
325   //
326   template<typename _Tp>
327     struct __is_fundamental
328     : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
329     { };
330
331   //
332   // A scalar type is an arithmetic type or a pointer type
333   // 
334   template<typename _Tp>
335     struct __is_scalar
336     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
337     { };
338
339   //
340   // For use in std::copy and std::find overloads for streambuf iterators.
341   //
342   template<typename _Tp>
343     struct __is_char
344     {
345       enum { __value = 0 };
346       typedef __false_type __type;
347     };
348
349   template<>
350     struct __is_char<char>
351     {
352       enum { __value = 1 };
353       typedef __true_type __type;
354     };
355
356 #ifdef _GLIBCXX_USE_WCHAR_T
357   template<>
358     struct __is_char<wchar_t>
359     {
360       enum { __value = 1 };
361       typedef __true_type __type;
362     };
363 #endif
364
365   template<typename _Tp>
366     struct __is_byte
367     {
368       enum { __value = 0 };
369       typedef __false_type __type;
370     };
371
372   template<>
373     struct __is_byte<char>
374     {
375       enum { __value = 1 };
376       typedef __true_type __type;
377     };
378
379   template<>
380     struct __is_byte<signed char>
381     {
382       enum { __value = 1 };
383       typedef __true_type __type;
384     };
385
386   template<>
387     struct __is_byte<unsigned char>
388     {
389       enum { __value = 1 };
390       typedef __true_type __type;
391     };
392
393   //
394   // Move iterator type
395   //
396   template<typename _Tp>
397     struct __is_move_iterator
398     {
399       enum { __value = 0 };
400       typedef __false_type __type;
401     };
402
403 #ifdef __GXX_EXPERIMENTAL_CXX0X__
404   template<typename _Iterator>
405     class move_iterator;
406
407   template<typename _Iterator>
408     struct __is_move_iterator< move_iterator<_Iterator> >
409     {
410       enum { __value = 1 };
411       typedef __true_type __type;
412     };
413 #endif
414
415 _GLIBCXX_END_NAMESPACE
416
417 #endif //_CPP_TYPE_TRAITS_H