Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:45

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___UTILITY_PAIR_H
0010 #define _LIBCPP___CXX03___UTILITY_PAIR_H
0011 
0012 #include <__cxx03/__compare/common_comparison_category.h>
0013 #include <__cxx03/__compare/synth_three_way.h>
0014 #include <__cxx03/__concepts/different_from.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__fwd/array.h>
0017 #include <__cxx03/__fwd/pair.h>
0018 #include <__cxx03/__fwd/tuple.h>
0019 #include <__cxx03/__tuple/sfinae_helpers.h>
0020 #include <__cxx03/__tuple/tuple_element.h>
0021 #include <__cxx03/__tuple/tuple_indices.h>
0022 #include <__cxx03/__tuple/tuple_like_no_subrange.h>
0023 #include <__cxx03/__tuple/tuple_size.h>
0024 #include <__cxx03/__type_traits/common_reference.h>
0025 #include <__cxx03/__type_traits/common_type.h>
0026 #include <__cxx03/__type_traits/conditional.h>
0027 #include <__cxx03/__type_traits/decay.h>
0028 #include <__cxx03/__type_traits/integral_constant.h>
0029 #include <__cxx03/__type_traits/is_assignable.h>
0030 #include <__cxx03/__type_traits/is_constructible.h>
0031 #include <__cxx03/__type_traits/is_convertible.h>
0032 #include <__cxx03/__type_traits/is_implicitly_default_constructible.h>
0033 #include <__cxx03/__type_traits/is_nothrow_assignable.h>
0034 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0035 #include <__cxx03/__type_traits/is_reference.h>
0036 #include <__cxx03/__type_traits/is_same.h>
0037 #include <__cxx03/__type_traits/is_swappable.h>
0038 #include <__cxx03/__type_traits/is_trivially_relocatable.h>
0039 #include <__cxx03/__type_traits/nat.h>
0040 #include <__cxx03/__type_traits/remove_cvref.h>
0041 #include <__cxx03/__type_traits/unwrap_ref.h>
0042 #include <__cxx03/__utility/declval.h>
0043 #include <__cxx03/__utility/forward.h>
0044 #include <__cxx03/__utility/move.h>
0045 #include <__cxx03/__utility/piecewise_construct.h>
0046 #include <__cxx03/cstddef>
0047 
0048 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0049 #  pragma GCC system_header
0050 #endif
0051 
0052 _LIBCPP_PUSH_MACROS
0053 #include <__cxx03/__undef_macros>
0054 
0055 _LIBCPP_BEGIN_NAMESPACE_STD
0056 
0057 template <class, class>
0058 struct __non_trivially_copyable_base {
0059   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __non_trivially_copyable_base() _NOEXCEPT {}
0060   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
0061   __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
0062 };
0063 
0064 template <class _T1, class _T2>
0065 struct _LIBCPP_TEMPLATE_VIS pair
0066 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
0067     : private __non_trivially_copyable_base<_T1, _T2>
0068 #endif
0069 {
0070   using first_type  = _T1;
0071   using second_type = _T2;
0072 
0073   _T1 first;
0074   _T2 second;
0075 
0076   using __trivially_relocatable =
0077       __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,
0078                       pair,
0079                       void>;
0080 
0081   _LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;
0082   _LIBCPP_HIDE_FROM_ABI pair(pair&&)      = default;
0083 
0084   // When we are requested for pair to be trivially copyable by the ABI macro, we use defaulted members
0085   // if it is both legal to do it (i.e. no references) and we have a way to actually implement it, which requires
0086   // the __enable_if__ attribute before C++20.
0087 #ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
0088   // FIXME: This should really just be a static constexpr variable. It's in a struct to avoid gdb printing the value
0089   // when printing a pair
0090   struct __has_defaulted_members {
0091     static const bool value = !is_reference<first_type>::value && !is_reference<second_type>::value;
0092   };
0093 #  if _LIBCPP_STD_VER >= 20
0094   _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)
0095     requires __has_defaulted_members::value
0096   = default;
0097 
0098   _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)
0099     requires __has_defaulted_members::value
0100   = default;
0101 #  elif __has_attribute(__enable_if__)
0102   _LIBCPP_HIDE_FROM_ABI pair& operator=(const pair&)
0103       __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
0104 
0105   _LIBCPP_HIDE_FROM_ABI pair& operator=(pair&&)
0106       __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
0107 #  else
0108 #    error "_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR isn't supported with this compiler"
0109 #  endif
0110 #else
0111   struct __has_defaulted_members {
0112     static const bool value = false;
0113   };
0114 #endif // defined(_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR) && __has_attribute(__enable_if__)
0115 
0116 #ifdef _LIBCPP_CXX03_LANG
0117   _LIBCPP_HIDE_FROM_ABI pair() : first(), second() {}
0118 
0119   _LIBCPP_HIDE_FROM_ABI pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
0120 
0121   template <class _U1, class _U2>
0122   _LIBCPP_HIDE_FROM_ABI pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
0123 
0124   _LIBCPP_HIDE_FROM_ABI pair& operator=(pair const& __p) {
0125     first  = __p.first;
0126     second = __p.second;
0127     return *this;
0128   }
0129 
0130   // Extension: This is provided in C++03 because it allows properly handling the
0131   //            assignment to a pair containing references, which would be a hard
0132   //            error otherwise.
0133   template <
0134       class _U1,
0135       class _U2,
0136       __enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,
0137                     int> = 0>
0138   _LIBCPP_HIDE_FROM_ABI pair& operator=(pair<_U1, _U2> const& __p) {
0139     first  = __p.first;
0140     second = __p.second;
0141     return *this;
0142   }
0143 #else
0144   struct _CheckArgs {
0145     template <int&...>
0146     static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {
0147       return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;
0148     }
0149 
0150     template <int&...>
0151     static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {
0152       return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;
0153     }
0154 
0155     template <class _U1, class _U2>
0156     static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_pair_constructible() {
0157       return is_constructible<first_type, _U1>::value && is_constructible<second_type, _U2>::value;
0158     }
0159 
0160     template <class _U1, class _U2>
0161     static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {
0162       return is_convertible<_U1, first_type>::value && is_convertible<_U2, second_type>::value;
0163     }
0164   };
0165 
0166   template <bool _MaybeEnable>
0167   using _CheckArgsDep _LIBCPP_NODEBUG =
0168       typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
0169 
0170   template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>
0171   explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
0172       is_nothrow_default_constructible<first_type>::value && is_nothrow_default_constructible<second_type>::value)
0173       : first(), second() {}
0174 
0175   template <bool _Dummy = true,
0176             __enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
0177   _LIBCPP_HIDE_FROM_ABI
0178   _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep<_Dummy>::template __is_implicit<_T1 const&, _T2 const&>())
0179       pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value &&
0180                                                       is_nothrow_copy_constructible<second_type>::value)
0181       : first(__t1), second(__t2) {}
0182 
0183   template <
0184 #  if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951
0185       class _U1 = _T1,
0186       class _U2 = _T2,
0187 #  else
0188       class _U1,
0189       class _U2,
0190 #  endif
0191       __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0 >
0192   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
0193       pair(_U1&& __u1, _U2&& __u2) noexcept(is_nothrow_constructible<first_type, _U1>::value &&
0194                                             is_nothrow_constructible<second_type, _U2>::value)
0195       : first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {
0196   }
0197 
0198 #  if _LIBCPP_STD_VER >= 23
0199   template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1&, _U2&>(), int> = 0>
0200   _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<_U1&, _U2&>())
0201       pair(pair<_U1, _U2>& __p) noexcept((is_nothrow_constructible<first_type, _U1&>::value &&
0202                                           is_nothrow_constructible<second_type, _U2&>::value))
0203       : first(__p.first), second(__p.second) {}
0204 #  endif
0205 
0206   template <class _U1,
0207             class _U2,
0208             __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1 const&, _U2 const&>(), int> = 0>
0209   _LIBCPP_HIDE_FROM_ABI
0210   _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1 const&, _U2 const&>())
0211       pair(pair<_U1, _U2> const& __p) noexcept(is_nothrow_constructible<first_type, _U1 const&>::value &&
0212                                                is_nothrow_constructible<second_type, _U2 const&>::value)
0213       : first(__p.first), second(__p.second) {}
0214 
0215   template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0>
0216   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
0217       pair(pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, _U1&&>::value &&
0218                                           is_nothrow_constructible<second_type, _U2&&>::value)
0219       : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}
0220 
0221 #  if _LIBCPP_STD_VER >= 23
0222   template <class _U1,
0223             class _U2,
0224             __enable_if_t<_CheckArgs::template __is_pair_constructible<const _U1&&, const _U2&&>(), int> = 0>
0225   _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<const _U1&&, const _U2&&>())
0226       pair(const pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, const _U1&&>::value &&
0227                                                 is_nothrow_constructible<second_type, const _U2&&>::value)
0228       : first(std::move(__p.first)), second(std::move(__p.second)) {}
0229 #  endif
0230 
0231 #  if _LIBCPP_STD_VER >= 23
0232   // TODO: Remove this workaround in LLVM 20. The bug got fixed in Clang 18.
0233   // This is a workaround for http://llvm.org/PR60710. We should be able to remove it once Clang is fixed.
0234   template <class _PairLike>
0235   _LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() {
0236     if constexpr (__pair_like_no_subrange<_PairLike>) {
0237       return !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||
0238              !is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>;
0239     }
0240     return false;
0241   }
0242 
0243   template <__pair_like_no_subrange _PairLike>
0244     requires(is_constructible_v<first_type, decltype(std::get<0>(std::declval<_PairLike &&>()))> &&
0245              is_constructible_v<second_type, decltype(std::get<1>(std::declval<_PairLike &&>()))>)
0246   _LIBCPP_HIDE_FROM_ABI constexpr explicit(__pair_like_explicit_wknd<_PairLike>()) pair(_PairLike&& __p)
0247       : first(std::get<0>(std::forward<_PairLike>(__p))), second(std::get<1>(std::forward<_PairLike>(__p))) {}
0248 #  endif
0249 
0250   template <class... _Args1, class... _Args2>
0251   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0252   pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept(
0253       is_nothrow_constructible<first_type, _Args1...>::value && is_nothrow_constructible<second_type, _Args2...>::value)
0254       : pair(__pc,
0255              __first_args,
0256              __second_args,
0257              typename __make_tuple_indices<sizeof...(_Args1)>::type(),
0258              typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
0259 
0260   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
0261   operator=(__conditional_t<!__has_defaulted_members::value && is_copy_assignable<first_type>::value &&
0262                                 is_copy_assignable<second_type>::value,
0263                             pair,
0264                             __nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value &&
0265                                                         is_nothrow_copy_assignable<second_type>::value) {
0266     first  = __p.first;
0267     second = __p.second;
0268     return *this;
0269   }
0270 
0271   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
0272   operator=(__conditional_t<!__has_defaulted_members::value && is_move_assignable<first_type>::value &&
0273                                 is_move_assignable<second_type>::value,
0274                             pair,
0275                             __nat>&& __p) noexcept(is_nothrow_move_assignable<first_type>::value &&
0276                                                    is_nothrow_move_assignable<second_type>::value) {
0277     first  = std::forward<first_type>(__p.first);
0278     second = std::forward<second_type>(__p.second);
0279     return *this;
0280   }
0281 
0282   template <
0283       class _U1,
0284       class _U2,
0285       __enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,
0286                     int> = 0>
0287   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2> const& __p) {
0288     first  = __p.first;
0289     second = __p.second;
0290     return *this;
0291   }
0292 
0293   template <class _U1,
0294             class _U2,
0295             __enable_if_t<is_assignable<first_type&, _U1>::value && is_assignable<second_type&, _U2>::value, int> = 0>
0296   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2>&& __p) {
0297     first  = std::forward<_U1>(__p.first);
0298     second = std::forward<_U2>(__p.second);
0299     return *this;
0300   }
0301 
0302 #  if _LIBCPP_STD_VER >= 23
0303   template <class = void>
0304   _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair const& __p) const
0305       noexcept(is_nothrow_copy_assignable_v<const first_type> && is_nothrow_copy_assignable_v<const second_type>)
0306     requires(is_copy_assignable_v<const first_type> && is_copy_assignable_v<const second_type>)
0307   {
0308     first  = __p.first;
0309     second = __p.second;
0310     return *this;
0311   }
0312 
0313   template <class = void>
0314   _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair&& __p) const
0315       noexcept(is_nothrow_assignable_v<const first_type&, first_type> &&
0316                is_nothrow_assignable_v<const second_type&, second_type>)
0317     requires(is_assignable_v<const first_type&, first_type> && is_assignable_v<const second_type&, second_type>)
0318   {
0319     first  = std::forward<first_type>(__p.first);
0320     second = std::forward<second_type>(__p.second);
0321     return *this;
0322   }
0323 
0324   template <class _U1, class _U2>
0325   _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(const pair<_U1, _U2>& __p) const
0326     requires(is_assignable_v<const first_type&, const _U1&> && is_assignable_v<const second_type&, const _U2&>)
0327   {
0328     first  = __p.first;
0329     second = __p.second;
0330     return *this;
0331   }
0332 
0333   template <class _U1, class _U2>
0334   _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair<_U1, _U2>&& __p) const
0335     requires(is_assignable_v<const first_type&, _U1> && is_assignable_v<const second_type&, _U2>)
0336   {
0337     first  = std::forward<_U1>(__p.first);
0338     second = std::forward<_U2>(__p.second);
0339     return *this;
0340   }
0341 
0342   template <__pair_like_no_subrange _PairLike>
0343     requires(__different_from<_PairLike, pair> &&
0344              is_assignable_v<first_type&, decltype(std::get<0>(std::declval<_PairLike>()))> &&
0345              is_assignable_v<second_type&, decltype(std::get<1>(std::declval<_PairLike>()))>)
0346   _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(_PairLike&& __p) {
0347     first  = std::get<0>(std::forward<_PairLike>(__p));
0348     second = std::get<1>(std::forward<_PairLike>(__p));
0349     return *this;
0350   }
0351 
0352   template <__pair_like_no_subrange _PairLike>
0353     requires(__different_from<_PairLike, pair> &&
0354              is_assignable_v<first_type const&, decltype(std::get<0>(std::declval<_PairLike>()))> &&
0355              is_assignable_v<second_type const&, decltype(std::get<1>(std::declval<_PairLike>()))>)
0356   _LIBCPP_HIDE_FROM_ABI constexpr pair const& operator=(_PairLike&& __p) const {
0357     first  = std::get<0>(std::forward<_PairLike>(__p));
0358     second = std::get<1>(std::forward<_PairLike>(__p));
0359     return *this;
0360   }
0361 #  endif // _LIBCPP_STD_VER >= 23
0362 
0363   // Prior to C++23, we provide an approximation of constructors and assignment operators from
0364   // pair-like types. This was historically provided as an extension.
0365 #  if _LIBCPP_STD_VER < 23
0366   // from std::tuple
0367   template <class _U1,
0368             class _U2,
0369             __enable_if_t<is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value, int> = 0>
0370   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2> const& __p)
0371       : first(std::get<0>(__p)), second(std::get<1>(__p)) {}
0372 
0373   template < class _U1,
0374              class _U2,
0375              __enable_if_t<is_constructible<_T1, _U1 const&>::value && is_constructible<_T2, _U2 const&>::value &&
0376                                !(is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value),
0377                            int> = 0>
0378   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2> const& __p)
0379       : first(std::get<0>(__p)), second(std::get<1>(__p)) {}
0380 
0381   template <class _U1,
0382             class _U2,
0383             __enable_if_t<is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value, int> = 0>
0384   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2>&& __p)
0385       : first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}
0386 
0387   template <class _U1,
0388             class _U2,
0389             __enable_if_t<is_constructible<_T1, _U1>::value && is_constructible<_T2, _U2>::value &&
0390                           !(is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value) > = 0>
0391   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2>&& __p)
0392       : first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}
0393 
0394   template <class _U1,
0395             class _U2,
0396             __enable_if_t<is_assignable<_T1&, _U1 const&>::value && is_assignable<_T2&, _U2 const&>::value, int> = 0>
0397   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2> const& __p) {
0398     first  = std::get<0>(__p);
0399     second = std::get<1>(__p);
0400     return *this;
0401   }
0402 
0403   template <class _U1,
0404             class _U2,
0405             __enable_if_t<is_assignable<_T1&, _U1&&>::value && is_assignable<_T2&, _U2&&>::value, int> = 0>
0406   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2>&& __p) {
0407     first  = std::get<0>(std::move(__p));
0408     second = std::get<1>(std::move(__p));
0409     return *this;
0410   }
0411 
0412   // from std::array
0413   template <class _Up,
0414             __enable_if_t<is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value, int> = 0>
0415   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2> const& __p) : first(__p[0]), second(__p[1]) {}
0416 
0417   template <class _Up,
0418             __enable_if_t<is_constructible<_T1, _Up const&>::value && is_constructible<_T2, _Up const&>::value &&
0419                               !(is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value),
0420                           int> = 0>
0421   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2> const& __p)
0422       : first(__p[0]), second(__p[1]) {}
0423 
0424   template <class _Up, __enable_if_t< is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value, int> = 0>
0425   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2>&& __p)
0426       : first(std::move(__p)[0]), second(std::move(__p)[1]) {}
0427 
0428   template <class _Up,
0429             __enable_if_t<is_constructible<_T1, _Up>::value && is_constructible<_T2, _Up>::value &&
0430                               !(is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value),
0431                           int> = 0>
0432   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2>&& __p)
0433       : first(std::move(__p)[0]), second(std::move(__p)[1]) {}
0434 
0435   template <class _Up,
0436             __enable_if_t<is_assignable<_T1&, _Up const&>::value && is_assignable<_T2&, _Up const&>::value, int> = 0>
0437   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2> const& __p) {
0438     first  = std::get<0>(__p);
0439     second = std::get<1>(__p);
0440     return *this;
0441   }
0442 
0443   template <class _Up, __enable_if_t<is_assignable<_T1&, _Up>::value && is_assignable<_T2&, _Up>::value, int> = 0>
0444   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2>&& __p) {
0445     first  = std::get<0>(std::move(__p));
0446     second = std::get<1>(std::move(__p));
0447     return *this;
0448   }
0449 #  endif // _LIBCPP_STD_VER < 23
0450 #endif   // _LIBCPP_CXX03_LANG
0451 
0452   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair& __p)
0453       _NOEXCEPT_(__is_nothrow_swappable_v<first_type>&& __is_nothrow_swappable_v<second_type>) {
0454     using std::swap;
0455     swap(first, __p.first);
0456     swap(second, __p.second);
0457   }
0458 
0459 #if _LIBCPP_STD_VER >= 23
0460   _LIBCPP_HIDE_FROM_ABI constexpr void swap(const pair& __p) const
0461       noexcept(__is_nothrow_swappable_v<const first_type> && __is_nothrow_swappable_v<const second_type>) {
0462     using std::swap;
0463     swap(first, __p.first);
0464     swap(second, __p.second);
0465   }
0466 #endif
0467 
0468 private:
0469 #ifndef _LIBCPP_CXX03_LANG
0470   template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
0471   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0472   pair(piecewise_construct_t,
0473        tuple<_Args1...>& __first_args,
0474        tuple<_Args2...>& __second_args,
0475        __tuple_indices<_I1...>,
0476        __tuple_indices<_I2...>)
0477       : first(std::forward<_Args1>(std::get<_I1>(__first_args))...),
0478         second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {}
0479 #endif
0480 };
0481 
0482 #if _LIBCPP_STD_VER >= 17
0483 template <class _T1, class _T2>
0484 pair(_T1, _T2) -> pair<_T1, _T2>;
0485 #endif
0486 
0487 // [pairs.spec], specialized algorithms
0488 
0489 template <class _T1, class _T2, class _U1, class _U2>
0490 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0491 operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0492   return __x.first == __y.first && __x.second == __y.second;
0493 }
0494 
0495 #if _LIBCPP_STD_VER >= 20
0496 
0497 template <class _T1, class _T2, class _U1, class _U2>
0498 _LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t< __synth_three_way_result<_T1, _U1>,
0499                                                               __synth_three_way_result<_T2, _U2> >
0500 operator<=>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0501   if (auto __c = std::__synth_three_way(__x.first, __y.first); __c != 0) {
0502     return __c;
0503   }
0504   return std::__synth_three_way(__x.second, __y.second);
0505 }
0506 
0507 #else // _LIBCPP_STD_VER >= 20
0508 
0509 template <class _T1, class _T2, class _U1, class _U2>
0510 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0511 operator!=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0512   return !(__x == __y);
0513 }
0514 
0515 template <class _T1, class _T2, class _U1, class _U2>
0516 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0517 operator<(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0518   return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
0519 }
0520 
0521 template <class _T1, class _T2, class _U1, class _U2>
0522 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0523 operator>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0524   return __y < __x;
0525 }
0526 
0527 template <class _T1, class _T2, class _U1, class _U2>
0528 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0529 operator>=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0530   return !(__x < __y);
0531 }
0532 
0533 template <class _T1, class _T2, class _U1, class _U2>
0534 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0535 operator<=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
0536   return !(__y < __x);
0537 }
0538 
0539 #endif // _LIBCPP_STD_VER >= 20
0540 
0541 #if _LIBCPP_STD_VER >= 23
0542 template <class _T1, class _T2, class _U1, class _U2, template <class> class _TQual, template <class> class _UQual>
0543   requires requires {
0544     typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
0545   }
0546 struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {
0547   using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
0548 };
0549 
0550 template <class _T1, class _T2, class _U1, class _U2>
0551   requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }
0552 struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {
0553   using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
0554 };
0555 #endif // _LIBCPP_STD_VER >= 23
0556 
0557 template <class _T1, class _T2, __enable_if_t<__is_swappable_v<_T1> && __is_swappable_v<_T2>, int> = 0>
0558 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
0559     _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) {
0560   __x.swap(__y);
0561 }
0562 
0563 #if _LIBCPP_STD_VER >= 23
0564 template <class _T1, class _T2>
0565   requires(__is_swappable_v<const _T1> && __is_swappable_v<const _T2>)
0566 _LIBCPP_HIDE_FROM_ABI constexpr void
0567 swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) noexcept(noexcept(__x.swap(__y))) {
0568   __x.swap(__y);
0569 }
0570 #endif
0571 
0572 template <class _T1, class _T2>
0573 inline _LIBCPP_HIDE_FROM_ABI
0574 _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
0575 make_pair(_T1&& __t1, _T2&& __t2) {
0576   return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>(
0577       std::forward<_T1>(__t1), std::forward<_T2>(__t2));
0578 }
0579 
0580 template <class _T1, class _T2>
0581 struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};
0582 
0583 template <size_t _Ip, class _T1, class _T2>
0584 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > {
0585   static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
0586 };
0587 
0588 template <class _T1, class _T2>
0589 struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > {
0590   using type _LIBCPP_NODEBUG = _T1;
0591 };
0592 
0593 template <class _T1, class _T2>
0594 struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > {
0595   using type _LIBCPP_NODEBUG = _T2;
0596 };
0597 
0598 template <size_t _Ip>
0599 struct __get_pair;
0600 
0601 template <>
0602 struct __get_pair<0> {
0603   template <class _T1, class _T2>
0604   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {
0605     return __p.first;
0606   }
0607 
0608   template <class _T1, class _T2>
0609   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {
0610     return __p.first;
0611   }
0612 
0613   template <class _T1, class _T2>
0614   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
0615     return std::forward<_T1>(__p.first);
0616   }
0617 
0618   template <class _T1, class _T2>
0619   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {
0620     return std::forward<const _T1>(__p.first);
0621   }
0622 };
0623 
0624 template <>
0625 struct __get_pair<1> {
0626   template <class _T1, class _T2>
0627   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {
0628     return __p.second;
0629   }
0630 
0631   template <class _T1, class _T2>
0632   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {
0633     return __p.second;
0634   }
0635 
0636   template <class _T1, class _T2>
0637   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
0638     return std::forward<_T2>(__p.second);
0639   }
0640 
0641   template <class _T1, class _T2>
0642   static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {
0643     return std::forward<const _T2>(__p.second);
0644   }
0645 };
0646 
0647 template <size_t _Ip, class _T1, class _T2>
0648 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
0649 get(pair<_T1, _T2>& __p) _NOEXCEPT {
0650   return __get_pair<_Ip>::get(__p);
0651 }
0652 
0653 template <size_t _Ip, class _T1, class _T2>
0654 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
0655 get(const pair<_T1, _T2>& __p) _NOEXCEPT {
0656   return __get_pair<_Ip>::get(__p);
0657 }
0658 
0659 template <size_t _Ip, class _T1, class _T2>
0660 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
0661 get(pair<_T1, _T2>&& __p) _NOEXCEPT {
0662   return __get_pair<_Ip>::get(std::move(__p));
0663 }
0664 
0665 template <size_t _Ip, class _T1, class _T2>
0666 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
0667 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {
0668   return __get_pair<_Ip>::get(std::move(__p));
0669 }
0670 
0671 #if _LIBCPP_STD_VER >= 14
0672 template <class _T1, class _T2>
0673 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {
0674   return __get_pair<0>::get(__p);
0675 }
0676 
0677 template <class _T1, class _T2>
0678 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {
0679   return __get_pair<0>::get(__p);
0680 }
0681 
0682 template <class _T1, class _T2>
0683 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
0684   return __get_pair<0>::get(std::move(__p));
0685 }
0686 
0687 template <class _T1, class _T2>
0688 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {
0689   return __get_pair<0>::get(std::move(__p));
0690 }
0691 
0692 template <class _T1, class _T2>
0693 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T2, _T1>& __p) _NOEXCEPT {
0694   return __get_pair<1>::get(__p);
0695 }
0696 
0697 template <class _T1, class _T2>
0698 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T2, _T1> const& __p) _NOEXCEPT {
0699   return __get_pair<1>::get(__p);
0700 }
0701 
0702 template <class _T1, class _T2>
0703 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T2, _T1>&& __p) _NOEXCEPT {
0704   return __get_pair<1>::get(std::move(__p));
0705 }
0706 
0707 template <class _T1, class _T2>
0708 inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T2, _T1> const&& __p) _NOEXCEPT {
0709   return __get_pair<1>::get(std::move(__p));
0710 }
0711 
0712 #endif // _LIBCPP_STD_VER >= 14
0713 
0714 _LIBCPP_END_NAMESPACE_STD
0715 
0716 _LIBCPP_POP_MACROS
0717 
0718 #endif // _LIBCPP___CXX03___UTILITY_PAIR_H