brintos

brintos / llvm-project-archived public Read only

0
0
Text · 27.4 KiB · 6148512 Raw
690 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___UTILITY_PAIR_H10#define _LIBCPP___UTILITY_PAIR_H11 12#include <__compare/common_comparison_category.h>13#include <__compare/synth_three_way.h>14#include <__concepts/boolean_testable.h>15#include <__concepts/different_from.h>16#include <__config>17#include <__cstddef/size_t.h>18#include <__fwd/array.h>19#include <__fwd/pair.h>20#include <__fwd/tuple.h>21#include <__tuple/tuple_like_no_subrange.h>22#include <__tuple/tuple_size.h>23#include <__type_traits/common_reference.h>24#include <__type_traits/common_type.h>25#include <__type_traits/conditional.h>26#include <__type_traits/enable_if.h>27#include <__type_traits/integral_constant.h>28#include <__type_traits/is_assignable.h>29#include <__type_traits/is_constructible.h>30#include <__type_traits/is_convertible.h>31#include <__type_traits/is_implicitly_default_constructible.h>32#include <__type_traits/is_nothrow_assignable.h>33#include <__type_traits/is_nothrow_constructible.h>34#include <__type_traits/is_swappable.h>35#include <__type_traits/is_trivially_relocatable.h>36#include <__type_traits/nat.h>37#include <__type_traits/unwrap_ref.h>38#include <__utility/declval.h>39#include <__utility/forward.h>40#include <__utility/integer_sequence.h>41#include <__utility/move.h>42#include <__utility/piecewise_construct.h>43 44#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)45#  pragma GCC system_header46#endif47 48_LIBCPP_PUSH_MACROS49#include <__undef_macros>50 51_LIBCPP_BEGIN_NAMESPACE_STD52 53#ifndef _LIBCPP_CXX03_LANG54 55template <class _T1, class _T2>56struct __check_pair_construction {57  template <int&...>58  static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {59    return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;60  }61 62  template <int&...>63  static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {64    return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;65  }66 67  template <class _U1, class _U2>68  static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_pair_constructible() {69    return is_constructible<_T1, _U1>::value && is_constructible<_T2, _U2>::value;70  }71 72  template <class _U1, class _U2>73  static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {74    return is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value;75  }76};77 78#endif79 80template <class, class>81struct __non_trivially_copyable_base {82  _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __non_trivially_copyable_base() _NOEXCEPT {}83  _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI84  __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}85};86 87template <class _T1, class _T2>88struct pair89#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)90    : private __non_trivially_copyable_base<_T1, _T2>91#endif92{93  using first_type  = _T1;94  using second_type = _T2;95 96  _T1 first;97  _T2 second;98 99  using __trivially_relocatable _LIBCPP_NODEBUG =100      __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,101                      pair,102                      void>;103 104  _LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;105  _LIBCPP_HIDE_FROM_ABI pair(pair&&)      = default;106 107#ifdef _LIBCPP_CXX03_LANG108  _LIBCPP_HIDE_FROM_ABI pair() : first(), second() {}109 110  _LIBCPP_HIDE_FROM_ABI pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}111 112  template <class _U1, class _U2>113  _LIBCPP_HIDE_FROM_ABI pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}114 115  _LIBCPP_HIDE_FROM_ABI pair& operator=(pair const& __p) {116    first  = __p.first;117    second = __p.second;118    return *this;119  }120 121  // Extension: This is provided in C++03 because it allows properly handling the122  //            assignment to a pair containing references, which would be a hard123  //            error otherwise.124  template <125      class _U1,126      class _U2,127      __enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,128                    int> = 0>129  _LIBCPP_HIDE_FROM_ABI pair& operator=(pair<_U1, _U2> const& __p) {130    first  = __p.first;131    second = __p.second;132    return *this;133  }134#else135  template <class _CheckArgsDep                                   = __check_pair_construction<_T1, _T2>,136            __enable_if_t<_CheckArgsDep::__enable_default(), int> = 0>137  explicit(!_CheckArgsDep::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(138      is_nothrow_default_constructible<first_type>::value && is_nothrow_default_constructible<second_type>::value)139      : first(), second() {}140 141  template <class _CheckArgsDep = __check_pair_construction<_T1, _T2>,142            __enable_if_t<_CheckArgsDep::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>143  _LIBCPP_HIDE_FROM_ABI144  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep::template __is_implicit<_T1 const&, _T2 const&>())145      pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value &&146                                                      is_nothrow_copy_constructible<second_type>::value)147      : first(__t1), second(__t2) {}148 149  template <150#  if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951151      class _U1 = _T1,152      class _U2 = _T2,153#  else154      class _U1,155      class _U2,156#  endif157      __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1, _U2>(), int> = 0 >158  _LIBCPP_HIDE_FROM_ABI159  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1, _U2>())160      pair(_U1&& __u1, _U2&& __u2) noexcept(is_nothrow_constructible<first_type, _U1>::value &&161                                            is_nothrow_constructible<second_type, _U2>::value)162      : first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {163  }164 165#  if _LIBCPP_STD_VER >= 23166  template <class _U1,167            class _U2,168            __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1&, _U2&>(), int> = 0>169  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1&, _U2&>())170      pair(pair<_U1, _U2>& __p) noexcept((is_nothrow_constructible<first_type, _U1&>::value &&171                                          is_nothrow_constructible<second_type, _U2&>::value))172      : first(__p.first), second(__p.second) {}173#  endif174 175  template <176      class _U1,177      class _U2,178      __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1 const&, _U2 const&>(),179                    int> = 0>180  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(181      !__check_pair_construction<_T1, _T2>::template __is_implicit<_U1 const&, _U2 const&>())182      pair(pair<_U1, _U2> const& __p) noexcept(is_nothrow_constructible<first_type, _U1 const&>::value &&183                                               is_nothrow_constructible<second_type, _U2 const&>::value)184      : first(__p.first), second(__p.second) {}185 186  template <class _U1,187            class _U2,188            __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1, _U2>(), int> = 0>189  _LIBCPP_HIDE_FROM_ABI190  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1, _U2>())191      pair(pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, _U1&&>::value &&192                                          is_nothrow_constructible<second_type, _U2&&>::value)193      : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}194 195#  if _LIBCPP_STD_VER >= 23196  template <197      class _U1,198      class _U2,199      __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<const _U1&&, const _U2&&>(),200                    int> = 0>201  _LIBCPP_HIDE_FROM_ABI constexpr explicit(202      !__check_pair_construction<_T1, _T2>::template __is_implicit<const _U1&&, const _U2&&>())203      pair(const pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, const _U1&&>::value &&204                                                is_nothrow_constructible<second_type, const _U2&&>::value)205      : first(std::move(__p.first)), second(std::move(__p.second)) {}206#  endif207 208#  if _LIBCPP_STD_VER >= 23209  template <__pair_like_no_subrange _PairLike>210    requires(is_constructible_v<first_type, decltype(std::get<0>(std::declval<_PairLike &&>()))> &&211             is_constructible_v<second_type, decltype(std::get<1>(std::declval<_PairLike &&>()))>)212  _LIBCPP_HIDE_FROM_ABI constexpr explicit(213      !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||214      !is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>) pair(_PairLike&& __p)215      : first(std::get<0>(std::forward<_PairLike>(__p))), second(std::get<1>(std::forward<_PairLike>(__p))) {}216#  endif217 218  template <class... _Args1, class... _Args2>219  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20220  pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept(221      is_nothrow_constructible<first_type, _Args1...>::value && is_nothrow_constructible<second_type, _Args2...>::value)222      : pair(__pc,223             __first_args,224             __second_args,225             __make_index_sequence<sizeof...(_Args1)>(),226             __make_index_sequence<sizeof...(_Args2)>()) {}227 228  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&229  operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,230                            pair,231                            __nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value &&232                                                        is_nothrow_copy_assignable<second_type>::value) {233    first  = __p.first;234    second = __p.second;235    return *this;236  }237 238  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(239      __conditional_t<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&&240          __p) noexcept(is_nothrow_move_assignable<first_type>::value &&241                        is_nothrow_move_assignable<second_type>::value) {242    first  = std::forward<first_type>(__p.first);243    second = std::forward<second_type>(__p.second);244    return *this;245  }246 247  template <248      class _U1,249      class _U2,250      __enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,251                    int> = 0>252  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2> const& __p) {253    first  = __p.first;254    second = __p.second;255    return *this;256  }257 258  template <class _U1,259            class _U2,260            __enable_if_t<is_assignable<first_type&, _U1>::value && is_assignable<second_type&, _U2>::value, int> = 0>261  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2>&& __p) {262    first  = std::forward<_U1>(__p.first);263    second = std::forward<_U2>(__p.second);264    return *this;265  }266 267#  if _LIBCPP_STD_VER >= 23268  template <class = void>269  _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair const& __p) const270      noexcept(is_nothrow_copy_assignable_v<const first_type> && is_nothrow_copy_assignable_v<const second_type>)271    requires(is_copy_assignable_v<const first_type> && is_copy_assignable_v<const second_type>)272  {273    first  = __p.first;274    second = __p.second;275    return *this;276  }277 278  template <class = void>279  _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair&& __p) const280      noexcept(is_nothrow_assignable_v<const first_type&, first_type> &&281               is_nothrow_assignable_v<const second_type&, second_type>)282    requires(is_assignable_v<const first_type&, first_type> && is_assignable_v<const second_type&, second_type>)283  {284    first  = std::forward<first_type>(__p.first);285    second = std::forward<second_type>(__p.second);286    return *this;287  }288 289  template <class _U1, class _U2>290  _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(const pair<_U1, _U2>& __p) const291    requires(is_assignable_v<const first_type&, const _U1&> && is_assignable_v<const second_type&, const _U2&>)292  {293    first  = __p.first;294    second = __p.second;295    return *this;296  }297 298  template <class _U1, class _U2>299  _LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair<_U1, _U2>&& __p) const300    requires(is_assignable_v<const first_type&, _U1> && is_assignable_v<const second_type&, _U2>)301  {302    first  = std::forward<_U1>(__p.first);303    second = std::forward<_U2>(__p.second);304    return *this;305  }306 307  template <__pair_like_no_subrange _PairLike>308    requires(__different_from<_PairLike, pair> &&309             is_assignable_v<first_type&, decltype(std::get<0>(std::declval<_PairLike>()))> &&310             is_assignable_v<second_type&, decltype(std::get<1>(std::declval<_PairLike>()))>)311  _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(_PairLike&& __p) {312    first  = std::get<0>(std::forward<_PairLike>(__p));313    second = std::get<1>(std::forward<_PairLike>(__p));314    return *this;315  }316 317  template <__pair_like_no_subrange _PairLike>318    requires(__different_from<_PairLike, pair> &&319             is_assignable_v<first_type const&, decltype(std::get<0>(std::declval<_PairLike>()))> &&320             is_assignable_v<second_type const&, decltype(std::get<1>(std::declval<_PairLike>()))>)321  _LIBCPP_HIDE_FROM_ABI constexpr pair const& operator=(_PairLike&& __p) const {322    first  = std::get<0>(std::forward<_PairLike>(__p));323    second = std::get<1>(std::forward<_PairLike>(__p));324    return *this;325  }326#  endif // _LIBCPP_STD_VER >= 23327 328  // Prior to C++23, we provide an approximation of constructors and assignment operators from329  // pair-like types. This was historically provided as an extension.330#  if _LIBCPP_STD_VER < 23331  // from std::tuple332  template <class _U1,333            class _U2,334            __enable_if_t<is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value, int> = 0>335  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2> const& __p)336      : first(std::get<0>(__p)), second(std::get<1>(__p)) {}337 338  template < class _U1,339             class _U2,340             __enable_if_t<is_constructible<_T1, _U1 const&>::value && is_constructible<_T2, _U2 const&>::value &&341                               !(is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value),342                           int> = 0>343  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2> const& __p)344      : first(std::get<0>(__p)), second(std::get<1>(__p)) {}345 346  template <class _U1,347            class _U2,348            __enable_if_t<is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value, int> = 0>349  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2>&& __p)350      : first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}351 352  template <class _U1,353            class _U2,354            __enable_if_t<is_constructible<_T1, _U1>::value && is_constructible<_T2, _U2>::value &&355                          !(is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value) > = 0>356  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2>&& __p)357      : first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}358 359  template <class _U1,360            class _U2,361            __enable_if_t<is_assignable<_T1&, _U1 const&>::value && is_assignable<_T2&, _U2 const&>::value, int> = 0>362  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2> const& __p) {363    first  = std::get<0>(__p);364    second = std::get<1>(__p);365    return *this;366  }367 368  template <class _U1,369            class _U2,370            __enable_if_t<is_assignable<_T1&, _U1&&>::value && is_assignable<_T2&, _U2&&>::value, int> = 0>371  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2>&& __p) {372    first  = std::get<0>(std::move(__p));373    second = std::get<1>(std::move(__p));374    return *this;375  }376 377  // from std::array378  template <class _Up,379            __enable_if_t<is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value, int> = 0>380  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2> const& __p) : first(__p[0]), second(__p[1]) {}381 382  template <class _Up,383            __enable_if_t<is_constructible<_T1, _Up const&>::value && is_constructible<_T2, _Up const&>::value &&384                              !(is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value),385                          int> = 0>386  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2> const& __p)387      : first(__p[0]), second(__p[1]) {}388 389  template <class _Up, __enable_if_t< is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value, int> = 0>390  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2>&& __p)391      : first(std::move(__p)[0]), second(std::move(__p)[1]) {}392 393  template <class _Up,394            __enable_if_t<is_constructible<_T1, _Up>::value && is_constructible<_T2, _Up>::value &&395                              !(is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value),396                          int> = 0>397  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2>&& __p)398      : first(std::move(__p)[0]), second(std::move(__p)[1]) {}399 400  template <class _Up,401            __enable_if_t<is_assignable<_T1&, _Up const&>::value && is_assignable<_T2&, _Up const&>::value, int> = 0>402  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2> const& __p) {403    first  = std::get<0>(__p);404    second = std::get<1>(__p);405    return *this;406  }407 408  template <class _Up, __enable_if_t<is_assignable<_T1&, _Up>::value && is_assignable<_T2&, _Up>::value, int> = 0>409  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2>&& __p) {410    first  = std::get<0>(std::move(__p));411    second = std::get<1>(std::move(__p));412    return *this;413  }414#  endif // _LIBCPP_STD_VER < 23415#endif   // _LIBCPP_CXX03_LANG416 417  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair& __p)418      _NOEXCEPT_(__is_nothrow_swappable_v<first_type>&& __is_nothrow_swappable_v<second_type>) {419    using std::swap;420    swap(first, __p.first);421    swap(second, __p.second);422  }423 424#if _LIBCPP_STD_VER >= 23425  _LIBCPP_HIDE_FROM_ABI constexpr void swap(const pair& __p) const426      noexcept(__is_nothrow_swappable_v<const first_type> && __is_nothrow_swappable_v<const second_type>) {427    using std::swap;428    swap(first, __p.first);429    swap(second, __p.second);430  }431#endif432 433private:434#ifndef _LIBCPP_CXX03_LANG435  template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>436  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20437  pair(piecewise_construct_t,438       tuple<_Args1...>& __first_args,439       tuple<_Args2...>& __second_args,440       __index_sequence<_I1...>,441       __index_sequence<_I2...>)442      : first(std::forward<_Args1>(std::get<_I1>(__first_args))...),443        second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {}444#endif445};446 447#if _LIBCPP_STD_VER >= 17448template <class _T1, class _T2>449pair(_T1, _T2) -> pair<_T1, _T2>;450#endif451 452// [pairs.spec], specialized algorithms453 454template <class _T1, class _T2, class _U1, class _U2>455inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool456operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y)457#if _LIBCPP_STD_VER >= 26458  requires requires {459    { __x.first == __y.first } -> __boolean_testable;460    { __x.second == __y.second } -> __boolean_testable;461  }462#endif463{464  return __x.first == __y.first && __x.second == __y.second;465}466 467#if _LIBCPP_STD_VER >= 20468 469template <class _T1, class _T2, class _U1, class _U2>470_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t< __synth_three_way_result<_T1, _U1>,471                                                              __synth_three_way_result<_T2, _U2> >472operator<=>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {473  if (auto __c = std::__synth_three_way(__x.first, __y.first); __c != 0) {474    return __c;475  }476  return std::__synth_three_way(__x.second, __y.second);477}478 479#else // _LIBCPP_STD_VER >= 20480 481template <class _T1, class _T2, class _U1, class _U2>482inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool483operator!=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {484  return !(__x == __y);485}486 487template <class _T1, class _T2, class _U1, class _U2>488inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool489operator<(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {490  return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);491}492 493template <class _T1, class _T2, class _U1, class _U2>494inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool495operator>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {496  return __y < __x;497}498 499template <class _T1, class _T2, class _U1, class _U2>500inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool501operator>=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {502  return !(__x < __y);503}504 505template <class _T1, class _T2, class _U1, class _U2>506inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool507operator<=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {508  return !(__y < __x);509}510 511#endif // _LIBCPP_STD_VER >= 20512 513#if _LIBCPP_STD_VER >= 23514template <class _T1, class _T2, class _U1, class _U2, template <class> class _TQual, template <class> class _UQual>515  requires requires {516    typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;517  }518struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {519  using type _LIBCPP_NODEBUG =520      pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;521};522 523template <class _T1, class _T2, class _U1, class _U2>524  requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }525struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {526  using type _LIBCPP_NODEBUG = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;527};528#endif // _LIBCPP_STD_VER >= 23529 530template <class _T1, class _T2, __enable_if_t<__is_swappable_v<_T1> && __is_swappable_v<_T2>, int> = 0>531inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)532    _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) {533  __x.swap(__y);534}535 536#if _LIBCPP_STD_VER >= 23537template <class _T1, class _T2>538  requires(__is_swappable_v<const _T1> && __is_swappable_v<const _T2>)539_LIBCPP_HIDE_FROM_ABI constexpr void540swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) noexcept(noexcept(__x.swap(__y))) {541  __x.swap(__y);542}543#endif544 545template <class _T1, class _T2>546inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> >547make_pair(_T1&& __t1, _T2&& __t2) {548  return pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> >(std::forward<_T1>(__t1), std::forward<_T2>(__t2));549}550 551template <class _T1, class _T2>552struct tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};553 554template <size_t _Ip, class _T1, class _T2>555struct tuple_element<_Ip, pair<_T1, _T2> > {556  static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");557};558 559template <class _T1, class _T2>560struct tuple_element<0, pair<_T1, _T2> > {561  using type _LIBCPP_NODEBUG = _T1;562};563 564template <class _T1, class _T2>565struct tuple_element<1, pair<_T1, _T2> > {566  using type _LIBCPP_NODEBUG = _T2;567};568 569template <size_t _Ip>570struct __get_pair;571 572template <>573struct __get_pair<0> {574  template <class _T1, class _T2>575  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {576    return __p.first;577  }578 579  template <class _T1, class _T2>580  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {581    return __p.first;582  }583 584  template <class _T1, class _T2>585  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {586    return std::forward<_T1>(__p.first);587  }588 589  template <class _T1, class _T2>590  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {591    return std::forward<const _T1>(__p.first);592  }593};594 595template <>596struct __get_pair<1> {597  template <class _T1, class _T2>598  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {599    return __p.second;600  }601 602  template <class _T1, class _T2>603  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {604    return __p.second;605  }606 607  template <class _T1, class _T2>608  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {609    return std::forward<_T2>(__p.second);610  }611 612  template <class _T1, class _T2>613  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {614    return std::forward<const _T2>(__p.second);615  }616};617 618template <size_t _Ip, class _T1, class _T2>619inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&620get(pair<_T1, _T2>& __p) _NOEXCEPT {621  return __get_pair<_Ip>::get(__p);622}623 624template <size_t _Ip, class _T1, class _T2>625inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&626get(const pair<_T1, _T2>& __p) _NOEXCEPT {627  return __get_pair<_Ip>::get(__p);628}629 630template <size_t _Ip, class _T1, class _T2>631inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&632get(pair<_T1, _T2>&& __p) _NOEXCEPT {633  return __get_pair<_Ip>::get(std::move(__p));634}635 636template <size_t _Ip, class _T1, class _T2>637inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&638get(const pair<_T1, _T2>&& __p) _NOEXCEPT {639  return __get_pair<_Ip>::get(std::move(__p));640}641 642#if _LIBCPP_STD_VER >= 14643template <class _T1, class _T2>644inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {645  return __p.first;646}647 648template <class _T1, class _T2>649inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {650  return __p.first;651}652 653template <class _T1, class _T2>654inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {655  return std::forward<_T1&&>(__p.first);656}657 658template <class _T1, class _T2>659inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {660  return std::forward<_T1 const&&>(__p.first);661}662 663template <class _T2, class _T1>664inline _LIBCPP_HIDE_FROM_ABI constexpr _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {665  return __p.second;666}667 668template <class _T2, class _T1>669inline _LIBCPP_HIDE_FROM_ABI constexpr _T2 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {670  return __p.second;671}672 673template <class _T2, class _T1>674inline _LIBCPP_HIDE_FROM_ABI constexpr _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {675  return std::forward<_T2&&>(__p.second);676}677 678template <class _T2, class _T1>679inline _LIBCPP_HIDE_FROM_ABI constexpr _T2 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {680  return std::forward<_T2 const&&>(__p.second);681}682 683#endif // _LIBCPP_STD_VER >= 14684 685_LIBCPP_END_NAMESPACE_STD686 687_LIBCPP_POP_MACROS688 689#endif // _LIBCPP___UTILITY_PAIR_H690