303 :
public __pair_base<_T1, _T2>
311#if __cplusplus >= 201103L
315 template<
typename... _Args1,
typename... _Args2>
320 _GLIBCXX20_CONSTEXPR
void
322 noexcept(__and_<__is_nothrow_swappable<_T1>,
323 __is_nothrow_swappable<_T2>>::value)
330#if __glibcxx_ranges_zip
339 noexcept(__and_v<__is_nothrow_swappable<const _T1>,
340 __is_nothrow_swappable<const _T2>>)
341 requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
350 template<
typename... _Args1,
size_t... _Indexes1,
351 typename... _Args2,
size_t... _Indexes2>
353 pair(tuple<_Args1...>&, tuple<_Args2...>&,
354 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>);
357#if __cpp_lib_concepts
362 explicit(__not_<__and_<__is_implicitly_default_constructible<_T1>,
363 __is_implicitly_default_constructible<_T2>>>())
365 noexcept(is_nothrow_default_constructible_v<_T1>
366 && is_nothrow_default_constructible_v<_T2>)
367 requires is_default_constructible_v<_T1>
368 && is_default_constructible_v<_T2>
375 template<
typename _U1,
typename _U2>
376 static constexpr bool
379 if constexpr (is_constructible_v<_T1, _U1>)
380 return is_constructible_v<_T2, _U2>;
384 template<
typename _U1,
typename _U2>
385 static constexpr bool
386 _S_nothrow_constructible()
388 if constexpr (is_nothrow_constructible_v<_T1, _U1>)
389 return is_nothrow_constructible_v<_T2, _U2>;
393 template<
typename _U1,
typename _U2>
394 static constexpr bool
397 if constexpr (is_convertible_v<_U1, _T1>)
398 return is_convertible_v<_U2, _T2>;
403 template<
typename _U1,
typename _U2>
404 static constexpr bool
407#if __has_builtin(__reference_constructs_from_temporary)
408 if constexpr (__reference_constructs_from_temporary(_T1, _U1&&))
411 return __reference_constructs_from_temporary(_T2, _U2&&);
417#if __glibcxx_tuple_like
418 template<
typename _UPair>
419 static constexpr bool
420 _S_constructible_from_pair_like()
426 template<
typename _UPair>
427 static constexpr bool
428 _S_convertible_from_pair_like()
434 template<
typename _UPair>
435 static constexpr bool
436 _S_dangles_from_pair_like()
447 constexpr explicit(!_S_convertible<const _T1&, const _T2&>())
448 pair(
const type_identity_t<_T1>& __x,
const _T2& __y)
449 noexcept(_S_nothrow_constructible<const _T1&, const _T2&>())
450 requires (_S_constructible<const _T1&, const _T2&>())
455#if __cplusplus > 202002L
456 template<
typename _U1 = _T1,
typename _U2 = _T2>
458 template<
typename _U1,
typename _U2>
460 requires (_S_constructible<_U1, _U2>()) && (!_S_dangles<_U1, _U2>())
461 constexpr explicit(!_S_convertible<_U1, _U2>())
462 pair(_U1&& __x, _U2&& __y)
463 noexcept(_S_nothrow_constructible<_U1, _U2>())
467#if __cplusplus > 202002L
468 template<
typename _U1 = _T1,
typename _U2 = _T2>
470 template<
typename _U1,
typename _U2>
472 requires (_S_constructible<_U1, _U2>()) && (_S_dangles<_U1, _U2>())
473 constexpr explicit(!_S_convertible<_U1, _U2>())
474 pair(_U1&&, _U2&&) =
delete;
477 template<
typename _U1,
typename _U2>
478 requires (_S_constructible<const _U1&, const _U2&>())
479 && (!_S_dangles<_U1, _U2>())
480 constexpr explicit(!_S_convertible<const _U1&, const _U2&>())
482 noexcept(_S_nothrow_constructible<const _U1&, const _U2&>())
486 template<
typename _U1,
typename _U2>
487 requires (_S_constructible<const _U1&, const _U2&>())
488 && (_S_dangles<const _U1&, const _U2&>())
489 constexpr explicit(!_S_convertible<const _U1&, const _U2&>())
493 template<
typename _U1,
typename _U2>
494 requires (_S_constructible<_U1, _U2>()) && (!_S_dangles<_U1, _U2>())
495 constexpr explicit(!_S_convertible<_U1, _U2>())
497 noexcept(_S_nothrow_constructible<_U1, _U2>())
502 template<
typename _U1,
typename _U2>
503 requires (_S_constructible<_U1, _U2>()) && (_S_dangles<_U1, _U2>())
504 constexpr explicit(!_S_convertible<_U1, _U2>())
507#if __glibcxx_ranges_zip
509 template<typename _U1, typename _U2>
510 requires (_S_constructible<_U1&, _U2&>()) && (!_S_dangles<_U1&, _U2&>())
511 constexpr explicit(!_S_convertible<_U1&, _U2&>())
513 noexcept(_S_nothrow_constructible<_U1&, _U2&>())
517 template<
typename _U1,
typename _U2>
518 requires (_S_constructible<_U1&, _U2&>()) && (_S_dangles<_U1&, _U2&>())
519 constexpr explicit(!_S_convertible<_U1&, _U2&>())
523 template<
typename _U1,
typename _U2>
524 requires (_S_constructible<const _U1, const _U2>())
525 && (!_S_dangles<const _U1, const _U2>())
526 constexpr explicit(!_S_convertible<const _U1, const _U2>())
528 noexcept(_S_nothrow_constructible<const _U1, const _U2>())
533 template<
typename _U1,
typename _U2>
534 requires (_S_constructible<const _U1, const _U2>())
535 && (_S_dangles<const _U1, const _U2>())
536 constexpr explicit(!_S_convertible<const _U1, const _U2>())
540#if __glibcxx_tuple_like
541 template<__eligible_pair_like<pair> _UPair>
542 requires (_S_constructible_from_pair_like<_UPair>())
543 && (!_S_dangles_from_pair_like<_UPair>())
544 constexpr explicit(!_S_convertible_from_pair_like<_UPair>())
550 template<__eligible_pair_like<pair> _UPair>
551 requires (_S_constructible_from_pair_like<_UPair>())
552 && (_S_dangles_from_pair_like<_UPair>())
553 constexpr explicit(!_S_convertible_from_pair_like<_UPair>())
554 pair(_UPair&&) =
delete;
559 template<
typename _U1,
typename _U2>
560 static constexpr bool
563 if constexpr (is_assignable_v<_T1&, _U1>)
564 return is_assignable_v<_T2&, _U2>;
568 template<
typename _U1,
typename _U2>
569 static constexpr bool
570 _S_const_assignable()
572 if constexpr (is_assignable_v<const _T1&, _U1>)
573 return is_assignable_v<const _T2&, _U2>;
577 template<
typename _U1,
typename _U2>
578 static constexpr bool
579 _S_nothrow_assignable()
581 if constexpr (is_nothrow_assignable_v<_T1&, _U1>)
582 return is_nothrow_assignable_v<_T2&, _U2>;
586#if __glibcxx_tuple_like
587 template<
typename _UPair>
588 static constexpr bool
589 _S_assignable_from_tuple_like()
595 template<
typename _UPair>
596 static constexpr bool
597 _S_const_assignable_from_tuple_like()
607 pair& operator=(
const pair&) =
delete;
611 operator=(
const pair& __p)
612 noexcept(_S_nothrow_assignable<const _T1&, const _T2&>())
613 requires (_S_assignable<const _T1&, const _T2&>())
622 operator=(
pair&& __p)
623 noexcept(_S_nothrow_assignable<_T1, _T2>())
624 requires (_S_assignable<_T1, _T2>())
632 template<
typename _U1,
typename _U2>
635 noexcept(_S_nothrow_assignable<const _U1&, const _U2&>())
636 requires (_S_assignable<const _U1&, const _U2&>())
644 template<
typename _U1,
typename _U2>
647 noexcept(_S_nothrow_assignable<_U1, _U2>())
648 requires (_S_assignable<_U1, _U2>())
655#if __glibcxx_ranges_zip
657 constexpr const pair&
658 operator=(
const pair& __p)
const
659 requires (_S_const_assignable<const first_type&, const second_type&>())
667 constexpr const pair&
668 operator=(
pair&& __p)
const
669 requires (_S_const_assignable<first_type, second_type>())
677 template<
typename _U1,
typename _U2>
678 constexpr const pair&
680 requires (_S_const_assignable<const _U1&, const _U2&>())
688 template<
typename _U1,
typename _U2>
689 constexpr const pair&
691 requires (_S_const_assignable<_U1, _U2>())
699#if __glibcxx_tuple_like
700 template<__eligible_pair_like<pair> _UPair>
701 requires (_S_assignable_from_tuple_like<_UPair>())
703 operator=(_UPair&& __p)
710 template<__eligible_pair_like<pair> _UPair>
711 requires (_S_const_assignable_from_tuple_like<_UPair>())
712 constexpr const pair&
713 operator=(_UPair&& __p)
const
726#if __has_builtin(__reference_constructs_from_temporary) \
727 && defined _GLIBCXX_DEBUG
728# define __glibcxx_no_dangling_refs(_U1, _U2) \
729 static_assert(!__reference_constructs_from_temporary(_T1, _U1) \
730 && !__reference_constructs_from_temporary(_T2, _U2), \
731 "std::pair constructor creates a dangling reference")
733# define __glibcxx_no_dangling_refs(_U1, _U2)
739 template <
typename _U1 = _T1,
741 typename enable_if<__and_<
742 __is_implicitly_default_constructible<_U1>,
743 __is_implicitly_default_constructible<_U2>>
744 ::value,
bool>::type =
true>
748 template <
typename _U1 = _T1,
754 __and_<__is_implicitly_default_constructible<_U1>,
755 __is_implicitly_default_constructible<_U2>>>>
756 ::value,
bool>
::type =
false>
757 explicit constexpr pair()
762 using _PCCP = _PCC<true, _T1, _T2>;
766 template<
typename _U1 = _T1,
typename _U2=_T2,
typename
767 enable_if<_PCCP::template
768 _ConstructiblePair<_U1, _U2>()
770 _ImplicitlyConvertiblePair<_U1, _U2>(),
772 constexpr pair(
const _T1& __a,
const _T2& __b)
776 template<
typename _U1 = _T1,
typename _U2=_T2,
typename
778 _ConstructiblePair<_U1, _U2>()
780 _ImplicitlyConvertiblePair<_U1, _U2>(),
782 explicit constexpr pair(
const _T1& __a,
const _T2& __b)
787 template <
typename _U1,
typename _U2>
788 using _PCCFP = _PCC<!is_same<_T1, _U1>::value
793 template<
typename _U1,
typename _U2,
typename
795 _ConstructiblePair<_U1, _U2>()
796 && _PCCFP<_U1, _U2>::template
797 _ImplicitlyConvertiblePair<_U1, _U2>(),
801 { __glibcxx_no_dangling_refs(
const _U1&,
const _U2&); }
803 template<
typename _U1,
typename _U2,
typename
804 enable_if<_PCCFP<_U1, _U2>::template
805 _ConstructiblePair<_U1, _U2>()
806 && !_PCCFP<_U1, _U2>::template
807 _ImplicitlyConvertiblePair<_U1, _U2>(),
811 { __glibcxx_no_dangling_refs(
const _U1&,
const _U2&); }
813#if _GLIBCXX_USE_DEPRECATED
814#if defined(__DEPRECATED)
815# define _GLIBCXX_DEPRECATED_PAIR_CTOR \
816 __attribute__ ((__deprecated__ ("use 'nullptr' instead of '0' to " \
817 "initialize std::pair of move-only " \
818 "type and pointer")))
820# define _GLIBCXX_DEPRECATED_PAIR_CTOR
827 struct __zero_as_null_pointer_constant
829 __zero_as_null_pointer_constant(
int __zero_as_null_pointer_constant::*)
831 template<
typename _Tp,
832 typename = __enable_if_t<is_null_pointer<_Tp>::value>>
833 __zero_as_null_pointer_constant(_Tp) =
delete;
841 template<
typename _U1,
842 __enable_if_t<__and_<__not_<is_reference<_U1>>,
844 is_constructible<_T1, _U1>,
845 __not_<is_constructible<_T1, const _U1&>>,
846 is_convertible<_U1, _T1>>::value,
848 _GLIBCXX_DEPRECATED_PAIR_CTOR
850 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
852 { __glibcxx_no_dangling_refs(_U1&&, std::nullptr_t); }
854 template<
typename _U1,
855 __enable_if_t<__and_<__not_<is_reference<_U1>>,
857 is_constructible<_T1, _U1>,
858 __not_<is_constructible<_T1, const _U1&>>,
859 __not_<is_convertible<_U1, _T1>>>::value,
861 _GLIBCXX_DEPRECATED_PAIR_CTOR
863 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
865 { __glibcxx_no_dangling_refs(_U1&&, std::nullptr_t); }
867 template<
typename _U2,
868 __enable_if_t<__and_<is_pointer<_T1>,
869 __not_<is_reference<_U2>>,
870 is_constructible<_T2, _U2>,
871 __not_<is_constructible<_T2, const _U2&>>,
872 is_convertible<_U2, _T2>>::value,
874 _GLIBCXX_DEPRECATED_PAIR_CTOR
876 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
878 { __glibcxx_no_dangling_refs(std::nullptr_t, _U2&&); }
880 template<
typename _U2,
881 __enable_if_t<__and_<is_pointer<_T1>,
882 __not_<is_reference<_U2>>,
883 is_constructible<_T2, _U2>,
884 __not_<is_constructible<_T2, const _U2&>>,
885 __not_<is_convertible<_U2, _T2>>>::value,
887 _GLIBCXX_DEPRECATED_PAIR_CTOR
889 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
891 { __glibcxx_no_dangling_refs(std::nullptr_t, _U2&&); }
892#undef _GLIBCXX_DEPRECATED_PAIR_CTOR
895 template<
typename _U1,
typename _U2,
typename
896 enable_if<_PCCP::template
897 _MoveConstructiblePair<_U1, _U2>()
899 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
901 constexpr pair(_U1&& __x, _U2&& __y)
903 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
905 template<
typename _U1,
typename _U2,
typename
906 enable_if<_PCCP::template
907 _MoveConstructiblePair<_U1, _U2>()
909 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
911 explicit constexpr pair(_U1&& __x, _U2&& __y)
913 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
916 template<
typename _U1,
typename _U2,
typename
917 enable_if<_PCCFP<_U1, _U2>::template
918 _MoveConstructiblePair<_U1, _U2>()
919 && _PCCFP<_U1, _U2>::template
920 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
925 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
927 template<
typename _U1,
typename _U2,
typename
928 enable_if<_PCCFP<_U1, _U2>::template
929 _MoveConstructiblePair<_U1, _U2>()
930 && !_PCCFP<_U1, _U2>::template
931 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
936 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
938#undef __glibcxx_no_dangling_refs
941 operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
942 is_copy_assignable<_T2>>::value,
943 const pair&,
const __nonesuch&> __p)
951 operator=(__conditional_t<__and_<is_move_assignable<_T1>,
952 is_move_assignable<_T2>>::value,
953 pair&&, __nonesuch&&> __p)
954 noexcept(__and_<is_nothrow_move_assignable<_T1>,
955 is_nothrow_move_assignable<_T2>>::value)
962 template<
typename _U1,
typename _U2>
963 typename enable_if<__and_<is_assignable<_T1&, const _U1&>,
964 is_assignable<_T2&, const _U2&>>::value,
973 template<
typename _U1,
typename _U2>
974 typename enable_if<__and_<is_assignable<_T1&, _U1&&>,
975 is_assignable<_T2&, _U2&&>>::value,
994 pair(
const _T1& __a,
const _T2& __b)
998 template<
typename _U1,
typename _U2>
1002#if __has_builtin(__reference_constructs_from_temporary)
1003#pragma GCC diagnostic push
1004#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
1005 typedef int _DanglingCheck1[
1006 __reference_constructs_from_temporary(_T1,
const _U1&) ? -1 : 1
1008 typedef int _DanglingCheck2[
1009 __reference_constructs_from_temporary(_T2,
const _U2&) ? -1 : 1
1011#pragma GCC diagnostic pop