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