type_traits: Implement extent.
[gcc.git] / libstdc++-v3 / include / tr1 / type_traits
1 // TR1 type_traits -*- C++ -*-
2
3 // Copyright (C) 2004 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.
10
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.
15
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,
19 // USA.
20
21 /** @file
22 * This is a TR1 C++ Library header.
23 */
24
25 #ifndef _TYPE_TRAITS
26 #define _TYPE_TRAITS 1
27
28 #include <bits/c++config.h>
29 #include <cstddef>
30
31 //namespace std::tr1
32 namespace std
33 {
34 namespace tr1
35 {
36 /// @brief helper classes [4.3].
37 template<typename _Tp, _Tp __v>
38 struct integral_constant
39 {
40 static const _Tp value = __v;
41 typedef _Tp value_type;
42 typedef integral_constant<_Tp, __v> type;
43 };
44 typedef integral_constant<bool, true> true_type;
45 typedef integral_constant<bool, false> false_type;
46
47 #define _DEFINE_SPEC_HELPER(_Header, _Spec) \
48 template _Header \
49 struct _Spec \
50 : public true_type { };
51
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>)
57
58 /// @brief primary type categories [4.5.1].
59 template<typename>
60 struct is_void
61 : public false_type { };
62 _DEFINE_SPEC(<>, is_void, void)
63
64 template<typename>
65 struct is_integral
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)
73 #endif
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)
82
83 template<typename>
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)
89
90 template<typename>
91 struct is_array
92 : public false_type { };
93
94 template<typename _Tp, std::size_t _Size>
95 struct is_array<_Tp[_Size]>
96 : public true_type { };
97
98 template<typename _Tp>
99 struct is_array<_Tp[]>
100 : public true_type { };
101
102 template<typename>
103 struct is_pointer
104 : public false_type { };
105 _DEFINE_SPEC(<typename _Tp>, is_pointer, _Tp*)
106
107 template<typename>
108 struct is_reference
109 : public false_type { };
110
111 template<typename _Tp>
112 struct is_reference<_Tp&>
113 : public true_type { };
114
115 template<typename _Tp>
116 struct is_member_object_pointer;
117
118 template<typename _Tp>
119 struct is_member_function_pointer;
120
121 template<typename _Tp>
122 struct is_enum;
123
124 template<typename _Tp>
125 struct is_union;
126
127 template<typename _Tp>
128 struct is_class;
129
130 template<typename _Tp>
131 struct is_function;
132
133 /// @brief composite type traits [4.5.2].
134 template<typename _Tp>
135 struct is_arithmetic
136 : public integral_constant<bool, (is_integral<_Tp>::value
137 || is_floating_point<_Tp>::value)>
138 { };
139
140 template<typename _Tp>
141 struct is_fundamental
142 : public integral_constant<bool, (is_arithmetic<_Tp>::value
143 || is_void<_Tp>::value)>
144 { };
145
146 template<typename _Tp>
147 struct is_object
148 : public integral_constant<bool, !(is_function<_Tp>::value
149 || is_reference<_Tp>::value
150 || is_void<_Tp>::value)>
151 { };
152
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)>
158 { };
159
160 template<typename _Tp>
161 struct is_scalar
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)>
166 { };
167
168 template<typename _Tp>
169 struct is_compound
170 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
171
172 /// @brief type properties [4.5.3].
173 template<typename>
174 struct is_const
175 : public false_type { };
176
177 template<typename _Tp>
178 struct is_const<_Tp const>
179 : public true_type { };
180
181 template<typename>
182 struct is_volatile
183 : public false_type { };
184
185 template<typename _Tp>
186 struct is_volatile<_Tp volatile>
187 : public true_type { };
188
189 template<typename _Tp>
190 struct is_pod;
191
192 template<typename _Tp>
193 struct is_empty;
194
195 template<typename _Tp>
196 struct is_polymorphic;
197
198 template<typename _Tp>
199 struct is_abstract;
200
201 template<typename _Tp>
202 struct has_trivial_constructor;
203
204 template<typename _Tp>
205 struct has_trivial_copy;
206
207 template<typename _Tp>
208 struct has_trivial_assign;
209
210 template<typename _Tp>
211 struct has_trivial_destructor;
212
213 template<typename _Tp>
214 struct has_nothrow_constructor;
215
216 template<typename _Tp>
217 struct has_nothrow_copy;
218
219 template<typename _Tp>
220 struct has_nothrow_assign;
221
222 template<typename _Tp>
223 struct has_virtual_destructor
224 : public false_type { };
225
226 template<typename _Tp>
227 struct is_signed;
228
229 template<typename _Tp>
230 struct is_unsigned;
231
232 template<typename _Tp>
233 struct alignment_of;
234
235 template<typename>
236 struct rank
237 : public integral_constant<std::size_t, 0> { };
238
239 template<typename _Tp, std::size_t _Size>
240 struct rank<_Tp[_Size]>
241 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
242
243 template<typename _Tp>
244 struct rank<_Tp[]>
245 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
246
247 template<typename, unsigned = 0>
248 struct extent
249 : integral_constant<std::size_t, 0> { };
250
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>
255 { };
256
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>
261 { };
262
263 /// @brief relationships between types [4.6].
264 template<typename, typename>
265 struct is_same
266 : public false_type { };
267
268 template<typename _Tp>
269 struct is_same<_Tp, _Tp>
270 : public true_type { };
271
272 template<typename _From, typename _To>
273 struct is_convertible;
274
275 template<typename _Base, typename _Derived>
276 struct is_base_of;
277
278 /// @brief const-volatile modifications [4.7.1].
279 template<typename _Tp>
280 struct remove_const
281 { typedef _Tp type; };
282
283 template<typename _Tp>
284 struct remove_const<_Tp const>
285 { typedef _Tp type; };
286
287 template<typename _Tp>
288 struct remove_volatile
289 { typedef _Tp type; };
290
291 template<typename _Tp>
292 struct remove_volatile<_Tp volatile>
293 { typedef _Tp type; };
294
295 template<typename _Tp>
296 struct remove_cv
297 {
298 typedef typename
299 remove_const<typename remove_volatile<_Tp>::type>::type type;
300 };
301
302 template<typename _Tp>
303 struct add_const;
304
305 template<typename _Tp>
306 struct add_volatile;
307
308 template<typename _Tp>
309 struct add_cv;
310
311 /// @brief reference modifications [4.7.2].
312 template<typename _Tp>
313 struct remove_reference
314 { typedef _Tp type; };
315
316 template<typename _Tp>
317 struct remove_reference<_Tp&>
318 { typedef _Tp type; };
319
320 template<typename _Tp>
321 struct add_reference
322 { typedef _Tp& type; };
323
324 template<typename _Tp>
325 struct add_reference<_Tp&>
326 { typedef _Tp& type; };
327
328 /// @brief array modififications [4.7.3].
329 template<typename _Tp>
330 struct remove_extent
331 { typedef _Tp type; };
332
333 template<typename _Tp, std::size_t _Size>
334 struct remove_extent<_Tp[_Size]>
335 { typedef _Tp type; };
336
337 template<typename _Tp>
338 struct remove_extent<_Tp[]>
339 { typedef _Tp type; };
340
341 template<typename _Tp>
342 struct remove_all_extents
343 { typedef _Tp type; };
344
345 template<typename _Tp, std::size_t _Size>
346 struct remove_all_extents<_Tp[_Size]>
347 { typedef typename remove_all_extents<_Tp>::type type; };
348
349 template<typename _Tp>
350 struct remove_all_extents<_Tp[]>
351 { typedef typename remove_all_extents<_Tp>::type type; };
352
353 /// @brief pointer modifications [4.7.4].
354 #undef _DEFINE_SPEC_HELPER
355 #define _DEFINE_SPEC_HELPER(_Header, _Spec) \
356 template _Header \
357 struct _Spec \
358 { typedef _Tp type; };
359
360 template<typename _Tp>
361 struct remove_pointer
362 { typedef _Tp type; };
363 _DEFINE_SPEC(<typename _Tp>, remove_pointer, _Tp*)
364
365 template<typename _Tp>
366 struct add_pointer
367 { typedef typename remove_reference<_Tp>::type* type; };
368
369 /// @brief other transformations [4.8].
370 template<std::size_t _Len, std::size_t _Align>
371 struct aligned_storage;
372
373 #undef _DEFINE_SPEC_HELPER
374 #undef _DEFINE_SPEC
375
376 }
377 }
378
379 #endif