1 // TR1 type_traits -*- C++ -*-
3 // Copyright (C) 2004 Free Software Foundation, Inc.
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)
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 * This is a TR1 C++ Library header.
26 #define _TYPE_TRAITS 1
28 #include <bits/c++config.h>
36 /// @brief helper classes [4.3].
37 template<typename _Tp, _Tp __v>
38 struct integral_constant
40 static const _Tp value = __v;
41 typedef _Tp value_type;
42 typedef integral_constant<_Tp, __v> type;
44 typedef integral_constant<bool, true> true_type;
45 typedef integral_constant<bool, false> false_type;
47 #define _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \
49 struct _Primary<_Type> \
50 : public true_type { };
52 #define _DEFINE_PRIMARY_SPEC(_Primary, _Type) \
53 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \
54 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const) \
55 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type volatile) \
56 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const volatile)
58 /// @brief primary type categories [4.5.1].
61 : public false_type { };
62 _DEFINE_PRIMARY_SPEC(is_void, void)
66 : public false_type { };
67 _DEFINE_PRIMARY_SPEC(is_integral, bool)
68 _DEFINE_PRIMARY_SPEC(is_integral, char)
69 _DEFINE_PRIMARY_SPEC(is_integral, signed char)
70 _DEFINE_PRIMARY_SPEC(is_integral, unsigned char)
71 #ifdef _GLIBCXX_USE_WCHAR_T
72 _DEFINE_PRIMARY_SPEC(is_integral, wchar_t)
74 _DEFINE_PRIMARY_SPEC(is_integral, short)
75 _DEFINE_PRIMARY_SPEC(is_integral, unsigned short)
76 _DEFINE_PRIMARY_SPEC(is_integral, int)
77 _DEFINE_PRIMARY_SPEC(is_integral, unsigned int)
78 _DEFINE_PRIMARY_SPEC(is_integral, long)
79 _DEFINE_PRIMARY_SPEC(is_integral, unsigned long)
80 _DEFINE_PRIMARY_SPEC(is_integral, long long)
81 _DEFINE_PRIMARY_SPEC(is_integral, unsigned long long)
84 struct is_floating_point
85 : public false_type { };
86 _DEFINE_PRIMARY_SPEC(is_floating_point, float)
87 _DEFINE_PRIMARY_SPEC(is_floating_point, double)
88 _DEFINE_PRIMARY_SPEC(is_floating_point, long double)
92 : public false_type { };
94 template<typename _Tp, std::size_t _Size>
95 struct is_array<_Tp[_Size]>
96 : public true_type { };
98 template<typename _Tp>
99 struct is_array<_Tp[]>
100 : public true_type { };
102 template<typename _Tp>
107 : public false_type { };
109 template<typename _Tp>
110 struct is_reference<_Tp&>
111 : public true_type { };
113 template<typename _Tp>
114 struct is_member_object_pointer;
116 template<typename _Tp>
117 struct is_member_function_pointer;
119 template<typename _Tp>
122 template<typename _Tp>
125 template<typename _Tp>
128 template<typename _Tp>
131 #undef _DEFINE_PRIMARY_SPEC_HELPER
132 #undef _DEFINE_PRIMARY_SPEC
134 /// @brief composite type traits [4.5.2].
135 template<typename _Tp>
137 : public integral_constant<bool, (is_integral<_Tp>::value
138 || is_floating_point<_Tp>::value)>
141 template<typename _Tp>
142 struct is_fundamental
143 : public integral_constant<bool, (is_arithmetic<_Tp>::value
144 || is_void<_Tp>::value)>
147 template<typename _Tp>
149 : public integral_constant<bool, !(is_function<_Tp>::value
150 || is_reference<_Tp>::value
151 || is_void<_Tp>::value)>
154 template<typename _Tp>
155 struct is_member_pointer
156 : public integral_constant<bool,
157 (is_member_object_pointer<_Tp>::value
158 || is_member_function_pointer<_Tp>::value)>
161 template<typename _Tp>
163 : public integral_constant<bool, (is_arithmetic<_Tp>::value
164 || is_enum<_Tp>::value
165 || is_pointer<_Tp>::value
166 || is_member_pointer<_Tp>::value)>
169 template<typename _Tp>
171 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
173 /// @brief type properties [4.5.3].
176 : public false_type { };
178 template<typename _Tp>
179 struct is_const<_Tp const>
180 : public true_type { };
184 : public false_type { };
186 template<typename _Tp>
187 struct is_volatile<_Tp volatile>
188 : public true_type { };
190 template<typename _Tp>
193 template<typename _Tp>
196 template<typename _Tp>
197 struct is_polymorphic;
199 template<typename _Tp>
202 template<typename _Tp>
203 struct has_trivial_constructor;
205 template<typename _Tp>
206 struct has_trivial_copy;
208 template<typename _Tp>
209 struct has_trivial_assign;
211 template<typename _Tp>
212 struct has_trivial_destructor;
214 template<typename _Tp>
215 struct has_nothrow_constructor;
217 template<typename _Tp>
218 struct has_nothrow_copy;
220 template<typename _Tp>
221 struct has_nothrow_assign;
223 template<typename _Tp>
224 struct has_virtual_destructor
225 : public false_type { };
227 template<typename _Tp>
230 template<typename _Tp>
233 template<typename _Tp>
236 template<typename _Tp>
239 template<typename _Tp, unsigned _Uint = 0>
242 /// @brief relationships between types [4.6].
243 template<typename _Tp, typename _Up>
246 template<typename _From, typename _To>
247 struct is_convertible;
249 template<typename _Base, typename _Derived>
252 /// @brief const-volatile modifications [4.7.1].
253 template<typename _Tp>
256 template<typename _Tp>
257 struct remove_volatile;
259 template<typename _Tp>
262 template<typename _Tp>
265 template<typename _Tp>
268 template<typename _Tp>
271 /// @brief reference modifications [4.7.2].
272 template<typename _Tp>
273 struct remove_reference;
275 template<typename _Tp>
276 struct add_reference;
278 /// @brief array modififications [4.7.3].
279 template<typename _Tp>
280 struct remove_extent;
282 template<typename _Tp>
283 struct remove_all_extents;
285 /// @brief pointer modifications [4.7.4].
286 template<typename _Tp>
287 struct remove_pointer;
289 template<typename _Tp>
292 /// @brief other transformations [4.8].
293 template<std::size_t _Len, std::size_t _Align>
294 struct aligned_storage;