285 :
public __pair_base<_T1, _T2>
293#if __cplusplus >= 201103L
297 template<
typename... _Args1,
typename... _Args2>
302 _GLIBCXX20_CONSTEXPR
void
304 noexcept(__and_<__is_nothrow_swappable<_T1>,
305 __is_nothrow_swappable<_T2>>::value)
312#if __glibcxx_ranges_zip
320 swap(
const pair& __p)
const
321 noexcept(__and_v<__is_nothrow_swappable<const _T1>,
322 __is_nothrow_swappable<const _T2>>)
323 requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
326 swap(
first, __p.first);
332 template<
typename... _Args1,
size_t... _Indexes1,
333 typename... _Args2,
size_t... _Indexes2>
335 pair(tuple<_Args1...>&, tuple<_Args2...>&,
336 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>);
339#if __cpp_lib_concepts
344 explicit(__not_<__and_<__is_implicitly_default_constructible<_T1>,
345 __is_implicitly_default_constructible<_T2>>>())
347 requires is_default_constructible_v<_T1>
348 && is_default_constructible_v<_T2>
355 template<
typename _U1,
typename _U2>
356 static constexpr bool
359 if constexpr (is_constructible_v<_T1, _U1>)
360 return is_constructible_v<_T2, _U2>;
364 template<
typename _U1,
typename _U2>
365 static constexpr bool
366 _S_nothrow_constructible()
368 if constexpr (is_nothrow_constructible_v<_T1, _U1>)
369 return is_nothrow_constructible_v<_T2, _U2>;
373 template<
typename _U1,
typename _U2>
374 static constexpr bool
377 if constexpr (is_convertible_v<_U1, _T1>)
378 return is_convertible_v<_U2, _T2>;
383 template<
typename _U1,
typename _U2>
384 static constexpr bool
387#if __has_builtin(__reference_constructs_from_temporary)
388 if constexpr (__reference_constructs_from_temporary(_T1, _U1&&))
391 return __reference_constructs_from_temporary(_T2, _U2&&);
397#if __glibcxx_tuple_like
398 template<
typename _UPair>
399 static constexpr bool
400 _S_constructible_from_pair_like()
402 return _S_constructible<decltype(std::get<0>(std::declval<_UPair>())),
403 decltype(std::get<1>(std::declval<_UPair>()))>();
406 template<
typename _UPair>
407 static constexpr bool
408 _S_convertible_from_pair_like()
410 return _S_convertible<decltype(std::get<0>(std::declval<_UPair>())),
411 decltype(std::get<1>(std::declval<_UPair>()))>();
414 template<
typename _UPair>
415 static constexpr bool
416 _S_dangles_from_pair_like()
418 return _S_dangles<decltype(std::get<0>(std::declval<_UPair>())),
419 decltype(std::get<1>(std::declval<_UPair>()))>();
427 constexpr explicit(!_S_convertible<const _T1&, const _T2&>())
428 pair(
const _T1& __x,
const _T2& __y)
429 noexcept(_S_nothrow_constructible<const _T1&, const _T2&>())
430 requires (_S_constructible<const _T1&, const _T2&>())
435#if __cplusplus > 202002L
436 template<
typename _U1 = _T1,
typename _U2 = _T2>
438 template<
typename _U1,
typename _U2>
440 requires (_S_constructible<_U1, _U2>()) && (!_S_dangles<_U1, _U2>())
441 constexpr explicit(!_S_convertible<_U1, _U2>())
442 pair(_U1&& __x, _U2&& __y)
443 noexcept(_S_nothrow_constructible<_U1, _U2>())
447#if __cplusplus > 202002L
448 template<
typename _U1 = _T1,
typename _U2 = _T2>
450 template<
typename _U1,
typename _U2>
452 requires (_S_constructible<_U1, _U2>()) && (_S_dangles<_U1, _U2>())
453 constexpr explicit(!_S_convertible<_U1, _U2>())
454 pair(_U1&&, _U2&&) =
delete;
457 template<
typename _U1,
typename _U2>
458 requires (_S_constructible<const _U1&, const _U2&>())
459 && (!_S_dangles<_U1, _U2>())
460 constexpr explicit(!_S_convertible<const _U1&, const _U2&>())
461 pair(
const pair<_U1, _U2>& __p)
462 noexcept(_S_nothrow_constructible<const _U1&, const _U2&>())
466 template<
typename _U1,
typename _U2>
467 requires (_S_constructible<const _U1&, const _U2&>())
468 && (_S_dangles<const _U1&, const _U2&>())
469 constexpr explicit(!_S_convertible<const _U1&, const _U2&>())
470 pair(
const pair<_U1, _U2>&) =
delete;
473 template<
typename _U1,
typename _U2>
474 requires (_S_constructible<_U1, _U2>()) && (!_S_dangles<_U1, _U2>())
475 constexpr explicit(!_S_convertible<_U1, _U2>())
476 pair(pair<_U1, _U2>&& __p)
477 noexcept(_S_nothrow_constructible<_U1, _U2>())
482 template<
typename _U1,
typename _U2>
483 requires (_S_constructible<_U1, _U2>()) && (_S_dangles<_U1, _U2>())
484 constexpr explicit(!_S_convertible<_U1, _U2>())
485 pair(pair<_U1, _U2>&&) =
delete;
487#if __glibcxx_ranges_zip
489 template<typename _U1, typename _U2>
490 requires (_S_constructible<_U1&, _U2&>()) && (!_S_dangles<_U1&, _U2&>())
491 constexpr explicit(!_S_convertible<_U1&, _U2&>())
492 pair(pair<_U1, _U2>& __p)
493 noexcept(_S_nothrow_constructible<_U1&, _U2&>())
497 template<
typename _U1,
typename _U2>
498 requires (_S_constructible<_U1&, _U2&>()) && (_S_dangles<_U1&, _U2&>())
499 constexpr explicit(!_S_convertible<_U1&, _U2&>())
500 pair(pair<_U1, _U2>&) =
delete;
503 template<
typename _U1,
typename _U2>
504 requires (_S_constructible<const _U1, const _U2>())
505 && (!_S_dangles<const _U1, const _U2>())
506 constexpr explicit(!_S_convertible<const _U1, const _U2>())
507 pair(
const pair<_U1, _U2>&& __p)
508 noexcept(_S_nothrow_constructible<const _U1, const _U2>())
513 template<
typename _U1,
typename _U2>
514 requires (_S_constructible<const _U1, const _U2>())
515 && (_S_dangles<const _U1, const _U2>())
516 constexpr explicit(!_S_convertible<const _U1, const _U2>())
517 pair(
const pair<_U1, _U2>&&) =
delete;
520#if __glibcxx_tuple_like
521 template<__eligible_pair_like<pair> _UPair>
522 requires (_S_constructible_from_pair_like<_UPair>())
523 && (!_S_dangles_from_pair_like<_UPair>())
524 constexpr explicit(!_S_convertible_from_pair_like<_UPair>())
526 :
first(std::get<0>(std::forward<_UPair>(__p))),
527 second(std::get<1>(std::forward<_UPair>(__p)))
530 template<__eligible_pair_like<pair> _UPair>
531 requires (_S_constructible_from_pair_like<_UPair>())
532 && (_S_dangles_from_pair_like<_UPair>())
533 constexpr explicit(!_S_convertible_from_pair_like<_UPair>())
534 pair(_UPair&&) =
delete;
539 template<
typename _U1,
typename _U2>
540 static constexpr bool
543 if constexpr (is_assignable_v<_T1&, _U1>)
544 return is_assignable_v<_T2&, _U2>;
548 template<
typename _U1,
typename _U2>
549 static constexpr bool
550 _S_const_assignable()
552 if constexpr (is_assignable_v<const _T1&, _U1>)
553 return is_assignable_v<const _T2&, _U2>;
557 template<
typename _U1,
typename _U2>
558 static constexpr bool
559 _S_nothrow_assignable()
561 if constexpr (is_nothrow_assignable_v<_T1&, _U1>)
562 return is_nothrow_assignable_v<_T2&, _U2>;
566#if __glibcxx_tuple_like
567 template<
typename _UPair>
568 static constexpr bool
569 _S_assignable_from_tuple_like()
571 return _S_assignable<decltype(std::get<0>(std::declval<_UPair>())),
572 decltype(std::get<1>(std::declval<_UPair>()))>();
575 template<
typename _UPair>
576 static constexpr bool
577 _S_const_assignable_from_tuple_like()
579 return _S_const_assignable<decltype(std::get<0>(std::declval<_UPair>())),
580 decltype(std::get<1>(std::declval<_UPair>()))>();
587 pair& operator=(
const pair&) =
delete;
591 operator=(
const pair& __p)
592 noexcept(_S_nothrow_assignable<const _T1&, const _T2&>())
593 requires (_S_assignable<const _T1&, const _T2&>())
602 operator=(
pair&& __p)
603 noexcept(_S_nothrow_assignable<_T1, _T2>())
604 requires (_S_assignable<_T1, _T2>())
606 first = std::forward<first_type>(__p.first);
607 second = std::forward<second_type>(__p.second);
612 template<
typename _U1,
typename _U2>
614 operator=(
const pair<_U1, _U2>& __p)
615 noexcept(_S_nothrow_assignable<const _U1&, const _U2&>())
616 requires (_S_assignable<const _U1&, const _U2&>())
624 template<
typename _U1,
typename _U2>
626 operator=(pair<_U1, _U2>&& __p)
627 noexcept(_S_nothrow_assignable<_U1, _U2>())
628 requires (_S_assignable<_U1, _U2>())
630 first = std::forward<_U1>(__p.first);
631 second = std::forward<_U2>(__p.second);
635#if __glibcxx_ranges_zip
637 constexpr const pair&
638 operator=(
const pair& __p)
const
639 requires (_S_const_assignable<const first_type&, const second_type&>())
647 constexpr const pair&
648 operator=(
pair&& __p)
const
649 requires (_S_const_assignable<first_type, second_type>())
651 first = std::forward<first_type>(__p.first);
652 second = std::forward<second_type>(__p.second);
657 template<
typename _U1,
typename _U2>
658 constexpr const pair&
659 operator=(
const pair<_U1, _U2>& __p)
const
660 requires (_S_const_assignable<const _U1&, const _U2&>())
668 template<
typename _U1,
typename _U2>
669 constexpr const pair&
670 operator=(pair<_U1, _U2>&& __p)
const
671 requires (_S_const_assignable<_U1, _U2>())
673 first = std::forward<_U1>(__p.first);
674 second = std::forward<_U2>(__p.second);
679#if __glibcxx_tuple_like
680 template<__eligible_pair_like<pair> _UPair>
681 requires (_S_assignable_from_tuple_like<_UPair>())
683 operator=(_UPair&& __p)
685 first = std::get<0>(std::forward<_UPair>(__p));
686 second = std::get<1>(std::forward<_UPair>(__p));
690 template<__eligible_pair_like<pair> _UPair>
691 requires (_S_const_assignable_from_tuple_like<_UPair>())
692 constexpr const pair&
693 operator=(_UPair&& __p)
const
695 first = std::get<0>(std::forward<_UPair>(__p));
696 second = std::get<1>(std::forward<_UPair>(__p));
706#if __has_builtin(__reference_constructs_from_temporary) \
707 && defined _GLIBCXX_DEBUG
708# define __glibcxx_no_dangling_refs(_U1, _U2) \
709 static_assert(!__reference_constructs_from_temporary(_T1, _U1) \
710 && !__reference_constructs_from_temporary(_T2, _U2), \
711 "std::pair constructor creates a dangling reference")
713# define __glibcxx_no_dangling_refs(_U1, _U2)
719 template <
typename _U1 = _T1,
721 typename enable_if<__and_<
722 __is_implicitly_default_constructible<_U1>,
723 __is_implicitly_default_constructible<_U2>>
724 ::value,
bool>::type =
true>
728 template <
typename _U1 = _T1,
734 __and_<__is_implicitly_default_constructible<_U1>,
735 __is_implicitly_default_constructible<_U2>>>>
736 ::value,
bool>::type =
false>
737 explicit constexpr pair()
742 using _PCCP = _PCC<true, _T1, _T2>;
746 template<
typename _U1 = _T1,
typename _U2=_T2,
typename
747 enable_if<_PCCP::template
748 _ConstructiblePair<_U1, _U2>()
750 _ImplicitlyConvertiblePair<_U1, _U2>(),
752 constexpr pair(
const _T1& __a,
const _T2& __b)
756 template<
typename _U1 = _T1,
typename _U2=_T2,
typename
758 _ConstructiblePair<_U1, _U2>()
760 _ImplicitlyConvertiblePair<_U1, _U2>(),
762 explicit constexpr pair(
const _T1& __a,
const _T2& __b)
767 template <
typename _U1,
typename _U2>
768 using _PCCFP = _PCC<!is_same<_T1, _U1>::value
773 template<
typename _U1,
typename _U2,
typename
775 _ConstructiblePair<_U1, _U2>()
776 && _PCCFP<_U1, _U2>::template
777 _ImplicitlyConvertiblePair<_U1, _U2>(),
781 { __glibcxx_no_dangling_refs(
const _U1&,
const _U2&); }
783 template<
typename _U1,
typename _U2,
typename
784 enable_if<_PCCFP<_U1, _U2>::template
785 _ConstructiblePair<_U1, _U2>()
786 && !_PCCFP<_U1, _U2>::template
787 _ImplicitlyConvertiblePair<_U1, _U2>(),
789 explicit constexpr pair(
const pair<_U1, _U2>& __p)
791 { __glibcxx_no_dangling_refs(
const _U1&,
const _U2&); }
793#if _GLIBCXX_USE_DEPRECATED
794#if defined(__DEPRECATED)
795# define _GLIBCXX_DEPRECATED_PAIR_CTOR \
796 __attribute__ ((__deprecated__ ("use 'nullptr' instead of '0' to " \
797 "initialize std::pair of move-only " \
798 "type and pointer")))
800# define _GLIBCXX_DEPRECATED_PAIR_CTOR
807 struct __zero_as_null_pointer_constant
809 __zero_as_null_pointer_constant(
int __zero_as_null_pointer_constant::*)
811 template<
typename _Tp,
812 typename = __enable_if_t<is_null_pointer<_Tp>::value>>
813 __zero_as_null_pointer_constant(_Tp) =
delete;
821 template<
typename _U1,
822 __enable_if_t<__and_<__not_<is_reference<_U1>>,
824 is_constructible<_T1, _U1>,
825 __not_<is_constructible<_T1, const _U1&>>,
826 is_convertible<_U1, _T1>>::value,
828 _GLIBCXX_DEPRECATED_PAIR_CTOR
830 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
832 { __glibcxx_no_dangling_refs(_U1&&, std::nullptr_t); }
834 template<
typename _U1,
835 __enable_if_t<__and_<__not_<is_reference<_U1>>,
837 is_constructible<_T1, _U1>,
838 __not_<is_constructible<_T1, const _U1&>>,
839 __not_<is_convertible<_U1, _T1>>>::value,
841 _GLIBCXX_DEPRECATED_PAIR_CTOR
843 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
845 { __glibcxx_no_dangling_refs(_U1&&, std::nullptr_t); }
847 template<
typename _U2,
848 __enable_if_t<__and_<is_pointer<_T1>,
849 __not_<is_reference<_U2>>,
850 is_constructible<_T2, _U2>,
851 __not_<is_constructible<_T2, const _U2&>>,
852 is_convertible<_U2, _T2>>::value,
854 _GLIBCXX_DEPRECATED_PAIR_CTOR
856 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
858 { __glibcxx_no_dangling_refs(std::nullptr_t, _U2&&); }
860 template<
typename _U2,
861 __enable_if_t<__and_<is_pointer<_T1>,
862 __not_<is_reference<_U2>>,
863 is_constructible<_T2, _U2>,
864 __not_<is_constructible<_T2, const _U2&>>,
865 __not_<is_convertible<_U2, _T2>>>::value,
867 _GLIBCXX_DEPRECATED_PAIR_CTOR
869 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
871 { __glibcxx_no_dangling_refs(std::nullptr_t, _U2&&); }
872#undef _GLIBCXX_DEPRECATED_PAIR_CTOR
875 template<
typename _U1,
typename _U2,
typename
876 enable_if<_PCCP::template
877 _MoveConstructiblePair<_U1, _U2>()
879 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
881 constexpr pair(_U1&& __x, _U2&& __y)
883 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
885 template<
typename _U1,
typename _U2,
typename
886 enable_if<_PCCP::template
887 _MoveConstructiblePair<_U1, _U2>()
889 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
891 explicit constexpr pair(_U1&& __x, _U2&& __y)
893 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
896 template<
typename _U1,
typename _U2,
typename
897 enable_if<_PCCFP<_U1, _U2>::template
898 _MoveConstructiblePair<_U1, _U2>()
899 && _PCCFP<_U1, _U2>::template
900 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
902 constexpr pair(pair<_U1, _U2>&& __p)
905 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
907 template<
typename _U1,
typename _U2,
typename
908 enable_if<_PCCFP<_U1, _U2>::template
909 _MoveConstructiblePair<_U1, _U2>()
910 && !_PCCFP<_U1, _U2>::template
911 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
913 explicit constexpr pair(pair<_U1, _U2>&& __p)
916 { __glibcxx_no_dangling_refs(_U1&&, _U2&&); }
918#undef __glibcxx_no_dangling_refs
921 operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
922 is_copy_assignable<_T2>>::value,
923 const pair&,
const __nonesuch&> __p)
931 operator=(__conditional_t<__and_<is_move_assignable<_T1>,
932 is_move_assignable<_T2>>::value,
933 pair&&, __nonesuch&&> __p)
934 noexcept(__and_<is_nothrow_move_assignable<_T1>,
935 is_nothrow_move_assignable<_T2>>::value)
937 first = std::forward<first_type>(__p.first);
938 second = std::forward<second_type>(__p.second);
942 template<
typename _U1,
typename _U2>
943 typename enable_if<__and_<is_assignable<_T1&, const _U1&>,
944 is_assignable<_T2&, const _U2&>>::value,
946 operator=(
const pair<_U1, _U2>& __p)
953 template<
typename _U1,
typename _U2>
954 typename enable_if<__and_<is_assignable<_T1&, _U1&&>,
955 is_assignable<_T2&, _U2&&>>::value,
957 operator=(pair<_U1, _U2>&& __p)
959 first = std::forward<_U1>(__p.first);
960 second = std::forward<_U2>(__p.second);
974 pair(
const _T1& __a,
const _T2& __b)
978 template<
typename _U1,
typename _U2>
979 pair(
const pair<_U1, _U2>& __p)
982#if __has_builtin(__reference_constructs_from_temporary)
983#pragma GCC diagnostic push
984#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
985 typedef int _DanglingCheck1[
986 __reference_constructs_from_temporary(_T1,
const _U1&) ? -1 : 1
988 typedef int _DanglingCheck2[
989 __reference_constructs_from_temporary(_T2,
const _U2&) ? -1 : 1
991#pragma GCC diagnostic pop