Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / tr1 / type_traits
blob734eec6ab7e24c970a210b145cdb36a72be4d4db
1 // TR1 type_traits -*- C++ -*-
3 // Copyright (C) 2004, 2005, 2006, 2007 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/type_traits
31  *  This is a TR1 C++ Library header. 
32  */
34 #ifndef _GLIBCXX_TR1_TYPE_TRAITS
35 #define _GLIBCXX_TR1_TYPE_TRAITS 1
37 #pragma GCC system_header
39 #if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
40 #  error TR1 header cannot be included from C++0x header
41 #endif
43 #include <cstddef>
45 #if defined(_GLIBCXX_INCLUDE_AS_TR1)
46 #  include <tr1_impl/type_traits>
47 #else
48 #  define _GLIBCXX_INCLUDE_AS_TR1
49 #  define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
50 #  define _GLIBCXX_END_NAMESPACE_TR1 }
51 #  define _GLIBCXX_TR1 tr1::
52 #  include <tr1_impl/type_traits>
53 #  undef _GLIBCXX_TR1
54 #  undef _GLIBCXX_END_NAMESPACE_TR1
55 #  undef _GLIBCXX_BEGIN_NAMESPACE_TR1
56 #  undef _GLIBCXX_INCLUDE_AS_TR1
57 #endif
59 namespace std
61 namespace tr1
63 #define _DEFINE_SPEC_HELPER(_Spec)                 \
64   template<>                                       \
65     struct _Spec                                   \
66     : public true_type { };
68 #define _DEFINE_SPEC(_Trait, _Type)                \
69   _DEFINE_SPEC_HELPER(_Trait<_Type>)               \
70   _DEFINE_SPEC_HELPER(_Trait<_Type const>)         \
71   _DEFINE_SPEC_HELPER(_Trait<_Type volatile>)      \
72   _DEFINE_SPEC_HELPER(_Trait<_Type const volatile>)
74   template<typename>
75     struct is_reference
76     : public false_type { };
78   template<typename _Tp>
79     struct is_reference<_Tp&>
80     : public true_type { };
82   template<typename _Tp>
83     struct is_pod
84     : public integral_constant<bool, __is_pod(_Tp) || is_void<_Tp>::value>
85     { };
87   template<typename _Tp>
88     struct has_trivial_constructor
89     : public integral_constant<bool, is_pod<_Tp>::value>
90     { };
92   template<typename _Tp>
93     struct has_trivial_copy
94     : public integral_constant<bool, is_pod<_Tp>::value>
95     { };
97   template<typename _Tp>
98     struct has_trivial_assign
99     : public integral_constant<bool, is_pod<_Tp>::value>
100     { };
102   template<typename _Tp>
103     struct has_trivial_destructor
104     : public integral_constant<bool, is_pod<_Tp>::value>
105     { };
107   template<typename _Tp>
108     struct has_nothrow_constructor
109     : public integral_constant<bool, is_pod<_Tp>::value>
110     { };
112   template<typename _Tp>
113     struct has_nothrow_copy
114     : public integral_constant<bool, is_pod<_Tp>::value>
115     { };
117   template<typename _Tp>
118     struct has_nothrow_assign
119     : public integral_constant<bool, is_pod<_Tp>::value>
120     { };
122   template<typename>
123     struct is_signed
124     : public false_type { };
125   _DEFINE_SPEC(is_signed, signed char)
126   _DEFINE_SPEC(is_signed, short)
127   _DEFINE_SPEC(is_signed, int)
128   _DEFINE_SPEC(is_signed, long)
129   _DEFINE_SPEC(is_signed, long long)
131   template<typename>
132     struct is_unsigned
133     : public false_type { };
134   _DEFINE_SPEC(is_unsigned, unsigned char)
135   _DEFINE_SPEC(is_unsigned, unsigned short)
136   _DEFINE_SPEC(is_unsigned, unsigned int)
137   _DEFINE_SPEC(is_unsigned, unsigned long)
138   _DEFINE_SPEC(is_unsigned, unsigned long long)
140   template<typename _Base, typename _Derived>
141     struct __is_base_of_helper
142     {
143       typedef typename remove_cv<_Base>::type    _NoCv_Base;
144       typedef typename remove_cv<_Derived>::type _NoCv_Derived;
145       static const bool __value = (is_same<_Base, _Derived>::value
146                                    || (__is_base_of(_Base, _Derived)
147                                        && !is_same<_NoCv_Base,
148                                                    _NoCv_Derived>::value));
149     };
151   template<typename _Base, typename _Derived>
152     struct is_base_of
153     : public integral_constant<bool,
154                                __is_base_of_helper<_Base, _Derived>::__value>
155     { };
157   template<typename _From, typename _To>
158     struct __is_convertible_simple
159     : public __sfinae_types
160     {
161     private:
162       static __one __test(_To);
163       static __two __test(...);
164       static _From __makeFrom();
165     
166     public:
167       static const bool __value = sizeof(__test(__makeFrom())) == 1;
168     };
170   template<typename _Tp>
171     struct add_reference;
173   template<typename _Tp>
174     struct __is_int_or_cref
175     {
176       typedef typename remove_reference<_Tp>::type __rr_Tp;
177       static const bool __value = (is_integral<_Tp>::value
178                                    || (is_integral<__rr_Tp>::value
179                                        && is_const<__rr_Tp>::value
180                                        && !is_volatile<__rr_Tp>::value));
181     };
183   template<typename _From, typename _To,
184            bool = (is_void<_From>::value || is_void<_To>::value
185                    || is_function<_To>::value || is_array<_To>::value
186                    // This special case is here only to avoid warnings. 
187                    || (is_floating_point<typename
188                        remove_reference<_From>::type>::value
189                        && __is_int_or_cref<_To>::__value))>
190     struct __is_convertible_helper
191     {
192       // "An imaginary lvalue of type From...".
193       static const bool __value = (__is_convertible_simple<typename
194                                    add_reference<_From>::type, _To>::__value);
195     };
197   template<typename _From, typename _To>
198     struct __is_convertible_helper<_From, _To, true>
199     { static const bool __value = (is_void<_To>::value
200                                    || (__is_int_or_cref<_To>::__value
201                                        && !is_void<_From>::value)); };
203   template<typename _From, typename _To>
204     struct is_convertible
205     : public integral_constant<bool,
206                                __is_convertible_helper<_From, _To>::__value>
207     { };
209   // reference modifications [4.7.2].
210   template<typename _Tp>
211     struct remove_reference
212     { typedef _Tp     type; };
214   template<typename _Tp>
215     struct remove_reference<_Tp&>
216     { typedef _Tp     type; };
218   // NB: Careful with reference to void.
219   template<typename _Tp, bool = (is_void<_Tp>::value
220                                  || is_reference<_Tp>::value)>
221     struct __add_reference_helper
222     { typedef _Tp&    type; };
224   template<typename _Tp>
225     struct __add_reference_helper<_Tp, true>
226     { typedef _Tp     type; };
228   template<typename _Tp>
229     struct add_reference
230     : public __add_reference_helper<_Tp>
231     { };
233   // other transformations [4.8].
234   template<std::size_t _Len, std::size_t _Align>
235     struct aligned_storage
236     { 
237       union type
238       {
239         unsigned char __data[_Len];
240         struct __attribute__((__aligned__((_Align)))) { } __align; 
241       };
242     };
244 #undef _DEFINE_SPEC_HELPER
245 #undef _DEFINE_SPEC
249 #endif // _GLIBCXX_TR1_TYPE_TRAITS