1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2016 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 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
41 # if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__)
44 typedef __UINT_LEAST16_TYPE__ uint_least16_t;
45 typedef __UINT_LEAST32_TYPE__ uint_least32_t;
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 * @defgroup metaprogramming Metaprogramming
60 * Template utilities for compile-time introspection and modification,
61 * including type classification traits, type property inspection traits
62 * and type transformation traits.
68 template<typename _Tp, _Tp __v>
69 struct integral_constant
71 static constexpr _Tp value = __v;
72 typedef _Tp value_type;
73 typedef integral_constant<_Tp, __v> type;
74 constexpr operator value_type() const { return value; }
75 #if __cplusplus > 201103L
77 #define __cpp_lib_integral_constant_callable 201304
79 constexpr value_type operator()() const { return value; }
83 template<typename _Tp, _Tp __v>
84 constexpr _Tp integral_constant<_Tp, __v>::value;
86 /// The type used as a compile-time boolean with true value.
87 typedef integral_constant<bool, true> true_type;
89 /// The type used as a compile-time boolean with false value.
90 typedef integral_constant<bool, false> false_type;
93 using __bool_constant = integral_constant<bool, __v>;
95 #if __cplusplus > 201402L
96 # define __cpp_lib_bool_constant 201505
98 using bool_constant = integral_constant<bool, __v>;
101 // Meta programming helper types.
103 template<bool, typename, typename>
106 template<typename...>
114 template<typename _B1>
119 template<typename _B1, typename _B2>
120 struct __or_<_B1, _B2>
121 : public conditional<_B1::value, _B1, _B2>::type
124 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
125 struct __or_<_B1, _B2, _B3, _Bn...>
126 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
129 template<typename...>
137 template<typename _B1>
142 template<typename _B1, typename _B2>
143 struct __and_<_B1, _B2>
144 : public conditional<_B1::value, _B2, _B1>::type
147 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
148 struct __and_<_B1, _B2, _B3, _Bn...>
149 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
152 template<typename _Pp>
154 : public integral_constant<bool, !_Pp::value>
158 __nonesuch() = delete;
159 ~__nonesuch() = delete;
160 __nonesuch(__nonesuch const&) = delete;
161 void operator=(__nonesuch const&) = delete;
164 #if __cplusplus > 201402L
166 #define __cpp_lib_logical_traits 201510
168 template<typename... _Bn>
173 template<typename... _Bn>
178 template<typename _Pp>
184 // For several sfinae-friendly trait implementations we transport both the
185 // result information (as the member type) and the failure information (no
186 // member type). This is very similar to std::enable_if, but we cannot use
187 // them, because we need to derive from them as an implementation detail.
189 template<typename _Tp>
190 struct __success_type
191 { typedef _Tp type; };
193 struct __failure_type
196 // Primary type categories.
202 struct __is_void_helper
203 : public false_type { };
206 struct __is_void_helper<void>
207 : public true_type { };
210 template<typename _Tp>
212 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
216 struct __is_integral_helper
217 : public false_type { };
220 struct __is_integral_helper<bool>
221 : public true_type { };
224 struct __is_integral_helper<char>
225 : public true_type { };
228 struct __is_integral_helper<signed char>
229 : public true_type { };
232 struct __is_integral_helper<unsigned char>
233 : public true_type { };
235 #ifdef _GLIBCXX_USE_WCHAR_T
237 struct __is_integral_helper<wchar_t>
238 : public true_type { };
242 struct __is_integral_helper<char16_t>
243 : public true_type { };
246 struct __is_integral_helper<char32_t>
247 : public true_type { };
250 struct __is_integral_helper<short>
251 : public true_type { };
254 struct __is_integral_helper<unsigned short>
255 : public true_type { };
258 struct __is_integral_helper<int>
259 : public true_type { };
262 struct __is_integral_helper<unsigned int>
263 : public true_type { };
266 struct __is_integral_helper<long>
267 : public true_type { };
270 struct __is_integral_helper<unsigned long>
271 : public true_type { };
274 struct __is_integral_helper<long long>
275 : public true_type { };
278 struct __is_integral_helper<unsigned long long>
279 : public true_type { };
281 // Conditionalizing on __STRICT_ANSI__ here will break any port that
282 // uses one of these types for size_t.
283 #if defined(__GLIBCXX_TYPE_INT_N_0)
285 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
286 : public true_type { };
289 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
290 : public true_type { };
292 #if defined(__GLIBCXX_TYPE_INT_N_1)
294 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
295 : public true_type { };
298 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
299 : public true_type { };
301 #if defined(__GLIBCXX_TYPE_INT_N_2)
303 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
304 : public true_type { };
307 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
308 : public true_type { };
310 #if defined(__GLIBCXX_TYPE_INT_N_3)
312 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
313 : public true_type { };
316 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
317 : public true_type { };
321 template<typename _Tp>
323 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
327 struct __is_floating_point_helper
328 : public false_type { };
331 struct __is_floating_point_helper<float>
332 : public true_type { };
335 struct __is_floating_point_helper<double>
336 : public true_type { };
339 struct __is_floating_point_helper<long double>
340 : public true_type { };
342 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
344 struct __is_floating_point_helper<__float128>
345 : public true_type { };
348 /// is_floating_point
349 template<typename _Tp>
350 struct is_floating_point
351 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
357 : public false_type { };
359 template<typename _Tp, std::size_t _Size>
360 struct is_array<_Tp[_Size]>
361 : public true_type { };
363 template<typename _Tp>
364 struct is_array<_Tp[]>
365 : public true_type { };
368 struct __is_pointer_helper
369 : public false_type { };
371 template<typename _Tp>
372 struct __is_pointer_helper<_Tp*>
373 : public true_type { };
376 template<typename _Tp>
378 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
381 /// is_lvalue_reference
383 struct is_lvalue_reference
384 : public false_type { };
386 template<typename _Tp>
387 struct is_lvalue_reference<_Tp&>
388 : public true_type { };
390 /// is_rvalue_reference
392 struct is_rvalue_reference
393 : public false_type { };
395 template<typename _Tp>
396 struct is_rvalue_reference<_Tp&&>
397 : public true_type { };
403 struct __is_member_object_pointer_helper
404 : public false_type { };
406 template<typename _Tp, typename _Cp>
407 struct __is_member_object_pointer_helper<_Tp _Cp::*>
408 : public integral_constant<bool, !is_function<_Tp>::value> { };
410 /// is_member_object_pointer
411 template<typename _Tp>
412 struct is_member_object_pointer
413 : public __is_member_object_pointer_helper<
414 typename remove_cv<_Tp>::type>::type
418 struct __is_member_function_pointer_helper
419 : public false_type { };
421 template<typename _Tp, typename _Cp>
422 struct __is_member_function_pointer_helper<_Tp _Cp::*>
423 : public integral_constant<bool, is_function<_Tp>::value> { };
425 /// is_member_function_pointer
426 template<typename _Tp>
427 struct is_member_function_pointer
428 : public __is_member_function_pointer_helper<
429 typename remove_cv<_Tp>::type>::type
433 template<typename _Tp>
435 : public integral_constant<bool, __is_enum(_Tp)>
439 template<typename _Tp>
441 : public integral_constant<bool, __is_union(_Tp)>
445 template<typename _Tp>
447 : public integral_constant<bool, __is_class(_Tp)>
453 : public false_type { };
455 template<typename _Res, typename... _ArgTypes>
456 struct is_function<_Res(_ArgTypes...)>
457 : public true_type { };
459 template<typename _Res, typename... _ArgTypes>
460 struct is_function<_Res(_ArgTypes...) &>
461 : public true_type { };
463 template<typename _Res, typename... _ArgTypes>
464 struct is_function<_Res(_ArgTypes...) &&>
465 : public true_type { };
467 template<typename _Res, typename... _ArgTypes>
468 struct is_function<_Res(_ArgTypes......)>
469 : public true_type { };
471 template<typename _Res, typename... _ArgTypes>
472 struct is_function<_Res(_ArgTypes......) &>
473 : public true_type { };
475 template<typename _Res, typename... _ArgTypes>
476 struct is_function<_Res(_ArgTypes......) &&>
477 : public true_type { };
479 template<typename _Res, typename... _ArgTypes>
480 struct is_function<_Res(_ArgTypes...) const>
481 : public true_type { };
483 template<typename _Res, typename... _ArgTypes>
484 struct is_function<_Res(_ArgTypes...) const &>
485 : public true_type { };
487 template<typename _Res, typename... _ArgTypes>
488 struct is_function<_Res(_ArgTypes...) const &&>
489 : public true_type { };
491 template<typename _Res, typename... _ArgTypes>
492 struct is_function<_Res(_ArgTypes......) const>
493 : public true_type { };
495 template<typename _Res, typename... _ArgTypes>
496 struct is_function<_Res(_ArgTypes......) const &>
497 : public true_type { };
499 template<typename _Res, typename... _ArgTypes>
500 struct is_function<_Res(_ArgTypes......) const &&>
501 : public true_type { };
503 template<typename _Res, typename... _ArgTypes>
504 struct is_function<_Res(_ArgTypes...) volatile>
505 : public true_type { };
507 template<typename _Res, typename... _ArgTypes>
508 struct is_function<_Res(_ArgTypes...) volatile &>
509 : public true_type { };
511 template<typename _Res, typename... _ArgTypes>
512 struct is_function<_Res(_ArgTypes...) volatile &&>
513 : public true_type { };
515 template<typename _Res, typename... _ArgTypes>
516 struct is_function<_Res(_ArgTypes......) volatile>
517 : public true_type { };
519 template<typename _Res, typename... _ArgTypes>
520 struct is_function<_Res(_ArgTypes......) volatile &>
521 : public true_type { };
523 template<typename _Res, typename... _ArgTypes>
524 struct is_function<_Res(_ArgTypes......) volatile &&>
525 : public true_type { };
527 template<typename _Res, typename... _ArgTypes>
528 struct is_function<_Res(_ArgTypes...) const volatile>
529 : public true_type { };
531 template<typename _Res, typename... _ArgTypes>
532 struct is_function<_Res(_ArgTypes...) const volatile &>
533 : public true_type { };
535 template<typename _Res, typename... _ArgTypes>
536 struct is_function<_Res(_ArgTypes...) const volatile &&>
537 : public true_type { };
539 template<typename _Res, typename... _ArgTypes>
540 struct is_function<_Res(_ArgTypes......) const volatile>
541 : public true_type { };
543 template<typename _Res, typename... _ArgTypes>
544 struct is_function<_Res(_ArgTypes......) const volatile &>
545 : public true_type { };
547 template<typename _Res, typename... _ArgTypes>
548 struct is_function<_Res(_ArgTypes......) const volatile &&>
549 : public true_type { };
551 #define __cpp_lib_is_null_pointer 201309
554 struct __is_null_pointer_helper
555 : public false_type { };
558 struct __is_null_pointer_helper<std::nullptr_t>
559 : public true_type { };
561 /// is_null_pointer (LWG 2247).
562 template<typename _Tp>
563 struct is_null_pointer
564 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
567 /// __is_nullptr_t (extension).
568 template<typename _Tp>
569 struct __is_nullptr_t
570 : public is_null_pointer<_Tp>
573 // Composite type categories.
576 template<typename _Tp>
578 : public __or_<is_lvalue_reference<_Tp>,
579 is_rvalue_reference<_Tp>>::type
583 template<typename _Tp>
585 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
589 template<typename _Tp>
590 struct is_fundamental
591 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
592 is_null_pointer<_Tp>>::type
596 template<typename _Tp>
598 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
603 struct is_member_pointer;
606 template<typename _Tp>
608 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
609 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
613 template<typename _Tp>
615 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
617 template<typename _Tp>
618 struct __is_member_pointer_helper
619 : public false_type { };
621 template<typename _Tp, typename _Cp>
622 struct __is_member_pointer_helper<_Tp _Cp::*>
623 : public true_type { };
625 /// is_member_pointer
626 template<typename _Tp>
627 struct is_member_pointer
628 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
631 // Utility to detect referenceable types ([defns.referenceable]).
633 template<typename _Tp>
634 struct __is_referenceable
635 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
638 template<typename _Res, typename... _Args>
639 struct __is_referenceable<_Res(_Args...)>
643 template<typename _Res, typename... _Args>
644 struct __is_referenceable<_Res(_Args......)>
653 : public false_type { };
655 template<typename _Tp>
656 struct is_const<_Tp const>
657 : public true_type { };
662 : public false_type { };
664 template<typename _Tp>
665 struct is_volatile<_Tp volatile>
666 : public true_type { };
669 template<typename _Tp>
671 : public integral_constant<bool, __is_trivial(_Tp)>
674 // is_trivially_copyable
675 template<typename _Tp>
676 struct is_trivially_copyable
677 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
680 /// is_standard_layout
681 template<typename _Tp>
682 struct is_standard_layout
683 : public integral_constant<bool, __is_standard_layout(_Tp)>
687 // Could use is_standard_layout && is_trivial instead of the builtin.
688 template<typename _Tp>
690 : public integral_constant<bool, __is_pod(_Tp)>
694 template<typename _Tp>
695 struct is_literal_type
696 : public integral_constant<bool, __is_literal_type(_Tp)>
700 template<typename _Tp>
702 : public integral_constant<bool, __is_empty(_Tp)>
706 template<typename _Tp>
707 struct is_polymorphic
708 : public integral_constant<bool, __is_polymorphic(_Tp)>
711 #if __cplusplus >= 201402L
712 #define __cpp_lib_is_final 201402L
714 template<typename _Tp>
716 : public integral_constant<bool, __is_final(_Tp)>
721 template<typename _Tp>
723 : public integral_constant<bool, __is_abstract(_Tp)>
726 template<typename _Tp,
727 bool = is_arithmetic<_Tp>::value>
728 struct __is_signed_helper
729 : public false_type { };
731 template<typename _Tp>
732 struct __is_signed_helper<_Tp, true>
733 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
737 template<typename _Tp>
739 : public __is_signed_helper<_Tp>::type
743 template<typename _Tp>
745 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
749 // Destructible and constructible type properties.
752 struct add_rvalue_reference;
755 * @brief Utility to simplify expressions used in unevaluated operands
758 template<typename _Tp>
759 typename add_rvalue_reference<_Tp>::type declval() noexcept;
761 template<typename, unsigned = 0>
765 struct remove_all_extents;
767 template<typename _Tp>
768 struct __is_array_known_bounds
769 : public integral_constant<bool, (extent<_Tp>::value > 0)>
772 template<typename _Tp>
773 struct __is_array_unknown_bounds
774 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
777 // In N3290 is_destructible does not say anything about function
778 // types and abstract types, see LWG 2049. This implementation
779 // describes function types as non-destructible and all complete
780 // object types as destructible, iff the explicit destructor
781 // call expression is wellformed.
782 struct __do_is_destructible_impl
784 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
785 static true_type __test(int);
788 static false_type __test(...);
791 template<typename _Tp>
792 struct __is_destructible_impl
793 : public __do_is_destructible_impl
795 typedef decltype(__test<_Tp>(0)) type;
798 template<typename _Tp,
799 bool = __or_<is_void<_Tp>,
800 __is_array_unknown_bounds<_Tp>,
801 is_function<_Tp>>::value,
802 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
803 struct __is_destructible_safe;
805 template<typename _Tp>
806 struct __is_destructible_safe<_Tp, false, false>
807 : public __is_destructible_impl<typename
808 remove_all_extents<_Tp>::type>::type
811 template<typename _Tp>
812 struct __is_destructible_safe<_Tp, true, false>
813 : public false_type { };
815 template<typename _Tp>
816 struct __is_destructible_safe<_Tp, false, true>
817 : public true_type { };
820 template<typename _Tp>
821 struct is_destructible
822 : public __is_destructible_safe<_Tp>::type
825 // is_nothrow_destructible requires that is_destructible is
826 // satisfied as well. We realize that by mimicing the
827 // implementation of is_destructible but refer to noexcept(expr)
828 // instead of decltype(expr).
829 struct __do_is_nt_destructible_impl
831 template<typename _Tp>
832 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
836 static false_type __test(...);
839 template<typename _Tp>
840 struct __is_nt_destructible_impl
841 : public __do_is_nt_destructible_impl
843 typedef decltype(__test<_Tp>(0)) type;
846 template<typename _Tp,
847 bool = __or_<is_void<_Tp>,
848 __is_array_unknown_bounds<_Tp>,
849 is_function<_Tp>>::value,
850 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
851 struct __is_nt_destructible_safe;
853 template<typename _Tp>
854 struct __is_nt_destructible_safe<_Tp, false, false>
855 : public __is_nt_destructible_impl<typename
856 remove_all_extents<_Tp>::type>::type
859 template<typename _Tp>
860 struct __is_nt_destructible_safe<_Tp, true, false>
861 : public false_type { };
863 template<typename _Tp>
864 struct __is_nt_destructible_safe<_Tp, false, true>
865 : public true_type { };
867 /// is_nothrow_destructible
868 template<typename _Tp>
869 struct is_nothrow_destructible
870 : public __is_nt_destructible_safe<_Tp>::type
873 struct __do_is_default_constructible_impl
875 template<typename _Tp, typename = decltype(_Tp())>
876 static true_type __test(int);
879 static false_type __test(...);
882 template<typename _Tp>
883 struct __is_default_constructible_impl
884 : public __do_is_default_constructible_impl
886 typedef decltype(__test<_Tp>(0)) type;
889 template<typename _Tp>
890 struct __is_default_constructible_atom
891 : public __and_<__not_<is_void<_Tp>>,
892 __is_default_constructible_impl<_Tp>>
895 template<typename _Tp, bool = is_array<_Tp>::value>
896 struct __is_default_constructible_safe;
898 // The following technique is a workaround for a current core language
899 // restriction, which does not allow for array types to occur in
900 // functional casts of the form T(). Complete arrays can be default-
901 // constructed, if the element type is default-constructible, but
902 // arrays with unknown bounds are not.
903 template<typename _Tp>
904 struct __is_default_constructible_safe<_Tp, true>
905 : public __and_<__is_array_known_bounds<_Tp>,
906 __is_default_constructible_atom<typename
907 remove_all_extents<_Tp>::type>>
910 template<typename _Tp>
911 struct __is_default_constructible_safe<_Tp, false>
912 : public __is_default_constructible_atom<_Tp>::type
915 /// is_default_constructible
916 template<typename _Tp>
917 struct is_default_constructible
918 : public __is_default_constructible_safe<_Tp>::type
922 // Implementation of is_constructible.
924 // The hardest part of this trait is the binary direct-initialization
925 // case, because we hit into a functional cast of the form T(arg).
926 // This implementation uses different strategies depending on the
927 // target type to reduce the test overhead as much as possible:
929 // a) For a reference target type, we use a static_cast expression
930 // modulo its extra cases.
932 // b) For a non-reference target type we use a ::new expression.
933 struct __do_is_static_castable_impl
935 template<typename _From, typename _To, typename
936 = decltype(static_cast<_To>(declval<_From>()))>
937 static true_type __test(int);
939 template<typename, typename>
940 static false_type __test(...);
943 template<typename _From, typename _To>
944 struct __is_static_castable_impl
945 : public __do_is_static_castable_impl
947 typedef decltype(__test<_From, _To>(0)) type;
950 template<typename _From, typename _To>
951 struct __is_static_castable_safe
952 : public __is_static_castable_impl<_From, _To>::type
955 // __is_static_castable
956 template<typename _From, typename _To>
957 struct __is_static_castable
958 : public integral_constant<bool, (__is_static_castable_safe<
962 // Implementation for non-reference types. To meet the proper
963 // variable definition semantics, we also need to test for
964 // is_destructible in this case.
965 // This form should be simplified by a single expression:
966 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
967 struct __do_is_direct_constructible_impl
969 template<typename _Tp, typename _Arg, typename
970 = decltype(::new _Tp(declval<_Arg>()))>
971 static true_type __test(int);
973 template<typename, typename>
974 static false_type __test(...);
977 template<typename _Tp, typename _Arg>
978 struct __is_direct_constructible_impl
979 : public __do_is_direct_constructible_impl
981 typedef decltype(__test<_Tp, _Arg>(0)) type;
984 template<typename _Tp, typename _Arg>
985 struct __is_direct_constructible_new_safe
986 : public __and_<is_destructible<_Tp>,
987 __is_direct_constructible_impl<_Tp, _Arg>>
990 template<typename, typename>
993 template<typename, typename>
997 struct remove_reference;
999 template<typename _From, typename _To, bool
1000 = __not_<__or_<is_void<_From>,
1001 is_function<_From>>>::value>
1002 struct __is_base_to_derived_ref;
1004 template<typename _Tp, typename... _Args>
1005 struct is_constructible;
1007 // Detect whether we have a downcast situation during
1008 // reference binding.
1009 template<typename _From, typename _To>
1010 struct __is_base_to_derived_ref<_From, _To, true>
1012 typedef typename remove_cv<typename remove_reference<_From
1013 >::type>::type __src_t;
1014 typedef typename remove_cv<typename remove_reference<_To
1015 >::type>::type __dst_t;
1016 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
1017 is_base_of<__src_t, __dst_t>,
1018 __not_<is_constructible<__dst_t, _From>>> type;
1019 static constexpr bool value = type::value;
1022 template<typename _From, typename _To>
1023 struct __is_base_to_derived_ref<_From, _To, false>
1027 template<typename _From, typename _To, bool
1028 = __and_<is_lvalue_reference<_From>,
1029 is_rvalue_reference<_To>>::value>
1030 struct __is_lvalue_to_rvalue_ref;
1032 // Detect whether we have an lvalue of non-function type
1033 // bound to a reference-compatible rvalue-reference.
1034 template<typename _From, typename _To>
1035 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
1037 typedef typename remove_cv<typename remove_reference<
1038 _From>::type>::type __src_t;
1039 typedef typename remove_cv<typename remove_reference<
1040 _To>::type>::type __dst_t;
1041 typedef __and_<__not_<is_function<__src_t>>,
1042 __or_<is_same<__src_t, __dst_t>,
1043 is_base_of<__dst_t, __src_t>>> type;
1044 static constexpr bool value = type::value;
1047 template<typename _From, typename _To>
1048 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
1052 // Here we handle direct-initialization to a reference type as
1053 // equivalent to a static_cast modulo overshooting conversions.
1054 // These are restricted to the following conversions:
1055 // a) A base class value to a derived class reference
1056 // b) An lvalue to an rvalue-reference of reference-compatible
1057 // types that are not functions
1058 template<typename _Tp, typename _Arg>
1059 struct __is_direct_constructible_ref_cast
1060 : public __and_<__is_static_castable<_Arg, _Tp>,
1061 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
1062 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
1066 template<typename _Tp, typename _Arg>
1067 struct __is_direct_constructible_new
1068 : public conditional<is_reference<_Tp>::value,
1069 __is_direct_constructible_ref_cast<_Tp, _Arg>,
1070 __is_direct_constructible_new_safe<_Tp, _Arg>
1074 template<typename _Tp, typename _Arg>
1075 struct __is_direct_constructible
1076 : public __is_direct_constructible_new<_Tp, _Arg>::type
1079 // Since default-construction and binary direct-initialization have
1080 // been handled separately, the implementation of the remaining
1081 // n-ary construction cases is rather straightforward. We can use
1082 // here a functional cast, because array types are excluded anyway
1083 // and this form is never interpreted as a C cast.
1084 struct __do_is_nary_constructible_impl
1086 template<typename _Tp, typename... _Args, typename
1087 = decltype(_Tp(declval<_Args>()...))>
1088 static true_type __test(int);
1090 template<typename, typename...>
1091 static false_type __test(...);
1094 template<typename _Tp, typename... _Args>
1095 struct __is_nary_constructible_impl
1096 : public __do_is_nary_constructible_impl
1098 typedef decltype(__test<_Tp, _Args...>(0)) type;
1101 template<typename _Tp, typename... _Args>
1102 struct __is_nary_constructible
1103 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1105 static_assert(sizeof...(_Args) > 1,
1106 "Only useful for > 1 arguments");
1109 template<typename _Tp, typename... _Args>
1110 struct __is_constructible_impl
1111 : public __is_nary_constructible<_Tp, _Args...>
1114 template<typename _Tp, typename _Arg>
1115 struct __is_constructible_impl<_Tp, _Arg>
1116 : public __is_direct_constructible<_Tp, _Arg>
1119 template<typename _Tp>
1120 struct __is_constructible_impl<_Tp>
1121 : public is_default_constructible<_Tp>
1124 /// is_constructible
1125 template<typename _Tp, typename... _Args>
1126 struct is_constructible
1127 : public __is_constructible_impl<_Tp, _Args...>::type
1130 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1131 struct __is_copy_constructible_impl;
1133 template<typename _Tp>
1134 struct __is_copy_constructible_impl<_Tp, false>
1135 : public false_type { };
1137 template<typename _Tp>
1138 struct __is_copy_constructible_impl<_Tp, true>
1139 : public is_constructible<_Tp, const _Tp&>
1142 /// is_copy_constructible
1143 template<typename _Tp>
1144 struct is_copy_constructible
1145 : public __is_copy_constructible_impl<_Tp>
1148 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1149 struct __is_move_constructible_impl;
1151 template<typename _Tp>
1152 struct __is_move_constructible_impl<_Tp, false>
1153 : public false_type { };
1155 template<typename _Tp>
1156 struct __is_move_constructible_impl<_Tp, true>
1157 : public is_constructible<_Tp, _Tp&&>
1160 /// is_move_constructible
1161 template<typename _Tp>
1162 struct is_move_constructible
1163 : public __is_move_constructible_impl<_Tp>
1166 template<typename _Tp>
1167 struct __is_nt_default_constructible_atom
1168 : public integral_constant<bool, noexcept(_Tp())>
1171 template<typename _Tp, bool = is_array<_Tp>::value>
1172 struct __is_nt_default_constructible_impl;
1174 template<typename _Tp>
1175 struct __is_nt_default_constructible_impl<_Tp, true>
1176 : public __and_<__is_array_known_bounds<_Tp>,
1177 __is_nt_default_constructible_atom<typename
1178 remove_all_extents<_Tp>::type>>
1181 template<typename _Tp>
1182 struct __is_nt_default_constructible_impl<_Tp, false>
1183 : public __is_nt_default_constructible_atom<_Tp>
1186 /// is_nothrow_default_constructible
1187 template<typename _Tp>
1188 struct is_nothrow_default_constructible
1189 : public __and_<is_default_constructible<_Tp>,
1190 __is_nt_default_constructible_impl<_Tp>>
1193 template<typename _Tp, typename... _Args>
1194 struct __is_nt_constructible_impl
1195 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1198 template<typename _Tp, typename _Arg>
1199 struct __is_nt_constructible_impl<_Tp, _Arg>
1200 : public integral_constant<bool,
1201 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1204 template<typename _Tp>
1205 struct __is_nt_constructible_impl<_Tp>
1206 : public is_nothrow_default_constructible<_Tp>
1209 /// is_nothrow_constructible
1210 template<typename _Tp, typename... _Args>
1211 struct is_nothrow_constructible
1212 : public __and_<is_constructible<_Tp, _Args...>,
1213 __is_nt_constructible_impl<_Tp, _Args...>>
1216 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1217 struct __is_nothrow_copy_constructible_impl;
1219 template<typename _Tp>
1220 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1221 : public false_type { };
1223 template<typename _Tp>
1224 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1225 : public is_nothrow_constructible<_Tp, const _Tp&>
1228 /// is_nothrow_copy_constructible
1229 template<typename _Tp>
1230 struct is_nothrow_copy_constructible
1231 : public __is_nothrow_copy_constructible_impl<_Tp>
1234 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1235 struct __is_nothrow_move_constructible_impl;
1237 template<typename _Tp>
1238 struct __is_nothrow_move_constructible_impl<_Tp, false>
1239 : public false_type { };
1241 template<typename _Tp>
1242 struct __is_nothrow_move_constructible_impl<_Tp, true>
1243 : public is_nothrow_constructible<_Tp, _Tp&&>
1246 /// is_nothrow_move_constructible
1247 template<typename _Tp>
1248 struct is_nothrow_move_constructible
1249 : public __is_nothrow_move_constructible_impl<_Tp>
1252 template<typename _Tp, typename _Up>
1253 class __is_assignable_helper
1255 template<typename _Tp1, typename _Up1,
1256 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1260 template<typename, typename>
1265 typedef decltype(__test<_Tp, _Up>(0)) type;
1269 template<typename _Tp, typename _Up>
1270 struct is_assignable
1271 : public __is_assignable_helper<_Tp, _Up>::type
1274 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1275 struct __is_copy_assignable_impl;
1277 template<typename _Tp>
1278 struct __is_copy_assignable_impl<_Tp, false>
1279 : public false_type { };
1281 template<typename _Tp>
1282 struct __is_copy_assignable_impl<_Tp, true>
1283 : public is_assignable<_Tp&, const _Tp&>
1286 /// is_copy_assignable
1287 template<typename _Tp>
1288 struct is_copy_assignable
1289 : public __is_copy_assignable_impl<_Tp>
1292 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1293 struct __is_move_assignable_impl;
1295 template<typename _Tp>
1296 struct __is_move_assignable_impl<_Tp, false>
1297 : public false_type { };
1299 template<typename _Tp>
1300 struct __is_move_assignable_impl<_Tp, true>
1301 : public is_assignable<_Tp&, _Tp&&>
1304 /// is_move_assignable
1305 template<typename _Tp>
1306 struct is_move_assignable
1307 : public __is_move_assignable_impl<_Tp>
1310 template<typename _Tp, typename _Up>
1311 struct __is_nt_assignable_impl
1312 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1315 /// is_nothrow_assignable
1316 template<typename _Tp, typename _Up>
1317 struct is_nothrow_assignable
1318 : public __and_<is_assignable<_Tp, _Up>,
1319 __is_nt_assignable_impl<_Tp, _Up>>
1322 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1323 struct __is_nt_copy_assignable_impl;
1325 template<typename _Tp>
1326 struct __is_nt_copy_assignable_impl<_Tp, false>
1327 : public false_type { };
1329 template<typename _Tp>
1330 struct __is_nt_copy_assignable_impl<_Tp, true>
1331 : public is_nothrow_assignable<_Tp&, const _Tp&>
1334 /// is_nothrow_copy_assignable
1335 template<typename _Tp>
1336 struct is_nothrow_copy_assignable
1337 : public __is_nt_copy_assignable_impl<_Tp>
1340 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1341 struct __is_nt_move_assignable_impl;
1343 template<typename _Tp>
1344 struct __is_nt_move_assignable_impl<_Tp, false>
1345 : public false_type { };
1347 template<typename _Tp>
1348 struct __is_nt_move_assignable_impl<_Tp, true>
1349 : public is_nothrow_assignable<_Tp&, _Tp&&>
1352 /// is_nothrow_move_assignable
1353 template<typename _Tp>
1354 struct is_nothrow_move_assignable
1355 : public __is_nt_move_assignable_impl<_Tp>
1358 /// is_trivially_constructible
1359 template<typename _Tp, typename... _Args>
1360 struct is_trivially_constructible
1361 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool,
1362 __is_trivially_constructible(_Tp, _Args...)>>
1365 /// is_trivially_default_constructible
1366 template<typename _Tp>
1367 struct is_trivially_default_constructible
1368 : public is_trivially_constructible<_Tp>::type
1371 struct __do_is_implicitly_default_constructible_impl
1373 template <typename _Tp>
1374 static void __helper(const _Tp&);
1376 template <typename _Tp>
1377 static true_type __test(const _Tp&,
1378 decltype(__helper<const _Tp&>({}))* = 0);
1380 static false_type __test(...);
1383 template<typename _Tp>
1384 struct __is_implicitly_default_constructible_impl
1385 : public __do_is_implicitly_default_constructible_impl
1387 typedef decltype(__test(declval<_Tp>())) type;
1390 template<typename _Tp>
1391 struct __is_implicitly_default_constructible_safe
1392 : public __is_implicitly_default_constructible_impl<_Tp>::type
1395 template <typename _Tp>
1396 struct __is_implicitly_default_constructible
1397 : public __and_<is_default_constructible<_Tp>,
1398 __is_implicitly_default_constructible_safe<_Tp>>
1401 /// is_trivially_copy_constructible
1402 template<typename _Tp>
1403 struct is_trivially_copy_constructible
1404 : public __and_<is_copy_constructible<_Tp>,
1405 integral_constant<bool,
1406 __is_trivially_constructible(_Tp, const _Tp&)>>
1409 /// is_trivially_move_constructible
1410 template<typename _Tp>
1411 struct is_trivially_move_constructible
1412 : public __and_<is_move_constructible<_Tp>,
1413 integral_constant<bool,
1414 __is_trivially_constructible(_Tp, _Tp&&)>>
1417 /// is_trivially_assignable
1418 template<typename _Tp, typename _Up>
1419 struct is_trivially_assignable
1420 : public __and_<is_assignable<_Tp, _Up>,
1421 integral_constant<bool,
1422 __is_trivially_assignable(_Tp, _Up)>>
1425 /// is_trivially_copy_assignable
1426 template<typename _Tp>
1427 struct is_trivially_copy_assignable
1428 : public __and_<is_copy_assignable<_Tp>,
1429 integral_constant<bool,
1430 __is_trivially_assignable(_Tp&, const _Tp&)>>
1433 /// is_trivially_move_assignable
1434 template<typename _Tp>
1435 struct is_trivially_move_assignable
1436 : public __and_<is_move_assignable<_Tp>,
1437 integral_constant<bool,
1438 __is_trivially_assignable(_Tp&, _Tp&&)>>
1441 /// is_trivially_destructible
1442 template<typename _Tp>
1443 struct is_trivially_destructible
1444 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1445 __has_trivial_destructor(_Tp)>>
1448 /// has_trivial_default_constructor (temporary legacy)
1449 template<typename _Tp>
1450 struct has_trivial_default_constructor
1451 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1452 { } _GLIBCXX_DEPRECATED;
1454 /// has_trivial_copy_constructor (temporary legacy)
1455 template<typename _Tp>
1456 struct has_trivial_copy_constructor
1457 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1458 { } _GLIBCXX_DEPRECATED;
1460 /// has_trivial_copy_assign (temporary legacy)
1461 template<typename _Tp>
1462 struct has_trivial_copy_assign
1463 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1464 { } _GLIBCXX_DEPRECATED;
1466 /// has_virtual_destructor
1467 template<typename _Tp>
1468 struct has_virtual_destructor
1469 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1473 // type property queries.
1476 template<typename _Tp>
1478 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1483 : public integral_constant<std::size_t, 0> { };
1485 template<typename _Tp, std::size_t _Size>
1486 struct rank<_Tp[_Size]>
1487 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1489 template<typename _Tp>
1491 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1494 template<typename, unsigned _Uint>
1496 : public integral_constant<std::size_t, 0> { };
1498 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1499 struct extent<_Tp[_Size], _Uint>
1500 : public integral_constant<std::size_t,
1501 _Uint == 0 ? _Size : extent<_Tp,
1505 template<typename _Tp, unsigned _Uint>
1506 struct extent<_Tp[], _Uint>
1507 : public integral_constant<std::size_t,
1508 _Uint == 0 ? 0 : extent<_Tp,
1516 template<typename, typename>
1518 : public false_type { };
1520 template<typename _Tp>
1521 struct is_same<_Tp, _Tp>
1522 : public true_type { };
1525 template<typename _Base, typename _Derived>
1527 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1530 template<typename _From, typename _To,
1531 bool = __or_<is_void<_From>, is_function<_To>,
1532 is_array<_To>>::value>
1533 struct __is_convertible_helper
1534 { typedef typename is_void<_To>::type type; };
1536 template<typename _From, typename _To>
1537 class __is_convertible_helper<_From, _To, false>
1539 template<typename _To1>
1540 static void __test_aux(_To1);
1542 template<typename _From1, typename _To1,
1543 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1547 template<typename, typename>
1552 typedef decltype(__test<_From, _To>(0)) type;
1557 template<typename _From, typename _To>
1558 struct is_convertible
1559 : public __is_convertible_helper<_From, _To>::type
1563 // Const-volatile modifications.
1566 template<typename _Tp>
1568 { typedef _Tp type; };
1570 template<typename _Tp>
1571 struct remove_const<_Tp const>
1572 { typedef _Tp type; };
1575 template<typename _Tp>
1576 struct remove_volatile
1577 { typedef _Tp type; };
1579 template<typename _Tp>
1580 struct remove_volatile<_Tp volatile>
1581 { typedef _Tp type; };
1584 template<typename _Tp>
1588 remove_const<typename remove_volatile<_Tp>::type>::type type;
1592 template<typename _Tp>
1594 { typedef _Tp const type; };
1597 template<typename _Tp>
1599 { typedef _Tp volatile type; };
1602 template<typename _Tp>
1606 add_const<typename add_volatile<_Tp>::type>::type type;
1609 #if __cplusplus > 201103L
1611 #define __cpp_lib_transformation_trait_aliases 201304
1613 /// Alias template for remove_const
1614 template<typename _Tp>
1615 using remove_const_t = typename remove_const<_Tp>::type;
1617 /// Alias template for remove_volatile
1618 template<typename _Tp>
1619 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1621 /// Alias template for remove_cv
1622 template<typename _Tp>
1623 using remove_cv_t = typename remove_cv<_Tp>::type;
1625 /// Alias template for add_const
1626 template<typename _Tp>
1627 using add_const_t = typename add_const<_Tp>::type;
1629 /// Alias template for add_volatile
1630 template<typename _Tp>
1631 using add_volatile_t = typename add_volatile<_Tp>::type;
1633 /// Alias template for add_cv
1634 template<typename _Tp>
1635 using add_cv_t = typename add_cv<_Tp>::type;
1638 // Reference transformations.
1640 /// remove_reference
1641 template<typename _Tp>
1642 struct remove_reference
1643 { typedef _Tp type; };
1645 template<typename _Tp>
1646 struct remove_reference<_Tp&>
1647 { typedef _Tp type; };
1649 template<typename _Tp>
1650 struct remove_reference<_Tp&&>
1651 { typedef _Tp type; };
1653 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1654 struct __add_lvalue_reference_helper
1655 { typedef _Tp type; };
1657 template<typename _Tp>
1658 struct __add_lvalue_reference_helper<_Tp, true>
1659 { typedef _Tp& type; };
1661 /// add_lvalue_reference
1662 template<typename _Tp>
1663 struct add_lvalue_reference
1664 : public __add_lvalue_reference_helper<_Tp>
1667 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1668 struct __add_rvalue_reference_helper
1669 { typedef _Tp type; };
1671 template<typename _Tp>
1672 struct __add_rvalue_reference_helper<_Tp, true>
1673 { typedef _Tp&& type; };
1675 /// add_rvalue_reference
1676 template<typename _Tp>
1677 struct add_rvalue_reference
1678 : public __add_rvalue_reference_helper<_Tp>
1681 #if __cplusplus > 201103L
1682 /// Alias template for remove_reference
1683 template<typename _Tp>
1684 using remove_reference_t = typename remove_reference<_Tp>::type;
1686 /// Alias template for add_lvalue_reference
1687 template<typename _Tp>
1688 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1690 /// Alias template for add_rvalue_reference
1691 template<typename _Tp>
1692 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1695 // Sign modifications.
1697 // Utility for constructing identically cv-qualified types.
1698 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1699 struct __cv_selector;
1701 template<typename _Unqualified>
1702 struct __cv_selector<_Unqualified, false, false>
1703 { typedef _Unqualified __type; };
1705 template<typename _Unqualified>
1706 struct __cv_selector<_Unqualified, false, true>
1707 { typedef volatile _Unqualified __type; };
1709 template<typename _Unqualified>
1710 struct __cv_selector<_Unqualified, true, false>
1711 { typedef const _Unqualified __type; };
1713 template<typename _Unqualified>
1714 struct __cv_selector<_Unqualified, true, true>
1715 { typedef const volatile _Unqualified __type; };
1717 template<typename _Qualified, typename _Unqualified,
1718 bool _IsConst = is_const<_Qualified>::value,
1719 bool _IsVol = is_volatile<_Qualified>::value>
1720 class __match_cv_qualifiers
1722 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1725 typedef typename __match::__type __type;
1728 // Utility for finding the unsigned versions of signed integral types.
1729 template<typename _Tp>
1730 struct __make_unsigned
1731 { typedef _Tp __type; };
1734 struct __make_unsigned<char>
1735 { typedef unsigned char __type; };
1738 struct __make_unsigned<signed char>
1739 { typedef unsigned char __type; };
1742 struct __make_unsigned<short>
1743 { typedef unsigned short __type; };
1746 struct __make_unsigned<int>
1747 { typedef unsigned int __type; };
1750 struct __make_unsigned<long>
1751 { typedef unsigned long __type; };
1754 struct __make_unsigned<long long>
1755 { typedef unsigned long long __type; };
1757 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1759 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1763 #if defined(__GLIBCXX_TYPE_INT_N_0)
1765 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1766 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1768 #if defined(__GLIBCXX_TYPE_INT_N_1)
1770 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1771 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1773 #if defined(__GLIBCXX_TYPE_INT_N_2)
1775 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1776 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1778 #if defined(__GLIBCXX_TYPE_INT_N_3)
1780 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1781 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
1784 // Select between integral and enum: not possible to be both.
1785 template<typename _Tp,
1786 bool _IsInt = is_integral<_Tp>::value,
1787 bool _IsEnum = is_enum<_Tp>::value>
1788 class __make_unsigned_selector;
1790 template<typename _Tp>
1791 class __make_unsigned_selector<_Tp, true, false>
1793 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1794 typedef typename __unsignedt::__type __unsigned_type;
1795 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1798 typedef typename __cv_unsigned::__type __type;
1801 template<typename _Tp>
1802 class __make_unsigned_selector<_Tp, false, true>
1804 // With -fshort-enums, an enum may be as small as a char.
1805 typedef unsigned char __smallest;
1806 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1807 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1808 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1809 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long);
1810 typedef conditional<__b3, unsigned long, unsigned long long> __cond3;
1811 typedef typename __cond3::type __cond3_type;
1812 typedef conditional<__b2, unsigned int, __cond3_type> __cond2;
1813 typedef typename __cond2::type __cond2_type;
1814 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1815 typedef typename __cond1::type __cond1_type;
1817 typedef typename conditional<__b0, __smallest, __cond1_type>::type
1819 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1822 typedef typename __cv_unsigned::__type __type;
1825 // Given an integral/enum type, return the corresponding unsigned
1827 // Primary template.
1829 template<typename _Tp>
1830 struct make_unsigned
1831 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1833 // Integral, but don't define.
1835 struct make_unsigned<bool>;
1838 // Utility for finding the signed versions of unsigned integral types.
1839 template<typename _Tp>
1840 struct __make_signed
1841 { typedef _Tp __type; };
1844 struct __make_signed<char>
1845 { typedef signed char __type; };
1848 struct __make_signed<unsigned char>
1849 { typedef signed char __type; };
1852 struct __make_signed<unsigned short>
1853 { typedef signed short __type; };
1856 struct __make_signed<unsigned int>
1857 { typedef signed int __type; };
1860 struct __make_signed<unsigned long>
1861 { typedef signed long __type; };
1864 struct __make_signed<unsigned long long>
1865 { typedef signed long long __type; };
1867 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1869 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1873 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1875 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1878 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1882 #if defined(__GLIBCXX_TYPE_INT_N_0)
1884 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1885 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1887 #if defined(__GLIBCXX_TYPE_INT_N_1)
1889 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1890 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1892 #if defined(__GLIBCXX_TYPE_INT_N_2)
1894 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1895 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1897 #if defined(__GLIBCXX_TYPE_INT_N_3)
1899 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1900 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
1903 // Select between integral and enum: not possible to be both.
1904 template<typename _Tp,
1905 bool _IsInt = is_integral<_Tp>::value,
1906 bool _IsEnum = is_enum<_Tp>::value>
1907 class __make_signed_selector;
1909 template<typename _Tp>
1910 class __make_signed_selector<_Tp, true, false>
1912 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1913 typedef typename __signedt::__type __signed_type;
1914 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1917 typedef typename __cv_signed::__type __type;
1920 template<typename _Tp>
1921 class __make_signed_selector<_Tp, false, true>
1923 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type;
1926 typedef typename __make_signed_selector<__unsigned_type>::__type __type;
1929 // Given an integral/enum type, return the corresponding signed
1931 // Primary template.
1933 template<typename _Tp>
1935 { typedef typename __make_signed_selector<_Tp>::__type type; };
1937 // Integral, but don't define.
1939 struct make_signed<bool>;
1941 #if __cplusplus > 201103L
1942 /// Alias template for make_signed
1943 template<typename _Tp>
1944 using make_signed_t = typename make_signed<_Tp>::type;
1946 /// Alias template for make_unsigned
1947 template<typename _Tp>
1948 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1951 // Array modifications.
1954 template<typename _Tp>
1955 struct remove_extent
1956 { typedef _Tp type; };
1958 template<typename _Tp, std::size_t _Size>
1959 struct remove_extent<_Tp[_Size]>
1960 { typedef _Tp type; };
1962 template<typename _Tp>
1963 struct remove_extent<_Tp[]>
1964 { typedef _Tp type; };
1966 /// remove_all_extents
1967 template<typename _Tp>
1968 struct remove_all_extents
1969 { typedef _Tp type; };
1971 template<typename _Tp, std::size_t _Size>
1972 struct remove_all_extents<_Tp[_Size]>
1973 { typedef typename remove_all_extents<_Tp>::type type; };
1975 template<typename _Tp>
1976 struct remove_all_extents<_Tp[]>
1977 { typedef typename remove_all_extents<_Tp>::type type; };
1979 #if __cplusplus > 201103L
1980 /// Alias template for remove_extent
1981 template<typename _Tp>
1982 using remove_extent_t = typename remove_extent<_Tp>::type;
1984 /// Alias template for remove_all_extents
1985 template<typename _Tp>
1986 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1989 // Pointer modifications.
1991 template<typename _Tp, typename>
1992 struct __remove_pointer_helper
1993 { typedef _Tp type; };
1995 template<typename _Tp, typename _Up>
1996 struct __remove_pointer_helper<_Tp, _Up*>
1997 { typedef _Up type; };
2000 template<typename _Tp>
2001 struct remove_pointer
2002 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
2006 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
2007 is_void<_Tp>>::value>
2008 struct __add_pointer_helper
2009 { typedef _Tp type; };
2011 template<typename _Tp>
2012 struct __add_pointer_helper<_Tp, true>
2013 { typedef typename remove_reference<_Tp>::type* type; };
2015 template<typename _Tp>
2017 : public __add_pointer_helper<_Tp>
2020 #if __cplusplus > 201103L
2021 /// Alias template for remove_pointer
2022 template<typename _Tp>
2023 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2025 /// Alias template for add_pointer
2026 template<typename _Tp>
2027 using add_pointer_t = typename add_pointer<_Tp>::type;
2030 template<std::size_t _Len>
2031 struct __aligned_storage_msa
2035 unsigned char __data[_Len];
2036 struct __attribute__((__aligned__)) { } __align;
2041 * @brief Alignment type.
2043 * The value of _Align is a default-alignment which shall be the
2044 * most stringent alignment requirement for any C++ object type
2045 * whose size is no greater than _Len (3.9). The member typedef
2046 * type shall be a POD type suitable for use as uninitialized
2047 * storage for any object whose size is at most _Len and whose
2048 * alignment is a divisor of _Align.
2050 template<std::size_t _Len, std::size_t _Align =
2051 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2052 struct aligned_storage
2056 unsigned char __data[_Len];
2057 struct __attribute__((__aligned__((_Align)))) { } __align;
2061 template <typename... _Types>
2062 struct __strictest_alignment
2064 static const size_t _S_alignment = 0;
2065 static const size_t _S_size = 0;
2068 template <typename _Tp, typename... _Types>
2069 struct __strictest_alignment<_Tp, _Types...>
2071 static const size_t _S_alignment =
2072 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2073 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2074 static const size_t _S_size =
2075 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2076 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2080 * @brief Provide aligned storage for types.
2082 * [meta.trans.other]
2084 * Provides aligned storage for any of the provided types of at
2087 * @see aligned_storage
2089 template <size_t _Len, typename... _Types>
2090 struct aligned_union
2093 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2095 using __strictest = __strictest_alignment<_Types...>;
2096 static const size_t _S_len = _Len > __strictest::_S_size
2097 ? _Len : __strictest::_S_size;
2099 /// The value of the strictest alignment of _Types.
2100 static const size_t alignment_value = __strictest::_S_alignment;
2102 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2105 template <size_t _Len, typename... _Types>
2106 const size_t aligned_union<_Len, _Types...>::alignment_value;
2108 // Decay trait for arrays and functions, used for perfect forwarding
2109 // in make_pair, make_tuple, etc.
2110 template<typename _Up,
2111 bool _IsArray = is_array<_Up>::value,
2112 bool _IsFunction = is_function<_Up>::value>
2113 struct __decay_selector;
2116 template<typename _Up>
2117 struct __decay_selector<_Up, false, false>
2118 { typedef typename remove_cv<_Up>::type __type; };
2120 template<typename _Up>
2121 struct __decay_selector<_Up, true, false>
2122 { typedef typename remove_extent<_Up>::type* __type; };
2124 template<typename _Up>
2125 struct __decay_selector<_Up, false, true>
2126 { typedef typename add_pointer<_Up>::type __type; };
2129 template<typename _Tp>
2132 typedef typename remove_reference<_Tp>::type __remove_type;
2135 typedef typename __decay_selector<__remove_type>::__type type;
2138 template<typename _Tp>
2139 class reference_wrapper;
2141 // Helper which adds a reference to a type when given a reference_wrapper
2142 template<typename _Tp>
2143 struct __strip_reference_wrapper
2148 template<typename _Tp>
2149 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2151 typedef _Tp& __type;
2154 template<typename _Tp>
2155 struct __decay_and_strip
2157 typedef typename __strip_reference_wrapper<
2158 typename decay<_Tp>::type>::__type __type;
2162 // Primary template.
2163 /// Define a member typedef @c type only if a boolean constant is true.
2164 template<bool, typename _Tp = void>
2168 // Partial specialization for true.
2169 template<typename _Tp>
2170 struct enable_if<true, _Tp>
2171 { typedef _Tp type; };
2173 template<typename... _Cond>
2174 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
2176 // Primary template.
2177 /// Define a member typedef @c type to one of two argument types.
2178 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2180 { typedef _Iftrue type; };
2182 // Partial specialization for false.
2183 template<typename _Iftrue, typename _Iffalse>
2184 struct conditional<false, _Iftrue, _Iffalse>
2185 { typedef _Iffalse type; };
2188 template<typename... _Tp>
2191 // Sfinae-friendly common_type implementation:
2193 struct __do_common_type_impl
2195 template<typename _Tp, typename _Up>
2196 static __success_type<typename decay<decltype
2197 (true ? std::declval<_Tp>()
2198 : std::declval<_Up>())>::type> _S_test(int);
2200 template<typename, typename>
2201 static __failure_type _S_test(...);
2204 template<typename _Tp, typename _Up>
2205 struct __common_type_impl
2206 : private __do_common_type_impl
2208 typedef decltype(_S_test<_Tp, _Up>(0)) type;
2211 struct __do_member_type_wrapper
2213 template<typename _Tp>
2214 static __success_type<typename _Tp::type> _S_test(int);
2217 static __failure_type _S_test(...);
2220 template<typename _Tp>
2221 struct __member_type_wrapper
2222 : private __do_member_type_wrapper
2224 typedef decltype(_S_test<_Tp>(0)) type;
2227 template<typename _CTp, typename... _Args>
2228 struct __expanded_common_type_wrapper
2230 typedef common_type<typename _CTp::type, _Args...> type;
2233 template<typename... _Args>
2234 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2235 { typedef __failure_type type; };
2237 template<typename _Tp>
2238 struct common_type<_Tp>
2239 { typedef typename decay<_Tp>::type type; };
2241 template<typename _Tp, typename _Up>
2242 struct common_type<_Tp, _Up>
2243 : public __common_type_impl<_Tp, _Up>::type
2246 template<typename _Tp, typename _Up, typename... _Vp>
2247 struct common_type<_Tp, _Up, _Vp...>
2248 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2249 common_type<_Tp, _Up>>::type, _Vp...>::type
2252 /// The underlying type of an enum.
2253 template<typename _Tp>
2254 struct underlying_type
2256 typedef __underlying_type(_Tp) type;
2259 template<typename _Tp>
2260 struct __declval_protector
2262 static const bool __stop = false;
2263 static typename add_rvalue_reference<_Tp>::type __delegate();
2266 template<typename _Tp>
2267 inline typename add_rvalue_reference<_Tp>::type
2270 static_assert(__declval_protector<_Tp>::__stop,
2271 "declval() must not be used!");
2272 return __declval_protector<_Tp>::__delegate();
2276 template<typename _Signature>
2279 // Sfinae-friendly result_of implementation:
2281 #define __cpp_lib_result_of_sfinae 201210
2283 struct __invoke_memfun_ref { };
2284 struct __invoke_memfun_deref { };
2285 struct __invoke_memobj_ref { };
2286 struct __invoke_memobj_deref { };
2287 struct __invoke_other { };
2289 // Associate a tag type with a specialization of __success_type.
2290 template<typename _Tp, typename _Tag>
2291 struct __result_of_success : __success_type<_Tp>
2292 { using __invoke_type = _Tag; };
2294 // [func.require] paragraph 1 bullet 1:
2295 struct __result_of_memfun_ref_impl
2297 template<typename _Fp, typename _Tp1, typename... _Args>
2298 static __result_of_success<decltype(
2299 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2300 ), __invoke_memfun_ref> _S_test(int);
2302 template<typename...>
2303 static __failure_type _S_test(...);
2306 template<typename _MemPtr, typename _Arg, typename... _Args>
2307 struct __result_of_memfun_ref
2308 : private __result_of_memfun_ref_impl
2310 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2313 // [func.require] paragraph 1 bullet 2:
2314 struct __result_of_memfun_deref_impl
2316 template<typename _Fp, typename _Tp1, typename... _Args>
2317 static __result_of_success<decltype(
2318 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2319 ), __invoke_memfun_deref> _S_test(int);
2321 template<typename...>
2322 static __failure_type _S_test(...);
2325 template<typename _MemPtr, typename _Arg, typename... _Args>
2326 struct __result_of_memfun_deref
2327 : private __result_of_memfun_deref_impl
2329 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2332 // [func.require] paragraph 1 bullet 3:
2333 struct __result_of_memobj_ref_impl
2335 template<typename _Fp, typename _Tp1>
2336 static __result_of_success<decltype(
2337 std::declval<_Tp1>().*std::declval<_Fp>()
2338 ), __invoke_memobj_ref> _S_test(int);
2340 template<typename, typename>
2341 static __failure_type _S_test(...);
2344 template<typename _MemPtr, typename _Arg>
2345 struct __result_of_memobj_ref
2346 : private __result_of_memobj_ref_impl
2348 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2351 // [func.require] paragraph 1 bullet 4:
2352 struct __result_of_memobj_deref_impl
2354 template<typename _Fp, typename _Tp1>
2355 static __result_of_success<decltype(
2356 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2357 ), __invoke_memobj_deref> _S_test(int);
2359 template<typename, typename>
2360 static __failure_type _S_test(...);
2363 template<typename _MemPtr, typename _Arg>
2364 struct __result_of_memobj_deref
2365 : private __result_of_memobj_deref_impl
2367 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2370 template<typename _MemPtr, typename _Arg>
2371 struct __result_of_memobj;
2373 template<typename _Res, typename _Class, typename _Arg>
2374 struct __result_of_memobj<_Res _Class::*, _Arg>
2376 typedef typename remove_cv<typename remove_reference<
2377 _Arg>::type>::type _Argval;
2378 typedef _Res _Class::* _MemPtr;
2379 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2380 is_base_of<_Class, _Argval>>::value,
2381 __result_of_memobj_ref<_MemPtr, _Arg>,
2382 __result_of_memobj_deref<_MemPtr, _Arg>
2386 template<typename _MemPtr, typename _Arg, typename... _Args>
2387 struct __result_of_memfun;
2389 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2390 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2392 typedef typename remove_cv<typename remove_reference<
2393 _Arg>::type>::type _Argval;
2394 typedef _Res _Class::* _MemPtr;
2395 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2396 is_base_of<_Class, _Argval>>::value,
2397 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2398 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2402 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2403 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2404 // as the object expression
2406 template<typename _Res, typename _Class, typename _Arg>
2407 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>>
2408 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2411 template<typename _Res, typename _Class, typename _Arg>
2412 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&>
2413 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2416 template<typename _Res, typename _Class, typename _Arg>
2417 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&>
2418 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2421 template<typename _Res, typename _Class, typename _Arg>
2422 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&&>
2423 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2426 template<typename _Res, typename _Class, typename _Arg>
2427 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&&>
2428 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2431 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2432 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...>
2433 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2436 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2437 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&,
2439 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2442 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2443 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&,
2445 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2448 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2449 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&&,
2451 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2454 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2455 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&&,
2457 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2460 template<bool, bool, typename _Functor, typename... _ArgTypes>
2461 struct __result_of_impl
2463 typedef __failure_type type;
2466 template<typename _MemPtr, typename _Arg>
2467 struct __result_of_impl<true, false, _MemPtr, _Arg>
2468 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2471 template<typename _MemPtr, typename _Arg, typename... _Args>
2472 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2473 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2476 // [func.require] paragraph 1 bullet 5:
2477 struct __result_of_other_impl
2479 template<typename _Fn, typename... _Args>
2480 static __result_of_success<decltype(
2481 std::declval<_Fn>()(std::declval<_Args>()...)
2482 ), __invoke_other> _S_test(int);
2484 template<typename...>
2485 static __failure_type _S_test(...);
2488 template<typename _Functor, typename... _ArgTypes>
2489 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2490 : private __result_of_other_impl
2492 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2495 template<typename _Functor, typename... _ArgTypes>
2496 struct result_of<_Functor(_ArgTypes...)>
2497 : public __result_of_impl<
2498 is_member_object_pointer<
2499 typename remove_reference<_Functor>::type
2501 is_member_function_pointer<
2502 typename remove_reference<_Functor>::type
2504 _Functor, _ArgTypes...
2508 #if __cplusplus > 201103L
2509 /// Alias template for aligned_storage
2510 template<size_t _Len, size_t _Align =
2511 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2512 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2514 template <size_t _Len, typename... _Types>
2515 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2517 /// Alias template for decay
2518 template<typename _Tp>
2519 using decay_t = typename decay<_Tp>::type;
2521 /// Alias template for enable_if
2522 template<bool _Cond, typename _Tp = void>
2523 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2525 /// Alias template for conditional
2526 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2527 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2529 /// Alias template for common_type
2530 template<typename... _Tp>
2531 using common_type_t = typename common_type<_Tp...>::type;
2533 /// Alias template for underlying_type
2534 template<typename _Tp>
2535 using underlying_type_t = typename underlying_type<_Tp>::type;
2537 /// Alias template for result_of
2538 template<typename _Tp>
2539 using result_of_t = typename result_of<_Tp>::type;
2542 template<typename...> using __void_t = void;
2544 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2545 #define __cpp_lib_void_t 201411
2546 /// A metafunction that always yields void, used for detecting valid types.
2547 template<typename...> using void_t = void;
2550 /// Implementation of the detection idiom (negative case).
2551 template<typename _Default, typename _AlwaysVoid,
2552 template<typename...> class _Op, typename... _Args>
2555 using value_t = false_type;
2556 using type = _Default;
2559 /// Implementation of the detection idiom (positive case).
2560 template<typename _Default, template<typename...> class _Op,
2562 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2564 using value_t = true_type;
2565 using type = _Op<_Args...>;
2568 // Detect whether _Op<_Args...> is a valid type, use _Default if not.
2569 template<typename _Default, template<typename...> class _Op,
2571 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2573 // _Op<_Args...> if that is a valid type, otherwise _Default.
2574 template<typename _Default, template<typename...> class _Op,
2576 using __detected_or_t
2577 = typename __detected_or<_Default, _Op, _Args...>::type;
2579 // _Op<_Args...> if that is a valid type, otherwise _Default<_Args...>.
2580 template<template<typename...> class _Default,
2581 template<typename...> class _Op, typename... _Args>
2582 using __detected_or_t_ =
2583 __detected_or_t<_Default<_Args...>, _Op, _Args...>;
2585 /// @} group metaprogramming
2588 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2589 * member type _NTYPE.
2591 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2592 template<typename _Tp, typename = __void_t<>> \
2593 struct __has_##_NTYPE \
2596 template<typename _Tp> \
2597 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2601 template <typename _Tp>
2602 struct __is_swappable;
2604 template <typename _Tp>
2605 struct __is_nothrow_swappable;
2607 template<typename _Tp>
2609 typename enable_if<__and_<is_move_constructible<_Tp>,
2610 is_move_assignable<_Tp>>::value>::type
2612 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2613 is_nothrow_move_assignable<_Tp>>::value);
2615 template<typename _Tp, size_t _Nm>
2617 typename enable_if<__is_swappable<_Tp>::value>::type
2618 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2619 noexcept(__is_nothrow_swappable<_Tp>::value);
2621 namespace __swappable_details {
2624 struct __do_is_swappable_impl
2626 template<typename _Tp, typename
2627 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2628 static true_type __test(int);
2631 static false_type __test(...);
2634 struct __do_is_nothrow_swappable_impl
2636 template<typename _Tp>
2637 static __bool_constant<
2638 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2642 static false_type __test(...);
2647 template<typename _Tp>
2648 struct __is_swappable_impl
2649 : public __swappable_details::__do_is_swappable_impl
2651 typedef decltype(__test<_Tp>(0)) type;
2654 template<typename _Tp>
2655 struct __is_nothrow_swappable_impl
2656 : public __swappable_details::__do_is_nothrow_swappable_impl
2658 typedef decltype(__test<_Tp>(0)) type;
2661 template<typename _Tp>
2662 struct __is_swappable
2663 : public __is_swappable_impl<_Tp>::type
2666 template<typename _Tp>
2667 struct __is_nothrow_swappable
2668 : public __is_nothrow_swappable_impl<_Tp>::type
2671 _GLIBCXX_END_NAMESPACE_VERSION
2676 #endif // _GLIBCXX_TYPE_TRAITS