1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2017 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 noexcept { return value; }
75 #if __cplusplus > 201103L
77 #define __cpp_lib_integral_constant_callable 201304
79 constexpr value_type operator()() const noexcept { 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 __bool_constant<!bool(_Pp::value)>
157 #if __cplusplus >= 201703L
159 #define __cpp_lib_logical_traits 201510
161 template<typename... _Bn>
166 template<typename... _Bn>
171 template<typename _Pp>
176 template<typename... _Bn>
177 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
179 template<typename... _Bn>
180 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
182 template<typename _Pp>
183 inline constexpr bool negation_v = negation<_Pp>::value;
187 // For several sfinae-friendly trait implementations we transport both the
188 // result information (as the member type) and the failure information (no
189 // member type). This is very similar to std::enable_if, but we cannot use
190 // them, because we need to derive from them as an implementation detail.
192 template<typename _Tp>
193 struct __success_type
194 { typedef _Tp type; };
196 struct __failure_type
199 // Primary type categories.
205 struct __is_void_helper
206 : public false_type { };
209 struct __is_void_helper<void>
210 : public true_type { };
213 template<typename _Tp>
215 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
219 struct __is_integral_helper
220 : public false_type { };
223 struct __is_integral_helper<bool>
224 : public true_type { };
227 struct __is_integral_helper<char>
228 : public true_type { };
231 struct __is_integral_helper<signed char>
232 : public true_type { };
235 struct __is_integral_helper<unsigned char>
236 : public true_type { };
238 #ifdef _GLIBCXX_USE_WCHAR_T
240 struct __is_integral_helper<wchar_t>
241 : public true_type { };
245 struct __is_integral_helper<char16_t>
246 : public true_type { };
249 struct __is_integral_helper<char32_t>
250 : public true_type { };
253 struct __is_integral_helper<short>
254 : public true_type { };
257 struct __is_integral_helper<unsigned short>
258 : public true_type { };
261 struct __is_integral_helper<int>
262 : public true_type { };
265 struct __is_integral_helper<unsigned int>
266 : public true_type { };
269 struct __is_integral_helper<long>
270 : public true_type { };
273 struct __is_integral_helper<unsigned long>
274 : public true_type { };
277 struct __is_integral_helper<long long>
278 : public true_type { };
281 struct __is_integral_helper<unsigned long long>
282 : public true_type { };
284 // Conditionalizing on __STRICT_ANSI__ here will break any port that
285 // uses one of these types for size_t.
286 #if defined(__GLIBCXX_TYPE_INT_N_0)
288 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
289 : public true_type { };
292 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
293 : public true_type { };
295 #if defined(__GLIBCXX_TYPE_INT_N_1)
297 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
298 : public true_type { };
301 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
302 : public true_type { };
304 #if defined(__GLIBCXX_TYPE_INT_N_2)
306 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
307 : public true_type { };
310 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
311 : public true_type { };
313 #if defined(__GLIBCXX_TYPE_INT_N_3)
315 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
316 : public true_type { };
319 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
320 : public true_type { };
324 template<typename _Tp>
326 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
330 struct __is_floating_point_helper
331 : public false_type { };
334 struct __is_floating_point_helper<float>
335 : public true_type { };
338 struct __is_floating_point_helper<double>
339 : public true_type { };
342 struct __is_floating_point_helper<long double>
343 : public true_type { };
345 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) && !defined(__CUDACC__)
347 struct __is_floating_point_helper<__float128>
348 : public true_type { };
351 /// is_floating_point
352 template<typename _Tp>
353 struct is_floating_point
354 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
360 : public false_type { };
362 template<typename _Tp, std::size_t _Size>
363 struct is_array<_Tp[_Size]>
364 : public true_type { };
366 template<typename _Tp>
367 struct is_array<_Tp[]>
368 : public true_type { };
371 struct __is_pointer_helper
372 : public false_type { };
374 template<typename _Tp>
375 struct __is_pointer_helper<_Tp*>
376 : public true_type { };
379 template<typename _Tp>
381 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
384 /// is_lvalue_reference
386 struct is_lvalue_reference
387 : public false_type { };
389 template<typename _Tp>
390 struct is_lvalue_reference<_Tp&>
391 : public true_type { };
393 /// is_rvalue_reference
395 struct is_rvalue_reference
396 : public false_type { };
398 template<typename _Tp>
399 struct is_rvalue_reference<_Tp&&>
400 : public true_type { };
406 struct __is_member_object_pointer_helper
407 : public false_type { };
409 template<typename _Tp, typename _Cp>
410 struct __is_member_object_pointer_helper<_Tp _Cp::*>
411 : public integral_constant<bool, !is_function<_Tp>::value> { };
413 /// is_member_object_pointer
414 template<typename _Tp>
415 struct is_member_object_pointer
416 : public __is_member_object_pointer_helper<
417 typename remove_cv<_Tp>::type>::type
421 struct __is_member_function_pointer_helper
422 : public false_type { };
424 template<typename _Tp, typename _Cp>
425 struct __is_member_function_pointer_helper<_Tp _Cp::*>
426 : public integral_constant<bool, is_function<_Tp>::value> { };
428 /// is_member_function_pointer
429 template<typename _Tp>
430 struct is_member_function_pointer
431 : public __is_member_function_pointer_helper<
432 typename remove_cv<_Tp>::type>::type
436 template<typename _Tp>
438 : public integral_constant<bool, __is_enum(_Tp)>
442 template<typename _Tp>
444 : public integral_constant<bool, __is_union(_Tp)>
448 template<typename _Tp>
450 : public integral_constant<bool, __is_class(_Tp)>
456 : public false_type { };
458 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
459 struct is_function<_Res(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
460 : public true_type { };
462 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
463 struct is_function<_Res(_ArgTypes...) & _GLIBCXX_NOEXCEPT_QUAL>
464 : public true_type { };
466 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
467 struct is_function<_Res(_ArgTypes...) && _GLIBCXX_NOEXCEPT_QUAL>
468 : public true_type { };
470 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
471 struct is_function<_Res(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
472 : public true_type { };
474 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
475 struct is_function<_Res(_ArgTypes......) & _GLIBCXX_NOEXCEPT_QUAL>
476 : public true_type { };
478 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
479 struct is_function<_Res(_ArgTypes......) && _GLIBCXX_NOEXCEPT_QUAL>
480 : public true_type { };
482 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
483 struct is_function<_Res(_ArgTypes...) const _GLIBCXX_NOEXCEPT_QUAL>
484 : public true_type { };
486 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
487 struct is_function<_Res(_ArgTypes...) const & _GLIBCXX_NOEXCEPT_QUAL>
488 : public true_type { };
490 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
491 struct is_function<_Res(_ArgTypes...) const && _GLIBCXX_NOEXCEPT_QUAL>
492 : public true_type { };
494 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
495 struct is_function<_Res(_ArgTypes......) const _GLIBCXX_NOEXCEPT_QUAL>
496 : public true_type { };
498 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
499 struct is_function<_Res(_ArgTypes......) const & _GLIBCXX_NOEXCEPT_QUAL>
500 : public true_type { };
502 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
503 struct is_function<_Res(_ArgTypes......) const && _GLIBCXX_NOEXCEPT_QUAL>
504 : public true_type { };
506 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
507 struct is_function<_Res(_ArgTypes...) volatile _GLIBCXX_NOEXCEPT_QUAL>
508 : public true_type { };
510 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
511 struct is_function<_Res(_ArgTypes...) volatile & _GLIBCXX_NOEXCEPT_QUAL>
512 : public true_type { };
514 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
515 struct is_function<_Res(_ArgTypes...) volatile && _GLIBCXX_NOEXCEPT_QUAL>
516 : public true_type { };
518 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
519 struct is_function<_Res(_ArgTypes......) volatile _GLIBCXX_NOEXCEPT_QUAL>
520 : public true_type { };
522 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
523 struct is_function<_Res(_ArgTypes......) volatile & _GLIBCXX_NOEXCEPT_QUAL>
524 : public true_type { };
526 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
527 struct is_function<_Res(_ArgTypes......) volatile && _GLIBCXX_NOEXCEPT_QUAL>
528 : public true_type { };
530 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
531 struct is_function<_Res(_ArgTypes...) const volatile _GLIBCXX_NOEXCEPT_QUAL>
532 : public true_type { };
534 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
535 struct is_function<_Res(_ArgTypes...) const volatile & _GLIBCXX_NOEXCEPT_QUAL>
536 : public true_type { };
538 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
539 struct is_function<_Res(_ArgTypes...) const volatile && _GLIBCXX_NOEXCEPT_QUAL>
540 : public true_type { };
542 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
543 struct is_function<_Res(_ArgTypes......) const volatile _GLIBCXX_NOEXCEPT_QUAL>
544 : public true_type { };
546 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
547 struct is_function<_Res(_ArgTypes......) const volatile & _GLIBCXX_NOEXCEPT_QUAL>
548 : public true_type { };
550 template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
551 struct is_function<_Res(_ArgTypes......) const volatile && _GLIBCXX_NOEXCEPT_QUAL>
552 : public true_type { };
554 #define __cpp_lib_is_null_pointer 201309
557 struct __is_null_pointer_helper
558 : public false_type { };
561 struct __is_null_pointer_helper<std::nullptr_t>
562 : public true_type { };
564 /// is_null_pointer (LWG 2247).
565 template<typename _Tp>
566 struct is_null_pointer
567 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
570 /// __is_nullptr_t (extension).
571 template<typename _Tp>
572 struct __is_nullptr_t
573 : public is_null_pointer<_Tp>
576 // Composite type categories.
579 template<typename _Tp>
581 : public __or_<is_lvalue_reference<_Tp>,
582 is_rvalue_reference<_Tp>>::type
586 template<typename _Tp>
588 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
592 template<typename _Tp>
593 struct is_fundamental
594 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
595 is_null_pointer<_Tp>>::type
599 template<typename _Tp>
601 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
606 struct is_member_pointer;
609 template<typename _Tp>
611 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
612 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
616 template<typename _Tp>
618 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
620 template<typename _Tp>
621 struct __is_member_pointer_helper
622 : public false_type { };
624 template<typename _Tp, typename _Cp>
625 struct __is_member_pointer_helper<_Tp _Cp::*>
626 : public true_type { };
628 /// is_member_pointer
629 template<typename _Tp>
630 struct is_member_pointer
631 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
634 // Utility to detect referenceable types ([defns.referenceable]).
636 template<typename _Tp>
637 struct __is_referenceable
638 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
641 template<typename _Res, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
642 struct __is_referenceable<_Res(_Args...) _GLIBCXX_NOEXCEPT_QUAL>
646 template<typename _Res, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
647 struct __is_referenceable<_Res(_Args......) _GLIBCXX_NOEXCEPT_QUAL>
656 : public false_type { };
658 template<typename _Tp>
659 struct is_const<_Tp const>
660 : public true_type { };
665 : public false_type { };
667 template<typename _Tp>
668 struct is_volatile<_Tp volatile>
669 : public true_type { };
672 template<typename _Tp>
674 : public integral_constant<bool, __is_trivial(_Tp)>
677 // is_trivially_copyable
678 template<typename _Tp>
679 struct is_trivially_copyable
680 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
683 /// is_standard_layout
684 template<typename _Tp>
685 struct is_standard_layout
686 : public integral_constant<bool, __is_standard_layout(_Tp)>
690 // Could use is_standard_layout && is_trivial instead of the builtin.
691 template<typename _Tp>
693 : public integral_constant<bool, __is_pod(_Tp)>
697 template<typename _Tp>
698 struct is_literal_type
699 : public integral_constant<bool, __is_literal_type(_Tp)>
703 template<typename _Tp>
705 : public integral_constant<bool, __is_empty(_Tp)>
709 template<typename _Tp>
710 struct is_polymorphic
711 : public integral_constant<bool, __is_polymorphic(_Tp)>
714 #if __cplusplus >= 201402L
715 #define __cpp_lib_is_final 201402L
717 template<typename _Tp>
719 : public integral_constant<bool, __is_final(_Tp)>
724 template<typename _Tp>
726 : public integral_constant<bool, __is_abstract(_Tp)>
729 template<typename _Tp,
730 bool = is_arithmetic<_Tp>::value>
731 struct __is_signed_helper
732 : public false_type { };
734 template<typename _Tp>
735 struct __is_signed_helper<_Tp, true>
736 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
740 template<typename _Tp>
742 : public __is_signed_helper<_Tp>::type
746 template<typename _Tp>
748 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
752 // Destructible and constructible type properties.
755 struct add_rvalue_reference;
758 * @brief Utility to simplify expressions used in unevaluated operands
761 template<typename _Tp>
762 typename add_rvalue_reference<_Tp>::type declval() noexcept;
764 template<typename, unsigned = 0>
768 struct remove_all_extents;
770 template<typename _Tp>
771 struct __is_array_known_bounds
772 : public integral_constant<bool, (extent<_Tp>::value > 0)>
775 template<typename _Tp>
776 struct __is_array_unknown_bounds
777 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
780 // In N3290 is_destructible does not say anything about function
781 // types and abstract types, see LWG 2049. This implementation
782 // describes function types as non-destructible and all complete
783 // object types as destructible, iff the explicit destructor
784 // call expression is wellformed.
785 struct __do_is_destructible_impl
787 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
788 static true_type __test(int);
791 static false_type __test(...);
794 template<typename _Tp>
795 struct __is_destructible_impl
796 : public __do_is_destructible_impl
798 typedef decltype(__test<_Tp>(0)) type;
801 template<typename _Tp,
802 bool = __or_<is_void<_Tp>,
803 __is_array_unknown_bounds<_Tp>,
804 is_function<_Tp>>::value,
805 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
806 struct __is_destructible_safe;
808 template<typename _Tp>
809 struct __is_destructible_safe<_Tp, false, false>
810 : public __is_destructible_impl<typename
811 remove_all_extents<_Tp>::type>::type
814 template<typename _Tp>
815 struct __is_destructible_safe<_Tp, true, false>
816 : public false_type { };
818 template<typename _Tp>
819 struct __is_destructible_safe<_Tp, false, true>
820 : public true_type { };
823 template<typename _Tp>
824 struct is_destructible
825 : public __is_destructible_safe<_Tp>::type
828 // is_nothrow_destructible requires that is_destructible is
829 // satisfied as well. We realize that by mimicing the
830 // implementation of is_destructible but refer to noexcept(expr)
831 // instead of decltype(expr).
832 struct __do_is_nt_destructible_impl
834 template<typename _Tp>
835 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
839 static false_type __test(...);
842 template<typename _Tp>
843 struct __is_nt_destructible_impl
844 : public __do_is_nt_destructible_impl
846 typedef decltype(__test<_Tp>(0)) type;
849 template<typename _Tp,
850 bool = __or_<is_void<_Tp>,
851 __is_array_unknown_bounds<_Tp>,
852 is_function<_Tp>>::value,
853 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
854 struct __is_nt_destructible_safe;
856 template<typename _Tp>
857 struct __is_nt_destructible_safe<_Tp, false, false>
858 : public __is_nt_destructible_impl<typename
859 remove_all_extents<_Tp>::type>::type
862 template<typename _Tp>
863 struct __is_nt_destructible_safe<_Tp, true, false>
864 : public false_type { };
866 template<typename _Tp>
867 struct __is_nt_destructible_safe<_Tp, false, true>
868 : public true_type { };
870 /// is_nothrow_destructible
871 template<typename _Tp>
872 struct is_nothrow_destructible
873 : public __is_nt_destructible_safe<_Tp>::type
876 struct __do_is_default_constructible_impl
878 template<typename _Tp, typename = decltype(_Tp())>
879 static true_type __test(int);
882 static false_type __test(...);
885 template<typename _Tp>
886 struct __is_default_constructible_impl
887 : public __do_is_default_constructible_impl
889 typedef decltype(__test<_Tp>(0)) type;
892 template<typename _Tp>
893 struct __is_default_constructible_atom
894 : public __and_<__not_<is_void<_Tp>>,
895 __is_default_constructible_impl<_Tp>>
898 template<typename _Tp, bool = is_array<_Tp>::value>
899 struct __is_default_constructible_safe;
901 // The following technique is a workaround for a current core language
902 // restriction, which does not allow for array types to occur in
903 // functional casts of the form T(). Complete arrays can be default-
904 // constructed, if the element type is default-constructible, but
905 // arrays with unknown bounds are not.
906 template<typename _Tp>
907 struct __is_default_constructible_safe<_Tp, true>
908 : public __and_<__is_array_known_bounds<_Tp>,
909 __is_default_constructible_atom<typename
910 remove_all_extents<_Tp>::type>>
913 template<typename _Tp>
914 struct __is_default_constructible_safe<_Tp, false>
915 : public __is_default_constructible_atom<_Tp>::type
918 /// is_default_constructible
919 template<typename _Tp>
920 struct is_default_constructible
921 : public __is_default_constructible_safe<_Tp>::type
925 // Implementation of is_constructible.
927 // The hardest part of this trait is the binary direct-initialization
928 // case, because we hit into a functional cast of the form T(arg).
929 // This implementation uses different strategies depending on the
930 // target type to reduce the test overhead as much as possible:
932 // a) For a reference target type, we use a static_cast expression
933 // modulo its extra cases.
935 // b) For a non-reference target type we use a ::new expression.
936 struct __do_is_static_castable_impl
938 template<typename _From, typename _To, typename
939 = decltype(static_cast<_To>(declval<_From>()))>
940 static true_type __test(int);
942 template<typename, typename>
943 static false_type __test(...);
946 template<typename _From, typename _To>
947 struct __is_static_castable_impl
948 : public __do_is_static_castable_impl
950 typedef decltype(__test<_From, _To>(0)) type;
953 template<typename _From, typename _To>
954 struct __is_static_castable_safe
955 : public __is_static_castable_impl<_From, _To>::type
958 // __is_static_castable
959 template<typename _From, typename _To>
960 struct __is_static_castable
961 : public integral_constant<bool, (__is_static_castable_safe<
965 // Implementation for non-reference types. To meet the proper
966 // variable definition semantics, we also need to test for
967 // is_destructible in this case.
968 // This form should be simplified by a single expression:
969 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
970 struct __do_is_direct_constructible_impl
972 template<typename _Tp, typename _Arg, typename
973 = decltype(::new _Tp(declval<_Arg>()))>
974 static true_type __test(int);
976 template<typename, typename>
977 static false_type __test(...);
980 template<typename _Tp, typename _Arg>
981 struct __is_direct_constructible_impl
982 : public __do_is_direct_constructible_impl
984 typedef decltype(__test<_Tp, _Arg>(0)) type;
987 template<typename _Tp, typename _Arg>
988 struct __is_direct_constructible_new_safe
989 : public __and_<is_destructible<_Tp>,
990 __is_direct_constructible_impl<_Tp, _Arg>>
993 template<typename, typename>
996 template<typename, typename>
1000 struct remove_reference;
1002 template<typename _From, typename _To, bool
1003 = __not_<__or_<is_void<_From>,
1004 is_function<_From>>>::value>
1005 struct __is_base_to_derived_ref;
1007 template<typename _Tp, typename... _Args>
1008 struct is_constructible;
1010 // Detect whether we have a downcast situation during
1011 // reference binding.
1012 template<typename _From, typename _To>
1013 struct __is_base_to_derived_ref<_From, _To, true>
1015 typedef typename remove_cv<typename remove_reference<_From
1016 >::type>::type __src_t;
1017 typedef typename remove_cv<typename remove_reference<_To
1018 >::type>::type __dst_t;
1019 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
1020 is_base_of<__src_t, __dst_t>,
1021 __not_<is_constructible<__dst_t, _From>>> type;
1022 static constexpr bool value = type::value;
1025 template<typename _From, typename _To>
1026 struct __is_base_to_derived_ref<_From, _To, false>
1030 template<typename _From, typename _To, bool
1031 = __and_<is_lvalue_reference<_From>,
1032 is_rvalue_reference<_To>>::value>
1033 struct __is_lvalue_to_rvalue_ref;
1035 // Detect whether we have an lvalue of non-function type
1036 // bound to a reference-compatible rvalue-reference.
1037 template<typename _From, typename _To>
1038 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
1040 typedef typename remove_cv<typename remove_reference<
1041 _From>::type>::type __src_t;
1042 typedef typename remove_cv<typename remove_reference<
1043 _To>::type>::type __dst_t;
1044 typedef __and_<__not_<is_function<__src_t>>,
1045 __or_<is_same<__src_t, __dst_t>,
1046 is_base_of<__dst_t, __src_t>>> type;
1047 static constexpr bool value = type::value;
1050 template<typename _From, typename _To>
1051 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
1055 // Here we handle direct-initialization to a reference type as
1056 // equivalent to a static_cast modulo overshooting conversions.
1057 // These are restricted to the following conversions:
1058 // a) A base class value to a derived class reference
1059 // b) An lvalue to an rvalue-reference of reference-compatible
1060 // types that are not functions
1061 template<typename _Tp, typename _Arg>
1062 struct __is_direct_constructible_ref_cast
1063 : public __and_<__is_static_castable<_Arg, _Tp>,
1064 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
1065 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
1069 template<typename _Tp, typename _Arg>
1070 struct __is_direct_constructible_new
1071 : public conditional<is_reference<_Tp>::value,
1072 __is_direct_constructible_ref_cast<_Tp, _Arg>,
1073 __is_direct_constructible_new_safe<_Tp, _Arg>
1077 template<typename _Tp, typename _Arg>
1078 struct __is_direct_constructible
1079 : public __is_direct_constructible_new<_Tp, _Arg>::type
1082 // Since default-construction and binary direct-initialization have
1083 // been handled separately, the implementation of the remaining
1084 // n-ary construction cases is rather straightforward. We can use
1085 // here a functional cast, because array types are excluded anyway
1086 // and this form is never interpreted as a C cast.
1087 struct __do_is_nary_constructible_impl
1089 template<typename _Tp, typename... _Args, typename
1090 = decltype(_Tp(declval<_Args>()...))>
1091 static true_type __test(int);
1093 template<typename, typename...>
1094 static false_type __test(...);
1097 template<typename _Tp, typename... _Args>
1098 struct __is_nary_constructible_impl
1099 : public __do_is_nary_constructible_impl
1101 typedef decltype(__test<_Tp, _Args...>(0)) type;
1104 template<typename _Tp, typename... _Args>
1105 struct __is_nary_constructible
1106 : public __is_nary_constructible_impl<_Tp, _Args...>::type
1108 static_assert(sizeof...(_Args) > 1,
1109 "Only useful for > 1 arguments");
1112 template<typename _Tp, typename... _Args>
1113 struct __is_constructible_impl
1114 : public __is_nary_constructible<_Tp, _Args...>
1117 template<typename _Tp, typename _Arg>
1118 struct __is_constructible_impl<_Tp, _Arg>
1119 : public __is_direct_constructible<_Tp, _Arg>
1122 template<typename _Tp>
1123 struct __is_constructible_impl<_Tp>
1124 : public is_default_constructible<_Tp>
1127 /// is_constructible
1128 template<typename _Tp, typename... _Args>
1129 struct is_constructible
1130 : public __is_constructible_impl<_Tp, _Args...>::type
1133 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1134 struct __is_copy_constructible_impl;
1136 template<typename _Tp>
1137 struct __is_copy_constructible_impl<_Tp, false>
1138 : public false_type { };
1140 template<typename _Tp>
1141 struct __is_copy_constructible_impl<_Tp, true>
1142 : public is_constructible<_Tp, const _Tp&>
1145 /// is_copy_constructible
1146 template<typename _Tp>
1147 struct is_copy_constructible
1148 : public __is_copy_constructible_impl<_Tp>
1151 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1152 struct __is_move_constructible_impl;
1154 template<typename _Tp>
1155 struct __is_move_constructible_impl<_Tp, false>
1156 : public false_type { };
1158 template<typename _Tp>
1159 struct __is_move_constructible_impl<_Tp, true>
1160 : public is_constructible<_Tp, _Tp&&>
1163 /// is_move_constructible
1164 template<typename _Tp>
1165 struct is_move_constructible
1166 : public __is_move_constructible_impl<_Tp>
1169 template<typename _Tp>
1170 struct __is_nt_default_constructible_atom
1171 : public integral_constant<bool, noexcept(_Tp())>
1174 template<typename _Tp, bool = is_array<_Tp>::value>
1175 struct __is_nt_default_constructible_impl;
1177 template<typename _Tp>
1178 struct __is_nt_default_constructible_impl<_Tp, true>
1179 : public __and_<__is_array_known_bounds<_Tp>,
1180 __is_nt_default_constructible_atom<typename
1181 remove_all_extents<_Tp>::type>>
1184 template<typename _Tp>
1185 struct __is_nt_default_constructible_impl<_Tp, false>
1186 : public __is_nt_default_constructible_atom<_Tp>
1189 /// is_nothrow_default_constructible
1190 template<typename _Tp>
1191 struct is_nothrow_default_constructible
1192 : public __and_<is_default_constructible<_Tp>,
1193 __is_nt_default_constructible_impl<_Tp>>
1196 template<typename _Tp, typename... _Args>
1197 struct __is_nt_constructible_impl
1198 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1201 template<typename _Tp, typename _Arg>
1202 struct __is_nt_constructible_impl<_Tp, _Arg>
1203 : public integral_constant<bool,
1204 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1207 template<typename _Tp>
1208 struct __is_nt_constructible_impl<_Tp>
1209 : public is_nothrow_default_constructible<_Tp>
1212 /// is_nothrow_constructible
1213 template<typename _Tp, typename... _Args>
1214 struct is_nothrow_constructible
1215 : public __and_<is_constructible<_Tp, _Args...>,
1216 __is_nt_constructible_impl<_Tp, _Args...>>
1219 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1220 struct __is_nothrow_copy_constructible_impl;
1222 template<typename _Tp>
1223 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1224 : public false_type { };
1226 template<typename _Tp>
1227 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1228 : public is_nothrow_constructible<_Tp, const _Tp&>
1231 /// is_nothrow_copy_constructible
1232 template<typename _Tp>
1233 struct is_nothrow_copy_constructible
1234 : public __is_nothrow_copy_constructible_impl<_Tp>
1237 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1238 struct __is_nothrow_move_constructible_impl;
1240 template<typename _Tp>
1241 struct __is_nothrow_move_constructible_impl<_Tp, false>
1242 : public false_type { };
1244 template<typename _Tp>
1245 struct __is_nothrow_move_constructible_impl<_Tp, true>
1246 : public is_nothrow_constructible<_Tp, _Tp&&>
1249 /// is_nothrow_move_constructible
1250 template<typename _Tp>
1251 struct is_nothrow_move_constructible
1252 : public __is_nothrow_move_constructible_impl<_Tp>
1255 template<typename _Tp, typename _Up>
1256 class __is_assignable_helper
1258 template<typename _Tp1, typename _Up1,
1259 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1263 template<typename, typename>
1268 typedef decltype(__test<_Tp, _Up>(0)) type;
1272 template<typename _Tp, typename _Up>
1273 struct is_assignable
1274 : public __is_assignable_helper<_Tp, _Up>::type
1277 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1278 struct __is_copy_assignable_impl;
1280 template<typename _Tp>
1281 struct __is_copy_assignable_impl<_Tp, false>
1282 : public false_type { };
1284 template<typename _Tp>
1285 struct __is_copy_assignable_impl<_Tp, true>
1286 : public is_assignable<_Tp&, const _Tp&>
1289 /// is_copy_assignable
1290 template<typename _Tp>
1291 struct is_copy_assignable
1292 : public __is_copy_assignable_impl<_Tp>
1295 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1296 struct __is_move_assignable_impl;
1298 template<typename _Tp>
1299 struct __is_move_assignable_impl<_Tp, false>
1300 : public false_type { };
1302 template<typename _Tp>
1303 struct __is_move_assignable_impl<_Tp, true>
1304 : public is_assignable<_Tp&, _Tp&&>
1307 /// is_move_assignable
1308 template<typename _Tp>
1309 struct is_move_assignable
1310 : public __is_move_assignable_impl<_Tp>
1313 template<typename _Tp, typename _Up>
1314 struct __is_nt_assignable_impl
1315 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1318 /// is_nothrow_assignable
1319 template<typename _Tp, typename _Up>
1320 struct is_nothrow_assignable
1321 : public __and_<is_assignable<_Tp, _Up>,
1322 __is_nt_assignable_impl<_Tp, _Up>>
1325 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1326 struct __is_nt_copy_assignable_impl;
1328 template<typename _Tp>
1329 struct __is_nt_copy_assignable_impl<_Tp, false>
1330 : public false_type { };
1332 template<typename _Tp>
1333 struct __is_nt_copy_assignable_impl<_Tp, true>
1334 : public is_nothrow_assignable<_Tp&, const _Tp&>
1337 /// is_nothrow_copy_assignable
1338 template<typename _Tp>
1339 struct is_nothrow_copy_assignable
1340 : public __is_nt_copy_assignable_impl<_Tp>
1343 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1344 struct __is_nt_move_assignable_impl;
1346 template<typename _Tp>
1347 struct __is_nt_move_assignable_impl<_Tp, false>
1348 : public false_type { };
1350 template<typename _Tp>
1351 struct __is_nt_move_assignable_impl<_Tp, true>
1352 : public is_nothrow_assignable<_Tp&, _Tp&&>
1355 /// is_nothrow_move_assignable
1356 template<typename _Tp>
1357 struct is_nothrow_move_assignable
1358 : public __is_nt_move_assignable_impl<_Tp>
1361 /// is_trivially_constructible
1362 template<typename _Tp, typename... _Args>
1363 struct is_trivially_constructible
1364 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool,
1365 __is_trivially_constructible(_Tp, _Args...)>>
1368 /// is_trivially_default_constructible
1369 template<typename _Tp>
1370 struct is_trivially_default_constructible
1371 : public is_trivially_constructible<_Tp>::type
1374 struct __do_is_implicitly_default_constructible_impl
1376 template <typename _Tp>
1377 static void __helper(const _Tp&);
1379 template <typename _Tp>
1380 static true_type __test(const _Tp&,
1381 decltype(__helper<const _Tp&>({}))* = 0);
1383 static false_type __test(...);
1386 template<typename _Tp>
1387 struct __is_implicitly_default_constructible_impl
1388 : public __do_is_implicitly_default_constructible_impl
1390 typedef decltype(__test(declval<_Tp>())) type;
1393 template<typename _Tp>
1394 struct __is_implicitly_default_constructible_safe
1395 : public __is_implicitly_default_constructible_impl<_Tp>::type
1398 template <typename _Tp>
1399 struct __is_implicitly_default_constructible
1400 : public __and_<is_default_constructible<_Tp>,
1401 __is_implicitly_default_constructible_safe<_Tp>>
1404 /// is_trivially_copy_constructible
1405 template<typename _Tp>
1406 struct is_trivially_copy_constructible
1407 : public __and_<is_copy_constructible<_Tp>,
1408 integral_constant<bool,
1409 __is_trivially_constructible(_Tp, const _Tp&)>>
1412 /// is_trivially_move_constructible
1413 template<typename _Tp>
1414 struct is_trivially_move_constructible
1415 : public __and_<is_move_constructible<_Tp>,
1416 integral_constant<bool,
1417 __is_trivially_constructible(_Tp, _Tp&&)>>
1420 /// is_trivially_assignable
1421 template<typename _Tp, typename _Up>
1422 struct is_trivially_assignable
1423 : public __and_<is_assignable<_Tp, _Up>,
1424 integral_constant<bool,
1425 __is_trivially_assignable(_Tp, _Up)>>
1428 /// is_trivially_copy_assignable
1429 template<typename _Tp>
1430 struct is_trivially_copy_assignable
1431 : public __and_<is_copy_assignable<_Tp>,
1432 integral_constant<bool,
1433 __is_trivially_assignable(_Tp&, const _Tp&)>>
1436 /// is_trivially_move_assignable
1437 template<typename _Tp>
1438 struct is_trivially_move_assignable
1439 : public __and_<is_move_assignable<_Tp>,
1440 integral_constant<bool,
1441 __is_trivially_assignable(_Tp&, _Tp&&)>>
1444 /// is_trivially_destructible
1445 template<typename _Tp>
1446 struct is_trivially_destructible
1447 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1448 __has_trivial_destructor(_Tp)>>
1452 /// has_virtual_destructor
1453 template<typename _Tp>
1454 struct has_virtual_destructor
1455 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1459 // type property queries.
1462 template<typename _Tp>
1464 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1469 : public integral_constant<std::size_t, 0> { };
1471 template<typename _Tp, std::size_t _Size>
1472 struct rank<_Tp[_Size]>
1473 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1475 template<typename _Tp>
1477 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1480 template<typename, unsigned _Uint>
1482 : public integral_constant<std::size_t, 0> { };
1484 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1485 struct extent<_Tp[_Size], _Uint>
1486 : public integral_constant<std::size_t,
1487 _Uint == 0 ? _Size : extent<_Tp,
1491 template<typename _Tp, unsigned _Uint>
1492 struct extent<_Tp[], _Uint>
1493 : public integral_constant<std::size_t,
1494 _Uint == 0 ? 0 : extent<_Tp,
1502 template<typename, typename>
1504 : public false_type { };
1506 template<typename _Tp>
1507 struct is_same<_Tp, _Tp>
1508 : public true_type { };
1511 template<typename _Base, typename _Derived>
1513 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1516 template<typename _From, typename _To,
1517 bool = __or_<is_void<_From>, is_function<_To>,
1518 is_array<_To>>::value>
1519 struct __is_convertible_helper
1520 { typedef typename is_void<_To>::type type; };
1522 template<typename _From, typename _To>
1523 class __is_convertible_helper<_From, _To, false>
1525 template<typename _To1>
1526 static void __test_aux(_To1);
1528 template<typename _From1, typename _To1,
1529 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1533 template<typename, typename>
1538 typedef decltype(__test<_From, _To>(0)) type;
1543 template<typename _From, typename _To>
1544 struct is_convertible
1545 : public __is_convertible_helper<_From, _To>::type
1549 // Const-volatile modifications.
1552 template<typename _Tp>
1554 { typedef _Tp type; };
1556 template<typename _Tp>
1557 struct remove_const<_Tp const>
1558 { typedef _Tp type; };
1561 template<typename _Tp>
1562 struct remove_volatile
1563 { typedef _Tp type; };
1565 template<typename _Tp>
1566 struct remove_volatile<_Tp volatile>
1567 { typedef _Tp type; };
1570 template<typename _Tp>
1574 remove_const<typename remove_volatile<_Tp>::type>::type type;
1578 template<typename _Tp>
1580 { typedef _Tp const type; };
1583 template<typename _Tp>
1585 { typedef _Tp volatile type; };
1588 template<typename _Tp>
1592 add_const<typename add_volatile<_Tp>::type>::type type;
1595 #if __cplusplus > 201103L
1597 #define __cpp_lib_transformation_trait_aliases 201304
1599 /// Alias template for remove_const
1600 template<typename _Tp>
1601 using remove_const_t = typename remove_const<_Tp>::type;
1603 /// Alias template for remove_volatile
1604 template<typename _Tp>
1605 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1607 /// Alias template for remove_cv
1608 template<typename _Tp>
1609 using remove_cv_t = typename remove_cv<_Tp>::type;
1611 /// Alias template for add_const
1612 template<typename _Tp>
1613 using add_const_t = typename add_const<_Tp>::type;
1615 /// Alias template for add_volatile
1616 template<typename _Tp>
1617 using add_volatile_t = typename add_volatile<_Tp>::type;
1619 /// Alias template for add_cv
1620 template<typename _Tp>
1621 using add_cv_t = typename add_cv<_Tp>::type;
1624 // Reference transformations.
1626 /// remove_reference
1627 template<typename _Tp>
1628 struct remove_reference
1629 { typedef _Tp type; };
1631 template<typename _Tp>
1632 struct remove_reference<_Tp&>
1633 { typedef _Tp type; };
1635 template<typename _Tp>
1636 struct remove_reference<_Tp&&>
1637 { typedef _Tp type; };
1639 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1640 struct __add_lvalue_reference_helper
1641 { typedef _Tp type; };
1643 template<typename _Tp>
1644 struct __add_lvalue_reference_helper<_Tp, true>
1645 { typedef _Tp& type; };
1647 /// add_lvalue_reference
1648 template<typename _Tp>
1649 struct add_lvalue_reference
1650 : public __add_lvalue_reference_helper<_Tp>
1653 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1654 struct __add_rvalue_reference_helper
1655 { typedef _Tp type; };
1657 template<typename _Tp>
1658 struct __add_rvalue_reference_helper<_Tp, true>
1659 { typedef _Tp&& type; };
1661 /// add_rvalue_reference
1662 template<typename _Tp>
1663 struct add_rvalue_reference
1664 : public __add_rvalue_reference_helper<_Tp>
1667 #if __cplusplus > 201103L
1668 /// Alias template for remove_reference
1669 template<typename _Tp>
1670 using remove_reference_t = typename remove_reference<_Tp>::type;
1672 /// Alias template for add_lvalue_reference
1673 template<typename _Tp>
1674 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1676 /// Alias template for add_rvalue_reference
1677 template<typename _Tp>
1678 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1681 // Sign modifications.
1683 // Utility for constructing identically cv-qualified types.
1684 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1685 struct __cv_selector;
1687 template<typename _Unqualified>
1688 struct __cv_selector<_Unqualified, false, false>
1689 { typedef _Unqualified __type; };
1691 template<typename _Unqualified>
1692 struct __cv_selector<_Unqualified, false, true>
1693 { typedef volatile _Unqualified __type; };
1695 template<typename _Unqualified>
1696 struct __cv_selector<_Unqualified, true, false>
1697 { typedef const _Unqualified __type; };
1699 template<typename _Unqualified>
1700 struct __cv_selector<_Unqualified, true, true>
1701 { typedef const volatile _Unqualified __type; };
1703 template<typename _Qualified, typename _Unqualified,
1704 bool _IsConst = is_const<_Qualified>::value,
1705 bool _IsVol = is_volatile<_Qualified>::value>
1706 class __match_cv_qualifiers
1708 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1711 typedef typename __match::__type __type;
1714 // Utility for finding the unsigned versions of signed integral types.
1715 template<typename _Tp>
1716 struct __make_unsigned
1717 { typedef _Tp __type; };
1720 struct __make_unsigned<char>
1721 { typedef unsigned char __type; };
1724 struct __make_unsigned<signed char>
1725 { typedef unsigned char __type; };
1728 struct __make_unsigned<short>
1729 { typedef unsigned short __type; };
1732 struct __make_unsigned<int>
1733 { typedef unsigned int __type; };
1736 struct __make_unsigned<long>
1737 { typedef unsigned long __type; };
1740 struct __make_unsigned<long long>
1741 { typedef unsigned long long __type; };
1743 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1745 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1749 #if defined(__GLIBCXX_TYPE_INT_N_0)
1751 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1752 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1754 #if defined(__GLIBCXX_TYPE_INT_N_1)
1756 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1757 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1759 #if defined(__GLIBCXX_TYPE_INT_N_2)
1761 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1762 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1764 #if defined(__GLIBCXX_TYPE_INT_N_3)
1766 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1767 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
1770 // Select between integral and enum: not possible to be both.
1771 template<typename _Tp,
1772 bool _IsInt = is_integral<_Tp>::value,
1773 bool _IsEnum = is_enum<_Tp>::value>
1774 class __make_unsigned_selector;
1776 template<typename _Tp>
1777 class __make_unsigned_selector<_Tp, true, false>
1779 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1780 typedef typename __unsignedt::__type __unsigned_type;
1781 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1784 typedef typename __cv_unsigned::__type __type;
1787 template<typename _Tp>
1788 class __make_unsigned_selector<_Tp, false, true>
1790 // With -fshort-enums, an enum may be as small as a char.
1791 typedef unsigned char __smallest;
1792 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1793 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1794 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1795 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long);
1796 typedef conditional<__b3, unsigned long, unsigned long long> __cond3;
1797 typedef typename __cond3::type __cond3_type;
1798 typedef conditional<__b2, unsigned int, __cond3_type> __cond2;
1799 typedef typename __cond2::type __cond2_type;
1800 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1801 typedef typename __cond1::type __cond1_type;
1803 typedef typename conditional<__b0, __smallest, __cond1_type>::type
1805 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1808 typedef typename __cv_unsigned::__type __type;
1811 // Given an integral/enum type, return the corresponding unsigned
1813 // Primary template.
1815 template<typename _Tp>
1816 struct make_unsigned
1817 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1819 // Integral, but don't define.
1821 struct make_unsigned<bool>;
1824 // Utility for finding the signed versions of unsigned integral types.
1825 template<typename _Tp>
1826 struct __make_signed
1827 { typedef _Tp __type; };
1830 struct __make_signed<char>
1831 { typedef signed char __type; };
1834 struct __make_signed<unsigned char>
1835 { typedef signed char __type; };
1838 struct __make_signed<unsigned short>
1839 { typedef signed short __type; };
1842 struct __make_signed<unsigned int>
1843 { typedef signed int __type; };
1846 struct __make_signed<unsigned long>
1847 { typedef signed long __type; };
1850 struct __make_signed<unsigned long long>
1851 { typedef signed long long __type; };
1853 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1855 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1859 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1861 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1864 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1868 #if defined(__GLIBCXX_TYPE_INT_N_0)
1870 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1871 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1873 #if defined(__GLIBCXX_TYPE_INT_N_1)
1875 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1876 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1878 #if defined(__GLIBCXX_TYPE_INT_N_2)
1880 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1881 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1883 #if defined(__GLIBCXX_TYPE_INT_N_3)
1885 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1886 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
1889 // Select between integral and enum: not possible to be both.
1890 template<typename _Tp,
1891 bool _IsInt = is_integral<_Tp>::value,
1892 bool _IsEnum = is_enum<_Tp>::value>
1893 class __make_signed_selector;
1895 template<typename _Tp>
1896 class __make_signed_selector<_Tp, true, false>
1898 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1899 typedef typename __signedt::__type __signed_type;
1900 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1903 typedef typename __cv_signed::__type __type;
1906 template<typename _Tp>
1907 class __make_signed_selector<_Tp, false, true>
1909 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type;
1912 typedef typename __make_signed_selector<__unsigned_type>::__type __type;
1915 // Given an integral/enum type, return the corresponding signed
1917 // Primary template.
1919 template<typename _Tp>
1921 { typedef typename __make_signed_selector<_Tp>::__type type; };
1923 // Integral, but don't define.
1925 struct make_signed<bool>;
1927 #if __cplusplus > 201103L
1928 /// Alias template for make_signed
1929 template<typename _Tp>
1930 using make_signed_t = typename make_signed<_Tp>::type;
1932 /// Alias template for make_unsigned
1933 template<typename _Tp>
1934 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1937 // Array modifications.
1940 template<typename _Tp>
1941 struct remove_extent
1942 { typedef _Tp type; };
1944 template<typename _Tp, std::size_t _Size>
1945 struct remove_extent<_Tp[_Size]>
1946 { typedef _Tp type; };
1948 template<typename _Tp>
1949 struct remove_extent<_Tp[]>
1950 { typedef _Tp type; };
1952 /// remove_all_extents
1953 template<typename _Tp>
1954 struct remove_all_extents
1955 { typedef _Tp type; };
1957 template<typename _Tp, std::size_t _Size>
1958 struct remove_all_extents<_Tp[_Size]>
1959 { typedef typename remove_all_extents<_Tp>::type type; };
1961 template<typename _Tp>
1962 struct remove_all_extents<_Tp[]>
1963 { typedef typename remove_all_extents<_Tp>::type type; };
1965 #if __cplusplus > 201103L
1966 /// Alias template for remove_extent
1967 template<typename _Tp>
1968 using remove_extent_t = typename remove_extent<_Tp>::type;
1970 /// Alias template for remove_all_extents
1971 template<typename _Tp>
1972 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1975 // Pointer modifications.
1977 template<typename _Tp, typename>
1978 struct __remove_pointer_helper
1979 { typedef _Tp type; };
1981 template<typename _Tp, typename _Up>
1982 struct __remove_pointer_helper<_Tp, _Up*>
1983 { typedef _Up type; };
1986 template<typename _Tp>
1987 struct remove_pointer
1988 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1992 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1993 is_void<_Tp>>::value>
1994 struct __add_pointer_helper
1995 { typedef _Tp type; };
1997 template<typename _Tp>
1998 struct __add_pointer_helper<_Tp, true>
1999 { typedef typename remove_reference<_Tp>::type* type; };
2001 template<typename _Tp>
2003 : public __add_pointer_helper<_Tp>
2006 #if __cplusplus > 201103L
2007 /// Alias template for remove_pointer
2008 template<typename _Tp>
2009 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2011 /// Alias template for add_pointer
2012 template<typename _Tp>
2013 using add_pointer_t = typename add_pointer<_Tp>::type;
2016 template<std::size_t _Len>
2017 struct __aligned_storage_msa
2021 unsigned char __data[_Len];
2022 struct __attribute__((__aligned__)) { } __align;
2027 * @brief Alignment type.
2029 * The value of _Align is a default-alignment which shall be the
2030 * most stringent alignment requirement for any C++ object type
2031 * whose size is no greater than _Len (3.9). The member typedef
2032 * type shall be a POD type suitable for use as uninitialized
2033 * storage for any object whose size is at most _Len and whose
2034 * alignment is a divisor of _Align.
2036 template<std::size_t _Len, std::size_t _Align =
2037 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2038 struct aligned_storage
2042 unsigned char __data[_Len];
2043 struct __attribute__((__aligned__((_Align)))) { } __align;
2047 template <typename... _Types>
2048 struct __strictest_alignment
2050 static const size_t _S_alignment = 0;
2051 static const size_t _S_size = 0;
2054 template <typename _Tp, typename... _Types>
2055 struct __strictest_alignment<_Tp, _Types...>
2057 static const size_t _S_alignment =
2058 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2059 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2060 static const size_t _S_size =
2061 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2062 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2066 * @brief Provide aligned storage for types.
2068 * [meta.trans.other]
2070 * Provides aligned storage for any of the provided types of at
2073 * @see aligned_storage
2075 template <size_t _Len, typename... _Types>
2076 struct aligned_union
2079 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2081 using __strictest = __strictest_alignment<_Types...>;
2082 static const size_t _S_len = _Len > __strictest::_S_size
2083 ? _Len : __strictest::_S_size;
2085 /// The value of the strictest alignment of _Types.
2086 static const size_t alignment_value = __strictest::_S_alignment;
2088 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2091 template <size_t _Len, typename... _Types>
2092 const size_t aligned_union<_Len, _Types...>::alignment_value;
2094 // Decay trait for arrays and functions, used for perfect forwarding
2095 // in make_pair, make_tuple, etc.
2096 template<typename _Up,
2097 bool _IsArray = is_array<_Up>::value,
2098 bool _IsFunction = is_function<_Up>::value>
2099 struct __decay_selector;
2102 template<typename _Up>
2103 struct __decay_selector<_Up, false, false>
2104 { typedef typename remove_cv<_Up>::type __type; };
2106 template<typename _Up>
2107 struct __decay_selector<_Up, true, false>
2108 { typedef typename remove_extent<_Up>::type* __type; };
2110 template<typename _Up>
2111 struct __decay_selector<_Up, false, true>
2112 { typedef typename add_pointer<_Up>::type __type; };
2115 template<typename _Tp>
2118 typedef typename remove_reference<_Tp>::type __remove_type;
2121 typedef typename __decay_selector<__remove_type>::__type type;
2124 template<typename _Tp>
2125 class reference_wrapper;
2127 // Helper which adds a reference to a type when given a reference_wrapper
2128 template<typename _Tp>
2129 struct __strip_reference_wrapper
2134 template<typename _Tp>
2135 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2137 typedef _Tp& __type;
2140 template<typename _Tp>
2141 struct __decay_and_strip
2143 typedef typename __strip_reference_wrapper<
2144 typename decay<_Tp>::type>::__type __type;
2148 // Primary template.
2149 /// Define a member typedef @c type only if a boolean constant is true.
2150 template<bool, typename _Tp = void>
2154 // Partial specialization for true.
2155 template<typename _Tp>
2156 struct enable_if<true, _Tp>
2157 { typedef _Tp type; };
2159 template<typename... _Cond>
2160 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
2162 // Primary template.
2163 /// Define a member typedef @c type to one of two argument types.
2164 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2166 { typedef _Iftrue type; };
2168 // Partial specialization for false.
2169 template<typename _Iftrue, typename _Iffalse>
2170 struct conditional<false, _Iftrue, _Iffalse>
2171 { typedef _Iffalse type; };
2174 template<typename... _Tp>
2177 // Sfinae-friendly common_type implementation:
2179 struct __do_common_type_impl
2181 template<typename _Tp, typename _Up>
2182 static __success_type<typename decay<decltype
2183 (true ? std::declval<_Tp>()
2184 : std::declval<_Up>())>::type> _S_test(int);
2186 template<typename, typename>
2187 static __failure_type _S_test(...);
2190 template<typename _Tp, typename _Up>
2191 struct __common_type_impl
2192 : private __do_common_type_impl
2194 typedef decltype(_S_test<_Tp, _Up>(0)) type;
2197 struct __do_member_type_wrapper
2199 template<typename _Tp>
2200 static __success_type<typename _Tp::type> _S_test(int);
2203 static __failure_type _S_test(...);
2206 template<typename _Tp>
2207 struct __member_type_wrapper
2208 : private __do_member_type_wrapper
2210 typedef decltype(_S_test<_Tp>(0)) type;
2213 template<typename _CTp, typename... _Args>
2214 struct __expanded_common_type_wrapper
2216 typedef common_type<typename _CTp::type, _Args...> type;
2219 template<typename... _Args>
2220 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2221 { typedef __failure_type type; };
2223 template<typename _Tp>
2224 struct common_type<_Tp>
2225 { typedef typename decay<_Tp>::type type; };
2227 template<typename _Tp, typename _Up>
2228 struct common_type<_Tp, _Up>
2229 : public __common_type_impl<_Tp, _Up>::type
2232 template<typename _Tp, typename _Up, typename... _Vp>
2233 struct common_type<_Tp, _Up, _Vp...>
2234 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2235 common_type<_Tp, _Up>>::type, _Vp...>::type
2238 /// The underlying type of an enum.
2239 template<typename _Tp>
2240 struct underlying_type
2242 typedef __underlying_type(_Tp) type;
2245 template<typename _Tp>
2246 struct __declval_protector
2248 static const bool __stop = false;
2249 static typename add_rvalue_reference<_Tp>::type __delegate();
2252 template<typename _Tp>
2253 inline typename add_rvalue_reference<_Tp>::type
2256 static_assert(__declval_protector<_Tp>::__stop,
2257 "declval() must not be used!");
2258 return __declval_protector<_Tp>::__delegate();
2262 template<typename _Signature>
2265 // Sfinae-friendly result_of implementation:
2267 #define __cpp_lib_result_of_sfinae 201210
2269 struct __invoke_memfun_ref { };
2270 struct __invoke_memfun_deref { };
2271 struct __invoke_memobj_ref { };
2272 struct __invoke_memobj_deref { };
2273 struct __invoke_other { };
2275 // Associate a tag type with a specialization of __success_type.
2276 template<typename _Tp, typename _Tag>
2277 struct __result_of_success : __success_type<_Tp>
2278 { using __invoke_type = _Tag; };
2280 // [func.require] paragraph 1 bullet 1:
2281 struct __result_of_memfun_ref_impl
2283 template<typename _Fp, typename _Tp1, typename... _Args>
2284 static __result_of_success<decltype(
2285 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2286 ), __invoke_memfun_ref> _S_test(int);
2288 template<typename...>
2289 static __failure_type _S_test(...);
2292 template<typename _MemPtr, typename _Arg, typename... _Args>
2293 struct __result_of_memfun_ref
2294 : private __result_of_memfun_ref_impl
2296 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2299 // [func.require] paragraph 1 bullet 2:
2300 struct __result_of_memfun_deref_impl
2302 template<typename _Fp, typename _Tp1, typename... _Args>
2303 static __result_of_success<decltype(
2304 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2305 ), __invoke_memfun_deref> _S_test(int);
2307 template<typename...>
2308 static __failure_type _S_test(...);
2311 template<typename _MemPtr, typename _Arg, typename... _Args>
2312 struct __result_of_memfun_deref
2313 : private __result_of_memfun_deref_impl
2315 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2318 // [func.require] paragraph 1 bullet 3:
2319 struct __result_of_memobj_ref_impl
2321 template<typename _Fp, typename _Tp1>
2322 static __result_of_success<decltype(
2323 std::declval<_Tp1>().*std::declval<_Fp>()
2324 ), __invoke_memobj_ref> _S_test(int);
2326 template<typename, typename>
2327 static __failure_type _S_test(...);
2330 template<typename _MemPtr, typename _Arg>
2331 struct __result_of_memobj_ref
2332 : private __result_of_memobj_ref_impl
2334 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2337 // [func.require] paragraph 1 bullet 4:
2338 struct __result_of_memobj_deref_impl
2340 template<typename _Fp, typename _Tp1>
2341 static __result_of_success<decltype(
2342 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2343 ), __invoke_memobj_deref> _S_test(int);
2345 template<typename, typename>
2346 static __failure_type _S_test(...);
2349 template<typename _MemPtr, typename _Arg>
2350 struct __result_of_memobj_deref
2351 : private __result_of_memobj_deref_impl
2353 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2356 template<typename _MemPtr, typename _Arg>
2357 struct __result_of_memobj;
2359 template<typename _Res, typename _Class, typename _Arg>
2360 struct __result_of_memobj<_Res _Class::*, _Arg>
2362 typedef typename remove_cv<typename remove_reference<
2363 _Arg>::type>::type _Argval;
2364 typedef _Res _Class::* _MemPtr;
2365 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2366 is_base_of<_Class, _Argval>>::value,
2367 __result_of_memobj_ref<_MemPtr, _Arg>,
2368 __result_of_memobj_deref<_MemPtr, _Arg>
2372 template<typename _MemPtr, typename _Arg, typename... _Args>
2373 struct __result_of_memfun;
2375 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2376 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2378 typedef typename remove_cv<typename remove_reference<
2379 _Arg>::type>::type _Argval;
2380 typedef _Res _Class::* _MemPtr;
2381 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2382 is_base_of<_Class, _Argval>>::value,
2383 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2384 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2388 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2389 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2390 // as the object expression
2392 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2393 template<typename _Tp, typename _Up = typename decay<_Tp>::type>
2399 template<typename _Tp, typename _Up>
2400 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2405 template<bool, bool, typename _Functor, typename... _ArgTypes>
2406 struct __result_of_impl
2408 typedef __failure_type type;
2411 template<typename _MemPtr, typename _Arg>
2412 struct __result_of_impl<true, false, _MemPtr, _Arg>
2413 : public __result_of_memobj<typename decay<_MemPtr>::type,
2414 typename __inv_unwrap<_Arg>::type>
2417 template<typename _MemPtr, typename _Arg, typename... _Args>
2418 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2419 : public __result_of_memfun<typename decay<_MemPtr>::type,
2420 typename __inv_unwrap<_Arg>::type, _Args...>
2423 // [func.require] paragraph 1 bullet 5:
2424 struct __result_of_other_impl
2426 template<typename _Fn, typename... _Args>
2427 static __result_of_success<decltype(
2428 std::declval<_Fn>()(std::declval<_Args>()...)
2429 ), __invoke_other> _S_test(int);
2431 template<typename...>
2432 static __failure_type _S_test(...);
2435 template<typename _Functor, typename... _ArgTypes>
2436 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2437 : private __result_of_other_impl
2439 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2442 // __invoke_result (std::invoke_result for C++11)
2443 template<typename _Functor, typename... _ArgTypes>
2444 struct __invoke_result
2445 : public __result_of_impl<
2446 is_member_object_pointer<
2447 typename remove_reference<_Functor>::type
2449 is_member_function_pointer<
2450 typename remove_reference<_Functor>::type
2452 _Functor, _ArgTypes...
2456 template<typename _Functor, typename... _ArgTypes>
2457 struct result_of<_Functor(_ArgTypes...)>
2458 : public __invoke_result<_Functor, _ArgTypes...>
2461 #if __cplusplus >= 201402L
2462 /// Alias template for aligned_storage
2463 template<size_t _Len, size_t _Align =
2464 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2465 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2467 template <size_t _Len, typename... _Types>
2468 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2470 /// Alias template for decay
2471 template<typename _Tp>
2472 using decay_t = typename decay<_Tp>::type;
2474 /// Alias template for enable_if
2475 template<bool _Cond, typename _Tp = void>
2476 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2478 /// Alias template for conditional
2479 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2480 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2482 /// Alias template for common_type
2483 template<typename... _Tp>
2484 using common_type_t = typename common_type<_Tp...>::type;
2486 /// Alias template for underlying_type
2487 template<typename _Tp>
2488 using underlying_type_t = typename underlying_type<_Tp>::type;
2490 /// Alias template for result_of
2491 template<typename _Tp>
2492 using result_of_t = typename result_of<_Tp>::type;
2495 // __enable_if_t (std::enable_if_t for C++11)
2496 template<bool _Cond, typename _Tp = void>
2497 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
2499 // __void_t (std::void_t for C++11)
2500 template<typename...> using __void_t = void;
2502 #if __cplusplus >= 201703L || !defined(__STRICT_ANSI__) // c++17 or gnu++11
2503 #define __cpp_lib_void_t 201411
2504 /// A metafunction that always yields void, used for detecting valid types.
2505 template<typename...> using void_t = void;
2508 /// Implementation of the detection idiom (negative case).
2509 template<typename _Default, typename _AlwaysVoid,
2510 template<typename...> class _Op, typename... _Args>
2513 using value_t = false_type;
2514 using type = _Default;
2517 /// Implementation of the detection idiom (positive case).
2518 template<typename _Default, template<typename...> class _Op,
2520 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2522 using value_t = true_type;
2523 using type = _Op<_Args...>;
2526 // Detect whether _Op<_Args...> is a valid type, use _Default if not.
2527 template<typename _Default, template<typename...> class _Op,
2529 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2531 // _Op<_Args...> if that is a valid type, otherwise _Default.
2532 template<typename _Default, template<typename...> class _Op,
2534 using __detected_or_t
2535 = typename __detected_or<_Default, _Op, _Args...>::type;
2537 /// @} group metaprogramming
2540 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2541 * member type _NTYPE.
2543 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2544 template<typename _Tp, typename = __void_t<>> \
2545 struct __has_##_NTYPE \
2548 template<typename _Tp> \
2549 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2553 template <typename _Tp>
2554 struct __is_swappable;
2556 template <typename _Tp>
2557 struct __is_nothrow_swappable;
2559 template<typename... _Elements>
2563 struct __is_tuple_like_impl : false_type
2566 template<typename... _Tps>
2567 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
2570 // Internal type trait that allows us to sfinae-protect tuple_cat.
2571 template<typename _Tp>
2572 struct __is_tuple_like
2573 : public __is_tuple_like_impl<typename remove_cv<
2574 typename remove_reference<_Tp>::type>::type>::type
2577 template<typename _Tp>
2579 typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
2580 is_move_constructible<_Tp>,
2581 is_move_assignable<_Tp>>::value>::type
2583 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2584 is_nothrow_move_assignable<_Tp>>::value);
2586 template<typename _Tp, size_t _Nm>
2588 typename enable_if<__is_swappable<_Tp>::value>::type
2589 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2590 noexcept(__is_nothrow_swappable<_Tp>::value);
2592 namespace __swappable_details {
2595 struct __do_is_swappable_impl
2597 template<typename _Tp, typename
2598 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2599 static true_type __test(int);
2602 static false_type __test(...);
2605 struct __do_is_nothrow_swappable_impl
2607 template<typename _Tp>
2608 static __bool_constant<
2609 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2613 static false_type __test(...);
2616 } // namespace __swappable_details
2618 template<typename _Tp>
2619 struct __is_swappable_impl
2620 : public __swappable_details::__do_is_swappable_impl
2622 typedef decltype(__test<_Tp>(0)) type;
2625 template<typename _Tp>
2626 struct __is_nothrow_swappable_impl
2627 : public __swappable_details::__do_is_nothrow_swappable_impl
2629 typedef decltype(__test<_Tp>(0)) type;
2632 template<typename _Tp>
2633 struct __is_swappable
2634 : public __is_swappable_impl<_Tp>::type
2637 template<typename _Tp>
2638 struct __is_nothrow_swappable
2639 : public __is_nothrow_swappable_impl<_Tp>::type
2642 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2643 #define __cpp_lib_is_swappable 201603
2644 /// Metafunctions used for detecting swappable types: p0185r1
2647 template<typename _Tp>
2649 : public __is_swappable_impl<_Tp>::type
2652 /// is_nothrow_swappable
2653 template<typename _Tp>
2654 struct is_nothrow_swappable
2655 : public __is_nothrow_swappable_impl<_Tp>::type
2658 #if __cplusplus >= 201402L
2660 template<typename _Tp>
2661 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
2662 is_swappable<_Tp>::value;
2664 /// is_nothrow_swappable_v
2665 template<typename _Tp>
2666 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
2667 is_nothrow_swappable<_Tp>::value;
2668 #endif // __cplusplus >= 201402L
2670 namespace __swappable_with_details {
2673 struct __do_is_swappable_with_impl
2675 template<typename _Tp, typename _Up, typename
2676 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
2678 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
2679 static true_type __test(int);
2681 template<typename, typename>
2682 static false_type __test(...);
2685 struct __do_is_nothrow_swappable_with_impl
2687 template<typename _Tp, typename _Up>
2688 static __bool_constant<
2689 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
2691 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
2694 template<typename, typename>
2695 static false_type __test(...);
2698 } // namespace __swappable_with_details
2700 template<typename _Tp, typename _Up>
2701 struct __is_swappable_with_impl
2702 : public __swappable_with_details::__do_is_swappable_with_impl
2704 typedef decltype(__test<_Tp, _Up>(0)) type;
2707 // Optimization for the homogenous lvalue case, not required:
2708 template<typename _Tp>
2709 struct __is_swappable_with_impl<_Tp&, _Tp&>
2710 : public __swappable_details::__do_is_swappable_impl
2712 typedef decltype(__test<_Tp&>(0)) type;
2715 template<typename _Tp, typename _Up>
2716 struct __is_nothrow_swappable_with_impl
2717 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
2719 typedef decltype(__test<_Tp, _Up>(0)) type;
2722 // Optimization for the homogenous lvalue case, not required:
2723 template<typename _Tp>
2724 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
2725 : public __swappable_details::__do_is_nothrow_swappable_impl
2727 typedef decltype(__test<_Tp&>(0)) type;
2730 /// is_swappable_with
2731 template<typename _Tp, typename _Up>
2732 struct is_swappable_with
2733 : public __is_swappable_with_impl<_Tp, _Up>::type
2736 /// is_nothrow_swappable_with
2737 template<typename _Tp, typename _Up>
2738 struct is_nothrow_swappable_with
2739 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
2742 #if __cplusplus >= 201402L
2743 /// is_swappable_with_v
2744 template<typename _Tp, typename _Up>
2745 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
2746 is_swappable_with<_Tp, _Up>::value;
2748 /// is_nothrow_swappable_with_v
2749 template<typename _Tp, typename _Up>
2750 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
2751 is_nothrow_swappable_with<_Tp, _Up>::value;
2752 #endif // __cplusplus >= 201402L
2754 #endif// c++1z or gnu++11
2756 // __is_invocable (std::is_invocable for C++11)
2758 template<typename _Result, typename _Ret, typename = void>
2759 struct __is_invocable_impl : false_type { };
2761 template<typename _Result, typename _Ret>
2762 struct __is_invocable_impl<_Result, _Ret, __void_t<typename _Result::type>>
2763 : __or_<is_void<_Ret>, is_convertible<typename _Result::type, _Ret>>::type
2766 template<typename _Fn, typename... _ArgTypes>
2767 struct __is_invocable
2768 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
2771 template<typename _Fn, typename _Tp, typename... _Args>
2772 constexpr bool __call_is_nt(__invoke_memfun_ref)
2774 using _Up = typename __inv_unwrap<_Tp>::type;
2775 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
2776 std::declval<_Args>()...));
2779 template<typename _Fn, typename _Tp, typename... _Args>
2780 constexpr bool __call_is_nt(__invoke_memfun_deref)
2782 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
2783 std::declval<_Args>()...));
2786 template<typename _Fn, typename _Tp>
2787 constexpr bool __call_is_nt(__invoke_memobj_ref)
2789 using _Up = typename __inv_unwrap<_Tp>::type;
2790 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
2793 template<typename _Fn, typename _Tp>
2794 constexpr bool __call_is_nt(__invoke_memobj_deref)
2796 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
2799 template<typename _Fn, typename... _Args>
2800 constexpr bool __call_is_nt(__invoke_other)
2802 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
2805 template<typename _Result, typename _Fn, typename... _Args>
2806 struct __call_is_nothrow
2808 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
2812 template<typename _Fn, typename... _Args>
2813 using __call_is_nothrow_
2814 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
2816 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
2817 template<typename _Fn, typename... _Args>
2818 struct __is_nothrow_invocable
2819 : __and_<__is_invocable<_Fn, _Args...>,
2820 __call_is_nothrow_<_Fn, _Args...>>::type
2824 __nonesuch() = delete;
2825 ~__nonesuch() = delete;
2826 __nonesuch(__nonesuch const&) = delete;
2827 void operator=(__nonesuch const&) = delete;
2830 #if __cplusplus > 201402L
2831 # define __cpp_lib_is_invocable 201703
2833 /// std::invoke_result
2834 template<typename _Functor, typename... _ArgTypes>
2835 struct invoke_result
2836 : public __invoke_result<_Functor, _ArgTypes...>
2839 /// std::invoke_result_t
2840 template<typename _Fn, typename... _Args>
2841 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
2843 /// std::is_invocable
2844 template<typename _Fn, typename... _ArgTypes>
2846 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
2849 /// std::is_invocable_r
2850 template<typename _Ret, typename _Fn, typename... _ArgTypes>
2851 struct is_invocable_r
2852 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
2855 /// std::is_nothrow_invocable
2856 template<typename _Fn, typename... _ArgTypes>
2857 struct is_nothrow_invocable
2858 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
2859 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
2862 template<typename _Result, typename _Ret, typename = void>
2863 struct __is_nt_invocable_impl : false_type { };
2865 template<typename _Result, typename _Ret>
2866 struct __is_nt_invocable_impl<_Result, _Ret,
2867 __void_t<typename _Result::type>>
2868 : __or_<is_void<_Ret>,
2869 __and_<is_convertible<typename _Result::type, _Ret>,
2870 is_nothrow_constructible<_Ret, typename _Result::type>>>
2873 /// std::is_nothrow_invocable_r
2874 template<typename _Ret, typename _Fn, typename... _ArgTypes>
2875 struct is_nothrow_invocable_r
2876 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
2877 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
2880 /// std::is_invocable_v
2881 template<typename _Fn, typename... _Args>
2882 inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
2884 /// std::is_nothrow_invocable_v
2885 template<typename _Fn, typename... _Args>
2886 inline constexpr bool is_nothrow_invocable_v
2887 = is_nothrow_invocable<_Fn, _Args...>::value;
2889 /// std::is_invocable_r_v
2890 template<typename _Fn, typename... _Args>
2891 inline constexpr bool is_invocable_r_v
2892 = is_invocable_r<_Fn, _Args...>::value;
2894 /// std::is_nothrow_invocable_r_v
2895 template<typename _Fn, typename... _Args>
2896 inline constexpr bool is_nothrow_invocable_r_v
2897 = is_nothrow_invocable_r<_Fn, _Args...>::value;
2900 #if __cplusplus > 201402L
2901 # define __cpp_lib_type_trait_variable_templates 201510L
2902 template <typename _Tp>
2903 inline constexpr bool is_void_v = is_void<_Tp>::value;
2904 template <typename _Tp>
2905 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
2906 template <typename _Tp>
2907 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
2908 template <typename _Tp>
2909 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
2910 template <typename _Tp>
2911 inline constexpr bool is_array_v = is_array<_Tp>::value;
2912 template <typename _Tp>
2913 inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
2914 template <typename _Tp>
2915 inline constexpr bool is_lvalue_reference_v =
2916 is_lvalue_reference<_Tp>::value;
2917 template <typename _Tp>
2918 inline constexpr bool is_rvalue_reference_v =
2919 is_rvalue_reference<_Tp>::value;
2920 template <typename _Tp>
2921 inline constexpr bool is_member_object_pointer_v =
2922 is_member_object_pointer<_Tp>::value;
2923 template <typename _Tp>
2924 inline constexpr bool is_member_function_pointer_v =
2925 is_member_function_pointer<_Tp>::value;
2926 template <typename _Tp>
2927 inline constexpr bool is_enum_v = is_enum<_Tp>::value;
2928 template <typename _Tp>
2929 inline constexpr bool is_union_v = is_union<_Tp>::value;
2930 template <typename _Tp>
2931 inline constexpr bool is_class_v = is_class<_Tp>::value;
2932 template <typename _Tp>
2933 inline constexpr bool is_function_v = is_function<_Tp>::value;
2934 template <typename _Tp>
2935 inline constexpr bool is_reference_v = is_reference<_Tp>::value;
2936 template <typename _Tp>
2937 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
2938 template <typename _Tp>
2939 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
2940 template <typename _Tp>
2941 inline constexpr bool is_object_v = is_object<_Tp>::value;
2942 template <typename _Tp>
2943 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
2944 template <typename _Tp>
2945 inline constexpr bool is_compound_v = is_compound<_Tp>::value;
2946 template <typename _Tp>
2947 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
2948 template <typename _Tp>
2949 inline constexpr bool is_const_v = is_const<_Tp>::value;
2950 template <typename _Tp>
2951 inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
2952 template <typename _Tp>
2953 inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
2954 template <typename _Tp>
2955 inline constexpr bool is_trivially_copyable_v =
2956 is_trivially_copyable<_Tp>::value;
2957 template <typename _Tp>
2958 inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
2959 template <typename _Tp>
2960 inline constexpr bool is_pod_v = is_pod<_Tp>::value;
2961 template <typename _Tp>
2962 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
2963 template <typename _Tp>
2964 inline constexpr bool is_empty_v = is_empty<_Tp>::value;
2965 template <typename _Tp>
2966 inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
2967 template <typename _Tp>
2968 inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
2969 template <typename _Tp>
2970 inline constexpr bool is_final_v = is_final<_Tp>::value;
2971 template <typename _Tp>
2972 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
2973 template <typename _Tp>
2974 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
2975 template <typename _Tp, typename... _Args>
2976 inline constexpr bool is_constructible_v =
2977 is_constructible<_Tp, _Args...>::value;
2978 template <typename _Tp>
2979 inline constexpr bool is_default_constructible_v =
2980 is_default_constructible<_Tp>::value;
2981 template <typename _Tp>
2982 inline constexpr bool is_copy_constructible_v =
2983 is_copy_constructible<_Tp>::value;
2984 template <typename _Tp>
2985 inline constexpr bool is_move_constructible_v =
2986 is_move_constructible<_Tp>::value;
2987 template <typename _Tp, typename _Up>
2988 inline constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value;
2989 template <typename _Tp>
2990 inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
2991 template <typename _Tp>
2992 inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
2993 template <typename _Tp>
2994 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
2995 template <typename _Tp, typename... _Args>
2996 inline constexpr bool is_trivially_constructible_v =
2997 is_trivially_constructible<_Tp, _Args...>::value;
2998 template <typename _Tp>
2999 inline constexpr bool is_trivially_default_constructible_v =
3000 is_trivially_default_constructible<_Tp>::value;
3001 template <typename _Tp>
3002 inline constexpr bool is_trivially_copy_constructible_v =
3003 is_trivially_copy_constructible<_Tp>::value;
3004 template <typename _Tp>
3005 inline constexpr bool is_trivially_move_constructible_v =
3006 is_trivially_move_constructible<_Tp>::value;
3007 template <typename _Tp, typename _Up>
3008 inline constexpr bool is_trivially_assignable_v =
3009 is_trivially_assignable<_Tp, _Up>::value;
3010 template <typename _Tp>
3011 inline constexpr bool is_trivially_copy_assignable_v =
3012 is_trivially_copy_assignable<_Tp>::value;
3013 template <typename _Tp>
3014 inline constexpr bool is_trivially_move_assignable_v =
3015 is_trivially_move_assignable<_Tp>::value;
3016 template <typename _Tp>
3017 inline constexpr bool is_trivially_destructible_v =
3018 is_trivially_destructible<_Tp>::value;
3019 template <typename _Tp, typename... _Args>
3020 inline constexpr bool is_nothrow_constructible_v =
3021 is_nothrow_constructible<_Tp, _Args...>::value;
3022 template <typename _Tp>
3023 inline constexpr bool is_nothrow_default_constructible_v =
3024 is_nothrow_default_constructible<_Tp>::value;
3025 template <typename _Tp>
3026 inline constexpr bool is_nothrow_copy_constructible_v =
3027 is_nothrow_copy_constructible<_Tp>::value;
3028 template <typename _Tp>
3029 inline constexpr bool is_nothrow_move_constructible_v =
3030 is_nothrow_move_constructible<_Tp>::value;
3031 template <typename _Tp, typename _Up>
3032 inline constexpr bool is_nothrow_assignable_v =
3033 is_nothrow_assignable<_Tp, _Up>::value;
3034 template <typename _Tp>
3035 inline constexpr bool is_nothrow_copy_assignable_v =
3036 is_nothrow_copy_assignable<_Tp>::value;
3037 template <typename _Tp>
3038 inline constexpr bool is_nothrow_move_assignable_v =
3039 is_nothrow_move_assignable<_Tp>::value;
3040 template <typename _Tp>
3041 inline constexpr bool is_nothrow_destructible_v =
3042 is_nothrow_destructible<_Tp>::value;
3043 template <typename _Tp>
3044 inline constexpr bool has_virtual_destructor_v =
3045 has_virtual_destructor<_Tp>::value;
3046 template <typename _Tp>
3047 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3048 template <typename _Tp>
3049 inline constexpr size_t rank_v = rank<_Tp>::value;
3050 template <typename _Tp, unsigned _Idx = 0>
3051 inline constexpr size_t extent_v = extent<_Tp, _Idx>::value;
3052 template <typename _Tp, typename _Up>
3053 inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
3054 template <typename _Base, typename _Derived>
3055 inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
3056 template <typename _From, typename _To>
3057 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3060 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
3061 #elif defined(__is_identifier)
3062 // For non-GNU compilers:
3063 # if ! __is_identifier(__has_unique_object_representations)
3064 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
3068 #ifdef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
3069 # define __cpp_lib_has_unique_object_representations 201606
3070 /// has_unique_object_representations
3071 template<typename _Tp>
3072 struct has_unique_object_representations
3073 : bool_constant<__has_unique_object_representations(
3074 remove_cv_t<remove_all_extents_t<_Tp>>
3078 template<typename _Tp>
3079 inline constexpr bool has_unique_object_representations_v
3080 = has_unique_object_representations<_Tp>::value;
3082 #undef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
3085 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
3086 #elif defined(__is_identifier)
3087 // For non-GNU compilers:
3088 # if ! __is_identifier(__is_aggregate)
3089 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
3093 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
3094 #define __cpp_lib_is_aggregate 201703
3096 template<typename _Tp>
3098 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)> { };
3101 template<typename _Tp>
3102 inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
3104 #undef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
3108 _GLIBCXX_END_NAMESPACE_VERSION
3113 #endif // _GLIBCXX_TYPE_TRAITS