brintos

brintos / llvm-project-archived public Read only

0
0
Text · 66.9 KiB · caa4730 Raw
1476 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_TUPLE11#define _LIBCPP_TUPLE12 13// clang-format off14 15/*16    tuple synopsis17 18namespace std19{20 21template <class... T>22class tuple {23public:24    explicit(see-below) constexpr tuple();25    explicit(see-below) tuple(const T&...);  // constexpr in C++1426    template <class... U>27        explicit(see-below) tuple(U&&...);  // constexpr in C++1428    tuple(const tuple&) = default;29    tuple(tuple&&) = default;30 31    template<class... UTypes>32        constexpr explicit(see-below) tuple(tuple<UTypes...>&);  // C++2333    template <class... U>34        explicit(see-below) tuple(const tuple<U...>&);  // constexpr in C++1435    template <class... U>36        explicit(see-below) tuple(tuple<U...>&&);  // constexpr in C++1437    template<class... UTypes>38        constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++2339 40    template<class U1, class U2>41        constexpr explicit(see-below) tuple(pair<U1, U2>&);  // iff sizeof...(Types) == 2 // C++2342    template <class U1, class U2>43        explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++1444    template <class U1, class U2>45        explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++1446    template<class U1, class U2>47        constexpr explicit(see-below) tuple(const pair<U1, U2>&&);  // iff sizeof...(Types) == 2 // C++2348 49    // allocator-extended constructors50    template <class Alloc>51        tuple(allocator_arg_t, const Alloc& a);52    template <class Alloc>53        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);          // constexpr in C++2054    template <class Alloc, class... U>55        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);               // constexpr in C++2056    template <class Alloc>57        tuple(allocator_arg_t, const Alloc& a, const tuple&);                             // constexpr in C++2058    template <class Alloc>59        tuple(allocator_arg_t, const Alloc& a, tuple&&);                                  // constexpr in C++2060    template<class Alloc, class... UTypes>61        constexpr explicit(see-below)62          tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&);                      // C++2363    template <class Alloc, class... U>64        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);   // constexpr in C++2065    template <class Alloc, class... U>66        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);        // constexpr in C++2067    template<class Alloc, class... UTypes>68        constexpr explicit(see-below)69          tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&);               // C++2370    template<class Alloc, class U1, class U2>71        constexpr explicit(see-below)72          tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&);                          // C++2373    template <class Alloc, class U1, class U2>74        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);  // constexpr in C++2075    template <class Alloc, class U1, class U2>76        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);       // constexpr in C++2077    template<class Alloc, class U1, class U2>78        constexpr explicit(see-below)79          tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&);                   // C++2380 81    tuple& operator=(const tuple&);                                                       // constexpr in C++2082    constexpr const tuple& operator=(const tuple&) const;                                 // C++2383    tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...);           // constexpr in C++2084    constexpr const tuple& operator=(tuple&&) const;                                      // C++2385    template <class... U>86        tuple& operator=(const tuple<U...>&);                                             // constexpr in C++2087    template<class... UTypes>88        constexpr const tuple& operator=(const tuple<UTypes...>&) const;                  // C++2389    template <class... U>90        tuple& operator=(tuple<U...>&&);                                                  // constexpr in C++2091    template<class... UTypes>92        constexpr const tuple& operator=(tuple<UTypes...>&&) const;                       // C++2393    template <class U1, class U2>94        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2                   // constexpr in C++2095    template<class U1, class U2>96        constexpr const tuple& operator=(const pair<U1, U2>&) const;   // iff sizeof...(Types) == 2 // C++2397    template <class U1, class U2>98        tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2                        // constexpr in C++2099    template<class U1, class U2>100        constexpr const tuple& operator=(pair<U1, U2>&&) const;  // iff sizeof...(Types) == 2 // C++23101 102    template<class U, size_t N>103        tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION104    template<class U, size_t N>105        tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION106 107    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));               // constexpr in C++20108    constexpr void swap(const tuple&) const noexcept(see-below);                          // C++23109 110    template<tuple-like UTuple>111        friend constexpr bool operator==(const tuple& t, const UTuple& u);                // C++23112    template<tuple-like UTuple>113        friend constexpr auto operator<=>(const tuple& t, const UTuple& u);               // C++23114};115 116 117template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23118  requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }119struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {120  using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;121};122 123template<class... TTypes, class... UTypes>                                // since C++23124  requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }125struct common_type<tuple<TTypes...>, tuple<UTypes...>> {126  using type = tuple<common_type_t<TTypes, UTypes>...>;127};128 129template <class ...T>130tuple(T...) -> tuple<T...>;                                         // since C++17131template <class T1, class T2>132tuple(pair<T1, T2>) -> tuple<T1, T2>;                               // since C++17133template <class Alloc, class ...T>134tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>;                 // since C++17135template <class Alloc, class T1, class T2>136tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>;       // since C++17137template <class Alloc, class ...T>138tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>;          // since C++17139 140struct ignore-type { // exposition only                             // Since C++26141  constexpr const ignore-type&142    operator=(const auto &) const noexcept143      { return *this; }144};145inline constexpr ignore-type ignore;146 147template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14148template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14149template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14150template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14151 152// [tuple.apply], calling a function with a tuple of arguments:153template <class F, class Tuple>154  constexpr decltype(auto) apply(F&& f, Tuple&& t) noexcept(see below);  // C++17 noexcept since C++23155template <class T, class Tuple>156  constexpr T make_from_tuple(Tuple&& t); // C++17157 158// 20.4.1.4, tuple helper classes:159template <class T> struct tuple_size; // undefined160template <class... T> struct tuple_size<tuple<T...>>;161template <class T>162 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17163template <size_t I, class T> struct tuple_element; // undefined164template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;165template <size_t I, class T>166  using tuple_element_t = typename tuple_element <I, T>::type; // C++14167 168// 20.4.1.5, element access:169template <size_t I, class... T>170    typename tuple_element<I, tuple<T...>>::type&171    get(tuple<T...>&) noexcept; // constexpr in C++14172template <size_t I, class... T>173    const typename tuple_element<I, tuple<T...>>::type&174    get(const tuple<T...>&) noexcept; // constexpr in C++14175template <size_t I, class... T>176    typename tuple_element<I, tuple<T...>>::type&&177    get(tuple<T...>&&) noexcept; // constexpr in C++14178template <size_t I, class... T>179    const typename tuple_element<I, tuple<T...>>::type&&180    get(const tuple<T...>&&) noexcept; // constexpr in C++14181 182template <class T1, class... T>183    constexpr T1& get(tuple<T...>&) noexcept;  // C++14184template <class T1, class... T>185    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14186template <class T1, class... T>187    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14188template <class T1, class... T>189    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14190 191// 20.4.1.6, relational operators:192template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14193template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20194template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20195template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20196template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20197template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20198template<class... T, class... U>199  constexpr common_comparison_category_t<synth-three-way-result<T, U>...>200    operator<=>(const tuple<T...>&, const tuple<U...>&);                                  // since C++20201 202template <class... Types, class Alloc>203  struct uses_allocator<tuple<Types...>, Alloc>;204 205template <class... Types>206  void207  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));208 209template <class... Types>210  constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below);   // C++23211 212}  // std213 214*/215 216// clang-format on217 218#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)219#  include <__cxx03/__config>220#else221#  include <__compare/common_comparison_category.h>222#  include <__compare/ordering.h>223#  include <__compare/synth_three_way.h>224#  include <__concepts/boolean_testable.h>225#  include <__config>226#  include <__cstddef/size_t.h>227#  include <__fwd/array.h>228#  include <__fwd/get.h>229#  include <__fwd/pair.h>230#  include <__fwd/tuple.h>231#  include <__memory/allocator_arg_t.h>232#  include <__memory/uses_allocator.h>233#  include <__tuple/find_index.h>234#  include <__tuple/ignore.h>235#  include <__tuple/tuple_element.h>236#  include <__tuple/tuple_like.h>237#  include <__tuple/tuple_size.h>238#  include <__type_traits/common_reference.h>239#  include <__type_traits/common_type.h>240#  include <__type_traits/conditional.h>241#  include <__type_traits/conjunction.h>242#  include <__type_traits/copy_cvref.h>243#  include <__type_traits/disjunction.h>244#  include <__type_traits/enable_if.h>245#  include <__type_traits/invoke.h>246#  include <__type_traits/is_assignable.h>247#  include <__type_traits/is_constructible.h>248#  include <__type_traits/is_convertible.h>249#  include <__type_traits/is_empty.h>250#  include <__type_traits/is_final.h>251#  include <__type_traits/is_implicitly_default_constructible.h>252#  include <__type_traits/is_nothrow_assignable.h>253#  include <__type_traits/is_nothrow_constructible.h>254#  include <__type_traits/is_reference.h>255#  include <__type_traits/is_same.h>256#  include <__type_traits/is_swappable.h>257#  include <__type_traits/is_trivially_relocatable.h>258#  include <__type_traits/lazy.h>259#  include <__type_traits/maybe_const.h>260#  include <__type_traits/nat.h>261#  include <__type_traits/negation.h>262#  include <__type_traits/reference_constructs_from_temporary.h>263#  include <__type_traits/remove_cv.h>264#  include <__type_traits/remove_cvref.h>265#  include <__type_traits/remove_reference.h>266#  include <__type_traits/type_list.h>267#  include <__type_traits/unwrap_ref.h>268#  include <__utility/declval.h>269#  include <__utility/forward.h>270#  include <__utility/integer_sequence.h>271#  include <__utility/move.h>272#  include <__utility/swap.h>273#  include <version>274 275// standard-mandated includes276 277// [tuple.syn]278#  include <compare>279 280#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)281#    pragma GCC system_header282#  endif283 284_LIBCPP_PUSH_MACROS285#  include <__undef_macros>286 287_LIBCPP_BEGIN_NAMESPACE_STD288 289#  ifndef _LIBCPP_CXX03_LANG290 291template <size_t _Ip, class _Tp, class _Up>292_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __tuple_compare_equal(const _Tp& __x, const _Up& __y) {293  if constexpr (_Ip == 0)294    return true;295  else296    return std::__tuple_compare_equal<_Ip - 1>(__x, __y) && std::get<_Ip - 1>(__x) == std::get<_Ip - 1>(__y);297}298 299#    if _LIBCPP_STD_VER >= 26300template <class _Tp, class _Up, class _IndexSeq = make_index_sequence<tuple_size_v<_Tp>>>301inline constexpr bool __can_tuple_compare_equal = false;302 303// TODO(LLVM 23): Remove `tuple_size_v<_Tp> == tuple_size_v<_Up>` here once once LLVM-20 support ends304// because the resolution of CWG2369 landed in LLVM-21.305template <class _Tp, class _Up, size_t... _Is>306  requires(tuple_size_v<_Tp> == tuple_size_v<_Up>)307inline constexpr bool __can_tuple_compare_equal<_Tp, _Up, index_sequence<_Is...>> =308    __all<requires(const tuple_element_t<_Is, _Tp>& __t, const tuple_element_t<_Is, _Up>& __u) {309      { __t == __u } -> __boolean_testable;310    }...>::value;311#    endif // _LIBCPP_STD_VER >= 26312 313#    if _LIBCPP_STD_VER >= 20314template <class _Ret, class _Tp, class _Up, size_t... _Is>315_LIBCPP_HIDE_FROM_ABI constexpr _Ret __tuple_compare_three_way(const _Tp& __x, const _Up& __y, index_sequence<_Is...>) {316  _Ret __result = strong_ordering::equal;317  static_cast<void>(318      ((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...));319  return __result;320}321#    endif // _LIBCPP_STD_VER >= 20322 323#    if _LIBCPP_STD_VER >= 23324template <class _Tp>325concept __tuple_like_no_tuple = __tuple_like<_Tp> && !__is_tuple_v<_Tp>;326 327template <class _Tp, class _Up, class _IndexSeq>328struct __tuple_common_comparison_category_impl {};329 330// TODO(LLVM 23): Remove `tuple_size_v<_Tp> == tuple_size_v<_Up>` here once once LLVM-20 support ends331// because the resolution of CWG2369 landed in LLVM-21.332template <class _Tp, class _Up, size_t... _Is>333  requires(tuple_size_v<_Tp> == tuple_size_v<_Up>) && requires {334    typename common_comparison_category_t<335        __synth_three_way_result<tuple_element_t<_Is, _Tp>, tuple_element_t<_Is, _Up>>...>;336  }337struct __tuple_common_comparison_category_impl<_Tp, _Up, index_sequence<_Is...>> {338  using type _LIBCPP_NODEBUG =339      common_comparison_category_t<__synth_three_way_result<tuple_element_t<_Is, _Tp>, tuple_element_t<_Is, _Up>>...>;340};341 342template <__tuple_like _Tp, __tuple_like _Up>343using __tuple_common_comparison_category _LIBCPP_NODEBUG =344    __tuple_common_comparison_category_impl<_Tp, _Up, make_index_sequence<tuple_size_v<_Tp>>>::type;345#    endif // _LIBCPP_STD_VER >= 23346 347// __tuple_leaf348 349template <size_t _Ip, class _Hp, bool = is_empty<_Hp>::value && !__is_final_v<_Hp> >350class __tuple_leaf;351 352template <size_t _Ip, class _Hp, bool _Ep>353inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void354swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<_Hp>) {355  swap(__x.get(), __y.get());356}357 358template <size_t _Ip, class _Hp, bool _Ep>359_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void360swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x,361     const __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<const _Hp>) {362  swap(__x.get(), __y.get());363}364 365template <size_t _Ip, class _Hp, bool>366class __tuple_leaf {367  _Hp __value_;368 369public:370  _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;371 372  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) : __value_() {373    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");374  }375 376  template <class _Alloc>377  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) : __value_() {378    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");379  }380 381  template <class _Alloc>382  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)383      : __value_(allocator_arg_t(), __a) {384    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");385  }386 387  template <class _Alloc>388  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : __value_(__a) {389    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");390  }391 392  template <393      class _Tp,394      __enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int> = 0>395  _LIBCPP_HIDE_FROM_ABI396  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)397      : __value_(std::forward<_Tp>(__t)) {398    static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,399                  "Attempted construction of reference element binds to a temporary whose lifetime has ended");400  }401 402  template <class _Tp, class _Alloc>403  _LIBCPP_HIDE_FROM_ABI404  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)405      : __value_(std::forward<_Tp>(__t)) {406    static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,407                  "Attempted construction of reference element binds to a temporary whose lifetime has ended");408  }409 410  template <class _Tp, class _Alloc>411  _LIBCPP_HIDE_FROM_ABI412  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)413      : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {414    static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");415  }416 417  template <class _Tp, class _Alloc>418  _LIBCPP_HIDE_FROM_ABI419  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)420      : __value_(std::forward<_Tp>(__t), __a) {421    static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");422  }423 424  _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default;425  _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t)      = default;426 427  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int428  swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {429    std::swap(*this, __t);430    return 0;431  }432 433  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __t) const434      noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {435    std::swap(*this, __t);436    return 0;437  }438 439  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return __value_; }440  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT { return __value_; }441};442 443template <size_t _Ip, class _Hp>444class __tuple_leaf<_Ip, _Hp, true> : private __remove_cv_t<_Hp> {445public:446  _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;447 448  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {}449 450  template <class _Alloc>451  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}452 453  template <class _Alloc>454  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)455      : _Hp(allocator_arg_t(), __a) {}456 457  template <class _Alloc>458  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : _Hp(__a) {}459 460  template <class _Tp,461            __enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value,462                           int> = 0>463  _LIBCPP_HIDE_FROM_ABI464  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)465      : _Hp(std::forward<_Tp>(__t)) {}466 467  template <class _Tp, class _Alloc>468  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)469      : _Hp(std::forward<_Tp>(__t)) {}470 471  template <class _Tp, class _Alloc>472  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)473      : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {}474 475  template <class _Tp, class _Alloc>476  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)477      : _Hp(std::forward<_Tp>(__t), __a) {}478 479  __tuple_leaf(__tuple_leaf const&) = default;480  __tuple_leaf(__tuple_leaf&&)      = default;481 482  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int483  swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {484    std::swap(*this, __t);485    return 0;486  }487 488  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __rhs) const489      noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {490    std::swap(*this, __rhs);491    return 0;492  }493 494  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return static_cast<_Hp&>(*this); }495  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT {496    return static_cast<const _Hp&>(*this);497  }498};499 500template <class... _Tp>501_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swallow(_Tp&&...) _NOEXCEPT {}502 503// __tuple_impl504 505template <class _Indx, class... _Tp>506struct __tuple_impl;507 508struct __forward_args {};509struct __value_init {};510struct __from_tuple {};511 512template <size_t... _Indx, class... _Tp>513struct _LIBCPP_DECLSPEC_EMPTY_BASES514    __tuple_impl<__index_sequence<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... {515  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(516      __all<is_nothrow_default_constructible<_Tp>::value...>::value) {}517 518  template <class... _Args>519  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(__forward_args, _Args&&... __args)520      : __tuple_leaf<_Indx, _Tp>(std::forward<_Args>(__args))... {}521 522  template <class _Alloc>523  _LIBCPP_HIDE_FROM_ABI524  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(allocator_arg_t, const _Alloc& __alloc, __value_init)525      : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc>(), __alloc)... {}526 527  template <class _Alloc, class... _Args>528  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(529      allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)530      : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}531 532  template <class _Tuple>533  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(__from_tuple, _Tuple&& __t) noexcept(534      (__all<is_nothrow_constructible<_Tp, __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>::535                 value...>::value))536      : __tuple_leaf<_Indx, _Tp>(537            std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(538                std::get<_Indx>(__t)))... {}539 540  template <class _Alloc, class _Tuple>541  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14542  __tuple_impl(allocator_arg_t, const _Alloc& __a, __from_tuple, _Tuple&& __t)543      : __tuple_leaf<_Indx, _Tp>(544            __uses_alloc_ctor<_Tp,545                              _Alloc,546                              __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(),547            __a,548            std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(549                std::get<_Indx>(__t)))... {}550 551  __tuple_impl(const __tuple_impl&) = default;552  __tuple_impl(__tuple_impl&&)      = default;553 554  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void555  swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {556    std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);557  }558 559  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(const __tuple_impl& __t) const560      noexcept(__all<__is_nothrow_swappable_v<const _Tp>...>::value) {561    std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);562  }563};564 565template <class _Dest, class _Source, size_t... _Np>566_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void567__memberwise_copy_assign(_Dest& __dest, _Source const& __source, __index_sequence<_Np...>) {568  std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...);569}570 571template <class _Dest, class _Source, class... _Up, size_t... _Np>572_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void573__memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up...>, __index_sequence<_Np...>) {574  std::__swallow(((std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source))), void(), 0)...);575}576 577template <class... _Tp>578class _LIBCPP_NO_SPECIALIZATIONS tuple {579  typedef __tuple_impl<__make_index_sequence<sizeof...(_Tp)>, _Tp...> _BaseT;580 581  _BaseT __base_;582 583  template <size_t _Jp, class... _Up>584  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;585  template <size_t _Jp, class... _Up>586  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&587  get(const tuple<_Up...>&) _NOEXCEPT;588  template <size_t _Jp, class... _Up>589  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type&&590  get(tuple<_Up...>&&) _NOEXCEPT;591  template <size_t _Jp, class... _Up>592  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&&593  get(const tuple<_Up...>&&) _NOEXCEPT;594 595public:596  using __trivially_relocatable _LIBCPP_NODEBUG =597      __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;598 599  // [tuple.cnstr]600 601  // tuple() constructors (including allocator_arg_t variants)602  template <template <class...> class _IsImpDefault                = __is_implicitly_default_constructible,603            template <class...> class _IsDefault                   = is_default_constructible,604            __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>605  _LIBCPP_HIDE_FROM_ABI constexpr explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)606      tuple() noexcept(_And<is_nothrow_default_constructible<_Tp>...>::value) {}607 608  template <class _Alloc,609            template <class...> class _IsImpDefault                = __is_implicitly_default_constructible,610            template <class...> class _IsDefault                   = is_default_constructible,611            __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>612  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)613      tuple(allocator_arg_t, _Alloc const& __a)614      : __base_(allocator_arg_t(), __a, __value_init{}) {}615 616  // tuple(const T&...) constructors (including allocator_arg_t variants)617  template <template <class...> class _And = _And,618            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>619  _LIBCPP_HIDE_FROM_ABI620  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)621      tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value)622      : __base_(__forward_args{}, __t...) {}623 624  template <class _Alloc,625            template <class...> class _And = _And,626            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>627  _LIBCPP_HIDE_FROM_ABI628  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)629      tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t)630      : __base_(allocator_arg_t(), __a, __forward_args{}, __t...) {}631 632  // tuple(U&& ...) constructors (including allocator_arg_t variants)633  template <class... _Up>634  struct _IsThisTuple : false_type {};635  template <class _Up>636  struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> {};637 638  template <class... _Up>639  struct _EnableUTypesCtor640      : _And< _BoolConstant<sizeof...(_Tp) >= 1>,641              _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors642              is_constructible<_Tp, _Up>... > {};643 644  template <class... _Up,645            __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,646                           int> = 0>647  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)648      tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)649      : __base_(__forward_args{}, std::forward<_Up>(__u)...) {}650 651  template <class _Alloc,652            class... _Up,653            __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,654                           int> = 0>655  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)656      tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)657      : __base_(allocator_arg_t(), __a, __forward_args{}, std::forward<_Up>(__u)...) {}658 659  // Copy and move constructors (including the allocator_arg_t variants)660  tuple(const tuple&) = default;661  tuple(tuple&&)      = default;662 663  template <class _Alloc,664            template <class...> class _And                                  = _And,665            __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0>666  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)667      : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}668 669  template <class _Alloc,670            template <class...> class _And                                  = _And,671            __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0>672  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)673      : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}674 675  // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)676 677  template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>678  struct _EnableCtorFromUTypesTuple : false_type {};679 680  template <class _OtherTuple, class... _Up>681  struct _EnableCtorFromUTypesTuple<682      _OtherTuple,683      tuple<_Up...>,684      // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below685      __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>>686      : _And<687            // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor688            // can work. Otherwise, is_constructible can trigger hard error in those cases689            // https://godbolt.org/z/M94cGdKcE690            _Not<is_same<_OtherTuple, const tuple&> >,691            _Not<is_same<_OtherTuple, tuple&&> >,692            is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,693            _Lazy<_Or,694                  _BoolConstant<sizeof...(_Tp) != 1>,695                  // _Tp and _Up are 1-element packs - the pack expansions look696                  // weird to avoid tripping up the type traits in degenerate cases697                  _Lazy<_And,698                        _Not<is_same<_Tp, _Up> >...,699                        _Not<is_convertible<_OtherTuple, _Tp> >...,700                        _Not<is_constructible<_Tp, _OtherTuple> >... > > > {};701 702  template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>703  _LIBCPP_HIDE_FROM_ABI704  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)705      tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)706      : __base_(__from_tuple(), __t) {}707 708  template <class... _Up,709            class _Alloc,710            __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>711  _LIBCPP_HIDE_FROM_ABI712  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)713      tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)714      : __base_(allocator_arg_t(), __a, __from_tuple(), __t) {}715 716#    if _LIBCPP_STD_VER >= 23717  // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)718 719  template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>720  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t)721      : __base_(__from_tuple(), __t) {}722 723  template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>724  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)725      tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)726      : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}727#    endif // _LIBCPP_STD_VER >= 23728 729  // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)730  template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>731  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)732      tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)733      : __base_(__from_tuple(), std::move(__t)) {}734 735  template <class _Alloc,736            class... _Up,737            __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>738  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)739      tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)740      : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__t)) {}741 742#    if _LIBCPP_STD_VER >= 23743  // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)744 745  template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>746  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)747      tuple(const tuple<_Up...>&& __t)748      : __base_(__from_tuple(), std::move(__t)) {}749 750  template <class _Alloc,751            class... _Up,752            enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>753  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)754      tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)755      : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}756#    endif // _LIBCPP_STD_VER >= 23757 758  // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)759 760  template <template <class...> class _Pred,761            class _Pair,762            class _DecayedPair = __remove_cvref_t<_Pair>,763            class _Tuple       = tuple>764  struct _CtorPredicateFromPair : false_type {};765 766  template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>767  struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >768      : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {};769 770  template <class _Pair>771  struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {};772 773  template <class _Pair>774  struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {};775 776  template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>777  struct _BothImplicitlyConvertible : false_type {};778 779  template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>780  struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >781      : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {};782 783  template <class _Up1,784            class _Up2,785            template <class...> class _And                                                   = _And,786            __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>787  _LIBCPP_HIDE_FROM_ABI788  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)789      tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)790      : __base_(__from_tuple(), __p) {}791 792  template <class _Alloc,793            class _Up1,794            class _Up2,795            template <class...> class _And                                                   = _And,796            __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>797  _LIBCPP_HIDE_FROM_ABI798  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)799      tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)800      : __base_(allocator_arg_t(), __a, __from_tuple(), __p) {}801 802#    if _LIBCPP_STD_VER >= 23803  // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)804 805  template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>806  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)807      tuple(pair<_U1, _U2>& __p)808      : __base_(__from_tuple(), __p) {}809 810  template <class _Alloc,811            class _U1,812            class _U2,813            enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>814  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)815      tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)816      : __base_(allocator_arg_t(), __alloc, __from_tuple(), __p) {}817#    endif818 819  // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)820 821  template <class _Up1,822            class _Up2,823            template <class...> class _And                                              = _And,824            __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>825  _LIBCPP_HIDE_FROM_ABI826  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)827      tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)828      : __base_(__from_tuple(), std::move(__p)) {}829 830  template <class _Alloc,831            class _Up1,832            class _Up2,833            template <class...> class _And                                              = _And,834            __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>835  _LIBCPP_HIDE_FROM_ABI836  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)837      tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)838      : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__p)) {}839 840#    if _LIBCPP_STD_VER >= 23841  // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)842 843  template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>844  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)845      tuple(const pair<_U1, _U2>&& __p)846      : __base_(__from_tuple(), std::move(__p)) {}847 848  template <class _Alloc,849            class _U1,850            class _U2,851            enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>852  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)853      tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)854      : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__p)) {}855#    endif // _LIBCPP_STD_VER >= 23856 857  // [tuple.assign]858  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&859  operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(860      _And<is_nothrow_copy_assignable<_Tp>...>::value) {861    std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());862    return *this;863  }864 865#    if _LIBCPP_STD_VER >= 23866  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const867    requires(_And<is_copy_assignable<const _Tp>...>::value)868  {869    std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());870    return *this;871  }872 873  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const874    requires(_And<is_assignable<const _Tp&, _Tp>...>::value)875  {876    std::__memberwise_forward_assign(877        *this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());878    return *this;879  }880#    endif // _LIBCPP_STD_VER >= 23881 882  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&883  operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(884      _And<is_nothrow_move_assignable<_Tp>...>::value) {885    std::__memberwise_forward_assign(886        *this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());887    return *this;888  }889 890  template <891      class... _Up,892      __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,893                     int> = 0>894  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&895  operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {896    std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());897    return *this;898  }899 900  template <class... _Up,901            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,902                           int> = 0>903  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&904  operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {905    std::__memberwise_forward_assign(906        *this, std::move(__tuple), __type_list<_Up...>(), __make_index_sequence<sizeof...(_Tp)>());907    return *this;908  }909 910#    if _LIBCPP_STD_VER >= 23911  template <class... _UTypes,912            enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,913                              is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>914  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {915    std::__memberwise_copy_assign(*this, __u, __make_index_sequence<sizeof...(_Tp)>());916    return *this;917  }918 919  template <class... _UTypes,920            enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,921                              is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>922  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {923    std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), __make_index_sequence<sizeof...(_Tp)>());924    return *this;925  }926#    endif // _LIBCPP_STD_VER >= 23927 928  template <template <class...> class _Pred,929            bool _Const,930            class _Pair,931            class _DecayedPair = __remove_cvref_t<_Pair>,932            class _Tuple       = tuple>933  struct _AssignPredicateFromPair : false_type {};934 935  template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>936  struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >937      : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,938             _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {};939 940  template <bool _Const, class _Pair>941  struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};942 943  template <bool _Const, class _Pair>944  struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};945 946#    if _LIBCPP_STD_VER >= 23947  template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>948  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const949      noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {950    std::get<0>(*this) = __pair.first;951    std::get<1>(*this) = __pair.second;952    return *this;953  }954 955  template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>956  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const957      noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {958    std::get<0>(*this) = std::move(__pair.first);959    std::get<1>(*this) = std::move(__pair.second);960    return *this;961  }962#    endif // _LIBCPP_STD_VER >= 23963 964  template <class _Up1,965            class _Up2,966            __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>967  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&968  operator=(pair<_Up1, _Up2> const& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {969    std::get<0>(*this) = __pair.first;970    std::get<1>(*this) = __pair.second;971    return *this;972  }973 974  template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>975  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&976  operator=(pair<_Up1, _Up2>&& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {977    std::get<0>(*this) = std::forward<_Up1>(__pair.first);978    std::get<1>(*this) = std::forward<_Up2>(__pair.second);979    return *this;980  }981 982  // EXTENSION983  template <984      class _Up,985      size_t _Np,986      __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>987  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&988  operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {989    std::__memberwise_copy_assign(*this, __array, __make_index_sequence<sizeof...(_Tp)>());990    return *this;991  }992 993  // EXTENSION994  template <class _Up,995            size_t _Np,996            class = void,997            __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>998  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&999  operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {1000    std::__memberwise_forward_assign(1001        *this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __make_index_sequence<sizeof...(_Tp)>());1002    return *this;1003  }1004 1005  // [tuple.swap]1006  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void1007  swap(tuple& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {1008    __base_.swap(__t.__base_);1009  }1010 1011#    if _LIBCPP_STD_VER >= 231012  _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const1013      noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {1014    __base_.swap(__t.__base_);1015  }1016 1017  template <__tuple_like_no_tuple _UTuple>1018#      if _LIBCPP_STD_VER >= 261019    requires __can_tuple_compare_equal<tuple, _UTuple> && (sizeof...(_Tp) == tuple_size_v<_UTuple>)1020#      endif // _LIBCPP_STD_VER >= 261021  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple& __x, const _UTuple& __y) {1022    static_assert(sizeof...(_Tp) == tuple_size_v<_UTuple>, "Can't compare tuple-like values of different sizes");1023    return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);1024  }1025 1026  template <__tuple_like_no_tuple _UTuple>1027    requires(sizeof...(_Tp) == tuple_size_v<_UTuple>)1028  _LIBCPP_HIDE_FROM_ABI friend constexpr __tuple_common_comparison_category<tuple, _UTuple>1029  operator<=>(const tuple& __x, const _UTuple& __y) {1030    return std::__tuple_compare_three_way<__tuple_common_comparison_category<tuple, _UTuple>>(1031        __x, __y, index_sequence_for<_Tp...>{});1032  }1033#    endif   // _LIBCPP_STD_VER >= 231034};1035 1036_LIBCPP_DIAGNOSTIC_PUSH1037#    if __has_warning("-Winvalid-specialization")1038_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")1039#    endif1040template <>1041class tuple<> {1042public:1043  constexpr tuple() _NOEXCEPT = default;1044  template <class _Alloc>1045  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}1046  template <class _Alloc>1047  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}1048  template <class _Up>1049  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) _NOEXCEPT {}1050  template <class _Alloc, class _Up>1051  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}1052  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {}1053#    if _LIBCPP_STD_VER >= 231054  _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}1055 1056  template <__tuple_like_no_tuple _UTuple>1057#      if _LIBCPP_STD_VER >= 261058    requires(tuple_size_v<_UTuple> == 0)1059#      endif // _LIBCPP_STD_VER >= 261060  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple&, const _UTuple&) {1061    static_assert(tuple_size_v<_UTuple> == 0, "Can't compare tuple-like values of different sizes");1062    return true;1063  }1064 1065  template <__tuple_like_no_tuple _UTuple>1066    requires(tuple_size_v<_UTuple> == 0)1067  _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const tuple&, const _UTuple&) {1068    return strong_ordering::equal;1069  }1070#    endif1071};1072_LIBCPP_DIAGNOSTIC_POP1073 1074#    if _LIBCPP_STD_VER >= 231075template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>1076  requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }1077struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {1078  using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;1079};1080 1081template <class... _TTypes, class... _UTypes>1082  requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }1083struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {1084  using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;1085};1086#    endif // _LIBCPP_STD_VER >= 231087 1088#    if _LIBCPP_STD_VER >= 171089template <class... _Tp>1090tuple(_Tp...) -> tuple<_Tp...>;1091template <class _Tp1, class _Tp2>1092tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;1093template <class _Alloc, class... _Tp>1094tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;1095template <class _Alloc, class _Tp1, class _Tp2>1096tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;1097template <class _Alloc, class... _Tp>1098tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;1099#    endif1100 1101template <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>1102inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void1103swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {1104  __t.swap(__u);1105}1106 1107#    if _LIBCPP_STD_VER >= 231108template <class... _Tp>1109_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>1110swap(const tuple<_Tp...>& __lhs,1111     const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {1112  __lhs.swap(__rhs);1113}1114#    endif1115 1116// get1117 1118template <size_t _Ip, class... _Tp>1119inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&1120get(tuple<_Tp...>& __t) _NOEXCEPT {1121  using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;1122  return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();1123}1124 1125template <size_t _Ip, class... _Tp>1126inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&1127get(const tuple<_Tp...>& __t) _NOEXCEPT {1128  using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;1129  return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();1130}1131 1132template <size_t _Ip, class... _Tp>1133inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&&1134get(tuple<_Tp...>&& __t) _NOEXCEPT {1135  using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;1136  return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());1137}1138 1139template <size_t _Ip, class... _Tp>1140inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&1141get(const tuple<_Tp...>&& __t) _NOEXCEPT {1142  using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;1143  return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());1144}1145 1146#    if _LIBCPP_STD_VER >= 141147 1148template <class _T1, class... _Args>1149inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {1150  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);1151}1152 1153template <class _T1, class... _Args>1154inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept {1155  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);1156}1157 1158template <class _T1, class... _Args>1159inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept {1160  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));1161}1162 1163template <class _T1, class... _Args>1164inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept {1165  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));1166}1167 1168#    endif1169 1170// tie1171 1172template <class... _Tp>1173inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) _NOEXCEPT {1174  return tuple<_Tp&...>(__t...);1175}1176 1177template <class... _Tp>1178inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<__unwrap_ref_decay_t<_Tp>...>1179make_tuple(_Tp&&... __t) {1180  return tuple<__unwrap_ref_decay_t<_Tp>...>(std::forward<_Tp>(__t)...);1181}1182 1183template <class... _Tp>1184inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) _NOEXCEPT {1185  return tuple<_Tp&&...>(std::forward<_Tp>(__t)...);1186}1187 1188template <class... _Tp, class... _Up>1189#    if _LIBCPP_STD_VER >= 261190  requires(__all<requires(const _Tp& __t, const _Up& __u) {1191             { __t == __u } -> __boolean_testable;1192           }...>::value && (sizeof...(_Tp) == sizeof...(_Up)))1193#    endif1194inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1195operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1196  static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");1197  return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);1198}1199 1200#    if _LIBCPP_STD_VER >= 201201 1202// operator<=>1203 1204template <class... _Tp, class... _Up>1205  requires(sizeof...(_Tp) == sizeof...(_Up))1206_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>1207operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1208  return std::__tuple_compare_three_way<common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>>(1209      __x, __y, index_sequence_for<_Tp...>{});1210}1211 1212#    else // _LIBCPP_STD_VER >= 201213 1214template <class... _Tp, class... _Up>1215inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1216operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1217  return !(__x == __y);1218}1219 1220template <size_t _Ip>1221struct __tuple_less {1222  template <class _Tp, class _Up>1223  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {1224    const size_t __idx = tuple_size<_Tp>::value - _Ip;1225    if (std::get<__idx>(__x) < std::get<__idx>(__y))1226      return true;1227    if (std::get<__idx>(__y) < std::get<__idx>(__x))1228      return false;1229    return __tuple_less<_Ip - 1>()(__x, __y);1230  }1231};1232 1233template <>1234struct __tuple_less<0> {1235  template <class _Tp, class _Up>1236  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {1237    return false;1238  }1239};1240 1241template <class... _Tp, class... _Up>1242inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1243operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1244  static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");1245  return __tuple_less<sizeof...(_Tp)>()(__x, __y);1246}1247 1248template <class... _Tp, class... _Up>1249inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1250operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1251  return __y < __x;1252}1253 1254template <class... _Tp, class... _Up>1255inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1256operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1257  return !(__x < __y);1258}1259 1260template <class... _Tp, class... _Up>1261inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool1262operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {1263  return !(__y < __x);1264}1265 1266#    endif // _LIBCPP_STD_VER >= 201267 1268// tuple_cat1269 1270template <class... _Tuples>1271struct __tuple_cat_return_impl;1272 1273template <class... _Types>1274struct __tuple_cat_return_impl<tuple<_Types...>> {1275  using type _LIBCPP_NODEBUG = tuple<_Types...>;1276};1277 1278template <class... _Types0, class... _Types1, class... _Tuples>1279struct __tuple_cat_return_impl<tuple<_Types0...>, tuple<_Types1...>, _Tuples...>1280    : __tuple_cat_return_impl<tuple<_Types0..., _Types1...>, _Tuples...> {};1281 1282template <class... _Types0, class _Tp, class _Up, class... _Tuples>1283struct __tuple_cat_return_impl<tuple<_Types0...>, pair<_Tp, _Up>, _Tuples...>1284    : __tuple_cat_return_impl<tuple<_Types0..., _Tp, _Up>, _Tuples...> {};1285 1286template <class, class, class>1287struct __tuple_cat_array;1288 1289template <class... _Types, class _ValueT, size_t... _Indices>1290struct __tuple_cat_array<tuple<_Types...>, _ValueT, __index_sequence<_Indices...>> {1291  template <size_t>1292  using __value_type _LIBCPP_NODEBUG = _ValueT;1293 1294  using type _LIBCPP_NODEBUG = tuple<_Types..., __value_type<_Indices>...>;1295};1296 1297template <class... _Types, class _ValueT, size_t _Np, class... _Tuples>1298struct __tuple_cat_return_impl<tuple<_Types...>, array<_ValueT, _Np>, _Tuples...>1299    : __tuple_cat_return_impl<typename __tuple_cat_array<tuple<_Types...>, _ValueT, __make_index_sequence<_Np>>::type,1300                              _Tuples...> {};1301 1302template <class... _Tuples>1303using __tuple_cat_return_t _LIBCPP_NODEBUG =1304    typename __tuple_cat_return_impl<tuple<>, __remove_cvref_t<_Tuples>...>::type;1305 1306inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }1307 1308template <class _Rp, class _Indices, class _Tuple0, class... _Tuples>1309struct __tuple_cat_return_ref_imp;1310 1311template <class... _Types, size_t... _I0, class _Tuple0>1312struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0> {1313  using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;1314  typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;1315};1316 1317template <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>1318struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0, _Tuple1, _Tuples...>1319    : public __tuple_cat_return_ref_imp<1320          tuple<_Types...,1321                __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,1322          __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>,1323          _Tuple1,1324          _Tuples...> {};1325 1326template <class _Tuple0, class... _Tuples>1327struct __tuple_cat_return_ref1328    : public __tuple_cat_return_ref_imp<1329          tuple<>,1330          __make_index_sequence< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >,1331          _Tuple0,1332          _Tuples...> {};1333 1334template <class _Types, class _I0, class _J0>1335struct __tuple_cat;1336 1337template <class... _Types, size_t... _I0, size_t... _J0>1338struct __tuple_cat<tuple<_Types...>, __index_sequence<_I0...>, __index_sequence<_J0...>> {1339  template <class _Tuple0>1340  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX141341  typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type1342  operator()(tuple<_Types...> __t, _Tuple0&& __t0) {1343    (void)__t; // avoid unused parameter warning on GCC when _I0 is empty1344    return std::forward_as_tuple(1345        std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...);1346  }1347 1348  template <class _Tuple0, class _Tuple1, class... _Tuples>1349  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX141350  typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type1351  operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {1352    (void)__t; // avoid unused parameter warning on GCC when _I0 is empty1353    using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;1354    using _T1 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple1>;1355    return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,1356                       __make_index_sequence<sizeof...(_Types) + tuple_size<_T0>::value>,1357                       __make_index_sequence<tuple_size<_T1>::value>>()(1358        std::forward_as_tuple(1359            std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...),1360        std::forward<_Tuple1>(__t1),1361        std::forward<_Tuples>(__tpls)...);1362  }1363};1364 1365template <class _TupleDst, class _TupleSrc, size_t... _Indices>1366inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _TupleDst1367__tuple_cat_select_element_wise(_TupleSrc&& __src, __index_sequence<_Indices...>) {1368  static_assert(tuple_size<_TupleDst>::value == tuple_size<_TupleSrc>::value,1369                "misuse of __tuple_cat_select_element_wise with tuples of different sizes");1370  return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);1371}1372 1373template <class _Tuple0, class... _Tuples>1374inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_cat_return_t<_Tuple0, _Tuples...>1375tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {1376  using _T0 _LIBCPP_NODEBUG          = __libcpp_remove_reference_t<_Tuple0>;1377  using _TRet _LIBCPP_NODEBUG        = __tuple_cat_return_t<_Tuple0, _Tuples...>;1378  using _T0Indices _LIBCPP_NODEBUG   = __make_index_sequence<tuple_size<_T0>::value>;1379  using _TRetIndices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_TRet>::value>;1380  return std::__tuple_cat_select_element_wise<_TRet>(1381      __tuple_cat<tuple<>, __index_sequence<>, _T0Indices>()(1382          tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...),1383      _TRetIndices());1384}1385 1386template <class... _Tp, class _Alloc>1387struct uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};1388 1389#    if _LIBCPP_STD_VER >= 171390#      define _LIBCPP_NOEXCEPT_RETURN(...)                                                                             \1391        noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }1392 1393// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting.1394// clang-format off1395template <class _Fn, class _Tuple, size_t... _Id>1396inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto)1397__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Id...>)1398    _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...))1399 1400template <class _Fn, class _Tuple>1401inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t)1402    _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl(1403        std::forward<_Fn>(__f),1404        std::forward<_Tuple>(__t),1405        make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))1406 1407#if _LIBCPP_STD_VER >= 201408template <class _Tp, class _Tuple, size_t... _Idx>1409inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)1410  noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))1411  requires is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> {1412  return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);1413}1414#else1415template <class _Tp, class _Tuple, size_t... _Idx>1416inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>,1417    enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr)1418    _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))1419#endif // _LIBCPP_STD_VER >= 201420#undef _LIBCPP_NOEXCEPT_RETURN1421 1422template <class _Tp, class _Tuple,1423          class _Seq = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>, class = void>1424inline constexpr bool __can_make_from_tuple = false;1425 1426template <class _Tp, class _Tuple, size_t... _Idx>1427inline constexpr bool __can_make_from_tuple<_Tp, _Tuple, index_sequence<_Idx...>,1428    enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>>> = true;1429 1430// Based on LWG3528(https://wg21.link/LWG3528) and http://eel.is/c++draft/description#structure.requirements-9,1431// the standard allows to impose requirements, we constraint std::make_from_tuple to make std::make_from_tuple1432// SFINAE friendly and also avoid worse diagnostic messages. We still keep the constraints of std::__make_from_tuple_impl1433// so that std::__make_from_tuple_impl will have the same advantages when used alone.1434#if _LIBCPP_STD_VER >= 201435template <class _Tp, class _Tuple>1436  requires __can_make_from_tuple<_Tp, _Tuple> // strengthen1437#else1438template <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen1439#endif // _LIBCPP_STD_VER >= 201440 1441inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)1442  noexcept(noexcept(std::__make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t),1443                    make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))) {1444#if _LIBCPP_STD_VER >= 231445  if constexpr (tuple_size_v<remove_reference_t<_Tuple>> == 1) {1446    static_assert(!std::reference_constructs_from_temporary_v<_Tp, decltype(std::get<0>(std::declval<_Tuple>()))>,1447                  "Attempted construction of reference element binds to a temporary whose lifetime has ended");1448  }1449#endif // _LIBCPP_STD_VER >= 231450  return std::__make_from_tuple_impl<_Tp>(1451        std::forward<_Tuple>(__t), make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>());1452}1453 1454#  endif // _LIBCPP_STD_VER >= 171455 1456#endif // !defined(_LIBCPP_CXX03_LANG)1457 1458_LIBCPP_END_NAMESPACE_STD1459 1460_LIBCPP_POP_MACROS1461 1462// clang-format on1463 1464#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 201465#    include <cstddef>1466#    include <exception>1467#    include <iosfwd>1468#    include <new>1469#    include <type_traits>1470#    include <typeinfo>1471#    include <utility>1472#  endif1473#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)1474 1475#endif // _LIBCPP_TUPLE1476