1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
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)
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.
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.
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/>.
25 /** @file include/type_traits
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TYPE_TRAITS
30 #define _GLIBCXX_TYPE_TRAITS 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
38 #include <bits/c++config.h>
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 * @defgroup metaprogramming Metaprogramming
48 * Template utilities for compile-time introspection and modification,
49 * including type classification traits, type property inspection traits
50 * and type transformation traits.
56 template<typename _Tp, _Tp __v>
57 struct integral_constant
59 static constexpr _Tp value = __v;
60 typedef _Tp value_type;
61 typedef integral_constant<_Tp, __v> type;
62 constexpr operator value_type() { return value; }
65 template<typename _Tp, _Tp __v>
66 constexpr _Tp integral_constant<_Tp, __v>::value;
68 /// The type used as a compile-time boolean with true value.
69 typedef integral_constant<bool, true> true_type;
71 /// The type used as a compile-time boolean with false value.
72 typedef integral_constant<bool, false> false_type;
74 // Meta programming helper types.
76 template<bool, typename, typename>
87 template<typename _B1>
92 template<typename _B1, typename _B2>
93 struct __or_<_B1, _B2>
94 : public conditional<_B1::value, _B1, _B2>::type
97 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
98 struct __or_<_B1, _B2, _B3, _Bn...>
99 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
102 template<typename...>
110 template<typename _B1>
115 template<typename _B1, typename _B2>
116 struct __and_<_B1, _B2>
117 : public conditional<_B1::value, _B2, _B1>::type
120 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
121 struct __and_<_B1, _B2, _B3, _Bn...>
122 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
125 template<typename _Pp>
127 : public integral_constant<bool, !_Pp::value>
130 struct __sfinae_types
133 typedef struct { char __arr[2]; } __two;
136 // For several sfinae-friendly trait implementations we transport both the
137 // result information (as the member type) and the failure information (no
138 // member type). This is very similar to std::enable_if, but we cannot use
139 // them, because we need to derive from them as an implementation detail.
141 template<typename _Tp>
142 struct __success_type
143 { typedef _Tp type; };
145 struct __failure_type
148 // Primary type categories.
154 struct __is_void_helper
155 : public false_type { };
158 struct __is_void_helper<void>
159 : public true_type { };
162 template<typename _Tp>
164 : public integral_constant<bool, (__is_void_helper<typename
165 remove_cv<_Tp>::type>::value)>
169 struct __is_integral_helper
170 : public false_type { };
173 struct __is_integral_helper<bool>
174 : public true_type { };
177 struct __is_integral_helper<char>
178 : public true_type { };
181 struct __is_integral_helper<signed char>
182 : public true_type { };
185 struct __is_integral_helper<unsigned char>
186 : public true_type { };
188 #ifdef _GLIBCXX_USE_WCHAR_T
190 struct __is_integral_helper<wchar_t>
191 : public true_type { };
195 struct __is_integral_helper<char16_t>
196 : public true_type { };
199 struct __is_integral_helper<char32_t>
200 : public true_type { };
203 struct __is_integral_helper<short>
204 : public true_type { };
207 struct __is_integral_helper<unsigned short>
208 : public true_type { };
211 struct __is_integral_helper<int>
212 : public true_type { };
215 struct __is_integral_helper<unsigned int>
216 : public true_type { };
219 struct __is_integral_helper<long>
220 : public true_type { };
223 struct __is_integral_helper<unsigned long>
224 : public true_type { };
227 struct __is_integral_helper<long long>
228 : public true_type { };
231 struct __is_integral_helper<unsigned long long>
232 : public true_type { };
234 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
236 struct __is_integral_helper<__int128>
237 : public true_type { };
240 struct __is_integral_helper<unsigned __int128>
241 : public true_type { };
245 template<typename _Tp>
247 : public integral_constant<bool, (__is_integral_helper<typename
248 remove_cv<_Tp>::type>::value)>
252 struct __is_floating_point_helper
253 : public false_type { };
256 struct __is_floating_point_helper<float>
257 : public true_type { };
260 struct __is_floating_point_helper<double>
261 : public true_type { };
264 struct __is_floating_point_helper<long double>
265 : public true_type { };
267 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
269 struct __is_floating_point_helper<__float128>
270 : public true_type { };
273 /// is_floating_point
274 template<typename _Tp>
275 struct is_floating_point
276 : public integral_constant<bool, (__is_floating_point_helper<typename
277 remove_cv<_Tp>::type>::value)>
283 : public false_type { };
285 template<typename _Tp, std::size_t _Size>
286 struct is_array<_Tp[_Size]>
287 : public true_type { };
289 template<typename _Tp>
290 struct is_array<_Tp[]>
291 : public true_type { };
294 struct __is_pointer_helper
295 : public false_type { };
297 template<typename _Tp>
298 struct __is_pointer_helper<_Tp*>
299 : public true_type { };
302 template<typename _Tp>
304 : public integral_constant<bool, (__is_pointer_helper<typename
305 remove_cv<_Tp>::type>::value)>
308 /// is_lvalue_reference
310 struct is_lvalue_reference
311 : public false_type { };
313 template<typename _Tp>
314 struct is_lvalue_reference<_Tp&>
315 : public true_type { };
317 /// is_rvalue_reference
319 struct is_rvalue_reference
320 : public false_type { };
322 template<typename _Tp>
323 struct is_rvalue_reference<_Tp&&>
324 : public true_type { };
330 struct __is_member_object_pointer_helper
331 : public false_type { };
333 template<typename _Tp, typename _Cp>
334 struct __is_member_object_pointer_helper<_Tp _Cp::*>
335 : public integral_constant<bool, !is_function<_Tp>::value> { };
337 /// is_member_object_pointer
338 template<typename _Tp>
339 struct is_member_object_pointer
340 : public integral_constant<bool, (__is_member_object_pointer_helper<
341 typename remove_cv<_Tp>::type>::value)>
345 struct __is_member_function_pointer_helper
346 : public false_type { };
348 template<typename _Tp, typename _Cp>
349 struct __is_member_function_pointer_helper<_Tp _Cp::*>
350 : public integral_constant<bool, is_function<_Tp>::value> { };
352 /// is_member_function_pointer
353 template<typename _Tp>
354 struct is_member_function_pointer
355 : public integral_constant<bool, (__is_member_function_pointer_helper<
356 typename remove_cv<_Tp>::type>::value)>
360 template<typename _Tp>
362 : public integral_constant<bool, __is_enum(_Tp)>
366 template<typename _Tp>
368 : public integral_constant<bool, __is_union(_Tp)>
372 template<typename _Tp>
374 : public integral_constant<bool, __is_class(_Tp)>
380 : public false_type { };
382 template<typename _Res, typename... _ArgTypes>
383 struct is_function<_Res(_ArgTypes...)>
384 : public true_type { };
386 template<typename _Res, typename... _ArgTypes>
387 struct is_function<_Res(_ArgTypes......)>
388 : public true_type { };
390 template<typename _Res, typename... _ArgTypes>
391 struct is_function<_Res(_ArgTypes...) const>
392 : public true_type { };
394 template<typename _Res, typename... _ArgTypes>
395 struct is_function<_Res(_ArgTypes......) const>
396 : public true_type { };
398 template<typename _Res, typename... _ArgTypes>
399 struct is_function<_Res(_ArgTypes...) volatile>
400 : public true_type { };
402 template<typename _Res, typename... _ArgTypes>
403 struct is_function<_Res(_ArgTypes......) volatile>
404 : public true_type { };
406 template<typename _Res, typename... _ArgTypes>
407 struct is_function<_Res(_ArgTypes...) const volatile>
408 : public true_type { };
410 template<typename _Res, typename... _ArgTypes>
411 struct is_function<_Res(_ArgTypes......) const volatile>
412 : public true_type { };
415 struct __is_nullptr_t_helper
416 : public false_type { };
419 struct __is_nullptr_t_helper<std::nullptr_t>
420 : public true_type { };
422 // __is_nullptr_t (extension).
423 template<typename _Tp>
424 struct __is_nullptr_t
425 : public integral_constant<bool, (__is_nullptr_t_helper<typename
426 remove_cv<_Tp>::type>::value)>
429 // Composite type categories.
432 template<typename _Tp>
434 : public __or_<is_lvalue_reference<_Tp>,
435 is_rvalue_reference<_Tp>>::type
439 template<typename _Tp>
441 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
445 template<typename _Tp>
446 struct is_fundamental
447 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>, __is_nullptr_t<_Tp>>::type
451 template<typename _Tp>
453 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
458 struct is_member_pointer;
461 template<typename _Tp>
463 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
464 is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
468 template<typename _Tp>
470 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
472 template<typename _Tp>
473 struct __is_member_pointer_helper
474 : public false_type { };
476 template<typename _Tp, typename _Cp>
477 struct __is_member_pointer_helper<_Tp _Cp::*>
478 : public true_type { };
480 /// is_member_pointer
481 template<typename _Tp>
482 struct is_member_pointer
483 : public integral_constant<bool, (__is_member_pointer_helper<
484 typename remove_cv<_Tp>::type>::value)>
492 : public false_type { };
494 template<typename _Tp>
495 struct is_const<_Tp const>
496 : public true_type { };
501 : public false_type { };
503 template<typename _Tp>
504 struct is_volatile<_Tp volatile>
505 : public true_type { };
508 template<typename _Tp>
510 : public integral_constant<bool, __is_trivial(_Tp)>
513 // is_trivially_copyable (still unimplemented)
515 /// is_standard_layout
516 template<typename _Tp>
517 struct is_standard_layout
518 : public integral_constant<bool, __is_standard_layout(_Tp)>
522 // Could use is_standard_layout && is_trivial instead of the builtin.
523 template<typename _Tp>
525 : public integral_constant<bool, __is_pod(_Tp)>
529 template<typename _Tp>
530 struct is_literal_type
531 : public integral_constant<bool, __is_literal_type(_Tp)>
535 template<typename _Tp>
537 : public integral_constant<bool, __is_empty(_Tp)>
541 template<typename _Tp>
542 struct is_polymorphic
543 : public integral_constant<bool, __is_polymorphic(_Tp)>
547 template<typename _Tp>
549 : public integral_constant<bool, __is_abstract(_Tp)>
552 template<typename _Tp,
553 bool = is_integral<_Tp>::value,
554 bool = is_floating_point<_Tp>::value>
555 struct __is_signed_helper
556 : public false_type { };
558 template<typename _Tp>
559 struct __is_signed_helper<_Tp, false, true>
560 : public true_type { };
562 template<typename _Tp>
563 struct __is_signed_helper<_Tp, true, false>
564 : public integral_constant<bool, static_cast<bool>(_Tp(-1) < _Tp(0))>
568 template<typename _Tp>
570 : public integral_constant<bool, __is_signed_helper<_Tp>::value>
574 template<typename _Tp>
576 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
580 // Destructible and constructible type properties.
583 struct add_rvalue_reference;
586 * @brief Utility to simplify expressions used in unevaluated operands
589 template<typename _Tp>
590 typename add_rvalue_reference<_Tp>::type declval() noexcept;
592 template<typename, unsigned = 0>
596 struct remove_all_extents;
598 template<typename _Tp>
599 struct __is_array_known_bounds
600 : public integral_constant<bool, (extent<_Tp>::value > 0)>
603 template<typename _Tp>
604 struct __is_array_unknown_bounds
605 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
608 // In N3290 is_destructible does not say anything about function
609 // types and abstract types, see LWG 2049. This implementation
610 // describes function types as non-destructible and all complete
611 // object types as destructible, iff the explicit destructor
612 // call expression is wellformed.
613 struct __do_is_destructible_impl
615 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
616 static true_type __test(int);
619 static false_type __test(...);
622 template<typename _Tp>
623 struct __is_destructible_impl
624 : public __do_is_destructible_impl
626 typedef decltype(__test<_Tp>(0)) type;
629 template<typename _Tp,
630 bool = __or_<is_void<_Tp>,
631 __is_array_unknown_bounds<_Tp>,
632 is_function<_Tp>>::value,
633 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
634 struct __is_destructible_safe;
636 template<typename _Tp>
637 struct __is_destructible_safe<_Tp, false, false>
638 : public __is_destructible_impl<typename
639 remove_all_extents<_Tp>::type>::type
642 template<typename _Tp>
643 struct __is_destructible_safe<_Tp, true, false>
644 : public false_type { };
646 template<typename _Tp>
647 struct __is_destructible_safe<_Tp, false, true>
648 : public true_type { };
651 template<typename _Tp>
652 struct is_destructible
653 : public integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
656 // is_nothrow_destructible requires that is_destructible is
657 // satisfied as well. We realize that by mimicing the
658 // implementation of is_destructible but refer to noexcept(expr)
659 // instead of decltype(expr).
660 struct __do_is_nt_destructible_impl
662 template<typename _Tp>
663 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
667 static false_type __test(...);
670 template<typename _Tp>
671 struct __is_nt_destructible_impl
672 : public __do_is_nt_destructible_impl
674 typedef decltype(__test<_Tp>(0)) type;
677 template<typename _Tp,
678 bool = __or_<is_void<_Tp>,
679 __is_array_unknown_bounds<_Tp>,
680 is_function<_Tp>>::value,
681 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
682 struct __is_nt_destructible_safe;
684 template<typename _Tp>
685 struct __is_nt_destructible_safe<_Tp, false, false>
686 : public __is_nt_destructible_impl<typename
687 remove_all_extents<_Tp>::type>::type
690 template<typename _Tp>
691 struct __is_nt_destructible_safe<_Tp, true, false>
692 : public false_type { };
694 template<typename _Tp>
695 struct __is_nt_destructible_safe<_Tp, false, true>
696 : public true_type { };
698 /// is_nothrow_destructible
699 template<typename _Tp>
700 struct is_nothrow_destructible
701 : public integral_constant<bool, (__is_nt_destructible_safe<_Tp>::value)>
704 struct __do_is_default_constructible_impl
706 template<typename _Tp, typename = decltype(_Tp())>
707 static true_type __test(int);
710 static false_type __test(...);
713 template<typename _Tp>
714 struct __is_default_constructible_impl
715 : public __do_is_default_constructible_impl
717 typedef decltype(__test<_Tp>(0)) type;
720 template<typename _Tp>
721 struct __is_default_constructible_atom
722 : public __and_<__not_<is_void<_Tp>>,
723 __is_default_constructible_impl<_Tp>>::type
726 template<typename _Tp, bool = is_array<_Tp>::value>
727 struct __is_default_constructible_safe;
729 // The following technique is a workaround for a current core language
730 // restriction, which does not allow for array types to occur in
731 // functional casts of the form T(). Complete arrays can be default-
732 // constructed, if the element type is default-constructible, but
733 // arrays with unknown bounds are not.
734 template<typename _Tp>
735 struct __is_default_constructible_safe<_Tp, true>
736 : public __and_<__is_array_known_bounds<_Tp>,
737 __is_default_constructible_atom<typename
738 remove_all_extents<_Tp>::type>>::type
741 template<typename _Tp>
742 struct __is_default_constructible_safe<_Tp, false>
743 : public __is_default_constructible_atom<_Tp>::type
746 /// is_default_constructible
747 template<typename _Tp>
748 struct is_default_constructible
749 : public integral_constant<bool, (__is_default_constructible_safe<
754 // Implementation of is_constructible.
756 // The hardest part of this trait is the binary direct-initialization
757 // case, because we hit into a functional cast of the form T(arg).
758 // This implementation uses different strategies depending on the
759 // target type to reduce the test overhead as much as possible:
761 // a) For a reference target type, we use a static_cast expression
762 // modulo its extra cases.
764 // b) For a non-reference target type we use a ::new expression.
765 struct __do_is_static_castable_impl
767 template<typename _From, typename _To, typename
768 = decltype(static_cast<_To>(declval<_From>()))>
769 static true_type __test(int);
771 template<typename, typename>
772 static false_type __test(...);
775 template<typename _From, typename _To>
776 struct __is_static_castable_impl
777 : public __do_is_static_castable_impl
779 typedef decltype(__test<_From, _To>(0)) type;
782 template<typename _From, typename _To>
783 struct __is_static_castable_safe
784 : public __is_static_castable_impl<_From, _To>::type
787 // __is_static_castable
788 template<typename _From, typename _To>
789 struct __is_static_castable
790 : public integral_constant<bool, (__is_static_castable_safe<
794 // Implementation for non-reference types. To meet the proper
795 // variable definition semantics, we also need to test for
796 // is_destructible in this case.
797 // This form should be simplified by a single expression:
798 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
799 struct __do_is_direct_constructible_impl
801 template<typename _Tp, typename _Arg, typename
802 = decltype(::new _Tp(declval<_Arg>()))>
803 static true_type __test(int);
805 template<typename, typename>
806 static false_type __test(...);
809 template<typename _Tp, typename _Arg>
810 struct __is_direct_constructible_impl
811 : public __do_is_direct_constructible_impl
813 typedef decltype(__test<_Tp, _Arg>(0)) type;
816 template<typename _Tp, typename _Arg>
817 struct __is_direct_constructible_new_safe
818 : public __and_<is_destructible<_Tp>,
819 __is_direct_constructible_impl<_Tp, _Arg>>::type
822 template<typename, typename>
825 template<typename, typename>
829 struct remove_reference;
831 template<typename _From, typename _To, bool
832 = __not_<__or_<is_void<_From>,
833 is_function<_From>>>::value>
834 struct __is_base_to_derived_ref;
836 // Detect whether we have a downcast situation during
837 // reference binding.
838 template<typename _From, typename _To>
839 struct __is_base_to_derived_ref<_From, _To, true>
841 typedef typename remove_cv<typename remove_reference<_From
842 >::type>::type __src_t;
843 typedef typename remove_cv<typename remove_reference<_To
844 >::type>::type __dst_t;
845 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
846 is_base_of<__src_t, __dst_t>> type;
847 static constexpr bool value = type::value;
850 template<typename _From, typename _To>
851 struct __is_base_to_derived_ref<_From, _To, false>
855 template<typename _From, typename _To, bool
856 = __and_<is_lvalue_reference<_From>,
857 is_rvalue_reference<_To>>::value>
858 struct __is_lvalue_to_rvalue_ref;
860 // Detect whether we have an lvalue of non-function type
861 // bound to a reference-compatible rvalue-reference.
862 template<typename _From, typename _To>
863 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
865 typedef typename remove_cv<typename remove_reference<
866 _From>::type>::type __src_t;
867 typedef typename remove_cv<typename remove_reference<
868 _To>::type>::type __dst_t;
869 typedef __and_<__not_<is_function<__src_t>>,
870 __or_<is_same<__src_t, __dst_t>,
871 is_base_of<__dst_t, __src_t>>> type;
872 static constexpr bool value = type::value;
875 template<typename _From, typename _To>
876 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
880 // Here we handle direct-initialization to a reference type as
881 // equivalent to a static_cast modulo overshooting conversions.
882 // These are restricted to the following conversions:
883 // a) A base class value to a derived class reference
884 // b) An lvalue to an rvalue-reference of reference-compatible
885 // types that are not functions
886 template<typename _Tp, typename _Arg>
887 struct __is_direct_constructible_ref_cast
888 : public __and_<__is_static_castable<_Arg, _Tp>,
889 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
890 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
894 template<typename _Tp, typename _Arg>
895 struct __is_direct_constructible_new
896 : public conditional<is_reference<_Tp>::value,
897 __is_direct_constructible_ref_cast<_Tp, _Arg>,
898 __is_direct_constructible_new_safe<_Tp, _Arg>
902 template<typename _Tp, typename _Arg>
903 struct __is_direct_constructible
904 : public integral_constant<bool, (__is_direct_constructible_new<
908 // Since default-construction and binary direct-initialization have
909 // been handled separately, the implementation of the remaining
910 // n-ary construction cases is rather straightforward. We can use
911 // here a functional cast, because array types are excluded anyway
912 // and this form is never interpreted as a C cast.
913 struct __do_is_nary_constructible_impl
915 template<typename _Tp, typename... _Args, typename
916 = decltype(_Tp(declval<_Args>()...))>
917 static true_type __test(int);
919 template<typename, typename...>
920 static false_type __test(...);
923 template<typename _Tp, typename... _Args>
924 struct __is_nary_constructible_impl
925 : public __do_is_nary_constructible_impl
927 typedef decltype(__test<_Tp, _Args...>(0)) type;
930 template<typename _Tp, typename... _Args>
931 struct __is_nary_constructible
932 : public __is_nary_constructible_impl<_Tp, _Args...>::type
934 static_assert(sizeof...(_Args) > 1,
935 "Only useful for > 1 arguments");
938 template<typename _Tp, typename... _Args>
939 struct __is_constructible_impl
940 : public __is_nary_constructible<_Tp, _Args...>
943 template<typename _Tp, typename _Arg>
944 struct __is_constructible_impl<_Tp, _Arg>
945 : public __is_direct_constructible<_Tp, _Arg>
948 template<typename _Tp>
949 struct __is_constructible_impl<_Tp>
950 : public is_default_constructible<_Tp>
954 template<typename _Tp, typename... _Args>
955 struct is_constructible
956 : public integral_constant<bool, (__is_constructible_impl<_Tp,
960 template<typename _Tp, bool = is_void<_Tp>::value>
961 struct __is_copy_constructible_impl;
963 template<typename _Tp>
964 struct __is_copy_constructible_impl<_Tp, true>
965 : public false_type { };
967 template<typename _Tp>
968 struct __is_copy_constructible_impl<_Tp, false>
969 : public is_constructible<_Tp, const _Tp&>
972 /// is_copy_constructible
973 template<typename _Tp>
974 struct is_copy_constructible
975 : public __is_copy_constructible_impl<_Tp>
978 template<typename _Tp, bool = is_void<_Tp>::value>
979 struct __is_move_constructible_impl;
981 template<typename _Tp>
982 struct __is_move_constructible_impl<_Tp, true>
983 : public false_type { };
985 template<typename _Tp>
986 struct __is_move_constructible_impl<_Tp, false>
987 : public is_constructible<_Tp, _Tp&&>
990 /// is_move_constructible
991 template<typename _Tp>
992 struct is_move_constructible
993 : public __is_move_constructible_impl<_Tp>
996 template<typename _Tp>
997 struct __is_nt_default_constructible_atom
998 : public integral_constant<bool, noexcept(_Tp())>
1001 template<typename _Tp, bool = is_array<_Tp>::value>
1002 struct __is_nt_default_constructible_impl;
1004 template<typename _Tp>
1005 struct __is_nt_default_constructible_impl<_Tp, true>
1006 : public __and_<__is_array_known_bounds<_Tp>,
1007 __is_nt_default_constructible_atom<typename
1008 remove_all_extents<_Tp>::type>>::type
1011 template<typename _Tp>
1012 struct __is_nt_default_constructible_impl<_Tp, false>
1013 : public __is_nt_default_constructible_atom<_Tp>
1016 /// is_nothrow_default_constructible
1017 template<typename _Tp>
1018 struct is_nothrow_default_constructible
1019 : public __and_<is_default_constructible<_Tp>,
1020 __is_nt_default_constructible_impl<_Tp>>::type
1023 template<typename _Tp, typename... _Args>
1024 struct __is_nt_constructible_impl
1025 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1028 template<typename _Tp, typename _Arg>
1029 struct __is_nt_constructible_impl<_Tp, _Arg>
1030 : public integral_constant<bool,
1031 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1034 template<typename _Tp>
1035 struct __is_nt_constructible_impl<_Tp>
1036 : public is_nothrow_default_constructible<_Tp>
1039 /// is_nothrow_constructible
1040 template<typename _Tp, typename... _Args>
1041 struct is_nothrow_constructible
1042 : public __and_<is_constructible<_Tp, _Args...>,
1043 __is_nt_constructible_impl<_Tp, _Args...>>::type
1046 template<typename _Tp, bool = is_void<_Tp>::value>
1047 struct __is_nothrow_copy_constructible_impl;
1049 template<typename _Tp>
1050 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1051 : public false_type { };
1053 template<typename _Tp>
1054 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1055 : public is_nothrow_constructible<_Tp, const _Tp&>
1058 /// is_nothrow_copy_constructible
1059 template<typename _Tp>
1060 struct is_nothrow_copy_constructible
1061 : public __is_nothrow_copy_constructible_impl<_Tp>
1064 template<typename _Tp, bool = is_void<_Tp>::value>
1065 struct __is_nothrow_move_constructible_impl;
1067 template<typename _Tp>
1068 struct __is_nothrow_move_constructible_impl<_Tp, true>
1069 : public false_type { };
1071 template<typename _Tp>
1072 struct __is_nothrow_move_constructible_impl<_Tp, false>
1073 : public is_nothrow_constructible<_Tp, _Tp&&>
1076 /// is_nothrow_move_constructible
1077 template<typename _Tp>
1078 struct is_nothrow_move_constructible
1079 : public __is_nothrow_move_constructible_impl<_Tp>
1082 template<typename _Tp, typename _Up>
1083 class __is_assignable_helper
1084 : public __sfinae_types
1086 template<typename _Tp1, typename _Up1>
1087 static decltype(declval<_Tp1>() = declval<_Up1>(), __one())
1090 template<typename, typename>
1091 static __two __test(...);
1094 static constexpr bool value = sizeof(__test<_Tp, _Up>(0)) == 1;
1098 template<typename _Tp, typename _Up>
1099 struct is_assignable
1100 : public integral_constant<bool,
1101 __is_assignable_helper<_Tp, _Up>::value>
1104 template<typename _Tp, bool = is_void<_Tp>::value>
1105 struct __is_copy_assignable_impl;
1107 template<typename _Tp>
1108 struct __is_copy_assignable_impl<_Tp, true>
1109 : public false_type { };
1111 template<typename _Tp>
1112 struct __is_copy_assignable_impl<_Tp, false>
1113 : public is_assignable<_Tp&, const _Tp&>
1116 /// is_copy_assignable
1117 template<typename _Tp>
1118 struct is_copy_assignable
1119 : public __is_copy_assignable_impl<_Tp>
1122 template<typename _Tp, bool = is_void<_Tp>::value>
1123 struct __is_move_assignable_impl;
1125 template<typename _Tp>
1126 struct __is_move_assignable_impl<_Tp, true>
1127 : public false_type { };
1129 template<typename _Tp>
1130 struct __is_move_assignable_impl<_Tp, false>
1131 : public is_assignable<_Tp&, _Tp&&>
1134 /// is_move_assignable
1135 template<typename _Tp>
1136 struct is_move_assignable
1137 : public __is_move_assignable_impl<_Tp>
1140 template<typename _Tp, typename _Up>
1141 struct __is_nt_assignable_impl
1142 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1145 /// is_nothrow_assignable
1146 template<typename _Tp, typename _Up>
1147 struct is_nothrow_assignable
1148 : public __and_<is_assignable<_Tp, _Up>,
1149 __is_nt_assignable_impl<_Tp, _Up>>::type
1152 template<typename _Tp, bool = is_void<_Tp>::value>
1153 struct __is_nt_copy_assignable_impl;
1155 template<typename _Tp>
1156 struct __is_nt_copy_assignable_impl<_Tp, true>
1157 : public false_type { };
1159 template<typename _Tp>
1160 struct __is_nt_copy_assignable_impl<_Tp, false>
1161 : public is_nothrow_assignable<_Tp&, const _Tp&>
1164 /// is_nothrow_copy_assignable
1165 template<typename _Tp>
1166 struct is_nothrow_copy_assignable
1167 : public __is_nt_copy_assignable_impl<_Tp>
1170 template<typename _Tp, bool = is_void<_Tp>::value>
1171 struct __is_nt_move_assignable_impl;
1173 template<typename _Tp>
1174 struct __is_nt_move_assignable_impl<_Tp, true>
1175 : public false_type { };
1177 template<typename _Tp>
1178 struct __is_nt_move_assignable_impl<_Tp, false>
1179 : public is_nothrow_assignable<_Tp&, _Tp&&>
1182 /// is_nothrow_move_assignable
1183 template<typename _Tp>
1184 struct is_nothrow_move_assignable
1185 : public __is_nt_move_assignable_impl<_Tp>
1188 /// is_trivially_constructible (still unimplemented)
1190 /// is_trivially_default_constructible (still unimplemented)
1192 /// is_trivially_copy_constructible (still unimplemented)
1194 /// is_trivially_move_constructible (still unimplemented)
1196 /// is_trivially_assignable (still unimplemented)
1198 /// is_trivially_copy_assignable (still unimplemented)
1200 /// is_trivially_move_assignable (still unimplemented)
1202 /// is_trivially_destructible
1203 template<typename _Tp>
1204 struct is_trivially_destructible
1205 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1206 __has_trivial_destructor(_Tp)>>::type
1209 /// has_trivial_default_constructor (temporary legacy)
1210 template<typename _Tp>
1211 struct has_trivial_default_constructor
1212 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1215 /// has_trivial_copy_constructor (temporary legacy)
1216 template<typename _Tp>
1217 struct has_trivial_copy_constructor
1218 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1221 /// has_trivial_copy_assign (temporary legacy)
1222 template<typename _Tp>
1223 struct has_trivial_copy_assign
1224 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1227 /// has_virtual_destructor
1228 template<typename _Tp>
1229 struct has_virtual_destructor
1230 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1234 // type property queries.
1237 template<typename _Tp>
1239 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1244 : public integral_constant<std::size_t, 0> { };
1246 template<typename _Tp, std::size_t _Size>
1247 struct rank<_Tp[_Size]>
1248 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1250 template<typename _Tp>
1252 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1255 template<typename, unsigned _Uint>
1257 : public integral_constant<std::size_t, 0> { };
1259 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1260 struct extent<_Tp[_Size], _Uint>
1261 : public integral_constant<std::size_t,
1262 _Uint == 0 ? _Size : extent<_Tp,
1266 template<typename _Tp, unsigned _Uint>
1267 struct extent<_Tp[], _Uint>
1268 : public integral_constant<std::size_t,
1269 _Uint == 0 ? 0 : extent<_Tp,
1277 template<typename, typename>
1279 : public false_type { };
1281 template<typename _Tp>
1282 struct is_same<_Tp, _Tp>
1283 : public true_type { };
1286 template<typename _Base, typename _Derived>
1288 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1291 template<typename _From, typename _To,
1292 bool = __or_<is_void<_From>, is_function<_To>,
1293 is_array<_To>>::value>
1294 struct __is_convertible_helper
1295 { static constexpr bool value = is_void<_To>::value; };
1297 template<typename _From, typename _To>
1298 class __is_convertible_helper<_From, _To, false>
1299 : public __sfinae_types
1301 template<typename _To1>
1302 static void __test_aux(_To1);
1304 template<typename _From1, typename _To1>
1305 static decltype(__test_aux<_To1>(std::declval<_From1>()), __one())
1308 template<typename, typename>
1309 static __two __test(...);
1312 static constexpr bool value = sizeof(__test<_From, _To>(0)) == 1;
1316 template<typename _From, typename _To>
1317 struct is_convertible
1318 : public integral_constant<bool,
1319 __is_convertible_helper<_From, _To>::value>
1323 // Const-volatile modifications.
1326 template<typename _Tp>
1328 { typedef _Tp type; };
1330 template<typename _Tp>
1331 struct remove_const<_Tp const>
1332 { typedef _Tp type; };
1335 template<typename _Tp>
1336 struct remove_volatile
1337 { typedef _Tp type; };
1339 template<typename _Tp>
1340 struct remove_volatile<_Tp volatile>
1341 { typedef _Tp type; };
1344 template<typename _Tp>
1348 remove_const<typename remove_volatile<_Tp>::type>::type type;
1352 template<typename _Tp>
1354 { typedef _Tp const type; };
1357 template<typename _Tp>
1359 { typedef _Tp volatile type; };
1362 template<typename _Tp>
1366 add_const<typename add_volatile<_Tp>::type>::type type;
1370 // Reference transformations.
1372 /// remove_reference
1373 template<typename _Tp>
1374 struct remove_reference
1375 { typedef _Tp type; };
1377 template<typename _Tp>
1378 struct remove_reference<_Tp&>
1379 { typedef _Tp type; };
1381 template<typename _Tp>
1382 struct remove_reference<_Tp&&>
1383 { typedef _Tp type; };
1385 template<typename _Tp,
1386 bool = __and_<__not_<is_reference<_Tp>>,
1387 __not_<is_void<_Tp>>>::value,
1388 bool = is_rvalue_reference<_Tp>::value>
1389 struct __add_lvalue_reference_helper
1390 { typedef _Tp type; };
1392 template<typename _Tp>
1393 struct __add_lvalue_reference_helper<_Tp, true, false>
1394 { typedef _Tp& type; };
1396 template<typename _Tp>
1397 struct __add_lvalue_reference_helper<_Tp, false, true>
1398 { typedef typename remove_reference<_Tp>::type& type; };
1400 /// add_lvalue_reference
1401 template<typename _Tp>
1402 struct add_lvalue_reference
1403 : public __add_lvalue_reference_helper<_Tp>
1406 template<typename _Tp,
1407 bool = __and_<__not_<is_reference<_Tp>>,
1408 __not_<is_void<_Tp>>>::value>
1409 struct __add_rvalue_reference_helper
1410 { typedef _Tp type; };
1412 template<typename _Tp>
1413 struct __add_rvalue_reference_helper<_Tp, true>
1414 { typedef _Tp&& type; };
1416 /// add_rvalue_reference
1417 template<typename _Tp>
1418 struct add_rvalue_reference
1419 : public __add_rvalue_reference_helper<_Tp>
1423 // Sign modifications.
1425 // Utility for constructing identically cv-qualified types.
1426 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1427 struct __cv_selector;
1429 template<typename _Unqualified>
1430 struct __cv_selector<_Unqualified, false, false>
1431 { typedef _Unqualified __type; };
1433 template<typename _Unqualified>
1434 struct __cv_selector<_Unqualified, false, true>
1435 { typedef volatile _Unqualified __type; };
1437 template<typename _Unqualified>
1438 struct __cv_selector<_Unqualified, true, false>
1439 { typedef const _Unqualified __type; };
1441 template<typename _Unqualified>
1442 struct __cv_selector<_Unqualified, true, true>
1443 { typedef const volatile _Unqualified __type; };
1445 template<typename _Qualified, typename _Unqualified,
1446 bool _IsConst = is_const<_Qualified>::value,
1447 bool _IsVol = is_volatile<_Qualified>::value>
1448 class __match_cv_qualifiers
1450 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1453 typedef typename __match::__type __type;
1456 // Utility for finding the unsigned versions of signed integral types.
1457 template<typename _Tp>
1458 struct __make_unsigned
1459 { typedef _Tp __type; };
1462 struct __make_unsigned<char>
1463 { typedef unsigned char __type; };
1466 struct __make_unsigned<signed char>
1467 { typedef unsigned char __type; };
1470 struct __make_unsigned<short>
1471 { typedef unsigned short __type; };
1474 struct __make_unsigned<int>
1475 { typedef unsigned int __type; };
1478 struct __make_unsigned<long>
1479 { typedef unsigned long __type; };
1482 struct __make_unsigned<long long>
1483 { typedef unsigned long long __type; };
1485 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1487 struct __make_unsigned<__int128>
1488 { typedef unsigned __int128 __type; };
1491 // Select between integral and enum: not possible to be both.
1492 template<typename _Tp,
1493 bool _IsInt = is_integral<_Tp>::value,
1494 bool _IsEnum = is_enum<_Tp>::value>
1495 class __make_unsigned_selector;
1497 template<typename _Tp>
1498 class __make_unsigned_selector<_Tp, true, false>
1500 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1501 typedef typename __unsignedt::__type __unsigned_type;
1502 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1505 typedef typename __cv_unsigned::__type __type;
1508 template<typename _Tp>
1509 class __make_unsigned_selector<_Tp, false, true>
1511 // With -fshort-enums, an enum may be as small as a char.
1512 typedef unsigned char __smallest;
1513 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1514 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1515 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1516 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1517 typedef typename __cond2::type __cond2_type;
1518 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1519 typedef typename __cond1::type __cond1_type;
1522 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1525 // Given an integral/enum type, return the corresponding unsigned
1527 // Primary template.
1529 template<typename _Tp>
1530 struct make_unsigned
1531 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1533 // Integral, but don't define.
1535 struct make_unsigned<bool>;
1538 // Utility for finding the signed versions of unsigned integral types.
1539 template<typename _Tp>
1540 struct __make_signed
1541 { typedef _Tp __type; };
1544 struct __make_signed<char>
1545 { typedef signed char __type; };
1548 struct __make_signed<unsigned char>
1549 { typedef signed char __type; };
1552 struct __make_signed<unsigned short>
1553 { typedef signed short __type; };
1556 struct __make_signed<unsigned int>
1557 { typedef signed int __type; };
1560 struct __make_signed<unsigned long>
1561 { typedef signed long __type; };
1564 struct __make_signed<unsigned long long>
1565 { typedef signed long long __type; };
1567 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1569 struct __make_signed<unsigned __int128>
1570 { typedef __int128 __type; };
1573 // Select between integral and enum: not possible to be both.
1574 template<typename _Tp,
1575 bool _IsInt = is_integral<_Tp>::value,
1576 bool _IsEnum = is_enum<_Tp>::value>
1577 class __make_signed_selector;
1579 template<typename _Tp>
1580 class __make_signed_selector<_Tp, true, false>
1582 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1583 typedef typename __signedt::__type __signed_type;
1584 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1587 typedef typename __cv_signed::__type __type;
1590 template<typename _Tp>
1591 class __make_signed_selector<_Tp, false, true>
1593 // With -fshort-enums, an enum may be as small as a char.
1594 typedef signed char __smallest;
1595 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1596 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1597 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1598 typedef conditional<__b2, signed int, signed long> __cond2;
1599 typedef typename __cond2::type __cond2_type;
1600 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1601 typedef typename __cond1::type __cond1_type;
1604 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1607 // Given an integral/enum type, return the corresponding signed
1609 // Primary template.
1611 template<typename _Tp>
1613 { typedef typename __make_signed_selector<_Tp>::__type type; };
1615 // Integral, but don't define.
1617 struct make_signed<bool>;
1620 // Array modifications.
1623 template<typename _Tp>
1624 struct remove_extent
1625 { typedef _Tp type; };
1627 template<typename _Tp, std::size_t _Size>
1628 struct remove_extent<_Tp[_Size]>
1629 { typedef _Tp type; };
1631 template<typename _Tp>
1632 struct remove_extent<_Tp[]>
1633 { typedef _Tp type; };
1635 /// remove_all_extents
1636 template<typename _Tp>
1637 struct remove_all_extents
1638 { typedef _Tp type; };
1640 template<typename _Tp, std::size_t _Size>
1641 struct remove_all_extents<_Tp[_Size]>
1642 { typedef typename remove_all_extents<_Tp>::type type; };
1644 template<typename _Tp>
1645 struct remove_all_extents<_Tp[]>
1646 { typedef typename remove_all_extents<_Tp>::type type; };
1649 // Pointer modifications.
1651 template<typename _Tp, typename>
1652 struct __remove_pointer_helper
1653 { typedef _Tp type; };
1655 template<typename _Tp, typename _Up>
1656 struct __remove_pointer_helper<_Tp, _Up*>
1657 { typedef _Up type; };
1660 template<typename _Tp>
1661 struct remove_pointer
1662 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1666 template<typename _Tp>
1668 { typedef typename remove_reference<_Tp>::type* type; };
1671 template<std::size_t _Len>
1672 struct __aligned_storage_msa
1676 unsigned char __data[_Len];
1677 struct __attribute__((__aligned__)) { } __align;
1682 * @brief Alignment type.
1684 * The value of _Align is a default-alignment which shall be the
1685 * most stringent alignment requirement for any C++ object type
1686 * whose size is no greater than _Len (3.9). The member typedef
1687 * type shall be a POD type suitable for use as uninitialized
1688 * storage for any object whose size is at most _Len and whose
1689 * alignment is a divisor of _Align.
1691 template<std::size_t _Len, std::size_t _Align =
1692 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1693 struct aligned_storage
1697 unsigned char __data[_Len];
1698 struct __attribute__((__aligned__((_Align)))) { } __align;
1703 // Decay trait for arrays and functions, used for perfect forwarding
1704 // in make_pair, make_tuple, etc.
1705 template<typename _Up,
1706 bool _IsArray = is_array<_Up>::value,
1707 bool _IsFunction = is_function<_Up>::value>
1708 struct __decay_selector;
1711 template<typename _Up>
1712 struct __decay_selector<_Up, false, false>
1713 { typedef typename remove_cv<_Up>::type __type; };
1715 template<typename _Up>
1716 struct __decay_selector<_Up, true, false>
1717 { typedef typename remove_extent<_Up>::type* __type; };
1719 template<typename _Up>
1720 struct __decay_selector<_Up, false, true>
1721 { typedef typename add_pointer<_Up>::type __type; };
1724 template<typename _Tp>
1727 typedef typename remove_reference<_Tp>::type __remove_type;
1730 typedef typename __decay_selector<__remove_type>::__type type;
1733 template<typename _Tp>
1734 class reference_wrapper;
1736 // Helper which adds a reference to a type when given a reference_wrapper
1737 template<typename _Tp>
1738 struct __strip_reference_wrapper
1743 template<typename _Tp>
1744 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1746 typedef _Tp& __type;
1749 template<typename _Tp>
1750 struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
1752 typedef _Tp& __type;
1755 template<typename _Tp>
1756 struct __decay_and_strip
1758 typedef typename __strip_reference_wrapper<
1759 typename decay<_Tp>::type>::__type __type;
1763 // Primary template.
1764 /// Define a member typedef @c type only if a boolean constant is true.
1765 template<bool, typename _Tp = void>
1769 // Partial specialization for true.
1770 template<typename _Tp>
1771 struct enable_if<true, _Tp>
1772 { typedef _Tp type; };
1774 template<typename... _Cond>
1775 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
1777 // Primary template.
1778 /// Define a member typedef @c type to one of two argument types.
1779 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1781 { typedef _Iftrue type; };
1783 // Partial specialization for false.
1784 template<typename _Iftrue, typename _Iffalse>
1785 struct conditional<false, _Iftrue, _Iffalse>
1786 { typedef _Iffalse type; };
1789 template<typename... _Tp>
1792 // Sfinae-friendly common_type implementation:
1794 struct __do_common_type_impl
1796 template<typename _Tp, typename _Up>
1797 static __success_type<typename decay<decltype
1798 (true ? std::declval<_Tp>()
1799 : std::declval<_Up>())>::type> _S_test(int);
1801 template<typename, typename>
1802 static __failure_type _S_test(...);
1805 template<typename _Tp, typename _Up>
1806 struct __common_type_impl
1807 : private __do_common_type_impl
1809 typedef decltype(_S_test<_Tp, _Up>(0)) type;
1812 struct __do_member_type_wrapper
1814 template<typename _Tp>
1815 static __success_type<typename _Tp::type> _S_test(int);
1818 static __failure_type _S_test(...);
1821 template<typename _Tp>
1822 struct __member_type_wrapper
1823 : private __do_member_type_wrapper
1825 typedef decltype(_S_test<_Tp>(0)) type;
1828 template<typename _CTp, typename... _Args>
1829 struct __expanded_common_type_wrapper
1831 typedef common_type<typename _CTp::type, _Args...> type;
1834 template<typename... _Args>
1835 struct __expanded_common_type_wrapper<__failure_type, _Args...>
1836 { typedef __failure_type type; };
1838 template<typename _Tp>
1839 struct common_type<_Tp>
1840 { typedef typename decay<_Tp>::type type; };
1842 template<typename _Tp, typename _Up>
1843 struct common_type<_Tp, _Up>
1844 : public __common_type_impl<_Tp, _Up>::type
1847 template<typename _Tp, typename _Up, typename... _Vp>
1848 struct common_type<_Tp, _Up, _Vp...>
1849 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
1850 common_type<_Tp, _Up>>::type, _Vp...>::type
1853 /// The underlying type of an enum.
1854 template<typename _Tp>
1855 struct underlying_type
1857 typedef __underlying_type(_Tp) type;
1860 template<typename _Tp>
1861 struct __declval_protector
1863 static const bool __stop = false;
1864 static typename add_rvalue_reference<_Tp>::type __delegate();
1867 template<typename _Tp>
1868 inline typename add_rvalue_reference<_Tp>::type
1871 static_assert(__declval_protector<_Tp>::__stop,
1872 "declval() must not be used!");
1873 return __declval_protector<_Tp>::__delegate();
1877 template<typename _Signature>
1880 // Sfinae-friendly result_of implementation:
1882 // [func.require] paragraph 1 bullet 1:
1883 struct __result_of_memfun_ref_impl
1885 template<typename _Fp, typename _Tp1, typename... _Args>
1886 static __success_type<decltype(
1887 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
1890 template<typename...>
1891 static __failure_type _S_test(...);
1894 template<typename _MemPtr, typename _Arg, typename... _Args>
1895 struct __result_of_memfun_ref
1896 : private __result_of_memfun_ref_impl
1898 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1901 // [func.require] paragraph 1 bullet 2:
1902 struct __result_of_memfun_deref_impl
1904 template<typename _Fp, typename _Tp1, typename... _Args>
1905 static __success_type<decltype(
1906 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
1909 template<typename...>
1910 static __failure_type _S_test(...);
1913 template<typename _MemPtr, typename _Arg, typename... _Args>
1914 struct __result_of_memfun_deref
1915 : private __result_of_memfun_deref_impl
1917 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1920 // [func.require] paragraph 1 bullet 3:
1921 struct __result_of_memobj_ref_impl
1923 template<typename _Fp, typename _Tp1>
1924 static __success_type<decltype(
1925 std::declval<_Tp1>().*std::declval<_Fp>()
1928 template<typename, typename>
1929 static __failure_type _S_test(...);
1932 template<typename _MemPtr, typename _Arg>
1933 struct __result_of_memobj_ref
1934 : private __result_of_memobj_ref_impl
1936 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
1939 // [func.require] paragraph 1 bullet 4:
1940 struct __result_of_memobj_deref_impl
1942 template<typename _Fp, typename _Tp1>
1943 static __success_type<decltype(
1944 (*std::declval<_Tp1>()).*std::declval<_Fp>()
1947 template<typename, typename>
1948 static __failure_type _S_test(...);
1951 template<typename _MemPtr, typename _Arg>
1952 struct __result_of_memobj_deref
1953 : private __result_of_memobj_deref_impl
1955 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
1958 template<typename _MemPtr, typename _Arg>
1959 struct __result_of_memobj;
1961 template<typename _Res, typename _Class, typename _Arg>
1962 struct __result_of_memobj<_Res _Class::*, _Arg>
1964 typedef typename remove_cv<typename remove_reference<
1965 _Arg>::type>::type _Argval;
1966 typedef _Res _Class::* _MemPtr;
1967 typedef typename conditional<__or_<is_same<_Argval, _Class>,
1968 is_base_of<_Class, _Argval>>::value,
1969 __result_of_memobj_ref<_MemPtr, _Arg>,
1970 __result_of_memobj_deref<_MemPtr, _Arg>
1974 template<typename _MemPtr, typename _Arg, typename... _Args>
1975 struct __result_of_memfun;
1977 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
1978 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
1980 typedef typename remove_cv<typename remove_reference<
1981 _Arg>::type>::type _Argval;
1982 typedef _Res _Class::* _MemPtr;
1983 typedef typename conditional<__or_<is_same<_Argval, _Class>,
1984 is_base_of<_Class, _Argval>>::value,
1985 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
1986 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
1990 template<bool, bool, typename _Functor, typename... _ArgTypes>
1991 struct __result_of_impl
1993 typedef __failure_type type;
1996 template<typename _MemPtr, typename _Arg>
1997 struct __result_of_impl<true, false, _MemPtr, _Arg>
1998 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2001 template<typename _MemPtr, typename _Arg, typename... _Args>
2002 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2003 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2006 // [func.require] paragraph 1 bullet 5:
2007 struct __result_of_other_impl
2009 template<typename _Fn, typename... _Args>
2010 static __success_type<decltype(
2011 std::declval<_Fn>()(std::declval<_Args>()...)
2014 template<typename...>
2015 static __failure_type _S_test(...);
2018 template<typename _Functor, typename... _ArgTypes>
2019 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2020 : private __result_of_other_impl
2022 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2025 template<typename _Functor, typename... _ArgTypes>
2026 struct result_of<_Functor(_ArgTypes...)>
2027 : public __result_of_impl<
2028 is_member_object_pointer<
2029 typename remove_reference<_Functor>::type
2031 is_member_function_pointer<
2032 typename remove_reference<_Functor>::type
2034 _Functor, _ArgTypes...
2038 /// @} group metaprogramming
2041 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2042 * member type _NTYPE.
2044 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2045 template<typename _Tp> \
2046 class __has_##_NTYPE##_helper \
2049 template<typename _Up> \
2053 template<typename _Up> \
2054 static __one __test(_Wrap_type<typename _Up::_NTYPE>*); \
2056 template<typename _Up> \
2057 static __two __test(...); \
2060 static constexpr bool value = sizeof(__test<_Tp>(0)) == 1; \
2063 template<typename _Tp> \
2064 struct __has_##_NTYPE \
2065 : integral_constant<bool, __has_##_NTYPE##_helper \
2066 <typename remove_cv<_Tp>::type>::value> \
2069 _GLIBCXX_END_NAMESPACE_VERSION
2074 #endif // _GLIBCXX_TYPE_TRAITS