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