]>
Commit | Line | Data |
---|---|---|
c0ffa2ba | 1 | // C++11 <type_traits> -*- C++ -*- |
af13a7a6 | 2 | |
405feeb8 | 3 | // Copyright (C) 2007-2013 Free Software Foundation, Inc. |
af13a7a6 BK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
af13a7a6 BK |
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 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
af13a7a6 BK |
24 | |
25 | /** @file include/type_traits | |
26 | * This is a Standard C++ Library header. | |
27 | */ | |
28 | ||
4514bed6 BK |
29 | #ifndef _GLIBCXX_TYPE_TRAITS |
30 | #define _GLIBCXX_TYPE_TRAITS 1 | |
af13a7a6 BK |
31 | |
32 | #pragma GCC system_header | |
33 | ||
734f5023 | 34 | #if __cplusplus < 201103L |
ab65a4c7 | 35 | # include <bits/c++0x_warning.h> |
57317d2a | 36 | #else |
af13a7a6 | 37 | |
8fc81078 | 38 | #include <bits/c++config.h> |
e133ace8 | 39 | |
12ffa228 BK |
40 | namespace std _GLIBCXX_VISIBILITY(default) |
41 | { | |
42 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
e133ace8 | 43 | |
8e32aa11 | 44 | /** |
c0ffa2ba | 45 | * @defgroup metaprogramming Metaprogramming |
13901e4b JW |
46 | * @ingroup utilities |
47 | * | |
48 | * Template utilities for compile-time introspection and modification, | |
49 | * including type classification traits, type property inspection traits | |
50 | * and type transformation traits. | |
51 | * | |
5b9daa7e BK |
52 | * @{ |
53 | */ | |
ac65b7d2 DK |
54 | |
55 | /// integral_constant | |
56 | template<typename _Tp, _Tp __v> | |
57 | struct integral_constant | |
58 | { | |
59 | static constexpr _Tp value = __v; | |
60 | typedef _Tp value_type; | |
61 | typedef integral_constant<_Tp, __v> type; | |
9191d7a8 | 62 | constexpr operator value_type() const { return value; } |
ac65b7d2 DK |
63 | }; |
64 | ||
c0ffa2ba BK |
65 | template<typename _Tp, _Tp __v> |
66 | constexpr _Tp integral_constant<_Tp, __v>::value; | |
67 | ||
13901e4b | 68 | /// The type used as a compile-time boolean with true value. |
ac65b7d2 DK |
69 | typedef integral_constant<bool, true> true_type; |
70 | ||
13901e4b | 71 | /// The type used as a compile-time boolean with false value. |
ac65b7d2 DK |
72 | typedef integral_constant<bool, false> false_type; |
73 | ||
123c516a | 74 | // Meta programming helper types. |
53dc5044 | 75 | |
123c516a PC |
76 | template<bool, typename, typename> |
77 | struct conditional; | |
53dc5044 | 78 | |
dd7b175e | 79 | template<typename...> |
123c516a PC |
80 | struct __or_; |
81 | ||
ac65b7d2 DK |
82 | template<> |
83 | struct __or_<> | |
84 | : public false_type | |
85 | { }; | |
86 | ||
dd7b175e PC |
87 | template<typename _B1> |
88 | struct __or_<_B1> | |
89 | : public _B1 | |
90 | { }; | |
91 | ||
123c516a PC |
92 | template<typename _B1, typename _B2> |
93 | struct __or_<_B1, _B2> | |
94 | : public conditional<_B1::value, _B1, _B2>::type | |
95 | { }; | |
96 | ||
97 | template<typename _B1, typename _B2, typename _B3, typename... _Bn> | |
98 | struct __or_<_B1, _B2, _B3, _Bn...> | |
99 | : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type | |
100 | { }; | |
53dc5044 | 101 | |
dd7b175e | 102 | template<typename...> |
123c516a | 103 | struct __and_; |
53dc5044 | 104 | |
ac65b7d2 DK |
105 | template<> |
106 | struct __and_<> | |
107 | : public true_type | |
108 | { }; | |
109 | ||
dd7b175e PC |
110 | template<typename _B1> |
111 | struct __and_<_B1> | |
112 | : public _B1 | |
113 | { }; | |
114 | ||
123c516a PC |
115 | template<typename _B1, typename _B2> |
116 | struct __and_<_B1, _B2> | |
117 | : public conditional<_B1::value, _B2, _B1>::type | |
118 | { }; | |
119 | ||
120 | template<typename _B1, typename _B2, typename _B3, typename... _Bn> | |
121 | struct __and_<_B1, _B2, _B3, _Bn...> | |
122 | : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type | |
123 | { }; | |
124 | ||
125 | template<typename _Pp> | |
126 | struct __not_ | |
127 | : public integral_constant<bool, !_Pp::value> | |
128 | { }; | |
129 | ||
b3618b71 DK |
130 | // For several sfinae-friendly trait implementations we transport both the |
131 | // result information (as the member type) and the failure information (no | |
132 | // member type). This is very similar to std::enable_if, but we cannot use | |
133 | // them, because we need to derive from them as an implementation detail. | |
134 | ||
135 | template<typename _Tp> | |
136 | struct __success_type | |
137 | { typedef _Tp type; }; | |
138 | ||
139 | struct __failure_type | |
140 | { }; | |
141 | ||
c0ffa2ba | 142 | // Primary type categories. |
123c516a | 143 | |
53dc5044 PC |
144 | template<typename> |
145 | struct remove_cv; | |
146 | ||
147 | template<typename> | |
148 | struct __is_void_helper | |
149 | : public false_type { }; | |
53dc5044 | 150 | |
123c516a PC |
151 | template<> |
152 | struct __is_void_helper<void> | |
153 | : public true_type { }; | |
53dc5044 PC |
154 | |
155 | /// is_void | |
156 | template<typename _Tp> | |
157 | struct is_void | |
82b12c4b | 158 | : public __is_void_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
159 | { }; |
160 | ||
161 | template<typename> | |
162 | struct __is_integral_helper | |
163 | : public false_type { }; | |
123c516a PC |
164 | |
165 | template<> | |
166 | struct __is_integral_helper<bool> | |
167 | : public true_type { }; | |
168 | ||
169 | template<> | |
170 | struct __is_integral_helper<char> | |
171 | : public true_type { }; | |
172 | ||
173 | template<> | |
174 | struct __is_integral_helper<signed char> | |
175 | : public true_type { }; | |
176 | ||
177 | template<> | |
178 | struct __is_integral_helper<unsigned char> | |
179 | : public true_type { }; | |
180 | ||
53dc5044 | 181 | #ifdef _GLIBCXX_USE_WCHAR_T |
123c516a PC |
182 | template<> |
183 | struct __is_integral_helper<wchar_t> | |
184 | : public true_type { }; | |
53dc5044 | 185 | #endif |
123c516a PC |
186 | |
187 | template<> | |
188 | struct __is_integral_helper<char16_t> | |
189 | : public true_type { }; | |
190 | ||
191 | template<> | |
192 | struct __is_integral_helper<char32_t> | |
193 | : public true_type { }; | |
194 | ||
195 | template<> | |
196 | struct __is_integral_helper<short> | |
197 | : public true_type { }; | |
198 | ||
199 | template<> | |
200 | struct __is_integral_helper<unsigned short> | |
201 | : public true_type { }; | |
202 | ||
203 | template<> | |
204 | struct __is_integral_helper<int> | |
205 | : public true_type { }; | |
206 | ||
207 | template<> | |
208 | struct __is_integral_helper<unsigned int> | |
209 | : public true_type { }; | |
210 | ||
211 | template<> | |
212 | struct __is_integral_helper<long> | |
213 | : public true_type { }; | |
214 | ||
215 | template<> | |
216 | struct __is_integral_helper<unsigned long> | |
217 | : public true_type { }; | |
218 | ||
219 | template<> | |
220 | struct __is_integral_helper<long long> | |
221 | : public true_type { }; | |
222 | ||
223 | template<> | |
224 | struct __is_integral_helper<unsigned long long> | |
225 | : public true_type { }; | |
53dc5044 | 226 | |
6d585f01 PC |
227 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
228 | template<> | |
fd1e62c2 | 229 | struct __is_integral_helper<__int128> |
6d585f01 PC |
230 | : public true_type { }; |
231 | ||
232 | template<> | |
fd1e62c2 | 233 | struct __is_integral_helper<unsigned __int128> |
6d585f01 PC |
234 | : public true_type { }; |
235 | #endif | |
236 | ||
53dc5044 PC |
237 | /// is_integral |
238 | template<typename _Tp> | |
239 | struct is_integral | |
82b12c4b | 240 | : public __is_integral_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
241 | { }; |
242 | ||
243 | template<typename> | |
244 | struct __is_floating_point_helper | |
245 | : public false_type { }; | |
123c516a PC |
246 | |
247 | template<> | |
248 | struct __is_floating_point_helper<float> | |
249 | : public true_type { }; | |
250 | ||
251 | template<> | |
252 | struct __is_floating_point_helper<double> | |
253 | : public true_type { }; | |
254 | ||
255 | template<> | |
256 | struct __is_floating_point_helper<long double> | |
257 | : public true_type { }; | |
53dc5044 | 258 | |
6d585f01 PC |
259 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) |
260 | template<> | |
261 | struct __is_floating_point_helper<__float128> | |
262 | : public true_type { }; | |
263 | #endif | |
264 | ||
53dc5044 PC |
265 | /// is_floating_point |
266 | template<typename _Tp> | |
267 | struct is_floating_point | |
82b12c4b | 268 | : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
269 | { }; |
270 | ||
271 | /// is_array | |
272 | template<typename> | |
273 | struct is_array | |
274 | : public false_type { }; | |
275 | ||
276 | template<typename _Tp, std::size_t _Size> | |
277 | struct is_array<_Tp[_Size]> | |
278 | : public true_type { }; | |
279 | ||
280 | template<typename _Tp> | |
281 | struct is_array<_Tp[]> | |
282 | : public true_type { }; | |
283 | ||
284 | template<typename> | |
285 | struct __is_pointer_helper | |
286 | : public false_type { }; | |
123c516a PC |
287 | |
288 | template<typename _Tp> | |
289 | struct __is_pointer_helper<_Tp*> | |
290 | : public true_type { }; | |
53dc5044 PC |
291 | |
292 | /// is_pointer | |
293 | template<typename _Tp> | |
294 | struct is_pointer | |
82b12c4b | 295 | : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
296 | { }; |
297 | ||
123c516a PC |
298 | /// is_lvalue_reference |
299 | template<typename> | |
300 | struct is_lvalue_reference | |
301 | : public false_type { }; | |
302 | ||
53dc5044 | 303 | template<typename _Tp> |
123c516a PC |
304 | struct is_lvalue_reference<_Tp&> |
305 | : public true_type { }; | |
306 | ||
307 | /// is_rvalue_reference | |
308 | template<typename> | |
309 | struct is_rvalue_reference | |
310 | : public false_type { }; | |
53dc5044 | 311 | |
53dc5044 | 312 | template<typename _Tp> |
123c516a PC |
313 | struct is_rvalue_reference<_Tp&&> |
314 | : public true_type { }; | |
315 | ||
316 | template<typename> | |
53dc5044 PC |
317 | struct is_function; |
318 | ||
319 | template<typename> | |
320 | struct __is_member_object_pointer_helper | |
321 | : public false_type { }; | |
123c516a PC |
322 | |
323 | template<typename _Tp, typename _Cp> | |
324 | struct __is_member_object_pointer_helper<_Tp _Cp::*> | |
325 | : public integral_constant<bool, !is_function<_Tp>::value> { }; | |
53dc5044 PC |
326 | |
327 | /// is_member_object_pointer | |
328 | template<typename _Tp> | |
329 | struct is_member_object_pointer | |
82b12c4b FD |
330 | : public __is_member_object_pointer_helper< |
331 | typename remove_cv<_Tp>::type>::type | |
53dc5044 PC |
332 | { }; |
333 | ||
334 | template<typename> | |
335 | struct __is_member_function_pointer_helper | |
336 | : public false_type { }; | |
123c516a PC |
337 | |
338 | template<typename _Tp, typename _Cp> | |
339 | struct __is_member_function_pointer_helper<_Tp _Cp::*> | |
340 | : public integral_constant<bool, is_function<_Tp>::value> { }; | |
53dc5044 PC |
341 | |
342 | /// is_member_function_pointer | |
343 | template<typename _Tp> | |
344 | struct is_member_function_pointer | |
82b12c4b FD |
345 | : public __is_member_function_pointer_helper< |
346 | typename remove_cv<_Tp>::type>::type | |
53dc5044 PC |
347 | { }; |
348 | ||
349 | /// is_enum | |
350 | template<typename _Tp> | |
351 | struct is_enum | |
352 | : public integral_constant<bool, __is_enum(_Tp)> | |
353 | { }; | |
354 | ||
355 | /// is_union | |
356 | template<typename _Tp> | |
357 | struct is_union | |
358 | : public integral_constant<bool, __is_union(_Tp)> | |
359 | { }; | |
360 | ||
361 | /// is_class | |
362 | template<typename _Tp> | |
363 | struct is_class | |
364 | : public integral_constant<bool, __is_class(_Tp)> | |
365 | { }; | |
366 | ||
367 | /// is_function | |
368 | template<typename> | |
369 | struct is_function | |
370 | : public false_type { }; | |
123c516a | 371 | |
53dc5044 PC |
372 | template<typename _Res, typename... _ArgTypes> |
373 | struct is_function<_Res(_ArgTypes...)> | |
374 | : public true_type { }; | |
123c516a | 375 | |
53dc5044 PC |
376 | template<typename _Res, typename... _ArgTypes> |
377 | struct is_function<_Res(_ArgTypes......)> | |
378 | : public true_type { }; | |
123c516a | 379 | |
53dc5044 PC |
380 | template<typename _Res, typename... _ArgTypes> |
381 | struct is_function<_Res(_ArgTypes...) const> | |
382 | : public true_type { }; | |
123c516a | 383 | |
53dc5044 PC |
384 | template<typename _Res, typename... _ArgTypes> |
385 | struct is_function<_Res(_ArgTypes......) const> | |
386 | : public true_type { }; | |
123c516a | 387 | |
53dc5044 PC |
388 | template<typename _Res, typename... _ArgTypes> |
389 | struct is_function<_Res(_ArgTypes...) volatile> | |
390 | : public true_type { }; | |
123c516a | 391 | |
53dc5044 PC |
392 | template<typename _Res, typename... _ArgTypes> |
393 | struct is_function<_Res(_ArgTypes......) volatile> | |
394 | : public true_type { }; | |
123c516a | 395 | |
53dc5044 PC |
396 | template<typename _Res, typename... _ArgTypes> |
397 | struct is_function<_Res(_ArgTypes...) const volatile> | |
398 | : public true_type { }; | |
123c516a | 399 | |
53dc5044 PC |
400 | template<typename _Res, typename... _ArgTypes> |
401 | struct is_function<_Res(_ArgTypes......) const volatile> | |
402 | : public true_type { }; | |
403 | ||
1e673415 PC |
404 | template<typename> |
405 | struct __is_nullptr_t_helper | |
406 | : public false_type { }; | |
123c516a PC |
407 | |
408 | template<> | |
409 | struct __is_nullptr_t_helper<std::nullptr_t> | |
410 | : public true_type { }; | |
1e673415 PC |
411 | |
412 | // __is_nullptr_t (extension). | |
413 | template<typename _Tp> | |
414 | struct __is_nullptr_t | |
82b12c4b | 415 | : public __is_nullptr_t_helper<typename remove_cv<_Tp>::type>::type |
1e673415 PC |
416 | { }; |
417 | ||
c0ffa2ba | 418 | // Composite type categories. |
123c516a PC |
419 | |
420 | /// is_reference | |
421 | template<typename _Tp> | |
422 | struct is_reference | |
423 | : public __or_<is_lvalue_reference<_Tp>, | |
424 | is_rvalue_reference<_Tp>>::type | |
425 | { }; | |
426 | ||
53dc5044 PC |
427 | /// is_arithmetic |
428 | template<typename _Tp> | |
429 | struct is_arithmetic | |
123c516a | 430 | : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type |
53dc5044 PC |
431 | { }; |
432 | ||
433 | /// is_fundamental | |
434 | template<typename _Tp> | |
435 | struct is_fundamental | |
8a38ebb6 | 436 | : public __or_<is_arithmetic<_Tp>, is_void<_Tp>, __is_nullptr_t<_Tp>>::type |
53dc5044 PC |
437 | { }; |
438 | ||
439 | /// is_object | |
440 | template<typename _Tp> | |
441 | struct is_object | |
123c516a PC |
442 | : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, |
443 | is_void<_Tp>>>::type | |
53dc5044 PC |
444 | { }; |
445 | ||
123c516a | 446 | template<typename> |
53dc5044 PC |
447 | struct is_member_pointer; |
448 | ||
449 | /// is_scalar | |
450 | template<typename _Tp> | |
451 | struct is_scalar | |
123c516a PC |
452 | : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>, |
453 | is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type | |
53dc5044 PC |
454 | { }; |
455 | ||
456 | /// is_compound | |
457 | template<typename _Tp> | |
458 | struct is_compound | |
459 | : public integral_constant<bool, !is_fundamental<_Tp>::value> { }; | |
460 | ||
53dc5044 PC |
461 | template<typename _Tp> |
462 | struct __is_member_pointer_helper | |
463 | : public false_type { }; | |
123c516a PC |
464 | |
465 | template<typename _Tp, typename _Cp> | |
466 | struct __is_member_pointer_helper<_Tp _Cp::*> | |
467 | : public true_type { }; | |
53dc5044 | 468 | |
13901e4b | 469 | /// is_member_pointer |
53dc5044 | 470 | template<typename _Tp> |
123c516a | 471 | struct is_member_pointer |
82b12c4b | 472 | : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
473 | { }; |
474 | ||
c0ffa2ba | 475 | // Type properties. |
123c516a | 476 | |
53dc5044 PC |
477 | /// is_const |
478 | template<typename> | |
479 | struct is_const | |
480 | : public false_type { }; | |
481 | ||
482 | template<typename _Tp> | |
483 | struct is_const<_Tp const> | |
484 | : public true_type { }; | |
485 | ||
486 | /// is_volatile | |
487 | template<typename> | |
488 | struct is_volatile | |
489 | : public false_type { }; | |
490 | ||
491 | template<typename _Tp> | |
492 | struct is_volatile<_Tp volatile> | |
493 | : public true_type { }; | |
494 | ||
123c516a PC |
495 | /// is_trivial |
496 | template<typename _Tp> | |
497 | struct is_trivial | |
498 | : public integral_constant<bool, __is_trivial(_Tp)> | |
499 | { }; | |
500 | ||
13901e4b | 501 | // is_trivially_copyable (still unimplemented) |
123c516a PC |
502 | |
503 | /// is_standard_layout | |
504 | template<typename _Tp> | |
505 | struct is_standard_layout | |
506 | : public integral_constant<bool, __is_standard_layout(_Tp)> | |
507 | { }; | |
508 | ||
509 | /// is_pod | |
510 | // Could use is_standard_layout && is_trivial instead of the builtin. | |
511 | template<typename _Tp> | |
512 | struct is_pod | |
513 | : public integral_constant<bool, __is_pod(_Tp)> | |
514 | { }; | |
515 | ||
516 | /// is_literal_type | |
517 | template<typename _Tp> | |
518 | struct is_literal_type | |
519 | : public integral_constant<bool, __is_literal_type(_Tp)> | |
520 | { }; | |
521 | ||
53dc5044 PC |
522 | /// is_empty |
523 | template<typename _Tp> | |
524 | struct is_empty | |
525 | : public integral_constant<bool, __is_empty(_Tp)> | |
526 | { }; | |
527 | ||
528 | /// is_polymorphic | |
529 | template<typename _Tp> | |
530 | struct is_polymorphic | |
531 | : public integral_constant<bool, __is_polymorphic(_Tp)> | |
532 | { }; | |
533 | ||
534 | /// is_abstract | |
535 | template<typename _Tp> | |
536 | struct is_abstract | |
537 | : public integral_constant<bool, __is_abstract(_Tp)> | |
538 | { }; | |
539 | ||
123c516a | 540 | template<typename _Tp, |
6a4b1a00 | 541 | bool = is_arithmetic<_Tp>::value> |
123c516a PC |
542 | struct __is_signed_helper |
543 | : public false_type { }; | |
544 | ||
53dc5044 | 545 | template<typename _Tp> |
6a4b1a00 PC |
546 | struct __is_signed_helper<_Tp, true> |
547 | : public integral_constant<bool, _Tp(-1) < _Tp(0)> | |
53dc5044 PC |
548 | { }; |
549 | ||
123c516a | 550 | /// is_signed |
53dc5044 | 551 | template<typename _Tp> |
123c516a | 552 | struct is_signed |
82b12c4b | 553 | : public __is_signed_helper<_Tp>::type |
123c516a PC |
554 | { }; |
555 | ||
556 | /// is_unsigned | |
557 | template<typename _Tp> | |
558 | struct is_unsigned | |
559 | : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type | |
560 | { }; | |
561 | ||
562 | ||
c0ffa2ba | 563 | // Destructible and constructible type properties. |
123c516a | 564 | |
53dc5044 | 565 | template<typename> |
123c516a | 566 | struct add_rvalue_reference; |
53dc5044 | 567 | |
13901e4b JW |
568 | /** |
569 | * @brief Utility to simplify expressions used in unevaluated operands | |
570 | * @ingroup utilities | |
571 | */ | |
53dc5044 | 572 | template<typename _Tp> |
123c516a | 573 | typename add_rvalue_reference<_Tp>::type declval() noexcept; |
53dc5044 | 574 | |
123c516a PC |
575 | template<typename, unsigned = 0> |
576 | struct extent; | |
577 | ||
578 | template<typename> | |
579 | struct remove_all_extents; | |
580 | ||
581 | template<typename _Tp> | |
582 | struct __is_array_known_bounds | |
583 | : public integral_constant<bool, (extent<_Tp>::value > 0)> | |
53dc5044 PC |
584 | { }; |
585 | ||
123c516a PC |
586 | template<typename _Tp> |
587 | struct __is_array_unknown_bounds | |
588 | : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type | |
53dc5044 | 589 | { }; |
2c7a09d7 | 590 | |
62fa805f | 591 | // In N3290 is_destructible does not say anything about function |
2c7a09d7 | 592 | // types and abstract types, see LWG 2049. This implementation |
62fa805f DK |
593 | // describes function types as non-destructible and all complete |
594 | // object types as destructible, iff the explicit destructor | |
2c7a09d7 | 595 | // call expression is wellformed. |
62fa805f | 596 | struct __do_is_destructible_impl |
123c516a | 597 | { |
62fa805f | 598 | template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())> |
123c516a PC |
599 | static true_type __test(int); |
600 | ||
601 | template<typename> | |
602 | static false_type __test(...); | |
603 | }; | |
53dc5044 PC |
604 | |
605 | template<typename _Tp> | |
62fa805f DK |
606 | struct __is_destructible_impl |
607 | : public __do_is_destructible_impl | |
123c516a PC |
608 | { |
609 | typedef decltype(__test<_Tp>(0)) type; | |
610 | }; | |
53dc5044 | 611 | |
62fa805f DK |
612 | template<typename _Tp, |
613 | bool = __or_<is_void<_Tp>, | |
614 | __is_array_unknown_bounds<_Tp>, | |
615 | is_function<_Tp>>::value, | |
616 | bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> | |
617 | struct __is_destructible_safe; | |
618 | ||
619 | template<typename _Tp> | |
620 | struct __is_destructible_safe<_Tp, false, false> | |
621 | : public __is_destructible_impl<typename | |
622 | remove_all_extents<_Tp>::type>::type | |
623 | { }; | |
624 | ||
625 | template<typename _Tp> | |
626 | struct __is_destructible_safe<_Tp, true, false> | |
627 | : public false_type { }; | |
628 | ||
629 | template<typename _Tp> | |
630 | struct __is_destructible_safe<_Tp, false, true> | |
631 | : public true_type { }; | |
632 | ||
633 | /// is_destructible | |
634 | template<typename _Tp> | |
635 | struct is_destructible | |
82b12c4b | 636 | : public __is_destructible_safe<_Tp>::type |
62fa805f DK |
637 | { }; |
638 | ||
639 | // is_nothrow_destructible requires that is_destructible is | |
640 | // satisfied as well. We realize that by mimicing the | |
641 | // implementation of is_destructible but refer to noexcept(expr) | |
642 | // instead of decltype(expr). | |
643 | struct __do_is_nt_destructible_impl | |
123c516a | 644 | { |
62fa805f DK |
645 | template<typename _Tp> |
646 | static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())> | |
647 | __test(int); | |
123c516a PC |
648 | |
649 | template<typename> | |
650 | static false_type __test(...); | |
651 | }; | |
53dc5044 | 652 | |
53dc5044 | 653 | template<typename _Tp> |
62fa805f DK |
654 | struct __is_nt_destructible_impl |
655 | : public __do_is_nt_destructible_impl | |
123c516a PC |
656 | { |
657 | typedef decltype(__test<_Tp>(0)) type; | |
658 | }; | |
659 | ||
660 | template<typename _Tp, | |
661 | bool = __or_<is_void<_Tp>, | |
62fa805f DK |
662 | __is_array_unknown_bounds<_Tp>, |
663 | is_function<_Tp>>::value, | |
664 | bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> | |
665 | struct __is_nt_destructible_safe; | |
53dc5044 PC |
666 | |
667 | template<typename _Tp> | |
62fa805f DK |
668 | struct __is_nt_destructible_safe<_Tp, false, false> |
669 | : public __is_nt_destructible_impl<typename | |
670 | remove_all_extents<_Tp>::type>::type | |
123c516a PC |
671 | { }; |
672 | ||
53dc5044 | 673 | template<typename _Tp> |
62fa805f | 674 | struct __is_nt_destructible_safe<_Tp, true, false> |
123c516a | 675 | : public false_type { }; |
53dc5044 PC |
676 | |
677 | template<typename _Tp> | |
62fa805f | 678 | struct __is_nt_destructible_safe<_Tp, false, true> |
123c516a PC |
679 | : public true_type { }; |
680 | ||
62fa805f | 681 | /// is_nothrow_destructible |
53dc5044 | 682 | template<typename _Tp> |
62fa805f | 683 | struct is_nothrow_destructible |
82b12c4b | 684 | : public __is_nt_destructible_safe<_Tp>::type |
123c516a PC |
685 | { }; |
686 | ||
687 | struct __do_is_default_constructible_impl | |
688 | { | |
689 | template<typename _Tp, typename = decltype(_Tp())> | |
690 | static true_type __test(int); | |
691 | ||
692 | template<typename> | |
693 | static false_type __test(...); | |
694 | }; | |
695 | ||
696 | template<typename _Tp> | |
697 | struct __is_default_constructible_impl | |
698 | : public __do_is_default_constructible_impl | |
53dc5044 | 699 | { |
123c516a | 700 | typedef decltype(__test<_Tp>(0)) type; |
53dc5044 | 701 | }; |
53dc5044 PC |
702 | |
703 | template<typename _Tp> | |
123c516a | 704 | struct __is_default_constructible_atom |
2c7a09d7 PC |
705 | : public __and_<__not_<is_void<_Tp>>, |
706 | __is_default_constructible_impl<_Tp>>::type | |
123c516a | 707 | { }; |
53dc5044 | 708 | |
123c516a PC |
709 | template<typename _Tp, bool = is_array<_Tp>::value> |
710 | struct __is_default_constructible_safe; | |
53dc5044 | 711 | |
2c7a09d7 PC |
712 | // The following technique is a workaround for a current core language |
713 | // restriction, which does not allow for array types to occur in | |
714 | // functional casts of the form T(). Complete arrays can be default- | |
715 | // constructed, if the element type is default-constructible, but | |
716 | // arrays with unknown bounds are not. | |
53dc5044 | 717 | template<typename _Tp> |
123c516a PC |
718 | struct __is_default_constructible_safe<_Tp, true> |
719 | : public __and_<__is_array_known_bounds<_Tp>, | |
720 | __is_default_constructible_atom<typename | |
2c7a09d7 | 721 | remove_all_extents<_Tp>::type>>::type |
53dc5044 PC |
722 | { }; |
723 | ||
53dc5044 | 724 | template<typename _Tp> |
123c516a PC |
725 | struct __is_default_constructible_safe<_Tp, false> |
726 | : public __is_default_constructible_atom<_Tp>::type | |
727 | { }; | |
4a27a739 | 728 | |
123c516a | 729 | /// is_default_constructible |
4a27a739 | 730 | template<typename _Tp> |
123c516a | 731 | struct is_default_constructible |
82b12c4b | 732 | : public __is_default_constructible_safe<_Tp>::type |
123c516a | 733 | { }; |
4a27a739 | 734 | |
2c7a09d7 PC |
735 | |
736 | // Implementation of is_constructible. | |
737 | ||
738 | // The hardest part of this trait is the binary direct-initialization | |
739 | // case, because we hit into a functional cast of the form T(arg). | |
740 | // This implementation uses different strategies depending on the | |
741 | // target type to reduce the test overhead as much as possible: | |
742 | // | |
743 | // a) For a reference target type, we use a static_cast expression | |
744 | // modulo its extra cases. | |
745 | // | |
746 | // b) For a non-reference target type we use a ::new expression. | |
123c516a PC |
747 | struct __do_is_static_castable_impl |
748 | { | |
749 | template<typename _From, typename _To, typename | |
750 | = decltype(static_cast<_To>(declval<_From>()))> | |
751 | static true_type __test(int); | |
4a27a739 | 752 | |
123c516a PC |
753 | template<typename, typename> |
754 | static false_type __test(...); | |
755 | }; | |
4a27a739 | 756 | |
123c516a PC |
757 | template<typename _From, typename _To> |
758 | struct __is_static_castable_impl | |
759 | : public __do_is_static_castable_impl | |
760 | { | |
761 | typedef decltype(__test<_From, _To>(0)) type; | |
762 | }; | |
939759fc | 763 | |
123c516a PC |
764 | template<typename _From, typename _To> |
765 | struct __is_static_castable_safe | |
2c7a09d7 | 766 | : public __is_static_castable_impl<_From, _To>::type |
4a27a739 PC |
767 | { }; |
768 | ||
123c516a PC |
769 | // __is_static_castable |
770 | template<typename _From, typename _To> | |
771 | struct __is_static_castable | |
772 | : public integral_constant<bool, (__is_static_castable_safe< | |
773 | _From, _To>::value)> | |
774 | { }; | |
939759fc | 775 | |
2c7a09d7 PC |
776 | // Implementation for non-reference types. To meet the proper |
777 | // variable definition semantics, we also need to test for | |
778 | // is_destructible in this case. | |
5db25ab1 DK |
779 | // This form should be simplified by a single expression: |
780 | // ::delete ::new _Tp(declval<_Arg>()), see c++/51222. | |
123c516a PC |
781 | struct __do_is_direct_constructible_impl |
782 | { | |
783 | template<typename _Tp, typename _Arg, typename | |
784 | = decltype(::new _Tp(declval<_Arg>()))> | |
785 | static true_type __test(int); | |
4a27a739 | 786 | |
123c516a PC |
787 | template<typename, typename> |
788 | static false_type __test(...); | |
789 | }; | |
4a27a739 | 790 | |
123c516a PC |
791 | template<typename _Tp, typename _Arg> |
792 | struct __is_direct_constructible_impl | |
793 | : public __do_is_direct_constructible_impl | |
794 | { | |
795 | typedef decltype(__test<_Tp, _Arg>(0)) type; | |
796 | }; | |
4a27a739 | 797 | |
123c516a PC |
798 | template<typename _Tp, typename _Arg> |
799 | struct __is_direct_constructible_new_safe | |
800 | : public __and_<is_destructible<_Tp>, | |
2c7a09d7 | 801 | __is_direct_constructible_impl<_Tp, _Arg>>::type |
123c516a | 802 | { }; |
4a27a739 | 803 | |
123c516a PC |
804 | template<typename, typename> |
805 | struct is_same; | |
4a27a739 | 806 | |
123c516a PC |
807 | template<typename, typename> |
808 | struct is_base_of; | |
4a27a739 | 809 | |
123c516a PC |
810 | template<typename> |
811 | struct remove_reference; | |
4a27a739 | 812 | |
123c516a | 813 | template<typename _From, typename _To, bool |
5db25ab1 DK |
814 | = __not_<__or_<is_void<_From>, |
815 | is_function<_From>>>::value> | |
123c516a | 816 | struct __is_base_to_derived_ref; |
4a27a739 | 817 | |
5db25ab1 DK |
818 | // Detect whether we have a downcast situation during |
819 | // reference binding. | |
123c516a PC |
820 | template<typename _From, typename _To> |
821 | struct __is_base_to_derived_ref<_From, _To, true> | |
822 | { | |
823 | typedef typename remove_cv<typename remove_reference<_From | |
824 | >::type>::type __src_t; | |
825 | typedef typename remove_cv<typename remove_reference<_To | |
826 | >::type>::type __dst_t; | |
2c7a09d7 PC |
827 | typedef __and_<__not_<is_same<__src_t, __dst_t>>, |
828 | is_base_of<__src_t, __dst_t>> type; | |
123c516a PC |
829 | static constexpr bool value = type::value; |
830 | }; | |
4a27a739 | 831 | |
123c516a PC |
832 | template<typename _From, typename _To> |
833 | struct __is_base_to_derived_ref<_From, _To, false> | |
834 | : public false_type | |
4a27a739 PC |
835 | { }; |
836 | ||
123c516a PC |
837 | template<typename _From, typename _To, bool |
838 | = __and_<is_lvalue_reference<_From>, | |
839 | is_rvalue_reference<_To>>::value> | |
840 | struct __is_lvalue_to_rvalue_ref; | |
e133ace8 | 841 | |
5db25ab1 DK |
842 | // Detect whether we have an lvalue of non-function type |
843 | // bound to a reference-compatible rvalue-reference. | |
123c516a PC |
844 | template<typename _From, typename _To> |
845 | struct __is_lvalue_to_rvalue_ref<_From, _To, true> | |
846 | { | |
847 | typedef typename remove_cv<typename remove_reference< | |
848 | _From>::type>::type __src_t; | |
849 | typedef typename remove_cv<typename remove_reference< | |
850 | _To>::type>::type __dst_t; | |
5db25ab1 DK |
851 | typedef __and_<__not_<is_function<__src_t>>, |
852 | __or_<is_same<__src_t, __dst_t>, | |
853 | is_base_of<__dst_t, __src_t>>> type; | |
123c516a PC |
854 | static constexpr bool value = type::value; |
855 | }; | |
e133ace8 | 856 | |
123c516a PC |
857 | template<typename _From, typename _To> |
858 | struct __is_lvalue_to_rvalue_ref<_From, _To, false> | |
859 | : public false_type | |
e133ace8 PC |
860 | { }; |
861 | ||
2c7a09d7 PC |
862 | // Here we handle direct-initialization to a reference type as |
863 | // equivalent to a static_cast modulo overshooting conversions. | |
864 | // These are restricted to the following conversions: | |
5db25ab1 | 865 | // a) A base class value to a derived class reference |
2c7a09d7 | 866 | // b) An lvalue to an rvalue-reference of reference-compatible |
5db25ab1 | 867 | // types that are not functions |
123c516a PC |
868 | template<typename _Tp, typename _Arg> |
869 | struct __is_direct_constructible_ref_cast | |
870 | : public __and_<__is_static_castable<_Arg, _Tp>, | |
871 | __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>, | |
872 | __is_lvalue_to_rvalue_ref<_Arg, _Tp> | |
2c7a09d7 | 873 | >>>::type |
e133ace8 PC |
874 | { }; |
875 | ||
123c516a PC |
876 | template<typename _Tp, typename _Arg> |
877 | struct __is_direct_constructible_new | |
878 | : public conditional<is_reference<_Tp>::value, | |
879 | __is_direct_constructible_ref_cast<_Tp, _Arg>, | |
880 | __is_direct_constructible_new_safe<_Tp, _Arg> | |
881 | >::type | |
b0302c68 PC |
882 | { }; |
883 | ||
123c516a PC |
884 | template<typename _Tp, typename _Arg> |
885 | struct __is_direct_constructible | |
82b12c4b | 886 | : public __is_direct_constructible_new<_Tp, _Arg>::type |
e133ace8 PC |
887 | { }; |
888 | ||
2c7a09d7 PC |
889 | // Since default-construction and binary direct-initialization have |
890 | // been handled separately, the implementation of the remaining | |
5db25ab1 DK |
891 | // n-ary construction cases is rather straightforward. We can use |
892 | // here a functional cast, because array types are excluded anyway | |
893 | // and this form is never interpreted as a C cast. | |
123c516a PC |
894 | struct __do_is_nary_constructible_impl |
895 | { | |
896 | template<typename _Tp, typename... _Args, typename | |
897 | = decltype(_Tp(declval<_Args>()...))> | |
898 | static true_type __test(int); | |
2b08f2c5 | 899 | |
123c516a PC |
900 | template<typename, typename...> |
901 | static false_type __test(...); | |
902 | }; | |
b0302c68 PC |
903 | |
904 | template<typename _Tp, typename... _Args> | |
123c516a PC |
905 | struct __is_nary_constructible_impl |
906 | : public __do_is_nary_constructible_impl | |
b0302c68 | 907 | { |
123c516a | 908 | typedef decltype(__test<_Tp, _Args...>(0)) type; |
b0302c68 PC |
909 | }; |
910 | ||
123c516a PC |
911 | template<typename _Tp, typename... _Args> |
912 | struct __is_nary_constructible | |
2c7a09d7 | 913 | : public __is_nary_constructible_impl<_Tp, _Args...>::type |
b0302c68 | 914 | { |
123c516a PC |
915 | static_assert(sizeof...(_Args) > 1, |
916 | "Only useful for > 1 arguments"); | |
917 | }; | |
b0302c68 | 918 | |
123c516a PC |
919 | template<typename _Tp, typename... _Args> |
920 | struct __is_constructible_impl | |
921 | : public __is_nary_constructible<_Tp, _Args...> | |
922 | { }; | |
b0302c68 | 923 | |
123c516a PC |
924 | template<typename _Tp, typename _Arg> |
925 | struct __is_constructible_impl<_Tp, _Arg> | |
926 | : public __is_direct_constructible<_Tp, _Arg> | |
927 | { }; | |
928 | ||
929 | template<typename _Tp> | |
930 | struct __is_constructible_impl<_Tp> | |
931 | : public is_default_constructible<_Tp> | |
932 | { }; | |
b0302c68 PC |
933 | |
934 | /// is_constructible | |
b0302c68 PC |
935 | template<typename _Tp, typename... _Args> |
936 | struct is_constructible | |
82b12c4b | 937 | : public __is_constructible_impl<_Tp, _Args...>::type |
c32097d8 JM |
938 | { }; |
939 | ||
65cee9bd PC |
940 | template<typename _Tp, bool = is_void<_Tp>::value> |
941 | struct __is_copy_constructible_impl; | |
123c516a | 942 | |
65cee9bd PC |
943 | template<typename _Tp> |
944 | struct __is_copy_constructible_impl<_Tp, true> | |
945 | : public false_type { }; | |
946 | ||
947 | template<typename _Tp> | |
948 | struct __is_copy_constructible_impl<_Tp, false> | |
949 | : public is_constructible<_Tp, const _Tp&> | |
950 | { }; | |
951 | ||
952 | /// is_copy_constructible | |
953 | template<typename _Tp> | |
954 | struct is_copy_constructible | |
955 | : public __is_copy_constructible_impl<_Tp> | |
956 | { }; | |
957 | ||
958 | template<typename _Tp, bool = is_void<_Tp>::value> | |
959 | struct __is_move_constructible_impl; | |
960 | ||
961 | template<typename _Tp> | |
962 | struct __is_move_constructible_impl<_Tp, true> | |
963 | : public false_type { }; | |
964 | ||
965 | template<typename _Tp> | |
966 | struct __is_move_constructible_impl<_Tp, false> | |
967 | : public is_constructible<_Tp, _Tp&&> | |
968 | { }; | |
969 | ||
970 | /// is_move_constructible | |
971 | template<typename _Tp> | |
972 | struct is_move_constructible | |
973 | : public __is_move_constructible_impl<_Tp> | |
974 | { }; | |
975 | ||
976 | template<typename _Tp> | |
977 | struct __is_nt_default_constructible_atom | |
978 | : public integral_constant<bool, noexcept(_Tp())> | |
979 | { }; | |
980 | ||
981 | template<typename _Tp, bool = is_array<_Tp>::value> | |
982 | struct __is_nt_default_constructible_impl; | |
983 | ||
984 | template<typename _Tp> | |
985 | struct __is_nt_default_constructible_impl<_Tp, true> | |
986 | : public __and_<__is_array_known_bounds<_Tp>, | |
987 | __is_nt_default_constructible_atom<typename | |
988 | remove_all_extents<_Tp>::type>>::type | |
989 | { }; | |
990 | ||
991 | template<typename _Tp> | |
992 | struct __is_nt_default_constructible_impl<_Tp, false> | |
993 | : public __is_nt_default_constructible_atom<_Tp> | |
994 | { }; | |
995 | ||
996 | /// is_nothrow_default_constructible | |
997 | template<typename _Tp> | |
998 | struct is_nothrow_default_constructible | |
999 | : public __and_<is_default_constructible<_Tp>, | |
1000 | __is_nt_default_constructible_impl<_Tp>>::type | |
1001 | { }; | |
e4f32cb0 PC |
1002 | |
1003 | template<typename _Tp, typename... _Args> | |
65cee9bd PC |
1004 | struct __is_nt_constructible_impl |
1005 | : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> | |
1006 | { }; | |
e4f32cb0 PC |
1007 | |
1008 | template<typename _Tp, typename _Arg> | |
65cee9bd PC |
1009 | struct __is_nt_constructible_impl<_Tp, _Arg> |
1010 | : public integral_constant<bool, | |
1011 | noexcept(static_cast<_Tp>(declval<_Arg>()))> | |
1012 | { }; | |
1013 | ||
1014 | template<typename _Tp> | |
1015 | struct __is_nt_constructible_impl<_Tp> | |
1016 | : public is_nothrow_default_constructible<_Tp> | |
1017 | { }; | |
e4f32cb0 PC |
1018 | |
1019 | /// is_nothrow_constructible | |
1020 | template<typename _Tp, typename... _Args> | |
1021 | struct is_nothrow_constructible | |
65cee9bd PC |
1022 | : public __and_<is_constructible<_Tp, _Args...>, |
1023 | __is_nt_constructible_impl<_Tp, _Args...>>::type | |
1024 | { }; | |
1025 | ||
1026 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1027 | struct __is_nothrow_copy_constructible_impl; | |
1028 | ||
1029 | template<typename _Tp> | |
1030 | struct __is_nothrow_copy_constructible_impl<_Tp, true> | |
1031 | : public false_type { }; | |
1032 | ||
1033 | template<typename _Tp> | |
1034 | struct __is_nothrow_copy_constructible_impl<_Tp, false> | |
1035 | : public is_nothrow_constructible<_Tp, const _Tp&> | |
1036 | { }; | |
1037 | ||
1038 | /// is_nothrow_copy_constructible | |
1039 | template<typename _Tp> | |
1040 | struct is_nothrow_copy_constructible | |
1041 | : public __is_nothrow_copy_constructible_impl<_Tp> | |
1042 | { }; | |
1043 | ||
1044 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1045 | struct __is_nothrow_move_constructible_impl; | |
1046 | ||
1047 | template<typename _Tp> | |
1048 | struct __is_nothrow_move_constructible_impl<_Tp, true> | |
1049 | : public false_type { }; | |
1050 | ||
1051 | template<typename _Tp> | |
1052 | struct __is_nothrow_move_constructible_impl<_Tp, false> | |
1053 | : public is_nothrow_constructible<_Tp, _Tp&&> | |
1054 | { }; | |
1055 | ||
1056 | /// is_nothrow_move_constructible | |
1057 | template<typename _Tp> | |
1058 | struct is_nothrow_move_constructible | |
1059 | : public __is_nothrow_move_constructible_impl<_Tp> | |
1060 | { }; | |
1061 | ||
f263981a PC |
1062 | template<typename _Tp, typename _Up> |
1063 | class __is_assignable_helper | |
f263981a | 1064 | { |
82b12c4b FD |
1065 | template<typename _Tp1, typename _Up1, |
1066 | typename = decltype(declval<_Tp1>() = declval<_Up1>())> | |
1067 | static true_type | |
f263981a PC |
1068 | __test(int); |
1069 | ||
1070 | template<typename, typename> | |
82b12c4b FD |
1071 | static false_type |
1072 | __test(...); | |
f263981a PC |
1073 | |
1074 | public: | |
82b12c4b | 1075 | typedef decltype(__test<_Tp, _Up>(0)) type; |
f263981a PC |
1076 | }; |
1077 | ||
1078 | /// is_assignable | |
1079 | template<typename _Tp, typename _Up> | |
1080 | struct is_assignable | |
82b12c4b | 1081 | : public __is_assignable_helper<_Tp, _Up>::type |
f263981a PC |
1082 | { }; |
1083 | ||
1084 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1085 | struct __is_copy_assignable_impl; | |
1086 | ||
1087 | template<typename _Tp> | |
1088 | struct __is_copy_assignable_impl<_Tp, true> | |
1089 | : public false_type { }; | |
1090 | ||
1091 | template<typename _Tp> | |
1092 | struct __is_copy_assignable_impl<_Tp, false> | |
9b3a81da | 1093 | : public is_assignable<_Tp&, const _Tp&> |
f263981a PC |
1094 | { }; |
1095 | ||
1096 | /// is_copy_assignable | |
1097 | template<typename _Tp> | |
1098 | struct is_copy_assignable | |
1099 | : public __is_copy_assignable_impl<_Tp> | |
1100 | { }; | |
1101 | ||
1102 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1103 | struct __is_move_assignable_impl; | |
1104 | ||
1105 | template<typename _Tp> | |
1106 | struct __is_move_assignable_impl<_Tp, true> | |
1107 | : public false_type { }; | |
1108 | ||
1109 | template<typename _Tp> | |
1110 | struct __is_move_assignable_impl<_Tp, false> | |
1111 | : public is_assignable<_Tp&, _Tp&&> | |
1112 | { }; | |
1113 | ||
1114 | /// is_move_assignable | |
1115 | template<typename _Tp> | |
1116 | struct is_move_assignable | |
1117 | : public __is_move_assignable_impl<_Tp> | |
1118 | { }; | |
1119 | ||
1120 | template<typename _Tp, typename _Up> | |
1121 | struct __is_nt_assignable_impl | |
1122 | : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())> | |
1123 | { }; | |
1124 | ||
1125 | /// is_nothrow_assignable | |
1126 | template<typename _Tp, typename _Up> | |
1127 | struct is_nothrow_assignable | |
1128 | : public __and_<is_assignable<_Tp, _Up>, | |
1129 | __is_nt_assignable_impl<_Tp, _Up>>::type | |
1130 | { }; | |
1131 | ||
1132 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1133 | struct __is_nt_copy_assignable_impl; | |
1134 | ||
1135 | template<typename _Tp> | |
1136 | struct __is_nt_copy_assignable_impl<_Tp, true> | |
1137 | : public false_type { }; | |
1138 | ||
1139 | template<typename _Tp> | |
1140 | struct __is_nt_copy_assignable_impl<_Tp, false> | |
9b3a81da | 1141 | : public is_nothrow_assignable<_Tp&, const _Tp&> |
f263981a PC |
1142 | { }; |
1143 | ||
1144 | /// is_nothrow_copy_assignable | |
1145 | template<typename _Tp> | |
1146 | struct is_nothrow_copy_assignable | |
1147 | : public __is_nt_copy_assignable_impl<_Tp> | |
1148 | { }; | |
1149 | ||
1150 | template<typename _Tp, bool = is_void<_Tp>::value> | |
1151 | struct __is_nt_move_assignable_impl; | |
1152 | ||
1153 | template<typename _Tp> | |
1154 | struct __is_nt_move_assignable_impl<_Tp, true> | |
1155 | : public false_type { }; | |
1156 | ||
1157 | template<typename _Tp> | |
1158 | struct __is_nt_move_assignable_impl<_Tp, false> | |
1159 | : public is_nothrow_assignable<_Tp&, _Tp&&> | |
1160 | { }; | |
1161 | ||
1162 | /// is_nothrow_move_assignable | |
65cee9bd | 1163 | template<typename _Tp> |
f263981a PC |
1164 | struct is_nothrow_move_assignable |
1165 | : public __is_nt_move_assignable_impl<_Tp> | |
e4f32cb0 PC |
1166 | { }; |
1167 | ||
6a9ecd34 PC |
1168 | /// is_trivially_constructible (still unimplemented) |
1169 | ||
1170 | /// is_trivially_default_constructible (still unimplemented) | |
1171 | ||
1172 | /// is_trivially_copy_constructible (still unimplemented) | |
1173 | ||
1174 | /// is_trivially_move_constructible (still unimplemented) | |
1175 | ||
1176 | /// is_trivially_assignable (still unimplemented) | |
1177 | ||
1178 | /// is_trivially_copy_assignable (still unimplemented) | |
1179 | ||
1180 | /// is_trivially_move_assignable (still unimplemented) | |
1181 | ||
1182 | /// is_trivially_destructible | |
1183 | template<typename _Tp> | |
1184 | struct is_trivially_destructible | |
1185 | : public __and_<is_destructible<_Tp>, integral_constant<bool, | |
1186 | __has_trivial_destructor(_Tp)>>::type | |
1187 | { }; | |
1188 | ||
1189 | /// has_trivial_default_constructor (temporary legacy) | |
e133ace8 PC |
1190 | template<typename _Tp> |
1191 | struct has_trivial_default_constructor | |
1192 | : public integral_constant<bool, __has_trivial_constructor(_Tp)> | |
1193 | { }; | |
1194 | ||
6a9ecd34 | 1195 | /// has_trivial_copy_constructor (temporary legacy) |
e133ace8 PC |
1196 | template<typename _Tp> |
1197 | struct has_trivial_copy_constructor | |
1198 | : public integral_constant<bool, __has_trivial_copy(_Tp)> | |
1199 | { }; | |
1200 | ||
6a9ecd34 | 1201 | /// has_trivial_copy_assign (temporary legacy) |
e133ace8 | 1202 | template<typename _Tp> |
6f5e9b8d | 1203 | struct has_trivial_copy_assign |
e133ace8 PC |
1204 | : public integral_constant<bool, __has_trivial_assign(_Tp)> |
1205 | { }; | |
1206 | ||
123c516a PC |
1207 | /// has_virtual_destructor |
1208 | template<typename _Tp> | |
1209 | struct has_virtual_destructor | |
1210 | : public integral_constant<bool, __has_virtual_destructor(_Tp)> | |
1211 | { }; | |
1212 | ||
1213 | ||
1214 | // type property queries. | |
1215 | ||
1216 | /// alignment_of | |
1217 | template<typename _Tp> | |
1218 | struct alignment_of | |
1219 | : public integral_constant<std::size_t, __alignof__(_Tp)> { }; | |
1220 | ||
1221 | /// rank | |
1222 | template<typename> | |
1223 | struct rank | |
1224 | : public integral_constant<std::size_t, 0> { }; | |
1225 | ||
1226 | template<typename _Tp, std::size_t _Size> | |
1227 | struct rank<_Tp[_Size]> | |
1228 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | |
1229 | ||
1230 | template<typename _Tp> | |
1231 | struct rank<_Tp[]> | |
1232 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | |
1233 | ||
1234 | /// extent | |
1235 | template<typename, unsigned _Uint> | |
1236 | struct extent | |
1237 | : public integral_constant<std::size_t, 0> { }; | |
1238 | ||
1239 | template<typename _Tp, unsigned _Uint, std::size_t _Size> | |
1240 | struct extent<_Tp[_Size], _Uint> | |
1241 | : public integral_constant<std::size_t, | |
1242 | _Uint == 0 ? _Size : extent<_Tp, | |
1243 | _Uint - 1>::value> | |
1244 | { }; | |
1245 | ||
1246 | template<typename _Tp, unsigned _Uint> | |
1247 | struct extent<_Tp[], _Uint> | |
1248 | : public integral_constant<std::size_t, | |
1249 | _Uint == 0 ? 0 : extent<_Tp, | |
1250 | _Uint - 1>::value> | |
1251 | { }; | |
1252 | ||
1253 | ||
c0ffa2ba | 1254 | // Type relations. |
123c516a PC |
1255 | |
1256 | /// is_same | |
1257 | template<typename, typename> | |
1258 | struct is_same | |
1259 | : public false_type { }; | |
1260 | ||
1261 | template<typename _Tp> | |
1262 | struct is_same<_Tp, _Tp> | |
1263 | : public true_type { }; | |
b0302c68 | 1264 | |
939759fc | 1265 | /// is_base_of |
e133ace8 PC |
1266 | template<typename _Base, typename _Derived> |
1267 | struct is_base_of | |
1268 | : public integral_constant<bool, __is_base_of(_Base, _Derived)> | |
1269 | { }; | |
1270 | ||
297f34d7 | 1271 | template<typename _From, typename _To, |
123c516a PC |
1272 | bool = __or_<is_void<_From>, is_function<_To>, |
1273 | is_array<_To>>::value> | |
297f34d7 | 1274 | struct __is_convertible_helper |
82b12c4b | 1275 | { typedef typename is_void<_To>::type type; }; |
297f34d7 | 1276 | |
e133ace8 | 1277 | template<typename _From, typename _To> |
b0302c68 | 1278 | class __is_convertible_helper<_From, _To, false> |
e133ace8 | 1279 | { |
82b12c4b FD |
1280 | template<typename _To1> |
1281 | static void __test_aux(_To1); | |
8e7d962a | 1282 | |
82b12c4b FD |
1283 | template<typename _From1, typename _To1, |
1284 | typename = decltype(__test_aux<_To1>(std::declval<_From1>()))> | |
1285 | static true_type | |
8e7d962a PC |
1286 | __test(int); |
1287 | ||
1288 | template<typename, typename> | |
82b12c4b FD |
1289 | static false_type |
1290 | __test(...); | |
297f34d7 | 1291 | |
e133ace8 | 1292 | public: |
82b12c4b | 1293 | typedef decltype(__test<_From, _To>(0)) type; |
e133ace8 PC |
1294 | }; |
1295 | ||
82b12c4b | 1296 | |
b0302c68 | 1297 | /// is_convertible |
e133ace8 PC |
1298 | template<typename _From, typename _To> |
1299 | struct is_convertible | |
82b12c4b | 1300 | : public __is_convertible_helper<_From, _To>::type |
e133ace8 PC |
1301 | { }; |
1302 | ||
fd735b6a | 1303 | |
c0ffa2ba | 1304 | // Const-volatile modifications. |
7b50cdef | 1305 | |
123c516a | 1306 | /// remove_const |
7b50cdef | 1307 | template<typename _Tp> |
123c516a PC |
1308 | struct remove_const |
1309 | { typedef _Tp type; }; | |
7b50cdef | 1310 | |
123c516a PC |
1311 | template<typename _Tp> |
1312 | struct remove_const<_Tp const> | |
1313 | { typedef _Tp type; }; | |
1314 | ||
1315 | /// remove_volatile | |
1316 | template<typename _Tp> | |
1317 | struct remove_volatile | |
1318 | { typedef _Tp type; }; | |
7b50cdef | 1319 | |
123c516a PC |
1320 | template<typename _Tp> |
1321 | struct remove_volatile<_Tp volatile> | |
1322 | { typedef _Tp type; }; | |
1323 | ||
1324 | /// remove_cv | |
1325 | template<typename _Tp> | |
1326 | struct remove_cv | |
1327 | { | |
1328 | typedef typename | |
1329 | remove_const<typename remove_volatile<_Tp>::type>::type type; | |
1330 | }; | |
1331 | ||
1332 | /// add_const | |
1333 | template<typename _Tp> | |
1334 | struct add_const | |
1335 | { typedef _Tp const type; }; | |
1336 | ||
1337 | /// add_volatile | |
1338 | template<typename _Tp> | |
1339 | struct add_volatile | |
1340 | { typedef _Tp volatile type; }; | |
1341 | ||
1342 | /// add_cv | |
1343 | template<typename _Tp> | |
1344 | struct add_cv | |
1345 | { | |
1346 | typedef typename | |
1347 | add_const<typename add_volatile<_Tp>::type>::type type; | |
1348 | }; | |
7b50cdef | 1349 | |
7b50cdef | 1350 | |
123c516a | 1351 | // Reference transformations. |
7b50cdef | 1352 | |
123c516a PC |
1353 | /// remove_reference |
1354 | template<typename _Tp> | |
1355 | struct remove_reference | |
1356 | { typedef _Tp type; }; | |
7b50cdef | 1357 | |
123c516a PC |
1358 | template<typename _Tp> |
1359 | struct remove_reference<_Tp&> | |
1360 | { typedef _Tp type; }; | |
7b50cdef | 1361 | |
123c516a PC |
1362 | template<typename _Tp> |
1363 | struct remove_reference<_Tp&&> | |
1364 | { typedef _Tp type; }; | |
1365 | ||
1366 | template<typename _Tp, | |
1367 | bool = __and_<__not_<is_reference<_Tp>>, | |
1368 | __not_<is_void<_Tp>>>::value, | |
1369 | bool = is_rvalue_reference<_Tp>::value> | |
1370 | struct __add_lvalue_reference_helper | |
1371 | { typedef _Tp type; }; | |
7b50cdef | 1372 | |
5e108459 | 1373 | template<typename _Tp> |
123c516a PC |
1374 | struct __add_lvalue_reference_helper<_Tp, true, false> |
1375 | { typedef _Tp& type; }; | |
5e108459 | 1376 | |
5e108459 | 1377 | template<typename _Tp> |
123c516a PC |
1378 | struct __add_lvalue_reference_helper<_Tp, false, true> |
1379 | { typedef typename remove_reference<_Tp>::type& type; }; | |
5e108459 | 1380 | |
123c516a | 1381 | /// add_lvalue_reference |
5e108459 | 1382 | template<typename _Tp> |
123c516a PC |
1383 | struct add_lvalue_reference |
1384 | : public __add_lvalue_reference_helper<_Tp> | |
1385 | { }; | |
1386 | ||
1387 | template<typename _Tp, | |
1388 | bool = __and_<__not_<is_reference<_Tp>>, | |
1389 | __not_<is_void<_Tp>>>::value> | |
1390 | struct __add_rvalue_reference_helper | |
1391 | { typedef _Tp type; }; | |
5e108459 PC |
1392 | |
1393 | template<typename _Tp> | |
123c516a PC |
1394 | struct __add_rvalue_reference_helper<_Tp, true> |
1395 | { typedef _Tp&& type; }; | |
5e108459 | 1396 | |
123c516a | 1397 | /// add_rvalue_reference |
5e108459 | 1398 | template<typename _Tp> |
123c516a PC |
1399 | struct add_rvalue_reference |
1400 | : public __add_rvalue_reference_helper<_Tp> | |
1401 | { }; | |
5e108459 | 1402 | |
7b50cdef | 1403 | |
c0ffa2ba | 1404 | // Sign modifications. |
123c516a | 1405 | |
7b50cdef BK |
1406 | // Utility for constructing identically cv-qualified types. |
1407 | template<typename _Unqualified, bool _IsConst, bool _IsVol> | |
1408 | struct __cv_selector; | |
1409 | ||
1410 | template<typename _Unqualified> | |
1411 | struct __cv_selector<_Unqualified, false, false> | |
1412 | { typedef _Unqualified __type; }; | |
1413 | ||
1414 | template<typename _Unqualified> | |
1415 | struct __cv_selector<_Unqualified, false, true> | |
1416 | { typedef volatile _Unqualified __type; }; | |
1417 | ||
1418 | template<typename _Unqualified> | |
1419 | struct __cv_selector<_Unqualified, true, false> | |
1420 | { typedef const _Unqualified __type; }; | |
1421 | ||
1422 | template<typename _Unqualified> | |
1423 | struct __cv_selector<_Unqualified, true, true> | |
1424 | { typedef const volatile _Unqualified __type; }; | |
1425 | ||
1426 | template<typename _Qualified, typename _Unqualified, | |
1427 | bool _IsConst = is_const<_Qualified>::value, | |
1428 | bool _IsVol = is_volatile<_Qualified>::value> | |
b0302c68 | 1429 | class __match_cv_qualifiers |
7b50cdef | 1430 | { |
7b50cdef BK |
1431 | typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; |
1432 | ||
1433 | public: | |
1434 | typedef typename __match::__type __type; | |
1435 | }; | |
1436 | ||
7b50cdef BK |
1437 | // Utility for finding the unsigned versions of signed integral types. |
1438 | template<typename _Tp> | |
e133ace8 PC |
1439 | struct __make_unsigned |
1440 | { typedef _Tp __type; }; | |
7b50cdef BK |
1441 | |
1442 | template<> | |
1443 | struct __make_unsigned<char> | |
1444 | { typedef unsigned char __type; }; | |
1445 | ||
1446 | template<> | |
1447 | struct __make_unsigned<signed char> | |
1448 | { typedef unsigned char __type; }; | |
1449 | ||
7b50cdef BK |
1450 | template<> |
1451 | struct __make_unsigned<short> | |
1452 | { typedef unsigned short __type; }; | |
1453 | ||
1454 | template<> | |
1455 | struct __make_unsigned<int> | |
1456 | { typedef unsigned int __type; }; | |
1457 | ||
1458 | template<> | |
1459 | struct __make_unsigned<long> | |
1460 | { typedef unsigned long __type; }; | |
1461 | ||
1462 | template<> | |
1463 | struct __make_unsigned<long long> | |
1464 | { typedef unsigned long long __type; }; | |
1465 | ||
6d585f01 PC |
1466 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
1467 | template<> | |
fd1e62c2 PC |
1468 | struct __make_unsigned<__int128> |
1469 | { typedef unsigned __int128 __type; }; | |
6d585f01 PC |
1470 | #endif |
1471 | ||
7b50cdef BK |
1472 | // Select between integral and enum: not possible to be both. |
1473 | template<typename _Tp, | |
1474 | bool _IsInt = is_integral<_Tp>::value, | |
7b50cdef | 1475 | bool _IsEnum = is_enum<_Tp>::value> |
b0302c68 PC |
1476 | class __make_unsigned_selector; |
1477 | ||
7b50cdef | 1478 | template<typename _Tp> |
b0302c68 | 1479 | class __make_unsigned_selector<_Tp, true, false> |
7b50cdef | 1480 | { |
7b50cdef BK |
1481 | typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; |
1482 | typedef typename __unsignedt::__type __unsigned_type; | |
1483 | typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; | |
1484 | ||
1485 | public: | |
1486 | typedef typename __cv_unsigned::__type __type; | |
1487 | }; | |
1488 | ||
7b50cdef | 1489 | template<typename _Tp> |
b0302c68 | 1490 | class __make_unsigned_selector<_Tp, false, true> |
7b50cdef | 1491 | { |
a0230468 MM |
1492 | // With -fshort-enums, an enum may be as small as a char. |
1493 | typedef unsigned char __smallest; | |
1494 | static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); | |
1495 | static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short); | |
ce2e6349 | 1496 | static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int); |
a0230468 MM |
1497 | typedef conditional<__b2, unsigned int, unsigned long> __cond2; |
1498 | typedef typename __cond2::type __cond2_type; | |
1499 | typedef conditional<__b1, unsigned short, __cond2_type> __cond1; | |
1500 | typedef typename __cond1::type __cond1_type; | |
7b50cdef BK |
1501 | |
1502 | public: | |
a0230468 | 1503 | typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; |
7b50cdef BK |
1504 | }; |
1505 | ||
7b50cdef BK |
1506 | // Given an integral/enum type, return the corresponding unsigned |
1507 | // integer type. | |
5b9daa7e BK |
1508 | // Primary template. |
1509 | /// make_unsigned | |
7b50cdef BK |
1510 | template<typename _Tp> |
1511 | struct make_unsigned | |
1512 | { typedef typename __make_unsigned_selector<_Tp>::__type type; }; | |
1513 | ||
1514 | // Integral, but don't define. | |
1515 | template<> | |
1516 | struct make_unsigned<bool>; | |
1517 | ||
1518 | ||
1519 | // Utility for finding the signed versions of unsigned integral types. | |
1520 | template<typename _Tp> | |
e133ace8 PC |
1521 | struct __make_signed |
1522 | { typedef _Tp __type; }; | |
7b50cdef BK |
1523 | |
1524 | template<> | |
1525 | struct __make_signed<char> | |
1526 | { typedef signed char __type; }; | |
1527 | ||
1528 | template<> | |
1529 | struct __make_signed<unsigned char> | |
1530 | { typedef signed char __type; }; | |
1531 | ||
7b50cdef BK |
1532 | template<> |
1533 | struct __make_signed<unsigned short> | |
1534 | { typedef signed short __type; }; | |
1535 | ||
1536 | template<> | |
1537 | struct __make_signed<unsigned int> | |
1538 | { typedef signed int __type; }; | |
1539 | ||
1540 | template<> | |
1541 | struct __make_signed<unsigned long> | |
1542 | { typedef signed long __type; }; | |
1543 | ||
1544 | template<> | |
1545 | struct __make_signed<unsigned long long> | |
1546 | { typedef signed long long __type; }; | |
1547 | ||
6d585f01 PC |
1548 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
1549 | template<> | |
fd1e62c2 PC |
1550 | struct __make_signed<unsigned __int128> |
1551 | { typedef __int128 __type; }; | |
6d585f01 PC |
1552 | #endif |
1553 | ||
fb8ffd10 | 1554 | // Select between integral and enum: not possible to be both. |
7b50cdef BK |
1555 | template<typename _Tp, |
1556 | bool _IsInt = is_integral<_Tp>::value, | |
7b50cdef | 1557 | bool _IsEnum = is_enum<_Tp>::value> |
b0302c68 PC |
1558 | class __make_signed_selector; |
1559 | ||
7b50cdef | 1560 | template<typename _Tp> |
b0302c68 | 1561 | class __make_signed_selector<_Tp, true, false> |
7b50cdef | 1562 | { |
7b50cdef BK |
1563 | typedef __make_signed<typename remove_cv<_Tp>::type> __signedt; |
1564 | typedef typename __signedt::__type __signed_type; | |
1565 | typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed; | |
1566 | ||
1567 | public: | |
1568 | typedef typename __cv_signed::__type __type; | |
1569 | }; | |
1570 | ||
7b50cdef | 1571 | template<typename _Tp> |
b0302c68 | 1572 | class __make_signed_selector<_Tp, false, true> |
7b50cdef | 1573 | { |
a0230468 MM |
1574 | // With -fshort-enums, an enum may be as small as a char. |
1575 | typedef signed char __smallest; | |
1576 | static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); | |
1577 | static const bool __b1 = sizeof(_Tp) <= sizeof(signed short); | |
ce2e6349 | 1578 | static const bool __b2 = sizeof(_Tp) <= sizeof(signed int); |
a0230468 MM |
1579 | typedef conditional<__b2, signed int, signed long> __cond2; |
1580 | typedef typename __cond2::type __cond2_type; | |
1581 | typedef conditional<__b1, signed short, __cond2_type> __cond1; | |
1582 | typedef typename __cond1::type __cond1_type; | |
7b50cdef BK |
1583 | |
1584 | public: | |
a0230468 | 1585 | typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; |
7b50cdef BK |
1586 | }; |
1587 | ||
7b50cdef BK |
1588 | // Given an integral/enum type, return the corresponding signed |
1589 | // integer type. | |
5b9daa7e BK |
1590 | // Primary template. |
1591 | /// make_signed | |
7b50cdef BK |
1592 | template<typename _Tp> |
1593 | struct make_signed | |
1594 | { typedef typename __make_signed_selector<_Tp>::__type type; }; | |
1595 | ||
1596 | // Integral, but don't define. | |
1597 | template<> | |
1598 | struct make_signed<bool>; | |
cfa9a96b | 1599 | |
123c516a | 1600 | |
c0ffa2ba | 1601 | // Array modifications. |
123c516a PC |
1602 | |
1603 | /// remove_extent | |
1604 | template<typename _Tp> | |
1605 | struct remove_extent | |
1606 | { typedef _Tp type; }; | |
1607 | ||
1608 | template<typename _Tp, std::size_t _Size> | |
1609 | struct remove_extent<_Tp[_Size]> | |
1610 | { typedef _Tp type; }; | |
1611 | ||
1612 | template<typename _Tp> | |
1613 | struct remove_extent<_Tp[]> | |
1614 | { typedef _Tp type; }; | |
1615 | ||
1616 | /// remove_all_extents | |
1617 | template<typename _Tp> | |
1618 | struct remove_all_extents | |
1619 | { typedef _Tp type; }; | |
1620 | ||
1621 | template<typename _Tp, std::size_t _Size> | |
1622 | struct remove_all_extents<_Tp[_Size]> | |
1623 | { typedef typename remove_all_extents<_Tp>::type type; }; | |
1624 | ||
1625 | template<typename _Tp> | |
1626 | struct remove_all_extents<_Tp[]> | |
1627 | { typedef typename remove_all_extents<_Tp>::type type; }; | |
1628 | ||
1629 | ||
c0ffa2ba | 1630 | // Pointer modifications. |
123c516a PC |
1631 | |
1632 | template<typename _Tp, typename> | |
1633 | struct __remove_pointer_helper | |
1634 | { typedef _Tp type; }; | |
1635 | ||
1636 | template<typename _Tp, typename _Up> | |
1637 | struct __remove_pointer_helper<_Tp, _Up*> | |
1638 | { typedef _Up type; }; | |
1639 | ||
1640 | /// remove_pointer | |
1641 | template<typename _Tp> | |
1642 | struct remove_pointer | |
1643 | : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> | |
1644 | { }; | |
1645 | ||
1646 | /// add_pointer | |
1647 | template<typename _Tp> | |
1648 | struct add_pointer | |
1649 | { typedef typename remove_reference<_Tp>::type* type; }; | |
1650 | ||
1651 | ||
1652 | template<std::size_t _Len> | |
1653 | struct __aligned_storage_msa | |
1654 | { | |
1655 | union __type | |
1656 | { | |
1657 | unsigned char __data[_Len]; | |
1658 | struct __attribute__((__aligned__)) { } __align; | |
1659 | }; | |
1660 | }; | |
1661 | ||
1662 | /** | |
1663 | * @brief Alignment type. | |
1664 | * | |
1665 | * The value of _Align is a default-alignment which shall be the | |
1666 | * most stringent alignment requirement for any C++ object type | |
1667 | * whose size is no greater than _Len (3.9). The member typedef | |
1668 | * type shall be a POD type suitable for use as uninitialized | |
1669 | * storage for any object whose size is at most _Len and whose | |
1670 | * alignment is a divisor of _Align. | |
1671 | */ | |
1672 | template<std::size_t _Len, std::size_t _Align = | |
1673 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | |
1674 | struct aligned_storage | |
1675 | { | |
1676 | union type | |
1677 | { | |
1678 | unsigned char __data[_Len]; | |
1679 | struct __attribute__((__aligned__((_Align)))) { } __align; | |
1680 | }; | |
1681 | }; | |
1682 | ||
1683 | ||
1684 | // Decay trait for arrays and functions, used for perfect forwarding | |
1685 | // in make_pair, make_tuple, etc. | |
1686 | template<typename _Up, | |
1687 | bool _IsArray = is_array<_Up>::value, | |
1688 | bool _IsFunction = is_function<_Up>::value> | |
1689 | struct __decay_selector; | |
1690 | ||
1691 | // NB: DR 705. | |
1692 | template<typename _Up> | |
1693 | struct __decay_selector<_Up, false, false> | |
1694 | { typedef typename remove_cv<_Up>::type __type; }; | |
1695 | ||
1696 | template<typename _Up> | |
1697 | struct __decay_selector<_Up, true, false> | |
1698 | { typedef typename remove_extent<_Up>::type* __type; }; | |
1699 | ||
1700 | template<typename _Up> | |
1701 | struct __decay_selector<_Up, false, true> | |
1702 | { typedef typename add_pointer<_Up>::type __type; }; | |
1703 | ||
1704 | /// decay | |
1705 | template<typename _Tp> | |
1706 | class decay | |
1707 | { | |
1708 | typedef typename remove_reference<_Tp>::type __remove_type; | |
1709 | ||
1710 | public: | |
1711 | typedef typename __decay_selector<__remove_type>::__type type; | |
1712 | }; | |
1713 | ||
1714 | template<typename _Tp> | |
1715 | class reference_wrapper; | |
1716 | ||
1717 | // Helper which adds a reference to a type when given a reference_wrapper | |
1718 | template<typename _Tp> | |
1719 | struct __strip_reference_wrapper | |
1720 | { | |
1721 | typedef _Tp __type; | |
1722 | }; | |
1723 | ||
1724 | template<typename _Tp> | |
1725 | struct __strip_reference_wrapper<reference_wrapper<_Tp> > | |
1726 | { | |
1727 | typedef _Tp& __type; | |
1728 | }; | |
1729 | ||
1730 | template<typename _Tp> | |
1731 | struct __strip_reference_wrapper<const reference_wrapper<_Tp> > | |
1732 | { | |
1733 | typedef _Tp& __type; | |
1734 | }; | |
1735 | ||
1736 | template<typename _Tp> | |
1737 | struct __decay_and_strip | |
1738 | { | |
1739 | typedef typename __strip_reference_wrapper< | |
1740 | typename decay<_Tp>::type>::__type __type; | |
1741 | }; | |
1742 | ||
1743 | ||
123c516a | 1744 | // Primary template. |
13901e4b | 1745 | /// Define a member typedef @c type only if a boolean constant is true. |
123c516a PC |
1746 | template<bool, typename _Tp = void> |
1747 | struct enable_if | |
1748 | { }; | |
1749 | ||
1750 | // Partial specialization for true. | |
1751 | template<typename _Tp> | |
1752 | struct enable_if<true, _Tp> | |
1753 | { typedef _Tp type; }; | |
1754 | ||
23df8534 JW |
1755 | template<typename... _Cond> |
1756 | using _Require = typename enable_if<__and_<_Cond...>::value>::type; | |
123c516a | 1757 | |
123c516a | 1758 | // Primary template. |
13901e4b | 1759 | /// Define a member typedef @c type to one of two argument types. |
123c516a PC |
1760 | template<bool _Cond, typename _Iftrue, typename _Iffalse> |
1761 | struct conditional | |
1762 | { typedef _Iftrue type; }; | |
1763 | ||
1764 | // Partial specialization for false. | |
1765 | template<typename _Iftrue, typename _Iffalse> | |
1766 | struct conditional<false, _Iftrue, _Iffalse> | |
1767 | { typedef _Iffalse type; }; | |
1768 | ||
5b9daa7e | 1769 | /// common_type |
cfa9a96b CF |
1770 | template<typename... _Tp> |
1771 | struct common_type; | |
1772 | ||
c0ffa2ba | 1773 | // Sfinae-friendly common_type implementation: |
b3618b71 DK |
1774 | |
1775 | struct __do_common_type_impl | |
1776 | { | |
1777 | template<typename _Tp, typename _Up> | |
6c5173c0 | 1778 | static __success_type<typename decay<decltype |
fe4e4e3b | 1779 | (true ? std::declval<_Tp>() |
6c5173c0 | 1780 | : std::declval<_Up>())>::type> _S_test(int); |
b3618b71 DK |
1781 | |
1782 | template<typename, typename> | |
1783 | static __failure_type _S_test(...); | |
1784 | }; | |
1785 | ||
1786 | template<typename _Tp, typename _Up> | |
1787 | struct __common_type_impl | |
1788 | : private __do_common_type_impl | |
1789 | { | |
1790 | typedef decltype(_S_test<_Tp, _Up>(0)) type; | |
1791 | }; | |
1792 | ||
1793 | struct __do_member_type_wrapper | |
1794 | { | |
1795 | template<typename _Tp> | |
1796 | static __success_type<typename _Tp::type> _S_test(int); | |
1797 | ||
1798 | template<typename> | |
1799 | static __failure_type _S_test(...); | |
1800 | }; | |
1801 | ||
1802 | template<typename _Tp> | |
1803 | struct __member_type_wrapper | |
1804 | : private __do_member_type_wrapper | |
1805 | { | |
1806 | typedef decltype(_S_test<_Tp>(0)) type; | |
1807 | }; | |
1808 | ||
1809 | template<typename _CTp, typename... _Args> | |
1810 | struct __expanded_common_type_wrapper | |
1811 | { | |
1812 | typedef common_type<typename _CTp::type, _Args...> type; | |
1813 | }; | |
1814 | ||
1815 | template<typename... _Args> | |
1816 | struct __expanded_common_type_wrapper<__failure_type, _Args...> | |
1817 | { typedef __failure_type type; }; | |
1818 | ||
cfa9a96b CF |
1819 | template<typename _Tp> |
1820 | struct common_type<_Tp> | |
6c5173c0 | 1821 | { typedef typename decay<_Tp>::type type; }; |
cfa9a96b CF |
1822 | |
1823 | template<typename _Tp, typename _Up> | |
7274deff | 1824 | struct common_type<_Tp, _Up> |
b3618b71 DK |
1825 | : public __common_type_impl<_Tp, _Up>::type |
1826 | { }; | |
cfa9a96b CF |
1827 | |
1828 | template<typename _Tp, typename _Up, typename... _Vp> | |
1829 | struct common_type<_Tp, _Up, _Vp...> | |
b3618b71 DK |
1830 | : public __expanded_common_type_wrapper<typename __member_type_wrapper< |
1831 | common_type<_Tp, _Up>>::type, _Vp...>::type | |
1832 | { }; | |
7274deff | 1833 | |
13901e4b | 1834 | /// The underlying type of an enum. |
a47407f6 PC |
1835 | template<typename _Tp> |
1836 | struct underlying_type | |
1837 | { | |
1838 | typedef __underlying_type(_Tp) type; | |
1839 | }; | |
123c516a | 1840 | |
7274deff PC |
1841 | template<typename _Tp> |
1842 | struct __declval_protector | |
1843 | { | |
1844 | static const bool __stop = false; | |
1845 | static typename add_rvalue_reference<_Tp>::type __delegate(); | |
1846 | }; | |
1847 | ||
1848 | template<typename _Tp> | |
1849 | inline typename add_rvalue_reference<_Tp>::type | |
e4f32cb0 | 1850 | declval() noexcept |
7274deff PC |
1851 | { |
1852 | static_assert(__declval_protector<_Tp>::__stop, | |
1853 | "declval() must not be used!"); | |
1854 | return __declval_protector<_Tp>::__delegate(); | |
1855 | } | |
1041daba | 1856 | |
be7f7822 JW |
1857 | /// result_of |
1858 | template<typename _Signature> | |
1859 | class result_of; | |
1860 | ||
c0ffa2ba | 1861 | // Sfinae-friendly result_of implementation: |
83ddb39f DK |
1862 | |
1863 | // [func.require] paragraph 1 bullet 1: | |
1864 | struct __result_of_memfun_ref_impl | |
1865 | { | |
1866 | template<typename _Fp, typename _Tp1, typename... _Args> | |
1867 | static __success_type<decltype( | |
1868 | (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...) | |
1869 | )> _S_test(int); | |
1870 | ||
1871 | template<typename...> | |
1872 | static __failure_type _S_test(...); | |
1873 | }; | |
1874 | ||
1875 | template<typename _MemPtr, typename _Arg, typename... _Args> | |
1876 | struct __result_of_memfun_ref | |
1877 | : private __result_of_memfun_ref_impl | |
1878 | { | |
1879 | typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; | |
1880 | }; | |
1881 | ||
1882 | // [func.require] paragraph 1 bullet 2: | |
1883 | struct __result_of_memfun_deref_impl | |
1884 | { | |
1885 | template<typename _Fp, typename _Tp1, typename... _Args> | |
1886 | static __success_type<decltype( | |
1887 | ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...) | |
1888 | )> _S_test(int); | |
1889 | ||
1890 | template<typename...> | |
1891 | static __failure_type _S_test(...); | |
1892 | }; | |
1893 | ||
1894 | template<typename _MemPtr, typename _Arg, typename... _Args> | |
1895 | struct __result_of_memfun_deref | |
1896 | : private __result_of_memfun_deref_impl | |
1897 | { | |
1898 | typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; | |
1899 | }; | |
1900 | ||
1901 | // [func.require] paragraph 1 bullet 3: | |
1902 | struct __result_of_memobj_ref_impl | |
1903 | { | |
1904 | template<typename _Fp, typename _Tp1> | |
1905 | static __success_type<decltype( | |
1906 | std::declval<_Tp1>().*std::declval<_Fp>() | |
1907 | )> _S_test(int); | |
1908 | ||
1909 | template<typename, typename> | |
1910 | static __failure_type _S_test(...); | |
1911 | }; | |
1912 | ||
1913 | template<typename _MemPtr, typename _Arg> | |
1914 | struct __result_of_memobj_ref | |
1915 | : private __result_of_memobj_ref_impl | |
1916 | { | |
1917 | typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; | |
1918 | }; | |
1919 | ||
1920 | // [func.require] paragraph 1 bullet 4: | |
1921 | struct __result_of_memobj_deref_impl | |
1922 | { | |
1923 | template<typename _Fp, typename _Tp1> | |
1924 | static __success_type<decltype( | |
1925 | (*std::declval<_Tp1>()).*std::declval<_Fp>() | |
1926 | )> _S_test(int); | |
1927 | ||
1928 | template<typename, typename> | |
1929 | static __failure_type _S_test(...); | |
1930 | }; | |
1931 | ||
be7f7822 | 1932 | template<typename _MemPtr, typename _Arg> |
83ddb39f DK |
1933 | struct __result_of_memobj_deref |
1934 | : private __result_of_memobj_deref_impl | |
1935 | { | |
1936 | typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; | |
1937 | }; | |
1938 | ||
1939 | template<typename _MemPtr, typename _Arg> | |
1940 | struct __result_of_memobj; | |
be7f7822 JW |
1941 | |
1942 | template<typename _Res, typename _Class, typename _Arg> | |
83ddb39f | 1943 | struct __result_of_memobj<_Res _Class::*, _Arg> |
be7f7822 | 1944 | { |
83ddb39f DK |
1945 | typedef typename remove_cv<typename remove_reference< |
1946 | _Arg>::type>::type _Argval; | |
1947 | typedef _Res _Class::* _MemPtr; | |
1948 | typedef typename conditional<__or_<is_same<_Argval, _Class>, | |
1949 | is_base_of<_Class, _Argval>>::value, | |
1950 | __result_of_memobj_ref<_MemPtr, _Arg>, | |
1951 | __result_of_memobj_deref<_MemPtr, _Arg> | |
1952 | >::type::type type; | |
be7f7822 JW |
1953 | }; |
1954 | ||
83ddb39f DK |
1955 | template<typename _MemPtr, typename _Arg, typename... _Args> |
1956 | struct __result_of_memfun; | |
be7f7822 JW |
1957 | |
1958 | template<typename _Res, typename _Class, typename _Arg, typename... _Args> | |
83ddb39f | 1959 | struct __result_of_memfun<_Res _Class::*, _Arg, _Args...> |
be7f7822 | 1960 | { |
83ddb39f DK |
1961 | typedef typename remove_cv<typename remove_reference< |
1962 | _Arg>::type>::type _Argval; | |
1963 | typedef _Res _Class::* _MemPtr; | |
1964 | typedef typename conditional<__or_<is_same<_Argval, _Class>, | |
1965 | is_base_of<_Class, _Argval>>::value, | |
1966 | __result_of_memfun_ref<_MemPtr, _Arg, _Args...>, | |
1967 | __result_of_memfun_deref<_MemPtr, _Arg, _Args...> | |
1968 | >::type::type type; | |
be7f7822 JW |
1969 | }; |
1970 | ||
1971 | template<bool, bool, typename _Functor, typename... _ArgTypes> | |
83ddb39f | 1972 | struct __result_of_impl |
be7f7822 | 1973 | { |
83ddb39f | 1974 | typedef __failure_type type; |
be7f7822 JW |
1975 | }; |
1976 | ||
1977 | template<typename _MemPtr, typename _Arg> | |
83ddb39f DK |
1978 | struct __result_of_impl<true, false, _MemPtr, _Arg> |
1979 | : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg> | |
c4db9a77 | 1980 | { }; |
be7f7822 | 1981 | |
83ddb39f DK |
1982 | template<typename _MemPtr, typename _Arg, typename... _Args> |
1983 | struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...> | |
1984 | : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...> | |
c4db9a77 | 1985 | { }; |
be7f7822 | 1986 | |
83ddb39f DK |
1987 | // [func.require] paragraph 1 bullet 5: |
1988 | struct __result_of_other_impl | |
1989 | { | |
1990 | template<typename _Fn, typename... _Args> | |
1991 | static __success_type<decltype( | |
1992 | std::declval<_Fn>()(std::declval<_Args>()...) | |
1993 | )> _S_test(int); | |
1994 | ||
1995 | template<typename...> | |
1996 | static __failure_type _S_test(...); | |
1997 | }; | |
1998 | ||
be7f7822 | 1999 | template<typename _Functor, typename... _ArgTypes> |
83ddb39f DK |
2000 | struct __result_of_impl<false, false, _Functor, _ArgTypes...> |
2001 | : private __result_of_other_impl | |
be7f7822 | 2002 | { |
83ddb39f | 2003 | typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type; |
be7f7822 JW |
2004 | }; |
2005 | ||
83ddb39f DK |
2006 | template<typename _Functor, typename... _ArgTypes> |
2007 | struct result_of<_Functor(_ArgTypes...)> | |
2008 | : public __result_of_impl< | |
2009 | is_member_object_pointer< | |
2010 | typename remove_reference<_Functor>::type | |
2011 | >::value, | |
2012 | is_member_function_pointer< | |
2013 | typename remove_reference<_Functor>::type | |
2014 | >::value, | |
2015 | _Functor, _ArgTypes... | |
2016 | >::type | |
2017 | { }; | |
c0ffa2ba BK |
2018 | |
2019 | /// @} group metaprogramming | |
83ddb39f | 2020 | |
033b71ce PC |
2021 | /** |
2022 | * Use SFINAE to determine if the type _Tp has a publicly-accessible | |
2023 | * member type _NTYPE. | |
2024 | */ | |
82b12c4b FD |
2025 | #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \ |
2026 | template<typename _Tp> \ | |
2027 | class __has_##_NTYPE##_helper \ | |
2028 | { \ | |
2029 | template<typename _Up> \ | |
2030 | struct _Wrap_type \ | |
2031 | { }; \ | |
2032 | \ | |
2033 | template<typename _Up> \ | |
2034 | static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \ | |
2035 | \ | |
2036 | template<typename _Up> \ | |
2037 | static false_type __test(...); \ | |
2038 | \ | |
2039 | public: \ | |
2040 | typedef decltype(__test<_Tp>(0)) type; \ | |
2041 | }; \ | |
2042 | \ | |
2043 | template<typename _Tp> \ | |
2044 | struct __has_##_NTYPE \ | |
2045 | : public __has_##_NTYPE##_helper \ | |
2046 | <typename remove_cv<_Tp>::type>::type \ | |
033b71ce PC |
2047 | { }; |
2048 | ||
12ffa228 | 2049 | _GLIBCXX_END_NAMESPACE_VERSION |
c0ffa2ba | 2050 | } // namespace std |
7b50cdef | 2051 | |
734f5023 | 2052 | #endif // C++11 |
57317d2a | 2053 | |
7274deff | 2054 | #endif // _GLIBCXX_TYPE_TRAITS |