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