1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2015 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 // Meta programming helper types.
97 template<bool, typename, typename>
100 template<typename...>
108 template<typename _B1>
113 template<typename _B1, typename _B2>
114 struct __or_<_B1, _B2>
115 : public conditional<_B1::value, _B1, _B2>::type
118 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
119 struct __or_<_B1, _B2, _B3, _Bn...>
120 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
123 template<typename...>
131 template<typename _B1>
136 template<typename _B1, typename _B2>
137 struct __and_<_B1, _B2>
138 : public conditional<_B1::value, _B2, _B1>::type
141 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
142 struct __and_<_B1, _B2, _B3, _Bn...>
143 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
146 template<typename _Pp>
148 : public integral_constant<bool, !_Pp::value>
151 // For several sfinae-friendly trait implementations we transport both the
152 // result information (as the member type) and the failure information (no
153 // member type). This is very similar to std::enable_if, but we cannot use
154 // them, because we need to derive from them as an implementation detail.
156 template<typename _Tp>
157 struct __success_type
158 { typedef _Tp type; };
160 struct __failure_type
163 // Primary type categories.
169 struct __is_void_helper
170 : public false_type { };
173 struct __is_void_helper<void>
174 : public true_type { };
177 template<typename _Tp>
179 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
183 struct __is_integral_helper
184 : public false_type { };
187 struct __is_integral_helper<bool>
188 : public true_type { };
191 struct __is_integral_helper<char>
192 : public true_type { };
195 struct __is_integral_helper<signed char>
196 : public true_type { };
199 struct __is_integral_helper<unsigned char>
200 : public true_type { };
202 #ifdef _GLIBCXX_USE_WCHAR_T
204 struct __is_integral_helper<wchar_t>
205 : public true_type { };
209 struct __is_integral_helper<char16_t>
210 : public true_type { };
213 struct __is_integral_helper<char32_t>
214 : public true_type { };
217 struct __is_integral_helper<short>
218 : public true_type { };
221 struct __is_integral_helper<unsigned short>
222 : public true_type { };
225 struct __is_integral_helper<int>
226 : public true_type { };
229 struct __is_integral_helper<unsigned int>
230 : public true_type { };
233 struct __is_integral_helper<long>
234 : public true_type { };
237 struct __is_integral_helper<unsigned long>
238 : public true_type { };
241 struct __is_integral_helper<long long>
242 : public true_type { };
245 struct __is_integral_helper<unsigned long long>
246 : public true_type { };
248 // Conditionalizing on __STRICT_ANSI__ here will break any port that
249 // uses one of these types for size_t.
250 #if defined(__GLIBCXX_TYPE_INT_N_0)
252 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
253 : public true_type { };
256 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
257 : public true_type { };
259 #if defined(__GLIBCXX_TYPE_INT_N_1)
261 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
262 : public true_type { };
265 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
266 : public true_type { };
268 #if defined(__GLIBCXX_TYPE_INT_N_2)
270 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
271 : public true_type { };
274 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
275 : public true_type { };
277 #if defined(__GLIBCXX_TYPE_INT_N_3)
279 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
280 : public true_type { };
283 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
284 : public true_type { };
288 template<typename _Tp>
290 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
294 struct __is_floating_point_helper
295 : public false_type { };
298 struct __is_floating_point_helper<float>
299 : public true_type { };
302 struct __is_floating_point_helper<double>
303 : public true_type { };
306 struct __is_floating_point_helper<long double>
307 : public true_type { };
309 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
311 struct __is_floating_point_helper<__float128>
312 : public true_type { };
315 /// is_floating_point
316 template<typename _Tp>
317 struct is_floating_point
318 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
324 : public false_type { };
326 template<typename _Tp, std::size_t _Size>
327 struct is_array<_Tp[_Size]>
328 : public true_type { };
330 template<typename _Tp>
331 struct is_array<_Tp[]>
332 : public true_type { };
335 struct __is_pointer_helper
336 : public false_type { };
338 template<typename _Tp>
339 struct __is_pointer_helper<_Tp*>
340 : public true_type { };
343 template<typename _Tp>
345 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
348 /// is_lvalue_reference
350 struct is_lvalue_reference
351 : public false_type { };
353 template<typename _Tp>
354 struct is_lvalue_reference<_Tp&>
355 : public true_type { };
357 /// is_rvalue_reference
359 struct is_rvalue_reference
360 : public false_type { };
362 template<typename _Tp>
363 struct is_rvalue_reference<_Tp&&>
364 : public true_type { };
370 struct __is_member_object_pointer_helper
371 : public false_type { };
373 template<typename _Tp, typename _Cp>
374 struct __is_member_object_pointer_helper<_Tp _Cp::*>
375 : public integral_constant<bool, !is_function<_Tp>::value> { };
377 /// is_member_object_pointer
378 template<typename _Tp>
379 struct is_member_object_pointer
380 : public __is_member_object_pointer_helper<
381 typename remove_cv<_Tp>::type>::type
385 struct __is_member_function_pointer_helper
386 : public false_type { };
388 template<typename _Tp, typename _Cp>
389 struct __is_member_function_pointer_helper<_Tp _Cp::*>
390 : public integral_constant<bool, is_function<_Tp>::value> { };
392 /// is_member_function_pointer
393 template<typename _Tp>
394 struct is_member_function_pointer
395 : public __is_member_function_pointer_helper<
396 typename remove_cv<_Tp>::type>::type
400 template<typename _Tp>
402 : public integral_constant<bool, __is_enum(_Tp)>
406 template<typename _Tp>
408 : public integral_constant<bool, __is_union(_Tp)>
412 template<typename _Tp>
414 : public integral_constant<bool, __is_class(_Tp)>
420 : public false_type { };
422 template<typename _Res, typename... _ArgTypes>
423 struct is_function<_Res(_ArgTypes...)>
424 : public true_type { };
426 template<typename _Res, typename... _ArgTypes>
427 struct is_function<_Res(_ArgTypes...) &>
428 : public true_type { };
430 template<typename _Res, typename... _ArgTypes>
431 struct is_function<_Res(_ArgTypes...) &&>
432 : public true_type { };
434 template<typename _Res, typename... _ArgTypes>
435 struct is_function<_Res(_ArgTypes......)>
436 : public true_type { };
438 template<typename _Res, typename... _ArgTypes>
439 struct is_function<_Res(_ArgTypes......) &>
440 : public true_type { };
442 template<typename _Res, typename... _ArgTypes>
443 struct is_function<_Res(_ArgTypes......) &&>
444 : public true_type { };
446 template<typename _Res, typename... _ArgTypes>
447 struct is_function<_Res(_ArgTypes...) const>
448 : public true_type { };
450 template<typename _Res, typename... _ArgTypes>
451 struct is_function<_Res(_ArgTypes...) const &>
452 : public true_type { };
454 template<typename _Res, typename... _ArgTypes>
455 struct is_function<_Res(_ArgTypes...) const &&>
456 : public true_type { };
458 template<typename _Res, typename... _ArgTypes>
459 struct is_function<_Res(_ArgTypes......) const>
460 : public true_type { };
462 template<typename _Res, typename... _ArgTypes>
463 struct is_function<_Res(_ArgTypes......) const &>
464 : public true_type { };
466 template<typename _Res, typename... _ArgTypes>
467 struct is_function<_Res(_ArgTypes......) const &&>
468 : public true_type { };
470 template<typename _Res, typename... _ArgTypes>
471 struct is_function<_Res(_ArgTypes...) volatile>
472 : public true_type { };
474 template<typename _Res, typename... _ArgTypes>
475 struct is_function<_Res(_ArgTypes...) volatile &>
476 : public true_type { };
478 template<typename _Res, typename... _ArgTypes>
479 struct is_function<_Res(_ArgTypes...) volatile &&>
480 : public true_type { };
482 template<typename _Res, typename... _ArgTypes>
483 struct is_function<_Res(_ArgTypes......) volatile>
484 : public true_type { };
486 template<typename _Res, typename... _ArgTypes>
487 struct is_function<_Res(_ArgTypes......) volatile &>
488 : public true_type { };
490 template<typename _Res, typename... _ArgTypes>
491 struct is_function<_Res(_ArgTypes......) volatile &&>
492 : public true_type { };
494 template<typename _Res, typename... _ArgTypes>
495 struct is_function<_Res(_ArgTypes...) const volatile>
496 : public true_type { };
498 template<typename _Res, typename... _ArgTypes>
499 struct is_function<_Res(_ArgTypes...) const volatile &>
500 : public true_type { };
502 template<typename _Res, typename... _ArgTypes>
503 struct is_function<_Res(_ArgTypes...) const volatile &&>
504 : public true_type { };
506 template<typename _Res, typename... _ArgTypes>
507 struct is_function<_Res(_ArgTypes......) const volatile>
508 : public true_type { };
510 template<typename _Res, typename... _ArgTypes>
511 struct is_function<_Res(_ArgTypes......) const volatile &>
512 : public true_type { };
514 template<typename _Res, typename... _ArgTypes>
515 struct is_function<_Res(_ArgTypes......) const volatile &&>
516 : public true_type { };
518 #define __cpp_lib_is_null_pointer 201309
521 struct __is_null_pointer_helper
522 : public false_type { };
525 struct __is_null_pointer_helper<std::nullptr_t>
526 : public true_type { };
528 /// is_null_pointer (LWG 2247).
529 template<typename _Tp>
530 struct is_null_pointer
531 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
534 /// __is_nullptr_t (extension).
535 template<typename _Tp>
536 struct __is_nullptr_t
537 : public is_null_pointer<_Tp>
540 // Composite type categories.
543 template<typename _Tp>
545 : public __or_<is_lvalue_reference<_Tp>,
546 is_rvalue_reference<_Tp>>::type
550 template<typename _Tp>
552 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
556 template<typename _Tp>
557 struct is_fundamental
558 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
559 is_null_pointer<_Tp>>::type
563 template<typename _Tp>
565 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
570 struct is_member_pointer;
573 template<typename _Tp>
575 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
576 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
580 template<typename _Tp>
582 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
584 template<typename _Tp>
585 struct __is_member_pointer_helper
586 : public false_type { };
588 template<typename _Tp, typename _Cp>
589 struct __is_member_pointer_helper<_Tp _Cp::*>
590 : public true_type { };
592 /// is_member_pointer
593 template<typename _Tp>
594 struct is_member_pointer
595 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
598 // Utility to detect referenceable types ([defns.referenceable]).
600 template<typename _Tp>
601 struct __is_referenceable
602 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
605 template<typename _Res, typename... _Args>
606 struct __is_referenceable<_Res(_Args...)>
610 template<typename _Res, typename... _Args>
611 struct __is_referenceable<_Res(_Args......)>
620 : public false_type { };
622 template<typename _Tp>
623 struct is_const<_Tp const>
624 : public true_type { };
629 : public false_type { };
631 template<typename _Tp>
632 struct is_volatile<_Tp volatile>
633 : public true_type { };
636 template<typename _Tp>
638 : public integral_constant<bool, __is_trivial(_Tp)>
641 // is_trivially_copyable
642 template<typename _Tp>
643 struct is_trivially_copyable
644 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
647 /// is_standard_layout
648 template<typename _Tp>
649 struct is_standard_layout
650 : public integral_constant<bool, __is_standard_layout(_Tp)>
654 // Could use is_standard_layout && is_trivial instead of the builtin.
655 template<typename _Tp>
657 : public integral_constant<bool, __is_pod(_Tp)>
661 template<typename _Tp>
662 struct is_literal_type
663 : public integral_constant<bool, __is_literal_type(_Tp)>
667 template<typename _Tp>
669 : public integral_constant<bool, __is_empty(_Tp)>
673 template<typename _Tp>
674 struct is_polymorphic
675 : public integral_constant<bool, __is_polymorphic(_Tp)>
678 #if __cplusplus >= 201402L
679 #define __cpp_lib_is_final 201402L
681 template<typename _Tp>
683 : public integral_constant<bool, __is_final(_Tp)>
688 template<typename _Tp>
690 : public integral_constant<bool, __is_abstract(_Tp)>
693 template<typename _Tp,
694 bool = is_arithmetic<_Tp>::value>
695 struct __is_signed_helper
696 : public false_type { };
698 template<typename _Tp>
699 struct __is_signed_helper<_Tp, true>
700 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
704 template<typename _Tp>
706 : public __is_signed_helper<_Tp>::type
710 template<typename _Tp>
712 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
716 // Destructible and constructible type properties.
719 struct add_rvalue_reference;
722 * @brief Utility to simplify expressions used in unevaluated operands
725 template<typename _Tp>
726 typename add_rvalue_reference<_Tp>::type declval() noexcept;
728 template<typename, unsigned = 0>
732 struct remove_all_extents;
734 template<typename _Tp>
735 struct __is_array_known_bounds
736 : public integral_constant<bool, (extent<_Tp>::value > 0)>
739 template<typename _Tp>
740 struct __is_array_unknown_bounds
741 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
744 // In N3290 is_destructible does not say anything about function
745 // types and abstract types, see LWG 2049. This implementation
746 // describes function types as non-destructible and all complete
747 // object types as destructible, iff the explicit destructor
748 // call expression is wellformed.
749 struct __do_is_destructible_impl
751 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
752 static true_type __test(int);
755 static false_type __test(...);
758 template<typename _Tp>
759 struct __is_destructible_impl
760 : public __do_is_destructible_impl
762 typedef decltype(__test<_Tp>(0)) type;
765 template<typename _Tp,
766 bool = __or_<is_void<_Tp>,
767 __is_array_unknown_bounds<_Tp>,
768 is_function<_Tp>>::value,
769 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
770 struct __is_destructible_safe;
772 template<typename _Tp>
773 struct __is_destructible_safe<_Tp, false, false>
774 : public __is_destructible_impl<typename
775 remove_all_extents<_Tp>::type>::type
778 template<typename _Tp>
779 struct __is_destructible_safe<_Tp, true, false>
780 : public false_type { };
782 template<typename _Tp>
783 struct __is_destructible_safe<_Tp, false, true>
784 : public true_type { };
787 template<typename _Tp>
788 struct is_destructible
789 : public __is_destructible_safe<_Tp>::type
792 // is_nothrow_destructible requires that is_destructible is
793 // satisfied as well. We realize that by mimicing the
794 // implementation of is_destructible but refer to noexcept(expr)
795 // instead of decltype(expr).
796 struct __do_is_nt_destructible_impl
798 template<typename _Tp>
799 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
803 static false_type __test(...);
806 template<typename _Tp>
807 struct __is_nt_destructible_impl
808 : public __do_is_nt_destructible_impl
810 typedef decltype(__test<_Tp>(0)) type;
813 template<typename _Tp,
814 bool = __or_<is_void<_Tp>,
815 __is_array_unknown_bounds<_Tp>,
816 is_function<_Tp>>::value,
817 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
818 struct __is_nt_destructible_safe;
820 template<typename _Tp>
821 struct __is_nt_destructible_safe<_Tp, false, false>
822 : public __is_nt_destructible_impl<typename
823 remove_all_extents<_Tp>::type>::type
826 template<typename _Tp>
827 struct __is_nt_destructible_safe<_Tp, true, false>
828 : public false_type { };
830 template<typename _Tp>
831 struct __is_nt_destructible_safe<_Tp, false, true>
832 : public true_type { };
834 /// is_nothrow_destructible
835 template<typename _Tp>
836 struct is_nothrow_destructible
837 : public __is_nt_destructible_safe<_Tp>::type
840 struct __do_is_default_constructible_impl
842 template<typename _Tp, typename = decltype(_Tp())>
843 static true_type __test(int);
846 static false_type __test(...);
849 template<typename _Tp>
850 struct __is_default_constructible_impl
851 : public __do_is_default_constructible_impl
853 typedef decltype(__test<_Tp>(0)) type;
856 template<typename _Tp>
857 struct __is_default_constructible_atom
858 : public __and_<__not_<is_void<_Tp>>,
859 __is_default_constructible_impl<_Tp>>::type
862 template<typename _Tp, bool = is_array<_Tp>::value>
863 struct __is_default_constructible_safe;
865 // The following technique is a workaround for a current core language
866 // restriction, which does not allow for array types to occur in
867 // functional casts of the form T(). Complete arrays can be default-
868 // constructed, if the element type is default-constructible, but
869 // arrays with unknown bounds are not.
870 template<typename _Tp>
871 struct __is_default_constructible_safe<_Tp, true>
872 : public __and_<__is_array_known_bounds<_Tp>,
873 __is_default_constructible_atom<typename
874 remove_all_extents<_Tp>::type>>::type
877 template<typename _Tp>
878 struct __is_default_constructible_safe<_Tp, false>
879 : public __is_default_constructible_atom<_Tp>::type
882 /// is_default_constructible
883 template<typename _Tp>
884 struct is_default_constructible
885 : public __is_default_constructible_safe<_Tp>::type
889 // Implementation of is_constructible.
891 // The hardest part of this trait is the binary direct-initialization
892 // case, because we hit into a functional cast of the form T(arg).
893 // This implementation uses different strategies depending on the
894 // target type to reduce the test overhead as much as possible:
896 // a) For a reference target type, we use a static_cast expression
897 // modulo its extra cases.
899 // b) For a non-reference target type we use a ::new expression.
900 struct __do_is_static_castable_impl
902 template<typename _From, typename _To, typename
903 = decltype(static_cast<_To>(declval<_From>()))>
904 static true_type __test(int);
906 template<typename, typename>
907 static false_type __test(...);
910 template<typename _From, typename _To>
911 struct __is_static_castable_impl
912 : public __do_is_static_castable_impl
914 typedef decltype(__test<_From, _To>(0)) type;
917 template<typename _From, typename _To>
918 struct __is_static_castable_safe
919 : public __is_static_castable_impl<_From, _To>::type
922 // __is_static_castable
923 template<typename _From, typename _To>
924 struct __is_static_castable
925 : public integral_constant<bool, (__is_static_castable_safe<
929 // Implementation for non-reference types. To meet the proper
930 // variable definition semantics, we also need to test for
931 // is_destructible in this case.
932 // This form should be simplified by a single expression:
933 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
934 struct __do_is_direct_constructible_impl
936 template<typename _Tp, typename _Arg, typename
937 = decltype(::new _Tp(declval<_Arg>()))>
938 static true_type __test(int);
940 template<typename, typename>
941 static false_type __test(...);
944 template<typename _Tp, typename _Arg>
945 struct __is_direct_constructible_impl
946 : public __do_is_direct_constructible_impl
948 typedef decltype(__test<_Tp, _Arg>(0)) type;
951 template<typename _Tp, typename _Arg>
952 struct __is_direct_constructible_new_safe
953 : public __and_<is_destructible<_Tp>,
954 __is_direct_constructible_impl<_Tp, _Arg>>::type
957 template<typename, typename>
960 template<typename, typename>
964 struct remove_reference;
966 template<typename _From, typename _To, bool
967 = __not_<__or_<is_void<_From>,
968 is_function<_From>>>::value>
969 struct __is_base_to_derived_ref;
971 // Detect whether we have a downcast situation during
972 // reference binding.
973 template<typename _From, typename _To>
974 struct __is_base_to_derived_ref<_From, _To, true>
976 typedef typename remove_cv<typename remove_reference<_From
977 >::type>::type __src_t;
978 typedef typename remove_cv<typename remove_reference<_To
979 >::type>::type __dst_t;
980 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
981 is_base_of<__src_t, __dst_t>> type;
982 static constexpr bool value = type::value;
985 template<typename _From, typename _To>
986 struct __is_base_to_derived_ref<_From, _To, false>
990 template<typename _From, typename _To, bool
991 = __and_<is_lvalue_reference<_From>,
992 is_rvalue_reference<_To>>::value>
993 struct __is_lvalue_to_rvalue_ref;
995 // Detect whether we have an lvalue of non-function type
996 // bound to a reference-compatible rvalue-reference.
997 template<typename _From, typename _To>
998 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
1000 typedef typename remove_cv<typename remove_reference<
1001 _From>::type>::type __src_t;
1002 typedef typename remove_cv<typename remove_reference<
1003 _To>::type>::type __dst_t;
1004 typedef __and_<__not_<is_function<__src_t>>,
1005 __or_<is_same<__src_t, __dst_t>,
1006 is_base_of<__dst_t, __src_t>>> type;
1007 static constexpr bool value = type::value;
1010 template<typename _From, typename _To>
1011 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
1015 // Here we handle direct-initialization to a reference type as
1016 // equivalent to a static_cast modulo overshooting conversions.
1017 // These are restricted to the following conversions:
1018 // a) A base class value to a derived class reference
1019 // b) An lvalue to an rvalue-reference of reference-compatible
1020 // types that are not functions
1021 template<typename _Tp, typename _Arg>
1022 struct __is_direct_constructible_ref_cast
1023 : public __and_<__is_static_castable<_Arg, _Tp>,
1024 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
1025 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
1029 template<typename _Tp, typename _Arg>
1030 struct __is_direct_constructible_new
1031 : public conditional<is_reference<_Tp>::value,
1032 __is_direct_constructible_ref_cast<_Tp, _Arg>,
1033 __is_direct_constructible_new_safe<_Tp, _Arg>
1037 template<typename _Tp, typename _Arg>
1038 struct __is_direct_constructible
1039 : public __is_direct_constructible_new<_Tp, _Arg>::type
1042 // Since default-construction and binary direct-initialization have
1043 // been handled separately, the implementation of the remaining
1044 // n-ary construction cases is rather straightforward. We can use
1045 // here a functional cast, because array types are excluded anyway
1046 // and this form is never interpreted as a C cast.
1047 struct __do_is_nary_constructible_impl
1049 template<typename _Tp, typename... _Args, typename
1050 = decltype(_Tp(declval<_Args>()...))>
1051 static true_type __test(int);
1053 template<typename, typename...>
1054 static false_type __test(...);
1057 template<typename _Tp, typename... _Args>
1058 struct __is_nary_constructible_impl
1059 : public __do_is_nary_constructible_impl
1061 typedef decltype(__test<_Tp, _Args...>(0)) type;
1064 template<typename _Tp, typename... _Args>
1065 struct __is_nary_constructible
1066 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1068 static_assert(sizeof...(_Args) > 1,
1069 "Only useful for > 1 arguments");
1072 template<typename _Tp, typename... _Args>
1073 struct __is_constructible_impl
1074 : public __is_nary_constructible<_Tp, _Args...>
1077 template<typename _Tp, typename _Arg>
1078 struct __is_constructible_impl<_Tp, _Arg>
1079 : public __is_direct_constructible<_Tp, _Arg>
1082 template<typename _Tp>
1083 struct __is_constructible_impl<_Tp>
1084 : public is_default_constructible<_Tp>
1087 /// is_constructible
1088 template<typename _Tp, typename... _Args>
1089 struct is_constructible
1090 : public __is_constructible_impl<_Tp, _Args...>::type
1093 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1094 struct __is_copy_constructible_impl;
1096 template<typename _Tp>
1097 struct __is_copy_constructible_impl<_Tp, false>
1098 : public false_type { };
1100 template<typename _Tp>
1101 struct __is_copy_constructible_impl<_Tp, true>
1102 : public is_constructible<_Tp, const _Tp&>
1105 /// is_copy_constructible
1106 template<typename _Tp>
1107 struct is_copy_constructible
1108 : public __is_copy_constructible_impl<_Tp>
1111 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1112 struct __is_move_constructible_impl;
1114 template<typename _Tp>
1115 struct __is_move_constructible_impl<_Tp, false>
1116 : public false_type { };
1118 template<typename _Tp>
1119 struct __is_move_constructible_impl<_Tp, true>
1120 : public is_constructible<_Tp, _Tp&&>
1123 /// is_move_constructible
1124 template<typename _Tp>
1125 struct is_move_constructible
1126 : public __is_move_constructible_impl<_Tp>
1129 template<typename _Tp>
1130 struct __is_nt_default_constructible_atom
1131 : public integral_constant<bool, noexcept(_Tp())>
1134 template<typename _Tp, bool = is_array<_Tp>::value>
1135 struct __is_nt_default_constructible_impl;
1137 template<typename _Tp>
1138 struct __is_nt_default_constructible_impl<_Tp, true>
1139 : public __and_<__is_array_known_bounds<_Tp>,
1140 __is_nt_default_constructible_atom<typename
1141 remove_all_extents<_Tp>::type>>::type
1144 template<typename _Tp>
1145 struct __is_nt_default_constructible_impl<_Tp, false>
1146 : public __is_nt_default_constructible_atom<_Tp>
1149 /// is_nothrow_default_constructible
1150 template<typename _Tp>
1151 struct is_nothrow_default_constructible
1152 : public __and_<is_default_constructible<_Tp>,
1153 __is_nt_default_constructible_impl<_Tp>>::type
1156 template<typename _Tp, typename... _Args>
1157 struct __is_nt_constructible_impl
1158 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1161 template<typename _Tp, typename _Arg>
1162 struct __is_nt_constructible_impl<_Tp, _Arg>
1163 : public integral_constant<bool,
1164 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1167 template<typename _Tp>
1168 struct __is_nt_constructible_impl<_Tp>
1169 : public is_nothrow_default_constructible<_Tp>
1172 /// is_nothrow_constructible
1173 template<typename _Tp, typename... _Args>
1174 struct is_nothrow_constructible
1175 : public __and_<is_constructible<_Tp, _Args...>,
1176 __is_nt_constructible_impl<_Tp, _Args...>>::type
1179 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1180 struct __is_nothrow_copy_constructible_impl;
1182 template<typename _Tp>
1183 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1184 : public false_type { };
1186 template<typename _Tp>
1187 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1188 : public is_nothrow_constructible<_Tp, const _Tp&>
1191 /// is_nothrow_copy_constructible
1192 template<typename _Tp>
1193 struct is_nothrow_copy_constructible
1194 : public __is_nothrow_copy_constructible_impl<_Tp>
1197 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1198 struct __is_nothrow_move_constructible_impl;
1200 template<typename _Tp>
1201 struct __is_nothrow_move_constructible_impl<_Tp, false>
1202 : public false_type { };
1204 template<typename _Tp>
1205 struct __is_nothrow_move_constructible_impl<_Tp, true>
1206 : public is_nothrow_constructible<_Tp, _Tp&&>
1209 /// is_nothrow_move_constructible
1210 template<typename _Tp>
1211 struct is_nothrow_move_constructible
1212 : public __is_nothrow_move_constructible_impl<_Tp>
1215 template<typename _Tp, typename _Up>
1216 class __is_assignable_helper
1218 template<typename _Tp1, typename _Up1,
1219 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1223 template<typename, typename>
1228 typedef decltype(__test<_Tp, _Up>(0)) type;
1232 template<typename _Tp, typename _Up>
1233 struct is_assignable
1234 : public __is_assignable_helper<_Tp, _Up>::type
1237 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1238 struct __is_copy_assignable_impl;
1240 template<typename _Tp>
1241 struct __is_copy_assignable_impl<_Tp, false>
1242 : public false_type { };
1244 template<typename _Tp>
1245 struct __is_copy_assignable_impl<_Tp, true>
1246 : public is_assignable<_Tp&, const _Tp&>
1249 /// is_copy_assignable
1250 template<typename _Tp>
1251 struct is_copy_assignable
1252 : public __is_copy_assignable_impl<_Tp>
1255 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1256 struct __is_move_assignable_impl;
1258 template<typename _Tp>
1259 struct __is_move_assignable_impl<_Tp, false>
1260 : public false_type { };
1262 template<typename _Tp>
1263 struct __is_move_assignable_impl<_Tp, true>
1264 : public is_assignable<_Tp&, _Tp&&>
1267 /// is_move_assignable
1268 template<typename _Tp>
1269 struct is_move_assignable
1270 : public __is_move_assignable_impl<_Tp>
1273 template<typename _Tp, typename _Up>
1274 struct __is_nt_assignable_impl
1275 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1278 /// is_nothrow_assignable
1279 template<typename _Tp, typename _Up>
1280 struct is_nothrow_assignable
1281 : public __and_<is_assignable<_Tp, _Up>,
1282 __is_nt_assignable_impl<_Tp, _Up>>::type
1285 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1286 struct __is_nt_copy_assignable_impl;
1288 template<typename _Tp>
1289 struct __is_nt_copy_assignable_impl<_Tp, false>
1290 : public false_type { };
1292 template<typename _Tp>
1293 struct __is_nt_copy_assignable_impl<_Tp, true>
1294 : public is_nothrow_assignable<_Tp&, const _Tp&>
1297 /// is_nothrow_copy_assignable
1298 template<typename _Tp>
1299 struct is_nothrow_copy_assignable
1300 : public __is_nt_copy_assignable_impl<_Tp>
1303 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1304 struct __is_nt_move_assignable_impl;
1306 template<typename _Tp>
1307 struct __is_nt_move_assignable_impl<_Tp, false>
1308 : public false_type { };
1310 template<typename _Tp>
1311 struct __is_nt_move_assignable_impl<_Tp, true>
1312 : public is_nothrow_assignable<_Tp&, _Tp&&>
1315 /// is_nothrow_move_assignable
1316 template<typename _Tp>
1317 struct is_nothrow_move_assignable
1318 : public __is_nt_move_assignable_impl<_Tp>
1321 /// is_trivially_constructible
1322 template<typename _Tp, typename... _Args>
1323 struct is_trivially_constructible
1324 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool,
1325 __is_trivially_constructible(_Tp, _Args...)>>::type
1328 /// is_trivially_default_constructible
1329 template<typename _Tp>
1330 struct is_trivially_default_constructible
1331 : public is_trivially_constructible<_Tp>::type
1334 /// is_trivially_copy_constructible
1335 template<typename _Tp>
1336 struct is_trivially_copy_constructible
1337 : public __and_<is_copy_constructible<_Tp>,
1338 integral_constant<bool,
1339 __is_trivially_constructible(_Tp, const _Tp&)>>::type
1342 /// is_trivially_move_constructible
1343 template<typename _Tp>
1344 struct is_trivially_move_constructible
1345 : public __and_<is_move_constructible<_Tp>,
1346 integral_constant<bool,
1347 __is_trivially_constructible(_Tp, _Tp&&)>>::type
1350 /// is_trivially_assignable
1351 template<typename _Tp, typename _Up>
1352 struct is_trivially_assignable
1353 : public __and_<is_assignable<_Tp, _Up>,
1354 integral_constant<bool,
1355 __is_trivially_assignable(_Tp, _Up)>>::type
1358 /// is_trivially_copy_assignable
1359 template<typename _Tp>
1360 struct is_trivially_copy_assignable
1361 : public __and_<is_copy_assignable<_Tp>,
1362 integral_constant<bool,
1363 __is_trivially_assignable(_Tp&, const _Tp&)>>::type
1366 /// is_trivially_move_assignable
1367 template<typename _Tp>
1368 struct is_trivially_move_assignable
1369 : public __and_<is_move_assignable<_Tp>,
1370 integral_constant<bool,
1371 __is_trivially_assignable(_Tp&, _Tp&&)>>::type
1374 /// is_trivially_destructible
1375 template<typename _Tp>
1376 struct is_trivially_destructible
1377 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1378 __has_trivial_destructor(_Tp)>>::type
1381 /// has_trivial_default_constructor (temporary legacy)
1382 template<typename _Tp>
1383 struct has_trivial_default_constructor
1384 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1385 { } _GLIBCXX_DEPRECATED;
1387 /// has_trivial_copy_constructor (temporary legacy)
1388 template<typename _Tp>
1389 struct has_trivial_copy_constructor
1390 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1391 { } _GLIBCXX_DEPRECATED;
1393 /// has_trivial_copy_assign (temporary legacy)
1394 template<typename _Tp>
1395 struct has_trivial_copy_assign
1396 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1397 { } _GLIBCXX_DEPRECATED;
1399 /// has_virtual_destructor
1400 template<typename _Tp>
1401 struct has_virtual_destructor
1402 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1406 // type property queries.
1409 template<typename _Tp>
1411 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1416 : public integral_constant<std::size_t, 0> { };
1418 template<typename _Tp, std::size_t _Size>
1419 struct rank<_Tp[_Size]>
1420 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1422 template<typename _Tp>
1424 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1427 template<typename, unsigned _Uint>
1429 : public integral_constant<std::size_t, 0> { };
1431 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1432 struct extent<_Tp[_Size], _Uint>
1433 : public integral_constant<std::size_t,
1434 _Uint == 0 ? _Size : extent<_Tp,
1438 template<typename _Tp, unsigned _Uint>
1439 struct extent<_Tp[], _Uint>
1440 : public integral_constant<std::size_t,
1441 _Uint == 0 ? 0 : extent<_Tp,
1449 template<typename, typename>
1451 : public false_type { };
1453 template<typename _Tp>
1454 struct is_same<_Tp, _Tp>
1455 : public true_type { };
1458 template<typename _Base, typename _Derived>
1460 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1463 template<typename _From, typename _To,
1464 bool = __or_<is_void<_From>, is_function<_To>,
1465 is_array<_To>>::value>
1466 struct __is_convertible_helper
1467 { typedef typename is_void<_To>::type type; };
1469 template<typename _From, typename _To>
1470 class __is_convertible_helper<_From, _To, false>
1472 template<typename _To1>
1473 static void __test_aux(_To1);
1475 template<typename _From1, typename _To1,
1476 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1480 template<typename, typename>
1485 typedef decltype(__test<_From, _To>(0)) type;
1490 template<typename _From, typename _To>
1491 struct is_convertible
1492 : public __is_convertible_helper<_From, _To>::type
1496 // Const-volatile modifications.
1499 template<typename _Tp>
1501 { typedef _Tp type; };
1503 template<typename _Tp>
1504 struct remove_const<_Tp const>
1505 { typedef _Tp type; };
1508 template<typename _Tp>
1509 struct remove_volatile
1510 { typedef _Tp type; };
1512 template<typename _Tp>
1513 struct remove_volatile<_Tp volatile>
1514 { typedef _Tp type; };
1517 template<typename _Tp>
1521 remove_const<typename remove_volatile<_Tp>::type>::type type;
1525 template<typename _Tp>
1527 { typedef _Tp const type; };
1530 template<typename _Tp>
1532 { typedef _Tp volatile type; };
1535 template<typename _Tp>
1539 add_const<typename add_volatile<_Tp>::type>::type type;
1542 #if __cplusplus > 201103L
1544 #define __cpp_lib_transformation_trait_aliases 201304
1546 /// Alias template for remove_const
1547 template<typename _Tp>
1548 using remove_const_t = typename remove_const<_Tp>::type;
1550 /// Alias template for remove_volatile
1551 template<typename _Tp>
1552 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1554 /// Alias template for remove_cv
1555 template<typename _Tp>
1556 using remove_cv_t = typename remove_cv<_Tp>::type;
1558 /// Alias template for add_const
1559 template<typename _Tp>
1560 using add_const_t = typename add_const<_Tp>::type;
1562 /// Alias template for add_volatile
1563 template<typename _Tp>
1564 using add_volatile_t = typename add_volatile<_Tp>::type;
1566 /// Alias template for add_cv
1567 template<typename _Tp>
1568 using add_cv_t = typename add_cv<_Tp>::type;
1571 // Reference transformations.
1573 /// remove_reference
1574 template<typename _Tp>
1575 struct remove_reference
1576 { typedef _Tp type; };
1578 template<typename _Tp>
1579 struct remove_reference<_Tp&>
1580 { typedef _Tp type; };
1582 template<typename _Tp>
1583 struct remove_reference<_Tp&&>
1584 { typedef _Tp type; };
1586 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1587 struct __add_lvalue_reference_helper
1588 { typedef _Tp type; };
1590 template<typename _Tp>
1591 struct __add_lvalue_reference_helper<_Tp, true>
1592 { typedef _Tp& type; };
1594 /// add_lvalue_reference
1595 template<typename _Tp>
1596 struct add_lvalue_reference
1597 : public __add_lvalue_reference_helper<_Tp>
1600 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1601 struct __add_rvalue_reference_helper
1602 { typedef _Tp type; };
1604 template<typename _Tp>
1605 struct __add_rvalue_reference_helper<_Tp, true>
1606 { typedef _Tp&& type; };
1608 /// add_rvalue_reference
1609 template<typename _Tp>
1610 struct add_rvalue_reference
1611 : public __add_rvalue_reference_helper<_Tp>
1614 #if __cplusplus > 201103L
1615 /// Alias template for remove_reference
1616 template<typename _Tp>
1617 using remove_reference_t = typename remove_reference<_Tp>::type;
1619 /// Alias template for add_lvalue_reference
1620 template<typename _Tp>
1621 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1623 /// Alias template for add_rvalue_reference
1624 template<typename _Tp>
1625 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1628 // Sign modifications.
1630 // Utility for constructing identically cv-qualified types.
1631 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1632 struct __cv_selector;
1634 template<typename _Unqualified>
1635 struct __cv_selector<_Unqualified, false, false>
1636 { typedef _Unqualified __type; };
1638 template<typename _Unqualified>
1639 struct __cv_selector<_Unqualified, false, true>
1640 { typedef volatile _Unqualified __type; };
1642 template<typename _Unqualified>
1643 struct __cv_selector<_Unqualified, true, false>
1644 { typedef const _Unqualified __type; };
1646 template<typename _Unqualified>
1647 struct __cv_selector<_Unqualified, true, true>
1648 { typedef const volatile _Unqualified __type; };
1650 template<typename _Qualified, typename _Unqualified,
1651 bool _IsConst = is_const<_Qualified>::value,
1652 bool _IsVol = is_volatile<_Qualified>::value>
1653 class __match_cv_qualifiers
1655 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1658 typedef typename __match::__type __type;
1661 // Utility for finding the unsigned versions of signed integral types.
1662 template<typename _Tp>
1663 struct __make_unsigned
1664 { typedef _Tp __type; };
1667 struct __make_unsigned<char>
1668 { typedef unsigned char __type; };
1671 struct __make_unsigned<signed char>
1672 { typedef unsigned char __type; };
1675 struct __make_unsigned<short>
1676 { typedef unsigned short __type; };
1679 struct __make_unsigned<int>
1680 { typedef unsigned int __type; };
1683 struct __make_unsigned<long>
1684 { typedef unsigned long __type; };
1687 struct __make_unsigned<long long>
1688 { typedef unsigned long long __type; };
1690 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1692 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1696 #if defined(__GLIBCXX_TYPE_INT_N_0)
1698 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1699 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1701 #if defined(__GLIBCXX_TYPE_INT_N_1)
1703 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1704 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1706 #if defined(__GLIBCXX_TYPE_INT_N_2)
1708 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1709 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1711 #if defined(__GLIBCXX_TYPE_INT_N_3)
1713 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1714 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
1717 // Select between integral and enum: not possible to be both.
1718 template<typename _Tp,
1719 bool _IsInt = is_integral<_Tp>::value,
1720 bool _IsEnum = is_enum<_Tp>::value>
1721 class __make_unsigned_selector;
1723 template<typename _Tp>
1724 class __make_unsigned_selector<_Tp, true, false>
1726 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1727 typedef typename __unsignedt::__type __unsigned_type;
1728 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1731 typedef typename __cv_unsigned::__type __type;
1734 template<typename _Tp>
1735 class __make_unsigned_selector<_Tp, false, true>
1737 // With -fshort-enums, an enum may be as small as a char.
1738 typedef unsigned char __smallest;
1739 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1740 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1741 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1742 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1743 typedef typename __cond2::type __cond2_type;
1744 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1745 typedef typename __cond1::type __cond1_type;
1748 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1751 // Given an integral/enum type, return the corresponding unsigned
1753 // Primary template.
1755 template<typename _Tp>
1756 struct make_unsigned
1757 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1759 // Integral, but don't define.
1761 struct make_unsigned<bool>;
1764 // Utility for finding the signed versions of unsigned integral types.
1765 template<typename _Tp>
1766 struct __make_signed
1767 { typedef _Tp __type; };
1770 struct __make_signed<char>
1771 { typedef signed char __type; };
1774 struct __make_signed<unsigned char>
1775 { typedef signed char __type; };
1778 struct __make_signed<unsigned short>
1779 { typedef signed short __type; };
1782 struct __make_signed<unsigned int>
1783 { typedef signed int __type; };
1786 struct __make_signed<unsigned long>
1787 { typedef signed long __type; };
1790 struct __make_signed<unsigned long long>
1791 { typedef signed long long __type; };
1793 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1795 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1799 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1801 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1804 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1808 #if defined(__GLIBCXX_TYPE_INT_N_0)
1810 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1811 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1813 #if defined(__GLIBCXX_TYPE_INT_N_1)
1815 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1816 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1818 #if defined(__GLIBCXX_TYPE_INT_N_2)
1820 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1821 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1823 #if defined(__GLIBCXX_TYPE_INT_N_3)
1825 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1826 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
1829 // Select between integral and enum: not possible to be both.
1830 template<typename _Tp,
1831 bool _IsInt = is_integral<_Tp>::value,
1832 bool _IsEnum = is_enum<_Tp>::value>
1833 class __make_signed_selector;
1835 template<typename _Tp>
1836 class __make_signed_selector<_Tp, true, false>
1838 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1839 typedef typename __signedt::__type __signed_type;
1840 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1843 typedef typename __cv_signed::__type __type;
1846 template<typename _Tp>
1847 class __make_signed_selector<_Tp, false, true>
1849 // With -fshort-enums, an enum may be as small as a char.
1850 typedef signed char __smallest;
1851 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1852 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1853 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1854 typedef conditional<__b2, signed int, signed long> __cond2;
1855 typedef typename __cond2::type __cond2_type;
1856 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1857 typedef typename __cond1::type __cond1_type;
1860 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1863 // Given an integral/enum type, return the corresponding signed
1865 // Primary template.
1867 template<typename _Tp>
1869 { typedef typename __make_signed_selector<_Tp>::__type type; };
1871 // Integral, but don't define.
1873 struct make_signed<bool>;
1875 #if __cplusplus > 201103L
1876 /// Alias template for make_signed
1877 template<typename _Tp>
1878 using make_signed_t = typename make_signed<_Tp>::type;
1880 /// Alias template for make_unsigned
1881 template<typename _Tp>
1882 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1885 // Array modifications.
1888 template<typename _Tp>
1889 struct remove_extent
1890 { typedef _Tp type; };
1892 template<typename _Tp, std::size_t _Size>
1893 struct remove_extent<_Tp[_Size]>
1894 { typedef _Tp type; };
1896 template<typename _Tp>
1897 struct remove_extent<_Tp[]>
1898 { typedef _Tp type; };
1900 /// remove_all_extents
1901 template<typename _Tp>
1902 struct remove_all_extents
1903 { typedef _Tp type; };
1905 template<typename _Tp, std::size_t _Size>
1906 struct remove_all_extents<_Tp[_Size]>
1907 { typedef typename remove_all_extents<_Tp>::type type; };
1909 template<typename _Tp>
1910 struct remove_all_extents<_Tp[]>
1911 { typedef typename remove_all_extents<_Tp>::type type; };
1913 #if __cplusplus > 201103L
1914 /// Alias template for remove_extent
1915 template<typename _Tp>
1916 using remove_extent_t = typename remove_extent<_Tp>::type;
1918 /// Alias template for remove_all_extents
1919 template<typename _Tp>
1920 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1923 // Pointer modifications.
1925 template<typename _Tp, typename>
1926 struct __remove_pointer_helper
1927 { typedef _Tp type; };
1929 template<typename _Tp, typename _Up>
1930 struct __remove_pointer_helper<_Tp, _Up*>
1931 { typedef _Up type; };
1934 template<typename _Tp>
1935 struct remove_pointer
1936 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1940 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1941 is_void<_Tp>>::value>
1942 struct __add_pointer_helper
1943 { typedef _Tp type; };
1945 template<typename _Tp>
1946 struct __add_pointer_helper<_Tp, true>
1947 { typedef typename remove_reference<_Tp>::type* type; };
1949 template<typename _Tp>
1951 : public __add_pointer_helper<_Tp>
1954 #if __cplusplus > 201103L
1955 /// Alias template for remove_pointer
1956 template<typename _Tp>
1957 using remove_pointer_t = typename remove_pointer<_Tp>::type;
1959 /// Alias template for add_pointer
1960 template<typename _Tp>
1961 using add_pointer_t = typename add_pointer<_Tp>::type;
1964 template<std::size_t _Len>
1965 struct __aligned_storage_msa
1969 unsigned char __data[_Len];
1970 struct __attribute__((__aligned__)) { } __align;
1975 * @brief Alignment type.
1977 * The value of _Align is a default-alignment which shall be the
1978 * most stringent alignment requirement for any C++ object type
1979 * whose size is no greater than _Len (3.9). The member typedef
1980 * type shall be a POD type suitable for use as uninitialized
1981 * storage for any object whose size is at most _Len and whose
1982 * alignment is a divisor of _Align.
1984 template<std::size_t _Len, std::size_t _Align =
1985 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1986 struct aligned_storage
1990 unsigned char __data[_Len];
1991 struct __attribute__((__aligned__((_Align)))) { } __align;
1995 template <typename... _Types>
1996 struct __strictest_alignment
1998 static const size_t _S_alignment = 0;
1999 static const size_t _S_size = 0;
2002 template <typename _Tp, typename... _Types>
2003 struct __strictest_alignment<_Tp, _Types...>
2005 static const size_t _S_alignment =
2006 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2007 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2008 static const size_t _S_size =
2009 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2010 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2014 * @brief Provide aligned storage for types.
2016 * [meta.trans.other]
2018 * Provides aligned storage for any of the provided types of at
2021 * @see aligned_storage
2023 template <size_t _Len, typename... _Types>
2024 struct aligned_union
2027 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2029 using __strictest = __strictest_alignment<_Types...>;
2030 static const size_t _S_len = _Len > __strictest::_S_size
2031 ? _Len : __strictest::_S_size;
2033 /// The value of the strictest alignment of _Types.
2034 static const size_t alignment_value = __strictest::_S_alignment;
2036 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2039 template <size_t _Len, typename... _Types>
2040 const size_t aligned_union<_Len, _Types...>::alignment_value;
2042 // Decay trait for arrays and functions, used for perfect forwarding
2043 // in make_pair, make_tuple, etc.
2044 template<typename _Up,
2045 bool _IsArray = is_array<_Up>::value,
2046 bool _IsFunction = is_function<_Up>::value>
2047 struct __decay_selector;
2050 template<typename _Up>
2051 struct __decay_selector<_Up, false, false>
2052 { typedef typename remove_cv<_Up>::type __type; };
2054 template<typename _Up>
2055 struct __decay_selector<_Up, true, false>
2056 { typedef typename remove_extent<_Up>::type* __type; };
2058 template<typename _Up>
2059 struct __decay_selector<_Up, false, true>
2060 { typedef typename add_pointer<_Up>::type __type; };
2063 template<typename _Tp>
2066 typedef typename remove_reference<_Tp>::type __remove_type;
2069 typedef typename __decay_selector<__remove_type>::__type type;
2072 template<typename _Tp>
2073 class reference_wrapper;
2075 // Helper which adds a reference to a type when given a reference_wrapper
2076 template<typename _Tp>
2077 struct __strip_reference_wrapper
2082 template<typename _Tp>
2083 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2085 typedef _Tp& __type;
2088 template<typename _Tp>
2089 struct __decay_and_strip
2091 typedef typename __strip_reference_wrapper<
2092 typename decay<_Tp>::type>::__type __type;
2096 // Primary template.
2097 /// Define a member typedef @c type only if a boolean constant is true.
2098 template<bool, typename _Tp = void>
2102 // Partial specialization for true.
2103 template<typename _Tp>
2104 struct enable_if<true, _Tp>
2105 { typedef _Tp type; };
2107 template<typename... _Cond>
2108 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
2110 // Primary template.
2111 /// Define a member typedef @c type to one of two argument types.
2112 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2114 { typedef _Iftrue type; };
2116 // Partial specialization for false.
2117 template<typename _Iftrue, typename _Iffalse>
2118 struct conditional<false, _Iftrue, _Iffalse>
2119 { typedef _Iffalse type; };
2122 template<typename... _Tp>
2125 // Sfinae-friendly common_type implementation:
2127 struct __do_common_type_impl
2129 template<typename _Tp, typename _Up>
2130 static __success_type<typename decay<decltype
2131 (true ? std::declval<_Tp>()
2132 : std::declval<_Up>())>::type> _S_test(int);
2134 template<typename, typename>
2135 static __failure_type _S_test(...);
2138 template<typename _Tp, typename _Up>
2139 struct __common_type_impl
2140 : private __do_common_type_impl
2142 typedef decltype(_S_test<_Tp, _Up>(0)) type;
2145 struct __do_member_type_wrapper
2147 template<typename _Tp>
2148 static __success_type<typename _Tp::type> _S_test(int);
2151 static __failure_type _S_test(...);
2154 template<typename _Tp>
2155 struct __member_type_wrapper
2156 : private __do_member_type_wrapper
2158 typedef decltype(_S_test<_Tp>(0)) type;
2161 template<typename _CTp, typename... _Args>
2162 struct __expanded_common_type_wrapper
2164 typedef common_type<typename _CTp::type, _Args...> type;
2167 template<typename... _Args>
2168 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2169 { typedef __failure_type type; };
2171 template<typename _Tp>
2172 struct common_type<_Tp>
2173 { typedef typename decay<_Tp>::type type; };
2175 template<typename _Tp, typename _Up>
2176 struct common_type<_Tp, _Up>
2177 : public __common_type_impl<_Tp, _Up>::type
2180 template<typename _Tp, typename _Up, typename... _Vp>
2181 struct common_type<_Tp, _Up, _Vp...>
2182 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2183 common_type<_Tp, _Up>>::type, _Vp...>::type
2186 /// The underlying type of an enum.
2187 template<typename _Tp>
2188 struct underlying_type
2190 typedef __underlying_type(_Tp) type;
2193 template<typename _Tp>
2194 struct __declval_protector
2196 static const bool __stop = false;
2197 static typename add_rvalue_reference<_Tp>::type __delegate();
2200 template<typename _Tp>
2201 inline typename add_rvalue_reference<_Tp>::type
2204 static_assert(__declval_protector<_Tp>::__stop,
2205 "declval() must not be used!");
2206 return __declval_protector<_Tp>::__delegate();
2210 template<typename _Signature>
2213 // Sfinae-friendly result_of implementation:
2215 #define __cpp_lib_result_of_sfinae 201210
2217 // [func.require] paragraph 1 bullet 1:
2218 struct __result_of_memfun_ref_impl
2220 template<typename _Fp, typename _Tp1, typename... _Args>
2221 static __success_type<decltype(
2222 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2225 template<typename...>
2226 static __failure_type _S_test(...);
2229 template<typename _MemPtr, typename _Arg, typename... _Args>
2230 struct __result_of_memfun_ref
2231 : private __result_of_memfun_ref_impl
2233 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2236 // [func.require] paragraph 1 bullet 2:
2237 struct __result_of_memfun_deref_impl
2239 template<typename _Fp, typename _Tp1, typename... _Args>
2240 static __success_type<decltype(
2241 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2244 template<typename...>
2245 static __failure_type _S_test(...);
2248 template<typename _MemPtr, typename _Arg, typename... _Args>
2249 struct __result_of_memfun_deref
2250 : private __result_of_memfun_deref_impl
2252 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2255 // [func.require] paragraph 1 bullet 3:
2256 struct __result_of_memobj_ref_impl
2258 template<typename _Fp, typename _Tp1>
2259 static __success_type<decltype(
2260 std::declval<_Tp1>().*std::declval<_Fp>()
2263 template<typename, typename>
2264 static __failure_type _S_test(...);
2267 template<typename _MemPtr, typename _Arg>
2268 struct __result_of_memobj_ref
2269 : private __result_of_memobj_ref_impl
2271 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2274 // [func.require] paragraph 1 bullet 4:
2275 struct __result_of_memobj_deref_impl
2277 template<typename _Fp, typename _Tp1>
2278 static __success_type<decltype(
2279 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2282 template<typename, typename>
2283 static __failure_type _S_test(...);
2286 template<typename _MemPtr, typename _Arg>
2287 struct __result_of_memobj_deref
2288 : private __result_of_memobj_deref_impl
2290 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2293 template<typename _MemPtr, typename _Arg>
2294 struct __result_of_memobj;
2296 template<typename _Res, typename _Class, typename _Arg>
2297 struct __result_of_memobj<_Res _Class::*, _Arg>
2299 typedef typename remove_cv<typename remove_reference<
2300 _Arg>::type>::type _Argval;
2301 typedef _Res _Class::* _MemPtr;
2302 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2303 is_base_of<_Class, _Argval>>::value,
2304 __result_of_memobj_ref<_MemPtr, _Arg>,
2305 __result_of_memobj_deref<_MemPtr, _Arg>
2309 template<typename _MemPtr, typename _Arg, typename... _Args>
2310 struct __result_of_memfun;
2312 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2313 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2315 typedef typename remove_cv<typename remove_reference<
2316 _Arg>::type>::type _Argval;
2317 typedef _Res _Class::* _MemPtr;
2318 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2319 is_base_of<_Class, _Argval>>::value,
2320 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2321 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2325 template<bool, bool, typename _Functor, typename... _ArgTypes>
2326 struct __result_of_impl
2328 typedef __failure_type type;
2331 template<typename _MemPtr, typename _Arg>
2332 struct __result_of_impl<true, false, _MemPtr, _Arg>
2333 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2336 template<typename _MemPtr, typename _Arg, typename... _Args>
2337 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2338 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2341 // [func.require] paragraph 1 bullet 5:
2342 struct __result_of_other_impl
2344 template<typename _Fn, typename... _Args>
2345 static __success_type<decltype(
2346 std::declval<_Fn>()(std::declval<_Args>()...)
2349 template<typename...>
2350 static __failure_type _S_test(...);
2353 template<typename _Functor, typename... _ArgTypes>
2354 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2355 : private __result_of_other_impl
2357 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2360 template<typename _Functor, typename... _ArgTypes>
2361 struct result_of<_Functor(_ArgTypes...)>
2362 : public __result_of_impl<
2363 is_member_object_pointer<
2364 typename remove_reference<_Functor>::type
2366 is_member_function_pointer<
2367 typename remove_reference<_Functor>::type
2369 _Functor, _ArgTypes...
2373 #if __cplusplus > 201103L
2374 /// Alias template for aligned_storage
2375 template<size_t _Len, size_t _Align =
2376 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2377 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2379 template <size_t _Len, typename... _Types>
2380 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2382 /// Alias template for decay
2383 template<typename _Tp>
2384 using decay_t = typename decay<_Tp>::type;
2386 /// Alias template for enable_if
2387 template<bool _Cond, typename _Tp = void>
2388 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2390 /// Alias template for conditional
2391 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2392 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2394 /// Alias template for common_type
2395 template<typename... _Tp>
2396 using common_type_t = typename common_type<_Tp...>::type;
2398 /// Alias template for underlying_type
2399 template<typename _Tp>
2400 using underlying_type_t = typename underlying_type<_Tp>::type;
2402 /// Alias template for result_of
2403 template<typename _Tp>
2404 using result_of_t = typename result_of<_Tp>::type;
2407 template<typename...> using __void_t = void;
2409 /// @} group metaprogramming
2412 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2413 * member type _NTYPE.
2415 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2416 template<typename _Tp, typename = __void_t<>> \
2417 struct __has_##_NTYPE \
2420 template<typename _Tp> \
2421 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2425 _GLIBCXX_END_NAMESPACE_VERSION
2430 #endif // _GLIBCXX_TYPE_TRAITS