Path: blob/main/contrib/llvm-project/libcxx/include/__utility/pair.h
35236 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___UTILITY_PAIR_H9#define _LIBCPP___UTILITY_PAIR_H1011#include <__compare/common_comparison_category.h>12#include <__compare/synth_three_way.h>13#include <__concepts/different_from.h>14#include <__config>15#include <__fwd/array.h>16#include <__fwd/pair.h>17#include <__fwd/tuple.h>18#include <__tuple/sfinae_helpers.h>19#include <__tuple/tuple_element.h>20#include <__tuple/tuple_indices.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/decay.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_reference.h>35#include <__type_traits/is_same.h>36#include <__type_traits/is_swappable.h>37#include <__type_traits/is_trivially_relocatable.h>38#include <__type_traits/nat.h>39#include <__type_traits/remove_cvref.h>40#include <__type_traits/unwrap_ref.h>41#include <__utility/declval.h>42#include <__utility/forward.h>43#include <__utility/move.h>44#include <__utility/piecewise_construct.h>45#include <cstddef>4647#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)48# pragma GCC system_header49#endif5051_LIBCPP_PUSH_MACROS52#include <__undef_macros>5354_LIBCPP_BEGIN_NAMESPACE_STD5556template <class, class>57struct __non_trivially_copyable_base {58_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __non_trivially_copyable_base() _NOEXCEPT {}59_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI60__non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}61};6263template <class _T1, class _T2>64struct _LIBCPP_TEMPLATE_VIS pair65#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)66: private __non_trivially_copyable_base<_T1, _T2>67#endif68{69using first_type = _T1;70using second_type = _T2;7172_T1 first;73_T2 second;7475using __trivially_relocatable =76__conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,77pair,78void>;7980_LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;81_LIBCPP_HIDE_FROM_ABI pair(pair&&) = default;8283// When we are requested for pair to be trivially copyable by the ABI macro, we use defaulted members84// if it is both legal to do it (i.e. no references) and we have a way to actually implement it, which requires85// the __enable_if__ attribute before C++20.86#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR87// FIXME: This should really just be a static constexpr variable. It's in a struct to avoid gdb printing the value88// when printing a pair89struct __has_defaulted_members {90static const bool value = !is_reference<first_type>::value && !is_reference<second_type>::value;91};92# if _LIBCPP_STD_VER >= 2093_LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)94requires __has_defaulted_members::value95= default;9697_LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)98requires __has_defaulted_members::value99= default;100# elif __has_attribute(__enable_if__)101_LIBCPP_HIDE_FROM_ABI pair& operator=(const pair&)102__attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;103104_LIBCPP_HIDE_FROM_ABI pair& operator=(pair&&)105__attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;106# else107# error "_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR isn't supported with this compiler"108# endif109#else110struct __has_defaulted_members {111static const bool value = false;112};113#endif // defined(_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR) && __has_attribute(__enable_if__)114115#ifdef _LIBCPP_CXX03_LANG116_LIBCPP_HIDE_FROM_ABI pair() : first(), second() {}117118_LIBCPP_HIDE_FROM_ABI pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}119120template <class _U1, class _U2>121_LIBCPP_HIDE_FROM_ABI pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}122123_LIBCPP_HIDE_FROM_ABI pair& operator=(pair const& __p) {124first = __p.first;125second = __p.second;126return *this;127}128129// Extension: This is provided in C++03 because it allows properly handling the130// assignment to a pair containing references, which would be a hard131// error otherwise.132template <133class _U1,134class _U2,135__enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,136int> = 0>137_LIBCPP_HIDE_FROM_ABI pair& operator=(pair<_U1, _U2> const& __p) {138first = __p.first;139second = __p.second;140return *this;141}142#else143struct _CheckArgs {144template <int&...>145static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {146return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;147}148149template <int&...>150static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {151return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;152}153154template <class _U1, class _U2>155static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_pair_constructible() {156return is_constructible<first_type, _U1>::value && is_constructible<second_type, _U2>::value;157}158159template <class _U1, class _U2>160static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {161return is_convertible<_U1, first_type>::value && is_convertible<_U2, second_type>::value;162}163};164165template <bool _MaybeEnable>166using _CheckArgsDep _LIBCPP_NODEBUG =167typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;168169template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>170explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(171is_nothrow_default_constructible<first_type>::value && is_nothrow_default_constructible<second_type>::value)172: first(), second() {}173174template <bool _Dummy = true,175__enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>176_LIBCPP_HIDE_FROM_ABI177_LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep<_Dummy>::template __is_implicit<_T1 const&, _T2 const&>())178pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value &&179is_nothrow_copy_constructible<second_type>::value)180: first(__t1), second(__t2) {}181182template <183# if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951184class _U1 = _T1,185class _U2 = _T2,186# else187class _U1,188class _U2,189# endif190__enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0 >191_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())192pair(_U1&& __u1, _U2&& __u2) noexcept(is_nothrow_constructible<first_type, _U1>::value &&193is_nothrow_constructible<second_type, _U2>::value)194: first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {195}196197# if _LIBCPP_STD_VER >= 23198template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1&, _U2&>(), int> = 0>199_LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<_U1&, _U2&>())200pair(pair<_U1, _U2>& __p) noexcept((is_nothrow_constructible<first_type, _U1&>::value &&201is_nothrow_constructible<second_type, _U2&>::value))202: first(__p.first), second(__p.second) {}203# endif204205template <class _U1,206class _U2,207__enable_if_t<_CheckArgs::template __is_pair_constructible<_U1 const&, _U2 const&>(), int> = 0>208_LIBCPP_HIDE_FROM_ABI209_LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1 const&, _U2 const&>())210pair(pair<_U1, _U2> const& __p) noexcept(is_nothrow_constructible<first_type, _U1 const&>::value &&211is_nothrow_constructible<second_type, _U2 const&>::value)212: first(__p.first), second(__p.second) {}213214template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0>215_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())216pair(pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, _U1&&>::value &&217is_nothrow_constructible<second_type, _U2&&>::value)218: first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}219220# if _LIBCPP_STD_VER >= 23221template <class _U1,222class _U2,223__enable_if_t<_CheckArgs::template __is_pair_constructible<const _U1&&, const _U2&&>(), int> = 0>224_LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<const _U1&&, const _U2&&>())225pair(const pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, const _U1&&>::value &&226is_nothrow_constructible<second_type, const _U2&&>::value)227: first(std::move(__p.first)), second(std::move(__p.second)) {}228# endif229230# if _LIBCPP_STD_VER >= 23231// TODO: Remove this workaround in LLVM 20. The bug got fixed in Clang 18.232// This is a workaround for http://llvm.org/PR60710. We should be able to remove it once Clang is fixed.233template <class _PairLike>234_LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() {235if constexpr (__pair_like_no_subrange<_PairLike>) {236return !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||237!is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>;238}239return false;240}241242template <__pair_like_no_subrange _PairLike>243requires(is_constructible_v<first_type, decltype(std::get<0>(std::declval<_PairLike &&>()))> &&244is_constructible_v<second_type, decltype(std::get<1>(std::declval<_PairLike &&>()))>)245_LIBCPP_HIDE_FROM_ABI constexpr explicit(__pair_like_explicit_wknd<_PairLike>()) pair(_PairLike&& __p)246: first(std::get<0>(std::forward<_PairLike>(__p))), second(std::get<1>(std::forward<_PairLike>(__p))) {}247# endif248249template <class... _Args1, class... _Args2>250_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20251pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept(252is_nothrow_constructible<first_type, _Args1...>::value && is_nothrow_constructible<second_type, _Args2...>::value)253: pair(__pc,254__first_args,255__second_args,256typename __make_tuple_indices<sizeof...(_Args1)>::type(),257typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}258259_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&260operator=(__conditional_t<!__has_defaulted_members::value && is_copy_assignable<first_type>::value &&261is_copy_assignable<second_type>::value,262pair,263__nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value &&264is_nothrow_copy_assignable<second_type>::value) {265first = __p.first;266second = __p.second;267return *this;268}269270_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&271operator=(__conditional_t<!__has_defaulted_members::value && is_move_assignable<first_type>::value &&272is_move_assignable<second_type>::value,273pair,274__nat>&& __p) noexcept(is_nothrow_move_assignable<first_type>::value &&275is_nothrow_move_assignable<second_type>::value) {276first = std::forward<first_type>(__p.first);277second = std::forward<second_type>(__p.second);278return *this;279}280281template <282class _U1,283class _U2,284__enable_if_t<is_assignable<first_type&, _U1 const&>::value && is_assignable<second_type&, _U2 const&>::value,285int> = 0>286_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2> const& __p) {287first = __p.first;288second = __p.second;289return *this;290}291292template <class _U1,293class _U2,294__enable_if_t<is_assignable<first_type&, _U1>::value && is_assignable<second_type&, _U2>::value, int> = 0>295_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2>&& __p) {296first = std::forward<_U1>(__p.first);297second = std::forward<_U2>(__p.second);298return *this;299}300301# if _LIBCPP_STD_VER >= 23302template <class = void>303_LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair const& __p) const304noexcept(is_nothrow_copy_assignable_v<const first_type> && is_nothrow_copy_assignable_v<const second_type>)305requires(is_copy_assignable_v<const first_type> && is_copy_assignable_v<const second_type>)306{307first = __p.first;308second = __p.second;309return *this;310}311312template <class = void>313_LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair&& __p) const314noexcept(is_nothrow_assignable_v<const first_type&, first_type> &&315is_nothrow_assignable_v<const second_type&, second_type>)316requires(is_assignable_v<const first_type&, first_type> && is_assignable_v<const second_type&, second_type>)317{318first = std::forward<first_type>(__p.first);319second = std::forward<second_type>(__p.second);320return *this;321}322323template <class _U1, class _U2>324_LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(const pair<_U1, _U2>& __p) const325requires(is_assignable_v<const first_type&, const _U1&> && is_assignable_v<const second_type&, const _U2&>)326{327first = __p.first;328second = __p.second;329return *this;330}331332template <class _U1, class _U2>333_LIBCPP_HIDE_FROM_ABI constexpr const pair& operator=(pair<_U1, _U2>&& __p) const334requires(is_assignable_v<const first_type&, _U1> && is_assignable_v<const second_type&, _U2>)335{336first = std::forward<_U1>(__p.first);337second = std::forward<_U2>(__p.second);338return *this;339}340341template <__pair_like_no_subrange _PairLike>342requires(__different_from<_PairLike, pair> &&343is_assignable_v<first_type&, decltype(std::get<0>(std::declval<_PairLike>()))> &&344is_assignable_v<second_type&, decltype(std::get<1>(std::declval<_PairLike>()))>)345_LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(_PairLike&& __p) {346first = std::get<0>(std::forward<_PairLike>(__p));347second = std::get<1>(std::forward<_PairLike>(__p));348return *this;349}350351template <__pair_like_no_subrange _PairLike>352requires(__different_from<_PairLike, pair> &&353is_assignable_v<first_type const&, decltype(std::get<0>(std::declval<_PairLike>()))> &&354is_assignable_v<second_type const&, decltype(std::get<1>(std::declval<_PairLike>()))>)355_LIBCPP_HIDE_FROM_ABI constexpr pair const& operator=(_PairLike&& __p) const {356first = std::get<0>(std::forward<_PairLike>(__p));357second = std::get<1>(std::forward<_PairLike>(__p));358return *this;359}360# endif // _LIBCPP_STD_VER >= 23361362// Prior to C++23, we provide an approximation of constructors and assignment operators from363// pair-like types. This was historically provided as an extension.364# if _LIBCPP_STD_VER < 23365// from std::tuple366template <class _U1,367class _U2,368__enable_if_t<is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value, int> = 0>369_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2> const& __p)370: first(std::get<0>(__p)), second(std::get<1>(__p)) {}371372template < class _U1,373class _U2,374__enable_if_t<is_constructible<_T1, _U1 const&>::value && is_constructible<_T2, _U2 const&>::value &&375!(is_convertible<_U1 const&, _T1>::value && is_convertible<_U2 const&, _T2>::value),376int> = 0>377_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2> const& __p)378: first(std::get<0>(__p)), second(std::get<1>(__p)) {}379380template <class _U1,381class _U2,382__enable_if_t<is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value, int> = 0>383_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(tuple<_U1, _U2>&& __p)384: first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}385386template <class _U1,387class _U2,388__enable_if_t<is_constructible<_T1, _U1>::value && is_constructible<_T2, _U2>::value &&389!(is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value) > = 0>390_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(tuple<_U1, _U2>&& __p)391: first(std::get<0>(std::move(__p))), second(std::get<1>(std::move(__p))) {}392393template <class _U1,394class _U2,395__enable_if_t<is_assignable<_T1&, _U1 const&>::value && is_assignable<_T2&, _U2 const&>::value, int> = 0>396_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2> const& __p) {397first = std::get<0>(__p);398second = std::get<1>(__p);399return *this;400}401402template <class _U1,403class _U2,404__enable_if_t<is_assignable<_T1&, _U1&&>::value && is_assignable<_T2&, _U2&&>::value, int> = 0>405_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2>&& __p) {406first = std::get<0>(std::move(__p));407second = std::get<1>(std::move(__p));408return *this;409}410411// from std::array412template <class _Up,413__enable_if_t<is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value, int> = 0>414_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2> const& __p) : first(__p[0]), second(__p[1]) {}415416template <class _Up,417__enable_if_t<is_constructible<_T1, _Up const&>::value && is_constructible<_T2, _Up const&>::value &&418!(is_convertible<_Up const&, _T1>::value && is_convertible<_Up const&, _T2>::value),419int> = 0>420_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2> const& __p)421: first(__p[0]), second(__p[1]) {}422423template <class _Up, __enable_if_t< is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value, int> = 0>424_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(array<_Up, 2>&& __p)425: first(std::move(__p)[0]), second(std::move(__p)[1]) {}426427template <class _Up,428__enable_if_t<is_constructible<_T1, _Up>::value && is_constructible<_T2, _Up>::value &&429!(is_convertible<_Up, _T1>::value && is_convertible<_Up, _T2>::value),430int> = 0>431_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(array<_Up, 2>&& __p)432: first(std::move(__p)[0]), second(std::move(__p)[1]) {}433434template <class _Up,435__enable_if_t<is_assignable<_T1&, _Up const&>::value && is_assignable<_T2&, _Up const&>::value, int> = 0>436_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2> const& __p) {437first = std::get<0>(__p);438second = std::get<1>(__p);439return *this;440}441442template <class _Up, __enable_if_t<is_assignable<_T1&, _Up>::value && is_assignable<_T2&, _Up>::value, int> = 0>443_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2>&& __p) {444first = std::get<0>(std::move(__p));445second = std::get<1>(std::move(__p));446return *this;447}448# endif // _LIBCPP_STD_VER < 23449#endif // _LIBCPP_CXX03_LANG450451_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair& __p)452_NOEXCEPT_(__is_nothrow_swappable_v<first_type>&& __is_nothrow_swappable_v<second_type>) {453using std::swap;454swap(first, __p.first);455swap(second, __p.second);456}457458#if _LIBCPP_STD_VER >= 23459_LIBCPP_HIDE_FROM_ABI constexpr void swap(const pair& __p) const460noexcept(__is_nothrow_swappable_v<const first_type> && __is_nothrow_swappable_v<const second_type>) {461using std::swap;462swap(first, __p.first);463swap(second, __p.second);464}465#endif466467private:468#ifndef _LIBCPP_CXX03_LANG469template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>470_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20471pair(piecewise_construct_t,472tuple<_Args1...>& __first_args,473tuple<_Args2...>& __second_args,474__tuple_indices<_I1...>,475__tuple_indices<_I2...>)476: first(std::forward<_Args1>(std::get<_I1>(__first_args))...),477second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {}478#endif479};480481#if _LIBCPP_STD_VER >= 17482template <class _T1, class _T2>483pair(_T1, _T2) -> pair<_T1, _T2>;484#endif485486// [pairs.spec], specialized algorithms487488template <class _T1, class _T2, class _U1, class _U2>489inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool490operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {491return __x.first == __y.first && __x.second == __y.second;492}493494#if _LIBCPP_STD_VER >= 20495496template <class _T1, class _T2, class _U1, class _U2>497_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t< __synth_three_way_result<_T1, _U1>,498__synth_three_way_result<_T2, _U2> >499operator<=>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {500if (auto __c = std::__synth_three_way(__x.first, __y.first); __c != 0) {501return __c;502}503return std::__synth_three_way(__x.second, __y.second);504}505506#else // _LIBCPP_STD_VER >= 20507508template <class _T1, class _T2, class _U1, class _U2>509inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool510operator!=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {511return !(__x == __y);512}513514template <class _T1, class _T2, class _U1, class _U2>515inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool516operator<(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {517return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);518}519520template <class _T1, class _T2, class _U1, class _U2>521inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool522operator>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {523return __y < __x;524}525526template <class _T1, class _T2, class _U1, class _U2>527inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool528operator>=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {529return !(__x < __y);530}531532template <class _T1, class _T2, class _U1, class _U2>533inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool534operator<=(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {535return !(__y < __x);536}537538#endif // _LIBCPP_STD_VER >= 20539540#if _LIBCPP_STD_VER >= 23541template <class _T1, class _T2, class _U1, class _U2, template <class> class _TQual, template <class> class _UQual>542requires requires {543typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;544}545struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {546using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;547};548549template <class _T1, class _T2, class _U1, class _U2>550requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }551struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {552using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;553};554#endif // _LIBCPP_STD_VER >= 23555556template <class _T1, class _T2, __enable_if_t<__is_swappable_v<_T1> && __is_swappable_v<_T2>, int> = 0>557inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)558_NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) {559__x.swap(__y);560}561562#if _LIBCPP_STD_VER >= 23563template <class _T1, class _T2>564requires(__is_swappable_v<const _T1> && __is_swappable_v<const _T2>)565_LIBCPP_HIDE_FROM_ABI constexpr void566swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) noexcept(noexcept(__x.swap(__y))) {567__x.swap(__y);568}569#endif570571template <class _T1, class _T2>572inline _LIBCPP_HIDE_FROM_ABI573_LIBCPP_CONSTEXPR_SINCE_CXX14 pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>574make_pair(_T1&& __t1, _T2&& __t2) {575return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>(576std::forward<_T1>(__t1), std::forward<_T2>(__t2));577}578579template <class _T1, class _T2>580struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};581582template <size_t _Ip, class _T1, class _T2>583struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > {584static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");585};586587template <class _T1, class _T2>588struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > {589using type _LIBCPP_NODEBUG = _T1;590};591592template <class _T1, class _T2>593struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > {594using type _LIBCPP_NODEBUG = _T2;595};596597template <size_t _Ip>598struct __get_pair;599600template <>601struct __get_pair<0> {602template <class _T1, class _T2>603static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {604return __p.first;605}606607template <class _T1, class _T2>608static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {609return __p.first;610}611612template <class _T1, class _T2>613static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {614return std::forward<_T1>(__p.first);615}616617template <class _T1, class _T2>618static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {619return std::forward<const _T1>(__p.first);620}621};622623template <>624struct __get_pair<1> {625template <class _T1, class _T2>626static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {627return __p.second;628}629630template <class _T1, class _T2>631static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {632return __p.second;633}634635template <class _T1, class _T2>636static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {637return std::forward<_T2>(__p.second);638}639640template <class _T1, class _T2>641static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {642return std::forward<const _T2>(__p.second);643}644};645646template <size_t _Ip, class _T1, class _T2>647inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&648get(pair<_T1, _T2>& __p) _NOEXCEPT {649return __get_pair<_Ip>::get(__p);650}651652template <size_t _Ip, class _T1, class _T2>653inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&654get(const pair<_T1, _T2>& __p) _NOEXCEPT {655return __get_pair<_Ip>::get(__p);656}657658template <size_t _Ip, class _T1, class _T2>659inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&660get(pair<_T1, _T2>&& __p) _NOEXCEPT {661return __get_pair<_Ip>::get(std::move(__p));662}663664template <size_t _Ip, class _T1, class _T2>665inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&666get(const pair<_T1, _T2>&& __p) _NOEXCEPT {667return __get_pair<_Ip>::get(std::move(__p));668}669670#if _LIBCPP_STD_VER >= 14671template <class _T1, class _T2>672inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {673return __get_pair<0>::get(__p);674}675676template <class _T1, class _T2>677inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {678return __get_pair<0>::get(__p);679}680681template <class _T1, class _T2>682inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {683return __get_pair<0>::get(std::move(__p));684}685686template <class _T1, class _T2>687inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {688return __get_pair<0>::get(std::move(__p));689}690691template <class _T1, class _T2>692inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T2, _T1>& __p) _NOEXCEPT {693return __get_pair<1>::get(__p);694}695696template <class _T1, class _T2>697inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T2, _T1> const& __p) _NOEXCEPT {698return __get_pair<1>::get(__p);699}700701template <class _T1, class _T2>702inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T2, _T1>&& __p) _NOEXCEPT {703return __get_pair<1>::get(std::move(__p));704}705706template <class _T1, class _T2>707inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T2, _T1> const&& __p) _NOEXCEPT {708return __get_pair<1>::get(std::move(__p));709}710711#endif // _LIBCPP_STD_VER >= 14712713_LIBCPP_END_NAMESPACE_STD714715_LIBCPP_POP_MACROS716717#endif // _LIBCPP___UTILITY_PAIR_H718719720