Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / tr1_impl / type_traits
blob4cf97dff31f07b6acece91ff4387ab50cf0ecabc
1 // TR1 type_traits -*- C++ -*-
3 // Copyright (C) 2007, 2008 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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
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.
30 /** @file tr1_impl/type_traits
31 *  This is an internal header file, included by other library headers.
32 *  You should not attempt to use it directly.
35 namespace std
37 _GLIBCXX_BEGIN_NAMESPACE_TR1
39   // For use in __is_convertible_simple.
40   struct __sfinae_types
41   {
42     typedef char __one;
43     typedef struct { char __arr[2]; } __two;
44   };
46 #define _DEFINE_SPEC_BODY(_Value)                                    \
47     : public integral_constant<bool, _Value> { };
49 #define _DEFINE_SPEC_0_HELPER(_Spec, _Value)                         \
50   template<>                                                         \
51     struct _Spec                                                     \
52     _DEFINE_SPEC_BODY(_Value)
54 #define _DEFINE_SPEC_1_HELPER(_Spec, _Value)                         \
55   template<typename _Tp>                                             \
56     struct _Spec                                                     \
57     _DEFINE_SPEC_BODY(_Value)
58       
59 #define _DEFINE_SPEC_2_HELPER(_Spec, _Value)                         \
60   template<typename _Tp, typename _Cp>                               \
61     struct _Spec                                                     \
62     _DEFINE_SPEC_BODY(_Value)
64 #define _DEFINE_SPEC(_Order, _Trait, _Type, _Value)                  \
65   _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value)              \
66   _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value)        \
67   _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value)     \
68   _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value)
70   /// helper classes [4.3].
71   template<typename _Tp, _Tp __v>
72     struct integral_constant
73     {
74       static const _Tp                      value = __v;
75       typedef _Tp                           value_type;
76       typedef integral_constant<_Tp, __v>   type;
77     };
78   
79   /// typedef for true_type
80   typedef integral_constant<bool, true>     true_type;
82   /// typedef for true_type
83   typedef integral_constant<bool, false>    false_type;
85   template<typename _Tp, _Tp __v>
86     const _Tp integral_constant<_Tp, __v>::value;
88   /// primary type categories [4.5.1].
89   template<typename>
90     struct is_void
91     : public false_type { };
92   _DEFINE_SPEC(0, is_void, void, true)
94   /// is_integral
95   template<typename>
96     struct is_integral
97     : public false_type { };
98   _DEFINE_SPEC(0, is_integral, bool, true)
99   _DEFINE_SPEC(0, is_integral, char, true)
100   _DEFINE_SPEC(0, is_integral, signed char, true)
101   _DEFINE_SPEC(0, is_integral, unsigned char, true)
102 #ifdef _GLIBCXX_USE_WCHAR_T
103   _DEFINE_SPEC(0, is_integral, wchar_t, true)
104 #endif
105   _DEFINE_SPEC(0, is_integral, short, true)
106   _DEFINE_SPEC(0, is_integral, unsigned short, true)
107   _DEFINE_SPEC(0, is_integral, int, true)
108   _DEFINE_SPEC(0, is_integral, unsigned int, true)
109   _DEFINE_SPEC(0, is_integral, long, true)
110   _DEFINE_SPEC(0, is_integral, unsigned long, true)
111   _DEFINE_SPEC(0, is_integral, long long, true)
112   _DEFINE_SPEC(0, is_integral, unsigned long long, true)
114   /// is_floating_point
115   template<typename>
116     struct is_floating_point
117     : public false_type { };
118   _DEFINE_SPEC(0, is_floating_point, float, true)
119   _DEFINE_SPEC(0, is_floating_point, double, true)
120   _DEFINE_SPEC(0, is_floating_point, long double, true)
122   /// is_array
123   template<typename>
124     struct is_array
125     : public false_type { };
127   template<typename _Tp, std::size_t _Size>
128     struct is_array<_Tp[_Size]>
129     : public true_type { };
131   template<typename _Tp>
132     struct is_array<_Tp[]>
133     : public true_type { };
135   /// is_pointer
136   template<typename>
137     struct is_pointer
138     : public false_type { };
139   _DEFINE_SPEC(1, is_pointer, _Tp*, true)
141   /// is_reference
142   template<typename _Tp>
143     struct is_reference;
145   /// is_function
146   template<typename _Tp>
147     struct is_function;
149   /// is_member_object_pointer
150   template<typename>
151     struct is_member_object_pointer
152     : public false_type { };
153   _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*,
154                !is_function<_Tp>::value)
156   /// is_member_function_pointer
157   template<typename>
158     struct is_member_function_pointer
159     : public false_type { };
160   _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*,
161                is_function<_Tp>::value)
163   /// is_enum
164   template<typename _Tp>
165     struct is_enum
166     : public integral_constant<bool, __is_enum(_Tp)>
167     { };
169   /// is_union
170   template<typename _Tp>
171     struct is_union
172     : public integral_constant<bool, __is_union(_Tp)>
173     { };
175   /// is_class
176   template<typename _Tp>
177     struct is_class
178     : public integral_constant<bool, __is_class(_Tp)>
179     { };
181   template<typename _Tp>
182     struct __in_array
183     : public __sfinae_types
184     {
185     private:
186       template<typename _Up>
187         static __one __test(_Up(*)[1]);
188       template<typename>
189         static __two __test(...);
190     
191     public:
192       static const bool __value = sizeof(__test<_Tp>(0)) == 1;
193     };
195   /// is_abstract
196   template<typename _Tp>
197     struct is_abstract;
199   /// is_function
200   template<typename _Tp>
201     struct is_function
202     : public integral_constant<bool, !(__in_array<_Tp>::__value
203                                        || is_abstract<_Tp>::value
204                                        || is_reference<_Tp>::value
205                                        || is_void<_Tp>::value)>
206     { };
208   /// composite type traits [4.5.2].
209   template<typename _Tp>
210     struct is_arithmetic
211     : public integral_constant<bool, (is_integral<_Tp>::value
212                                       || is_floating_point<_Tp>::value)>
213     { };
215   /// is_fundamental
216   template<typename _Tp>
217     struct is_fundamental
218     : public integral_constant<bool, (is_arithmetic<_Tp>::value
219                                       || is_void<_Tp>::value)>
220     { };
222   /// is_object
223   template<typename _Tp>
224     struct is_object
225     : public integral_constant<bool, !(is_function<_Tp>::value
226                                        || is_reference<_Tp>::value
227                                        || is_void<_Tp>::value)>
228     { };
230   /// is_member_pointer
231   template<typename _Tp>
232     struct is_member_pointer;
234   /// is_scalal
235   template<typename _Tp>
236     struct is_scalar
237     : public integral_constant<bool, (is_arithmetic<_Tp>::value
238                                       || is_enum<_Tp>::value
239                                       || is_pointer<_Tp>::value
240                                       || is_member_pointer<_Tp>::value)>
241     { };
243   /// is_compound
244   template<typename _Tp>
245     struct is_compound
246     : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
248   /// is_member_pointer
249   template<typename _Tp>
250     struct is_member_pointer
251     : public integral_constant<bool,
252                                (is_member_object_pointer<_Tp>::value
253                                 || is_member_function_pointer<_Tp>::value)>
254     { };
256   /// type properties [4.5.3].
257   template<typename>
258     struct is_const
259     : public false_type { };
261   /// is_const
262   template<typename _Tp>
263     struct is_const<_Tp const>
264     : public true_type { };
265   
266   /// is_volatile
267   template<typename>
268     struct is_volatile
269     : public false_type { };
271   template<typename _Tp>
272     struct is_volatile<_Tp volatile>
273     : public true_type { };
275   /// is_empty
276   template<typename _Tp>
277     struct is_empty
278     : public integral_constant<bool, __is_empty(_Tp)>
279     { };
281   /// is_polymorphic
282   template<typename _Tp>
283     struct is_polymorphic
284     : public integral_constant<bool, __is_polymorphic(_Tp)>
285     { };
287   /// is_abstract
288   template<typename _Tp>
289     struct is_abstract
290     : public integral_constant<bool, __is_abstract(_Tp)>
291     { };
293   /// has_virtual_destructor
294   template<typename _Tp>
295     struct has_virtual_destructor
296     : public integral_constant<bool, __has_virtual_destructor(_Tp)>
297     { };
299   /// alignment_of
300   template<typename _Tp>
301     struct alignment_of
302     : public integral_constant<std::size_t, __alignof__(_Tp)> { };
303   
304   /// rank
305   template<typename>
306     struct rank
307     : public integral_constant<std::size_t, 0> { };
308    
309   template<typename _Tp, std::size_t _Size>
310     struct rank<_Tp[_Size]>
311     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
313   template<typename _Tp>
314     struct rank<_Tp[]>
315     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
317   /// extent
318   template<typename, unsigned _Uint = 0>
319     struct extent
320     : public integral_constant<std::size_t, 0> { };
321   
322   template<typename _Tp, unsigned _Uint, std::size_t _Size>
323     struct extent<_Tp[_Size], _Uint>
324     : public integral_constant<std::size_t,
325                                _Uint == 0 ? _Size : extent<_Tp,
326                                                            _Uint - 1>::value>
327     { };
329   template<typename _Tp, unsigned _Uint>
330     struct extent<_Tp[], _Uint>
331     : public integral_constant<std::size_t,
332                                _Uint == 0 ? 0 : extent<_Tp,
333                                                        _Uint - 1>::value>
334     { };
336   /// relationships between types [4.6].
337   template<typename, typename>
338     struct is_same
339     : public false_type { };
341   template<typename _Tp>
342     struct is_same<_Tp, _Tp>
343     : public true_type { };
345   /// const-volatile modifications [4.7.1].
346   template<typename _Tp>
347     struct remove_const
348     { typedef _Tp     type; };
350   template<typename _Tp>
351     struct remove_const<_Tp const>
352     { typedef _Tp     type; };
353   
354   /// remove_volatile
355   template<typename _Tp>
356     struct remove_volatile
357     { typedef _Tp     type; };
359   template<typename _Tp>
360     struct remove_volatile<_Tp volatile>
361     { typedef _Tp     type; };
362   
363   /// remove_cv
364   template<typename _Tp>
365     struct remove_cv
366     {
367       typedef typename
368       remove_const<typename remove_volatile<_Tp>::type>::type     type;
369     };
370   
371   /// add_const
372   template<typename _Tp>
373     struct add_const
374     { typedef _Tp const     type; };
375    
376   /// add_volatile
377   template<typename _Tp>
378     struct add_volatile
379     { typedef _Tp volatile     type; };
380   
381   /// add_cv
382   template<typename _Tp>
383     struct add_cv
384     {
385       typedef typename
386       add_const<typename add_volatile<_Tp>::type>::type     type;
387     };
389   /// array modifications [4.7.3].
390   template<typename _Tp>
391     struct remove_extent
392     { typedef _Tp     type; };
394   template<typename _Tp, std::size_t _Size>
395     struct remove_extent<_Tp[_Size]>
396     { typedef _Tp     type; };
398   template<typename _Tp>
399     struct remove_extent<_Tp[]>
400     { typedef _Tp     type; };
402   /// remove_all_extents
403   template<typename _Tp>
404     struct remove_all_extents
405     { typedef _Tp     type; };
407   template<typename _Tp, std::size_t _Size>
408     struct remove_all_extents<_Tp[_Size]>
409     { typedef typename remove_all_extents<_Tp>::type     type; };
411   template<typename _Tp>
412     struct remove_all_extents<_Tp[]>
413     { typedef typename remove_all_extents<_Tp>::type     type; };
415   /// pointer modifications [4.7.4].
416 #undef _DEFINE_SPEC_BODY
417 #define _DEFINE_SPEC_BODY(_Value)      \
418     { typedef _Tp     type; };
420   /// remove_pointer
421   template<typename _Tp>
422     struct remove_pointer
423     { typedef _Tp     type; };
424   _DEFINE_SPEC(1, remove_pointer, _Tp*, false)
426   /// remove_reference
427   template<typename _Tp>
428     struct remove_reference;
430   /// add_pointer
431   template<typename _Tp>
432     struct add_pointer
433     { typedef typename remove_reference<_Tp>::type*     type; };
435 #undef _DEFINE_SPEC_0_HELPER
436 #undef _DEFINE_SPEC_1_HELPER
437 #undef _DEFINE_SPEC_2_HELPER
438 #undef _DEFINE_SPEC
439 #undef _DEFINE_SPEC_BODY
441 _GLIBCXX_END_NAMESPACE_TR1