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_SPEC_HELPER(_Header, _Spec) \
50 : public true_type { };
52 #define _DEFINE_SPEC(_Header, _Primary, _Type) \
53 _DEFINE_SPEC_HELPER(_Header, _Primary<_Type>) \
54 _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const>) \
55 _DEFINE_SPEC_HELPER(_Header, _Primary<_Type volatile>) \
56 _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const volatile>)
58 /// @brief primary type categories [4.5.1].
61 : public false_type { };
62 _DEFINE_SPEC(<>, is_void, void)
66 : public false_type { };
67 _DEFINE_SPEC(<>, is_integral, bool)
68 _DEFINE_SPEC(<>, is_integral, char)
69 _DEFINE_SPEC(<>, is_integral, signed char)
70 _DEFINE_SPEC(<>, is_integral, unsigned char)
71 #ifdef _GLIBCXX_USE_WCHAR_T
72 _DEFINE_SPEC(<>, is_integral, wchar_t)
74 _DEFINE_SPEC(<>, is_integral, short)
75 _DEFINE_SPEC(<>, is_integral, unsigned short)
76 _DEFINE_SPEC(<>, is_integral, int)
77 _DEFINE_SPEC(<>, is_integral, unsigned int)
78 _DEFINE_SPEC(<>, is_integral, long)
79 _DEFINE_SPEC(<>, is_integral, unsigned long)
80 _DEFINE_SPEC(<>, is_integral, long long)
81 _DEFINE_SPEC(<>, is_integral, unsigned long long)
84 struct is_floating_point
85 : public false_type { };
86 _DEFINE_SPEC(<>, is_floating_point, float)
87 _DEFINE_SPEC(<>, is_floating_point, double)
88 _DEFINE_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 { };
104 : public false_type { };
105 _DEFINE_SPEC(<typename _Tp>, is_pointer, _Tp*)
109 : public false_type { };
111 template<typename _Tp>
112 struct is_reference<_Tp&>
113 : public true_type { };
115 template<typename _Tp>
116 struct is_member_object_pointer;
118 template<typename _Tp>
119 struct is_member_function_pointer;
121 template<typename _Tp>
124 template<typename _Tp>
127 template<typename _Tp>
130 template<typename _Tp>
133 /// @brief composite type traits [4.5.2].
134 template<typename _Tp>
136 : public integral_constant<bool, (is_integral<_Tp>::value
137 || is_floating_point<_Tp>::value)>
140 template<typename _Tp>
141 struct is_fundamental
142 : public integral_constant<bool, (is_arithmetic<_Tp>::value
143 || is_void<_Tp>::value)>
146 template<typename _Tp>
148 : public integral_constant<bool, !(is_function<_Tp>::value
149 || is_reference<_Tp>::value
150 || is_void<_Tp>::value)>
153 template<typename _Tp>
154 struct is_member_pointer
155 : public integral_constant<bool,
156 (is_member_object_pointer<_Tp>::value
157 || is_member_function_pointer<_Tp>::value)>
160 template<typename _Tp>
162 : public integral_constant<bool, (is_arithmetic<_Tp>::value
163 || is_enum<_Tp>::value
164 || is_pointer<_Tp>::value
165 || is_member_pointer<_Tp>::value)>
168 template<typename _Tp>
170 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
172 /// @brief type properties [4.5.3].
175 : public false_type { };
177 template<typename _Tp>
178 struct is_const<_Tp const>
179 : public true_type { };
183 : public false_type { };
185 template<typename _Tp>
186 struct is_volatile<_Tp volatile>
187 : public true_type { };
189 template<typename _Tp>
192 template<typename _Tp>
195 template<typename _Tp>
196 struct is_polymorphic;
198 template<typename _Tp>
201 template<typename _Tp>
202 struct has_trivial_constructor;
204 template<typename _Tp>
205 struct has_trivial_copy;
207 template<typename _Tp>
208 struct has_trivial_assign;
210 template<typename _Tp>
211 struct has_trivial_destructor;
213 template<typename _Tp>
214 struct has_nothrow_constructor;
216 template<typename _Tp>
217 struct has_nothrow_copy;
219 template<typename _Tp>
220 struct has_nothrow_assign;
222 template<typename _Tp>
223 struct has_virtual_destructor
224 : public false_type { };
226 template<typename _Tp>
229 template<typename _Tp>
232 template<typename _Tp>
237 : public integral_constant<std::size_t, 0> { };
239 template<typename _Tp, std::size_t _Size>
240 struct rank<_Tp[_Size]>
241 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
243 template<typename _Tp>
245 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
247 template<typename, unsigned = 0>
249 : integral_constant<std::size_t, 0> { };
251 template<typename _Tp, unsigned _Uint, std::size_t _Size>
252 struct extent<_Tp[_Size], _Uint>
253 : integral_constant<std::size_t,
254 _Uint == 0 ? _Size : extent<_Tp, _Uint - 1>::value>
257 template<typename _Tp, unsigned _Uint>
258 struct extent<_Tp[], _Uint>
259 : integral_constant<std::size_t,
260 _Uint == 0 ? 0 : extent<_Tp, _Uint - 1>::value>
263 /// @brief relationships between types [4.6].
264 template<typename, typename>
266 : public false_type { };
268 template<typename _Tp>
269 struct is_same<_Tp, _Tp>
270 : public true_type { };
272 template<typename _From, typename _To>
273 struct is_convertible;
275 template<typename _Base, typename _Derived>
278 /// @brief const-volatile modifications [4.7.1].
279 template<typename _Tp>
281 { typedef _Tp type; };
283 template<typename _Tp>
284 struct remove_const<_Tp const>
285 { typedef _Tp type; };
287 template<typename _Tp>
288 struct remove_volatile
289 { typedef _Tp type; };
291 template<typename _Tp>
292 struct remove_volatile<_Tp volatile>
293 { typedef _Tp type; };
295 template<typename _Tp>
299 remove_const<typename remove_volatile<_Tp>::type>::type type;
302 template<typename _Tp>
305 template<typename _Tp>
308 template<typename _Tp>
311 /// @brief reference modifications [4.7.2].
312 template<typename _Tp>
313 struct remove_reference
314 { typedef _Tp type; };
316 template<typename _Tp>
317 struct remove_reference<_Tp&>
318 { typedef _Tp type; };
320 template<typename _Tp>
322 { typedef _Tp& type; };
324 template<typename _Tp>
325 struct add_reference<_Tp&>
326 { typedef _Tp& type; };
328 /// @brief array modififications [4.7.3].
329 template<typename _Tp>
331 { typedef _Tp type; };
333 template<typename _Tp, std::size_t _Size>
334 struct remove_extent<_Tp[_Size]>
335 { typedef _Tp type; };
337 template<typename _Tp>
338 struct remove_extent<_Tp[]>
339 { typedef _Tp type; };
341 template<typename _Tp>
342 struct remove_all_extents
343 { typedef _Tp type; };
345 template<typename _Tp, std::size_t _Size>
346 struct remove_all_extents<_Tp[_Size]>
347 { typedef typename remove_all_extents<_Tp>::type type; };
349 template<typename _Tp>
350 struct remove_all_extents<_Tp[]>
351 { typedef typename remove_all_extents<_Tp>::type type; };
353 /// @brief pointer modifications [4.7.4].
354 #undef _DEFINE_SPEC_HELPER
355 #define _DEFINE_SPEC_HELPER(_Header, _Spec) \
358 { typedef _Tp type; };
360 template<typename _Tp>
361 struct remove_pointer
362 { typedef _Tp type; };
363 _DEFINE_SPEC(<typename _Tp>, remove_pointer, _Tp*)
365 template<typename _Tp>
367 { typedef typename remove_reference<_Tp>::type* type; };
369 /// @brief other transformations [4.8].
370 template<std::size_t _Len, std::size_t _Align>
371 struct aligned_storage;
373 #undef _DEFINE_SPEC_HELPER