xref: /freebsd/contrib/llvm-project/libcxx/include/tuple (revision dee76cf2f3dace6290ccab07c2db17355994e70f)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_TUPLE
110b57cec5SDimitry Andric#define _LIBCPP_TUPLE
120b57cec5SDimitry Andric
135f757f3fSDimitry Andric// clang-format off
145f757f3fSDimitry Andric
150b57cec5SDimitry Andric/*
160b57cec5SDimitry Andric    tuple synopsis
170b57cec5SDimitry Andric
180b57cec5SDimitry Andricnamespace std
190b57cec5SDimitry Andric{
200b57cec5SDimitry Andric
210b57cec5SDimitry Andrictemplate <class... T>
220b57cec5SDimitry Andricclass tuple {
230b57cec5SDimitry Andricpublic:
24e40139ffSDimitry Andric    explicit(see-below) constexpr tuple();
25e40139ffSDimitry Andric    explicit(see-below) tuple(const T&...);  // constexpr in C++14
260b57cec5SDimitry Andric    template <class... U>
27e40139ffSDimitry Andric        explicit(see-below) tuple(U&&...);  // constexpr in C++14
280b57cec5SDimitry Andric    tuple(const tuple&) = default;
290b57cec5SDimitry Andric    tuple(tuple&&) = default;
3081ad6265SDimitry Andric
3181ad6265SDimitry Andric    template<class... UTypes>
3281ad6265SDimitry Andric        constexpr explicit(see-below) tuple(tuple<UTypes...>&);  // C++23
330b57cec5SDimitry Andric    template <class... U>
34e40139ffSDimitry Andric        explicit(see-below) tuple(const tuple<U...>&);  // constexpr in C++14
350b57cec5SDimitry Andric    template <class... U>
36e40139ffSDimitry Andric        explicit(see-below) tuple(tuple<U...>&&);  // constexpr in C++14
3781ad6265SDimitry Andric    template<class... UTypes>
3881ad6265SDimitry Andric        constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23
3981ad6265SDimitry Andric
4081ad6265SDimitry Andric    template<class U1, class U2>
4181ad6265SDimitry Andric        constexpr explicit(see-below) tuple(pair<U1, U2>&);  // iff sizeof...(Types) == 2 // C++23
420b57cec5SDimitry Andric    template <class U1, class U2>
43e40139ffSDimitry Andric        explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
440b57cec5SDimitry Andric    template <class U1, class U2>
45e40139ffSDimitry Andric        explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++14
4681ad6265SDimitry Andric    template<class U1, class U2>
4781ad6265SDimitry Andric        constexpr explicit(see-below) tuple(const pair<U1, U2>&&);  // iff sizeof...(Types) == 2 // C++23
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric    // allocator-extended constructors
500b57cec5SDimitry Andric    template <class Alloc>
510b57cec5SDimitry Andric        tuple(allocator_arg_t, const Alloc& a);
520b57cec5SDimitry Andric    template <class Alloc>
53fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);          // constexpr in C++20
540b57cec5SDimitry Andric    template <class Alloc, class... U>
55fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);               // constexpr in C++20
560b57cec5SDimitry Andric    template <class Alloc>
57fe6060f1SDimitry Andric        tuple(allocator_arg_t, const Alloc& a, const tuple&);                             // constexpr in C++20
580b57cec5SDimitry Andric    template <class Alloc>
59fe6060f1SDimitry Andric        tuple(allocator_arg_t, const Alloc& a, tuple&&);                                  // constexpr in C++20
6081ad6265SDimitry Andric    template<class Alloc, class... UTypes>
6181ad6265SDimitry Andric        constexpr explicit(see-below)
6281ad6265SDimitry Andric          tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&);                      // C++23
630b57cec5SDimitry Andric    template <class Alloc, class... U>
64fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);   // constexpr in C++20
650b57cec5SDimitry Andric    template <class Alloc, class... U>
66fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);        // constexpr in C++20
6781ad6265SDimitry Andric    template<class Alloc, class... UTypes>
6881ad6265SDimitry Andric        constexpr explicit(see-below)
6981ad6265SDimitry Andric          tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&);               // C++23
7081ad6265SDimitry Andric    template<class Alloc, class U1, class U2>
7181ad6265SDimitry Andric        constexpr explicit(see-below)
7281ad6265SDimitry Andric          tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&);                          // C++23
730b57cec5SDimitry Andric    template <class Alloc, class U1, class U2>
74fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);  // constexpr in C++20
750b57cec5SDimitry Andric    template <class Alloc, class U1, class U2>
76fe6060f1SDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);       // constexpr in C++20
7781ad6265SDimitry Andric    template<class Alloc, class U1, class U2>
7881ad6265SDimitry Andric        constexpr explicit(see-below)
7981ad6265SDimitry Andric          tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&);                   // C++23
800b57cec5SDimitry Andric
81fe6060f1SDimitry Andric    tuple& operator=(const tuple&);                                                       // constexpr in C++20
8281ad6265SDimitry Andric    constexpr const tuple& operator=(const tuple&) const;                                 // C++23
83fe6060f1SDimitry Andric    tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...);           // constexpr in C++20
8481ad6265SDimitry Andric    constexpr const tuple& operator=(tuple&&) const;                                      // C++23
850b57cec5SDimitry Andric    template <class... U>
86fe6060f1SDimitry Andric        tuple& operator=(const tuple<U...>&);                                             // constexpr in C++20
8781ad6265SDimitry Andric    template<class... UTypes>
8881ad6265SDimitry Andric        constexpr const tuple& operator=(const tuple<UTypes...>&) const;                  // C++23
890b57cec5SDimitry Andric    template <class... U>
90fe6060f1SDimitry Andric        tuple& operator=(tuple<U...>&&);                                                  // constexpr in C++20
9181ad6265SDimitry Andric    template<class... UTypes>
9281ad6265SDimitry Andric        constexpr const tuple& operator=(tuple<UTypes...>&&) const;                       // C++23
930b57cec5SDimitry Andric    template <class U1, class U2>
94fe6060f1SDimitry Andric        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2                   // constexpr in C++20
950b57cec5SDimitry Andric    template<class U1, class U2>
9681ad6265SDimitry Andric        constexpr const tuple& operator=(const pair<U1, U2>&) const;   // iff sizeof...(Types) == 2 // C++23
9781ad6265SDimitry Andric    template <class U1, class U2>
98fe6060f1SDimitry Andric        tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2                        // constexpr in C++20
9981ad6265SDimitry Andric    template<class U1, class U2>
10081ad6265SDimitry Andric        constexpr const tuple& operator=(pair<U1, U2>&&) const;  // iff sizeof...(Types) == 2 // C++23
1010b57cec5SDimitry Andric
102fe6060f1SDimitry Andric    template<class U, size_t N>
103fe6060f1SDimitry Andric        tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
104fe6060f1SDimitry Andric    template<class U, size_t N>
105fe6060f1SDimitry Andric        tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
106fe6060f1SDimitry Andric
107fe6060f1SDimitry Andric    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));               // constexpr in C++20
10881ad6265SDimitry Andric    constexpr void swap(const tuple&) const noexcept(see-below);                          // C++23
1090b57cec5SDimitry Andric};
1100b57cec5SDimitry Andric
11104eeddc0SDimitry Andric
11204eeddc0SDimitry Andrictemplate<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
11304eeddc0SDimitry Andric  requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
11404eeddc0SDimitry Andricstruct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
11504eeddc0SDimitry Andric  using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
11604eeddc0SDimitry Andric};
11704eeddc0SDimitry Andric
11804eeddc0SDimitry Andrictemplate<class... TTypes, class... UTypes>                                // since C++23
11904eeddc0SDimitry Andric  requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
12004eeddc0SDimitry Andricstruct common_type<tuple<TTypes...>, tuple<UTypes...>> {
12104eeddc0SDimitry Andric  using type = tuple<common_type_t<TTypes, UTypes>...>;
12204eeddc0SDimitry Andric};
12304eeddc0SDimitry Andric
124e40139ffSDimitry Andrictemplate <class ...T>
125e40139ffSDimitry Andrictuple(T...) -> tuple<T...>;                                         // since C++17
126e40139ffSDimitry Andrictemplate <class T1, class T2>
127e40139ffSDimitry Andrictuple(pair<T1, T2>) -> tuple<T1, T2>;                               // since C++17
128e40139ffSDimitry Andrictemplate <class Alloc, class ...T>
129e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, T...) -> tuple<T...>;                 // since C++17
130e40139ffSDimitry Andrictemplate <class Alloc, class T1, class T2>
131e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>;       // since C++17
132e40139ffSDimitry Andrictemplate <class Alloc, class ...T>
133e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>;          // since C++17
134e40139ffSDimitry Andric
1350fca6ea1SDimitry Andricstruct ignore-type { // exposition only                             // Since C++26
1360fca6ea1SDimitry Andric  constexpr const ignore-type&
1370fca6ea1SDimitry Andric    operator=(const auto &) const noexcept
1380fca6ea1SDimitry Andric      { return *this; }
1390fca6ea1SDimitry Andric};
1400fca6ea1SDimitry Andricinline constexpr ignore-type ignore;
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andrictemplate <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
1430b57cec5SDimitry Andrictemplate <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
1440b57cec5SDimitry Andrictemplate <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
1450b57cec5SDimitry Andrictemplate <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
1460b57cec5SDimitry Andric
1470b57cec5SDimitry Andric// [tuple.apply], calling a function with a tuple of arguments:
1480b57cec5SDimitry Andrictemplate <class F, class Tuple>
149297eecfbSDimitry Andric  constexpr decltype(auto) apply(F&& f, Tuple&& t) noexcept(see below);  // C++17 noexcept since C++23
1500b57cec5SDimitry Andrictemplate <class T, class Tuple>
1510b57cec5SDimitry Andric  constexpr T make_from_tuple(Tuple&& t); // C++17
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric// 20.4.1.4, tuple helper classes:
1540b57cec5SDimitry Andrictemplate <class T> struct tuple_size; // undefined
1550b57cec5SDimitry Andrictemplate <class... T> struct tuple_size<tuple<T...>>;
1560b57cec5SDimitry Andrictemplate <class T>
1570b57cec5SDimitry Andric inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
1580b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; // undefined
1590b57cec5SDimitry Andrictemplate <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
1600b57cec5SDimitry Andrictemplate <size_t I, class T>
1610b57cec5SDimitry Andric  using tuple_element_t = typename tuple_element <I, T>::type; // C++14
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andric// 20.4.1.5, element access:
1640b57cec5SDimitry Andrictemplate <size_t I, class... T>
1650b57cec5SDimitry Andric    typename tuple_element<I, tuple<T...>>::type&
1660b57cec5SDimitry Andric    get(tuple<T...>&) noexcept; // constexpr in C++14
1670b57cec5SDimitry Andrictemplate <size_t I, class... T>
1680b57cec5SDimitry Andric    const typename tuple_element<I, tuple<T...>>::type&
1690b57cec5SDimitry Andric    get(const tuple<T...>&) noexcept; // constexpr in C++14
1700b57cec5SDimitry Andrictemplate <size_t I, class... T>
1710b57cec5SDimitry Andric    typename tuple_element<I, tuple<T...>>::type&&
1720b57cec5SDimitry Andric    get(tuple<T...>&&) noexcept; // constexpr in C++14
1730b57cec5SDimitry Andrictemplate <size_t I, class... T>
1740b57cec5SDimitry Andric    const typename tuple_element<I, tuple<T...>>::type&&
1750b57cec5SDimitry Andric    get(const tuple<T...>&&) noexcept; // constexpr in C++14
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andrictemplate <class T1, class... T>
1780b57cec5SDimitry Andric    constexpr T1& get(tuple<T...>&) noexcept;  // C++14
1790b57cec5SDimitry Andrictemplate <class T1, class... T>
1800b57cec5SDimitry Andric    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
1810b57cec5SDimitry Andrictemplate <class T1, class... T>
1820b57cec5SDimitry Andric    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
1830b57cec5SDimitry Andrictemplate <class T1, class... T>
1840b57cec5SDimitry Andric    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric// 20.4.1.6, relational operators:
1870b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
188349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
189349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
190349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
191349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
192349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
193349cc55cSDimitry Andrictemplate<class... T, class... U>
194349cc55cSDimitry Andric  constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
195349cc55cSDimitry Andric    operator<=>(const tuple<T...>&, const tuple<U...>&);                                  // since C++20
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andrictemplate <class... Types, class Alloc>
1980b57cec5SDimitry Andric  struct uses_allocator<tuple<Types...>, Alloc>;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andrictemplate <class... Types>
2010b57cec5SDimitry Andric  void
2020b57cec5SDimitry Andric  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
2030b57cec5SDimitry Andric
20481ad6265SDimitry Andrictemplate <class... Types>
20581ad6265SDimitry Andric  constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below);   // C++23
20681ad6265SDimitry Andric
2070b57cec5SDimitry Andric}  // std
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric*/
2100b57cec5SDimitry Andric
2115f757f3fSDimitry Andric// clang-format on
2125f757f3fSDimitry Andric
213349cc55cSDimitry Andric#include <__compare/common_comparison_category.h>
214349cc55cSDimitry Andric#include <__compare/synth_three_way.h>
2150b57cec5SDimitry Andric#include <__config>
216bdd1243dSDimitry Andric#include <__functional/invoke.h>
217bdd1243dSDimitry Andric#include <__fwd/array.h>
2180fca6ea1SDimitry Andric#include <__fwd/pair.h>
21906c3fb27SDimitry Andric#include <__fwd/tuple.h>
220fe6060f1SDimitry Andric#include <__memory/allocator_arg_t.h>
221fe6060f1SDimitry Andric#include <__memory/uses_allocator.h>
2220fca6ea1SDimitry Andric#include <__tuple/find_index.h>
2230fca6ea1SDimitry Andric#include <__tuple/ignore.h>
22406c3fb27SDimitry Andric#include <__tuple/make_tuple_types.h>
22506c3fb27SDimitry Andric#include <__tuple/sfinae_helpers.h>
22606c3fb27SDimitry Andric#include <__tuple/tuple_element.h>
22706c3fb27SDimitry Andric#include <__tuple/tuple_indices.h>
22806c3fb27SDimitry Andric#include <__tuple/tuple_like_ext.h>
22906c3fb27SDimitry Andric#include <__tuple/tuple_size.h>
23006c3fb27SDimitry Andric#include <__tuple/tuple_types.h>
231bdd1243dSDimitry Andric#include <__type_traits/common_reference.h>
232bdd1243dSDimitry Andric#include <__type_traits/common_type.h>
233bdd1243dSDimitry Andric#include <__type_traits/conditional.h>
234bdd1243dSDimitry Andric#include <__type_traits/conjunction.h>
235bdd1243dSDimitry Andric#include <__type_traits/copy_cvref.h>
236bdd1243dSDimitry Andric#include <__type_traits/disjunction.h>
237bdd1243dSDimitry Andric#include <__type_traits/is_arithmetic.h>
238bdd1243dSDimitry Andric#include <__type_traits/is_assignable.h>
239bdd1243dSDimitry Andric#include <__type_traits/is_constructible.h>
240bdd1243dSDimitry Andric#include <__type_traits/is_convertible.h>
241bdd1243dSDimitry Andric#include <__type_traits/is_empty.h>
242bdd1243dSDimitry Andric#include <__type_traits/is_final.h>
243bdd1243dSDimitry Andric#include <__type_traits/is_implicitly_default_constructible.h>
244bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_assignable.h>
245bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_constructible.h>
246bdd1243dSDimitry Andric#include <__type_traits/is_reference.h>
247bdd1243dSDimitry Andric#include <__type_traits/is_same.h>
248bdd1243dSDimitry Andric#include <__type_traits/is_swappable.h>
2490fca6ea1SDimitry Andric#include <__type_traits/is_trivially_relocatable.h>
250bdd1243dSDimitry Andric#include <__type_traits/lazy.h>
251bdd1243dSDimitry Andric#include <__type_traits/maybe_const.h>
252bdd1243dSDimitry Andric#include <__type_traits/nat.h>
253bdd1243dSDimitry Andric#include <__type_traits/negation.h>
254bdd1243dSDimitry Andric#include <__type_traits/remove_cvref.h>
255bdd1243dSDimitry Andric#include <__type_traits/remove_reference.h>
25606c3fb27SDimitry Andric#include <__type_traits/unwrap_ref.h>
257fe6060f1SDimitry Andric#include <__utility/forward.h>
258349cc55cSDimitry Andric#include <__utility/integer_sequence.h>
259fe6060f1SDimitry Andric#include <__utility/move.h>
26081ad6265SDimitry Andric#include <__utility/piecewise_construct.h>
26181ad6265SDimitry Andric#include <__utility/swap.h>
2620b57cec5SDimitry Andric#include <cstddef>
2630b57cec5SDimitry Andric#include <version>
2640b57cec5SDimitry Andric
26581ad6265SDimitry Andric// standard-mandated includes
266bdd1243dSDimitry Andric
267bdd1243dSDimitry Andric// [tuple.syn]
26881ad6265SDimitry Andric#include <compare>
26981ad6265SDimitry Andric
2700b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2710b57cec5SDimitry Andric#  pragma GCC system_header
2720b57cec5SDimitry Andric#endif
2730b57cec5SDimitry Andric
27406c3fb27SDimitry Andric_LIBCPP_PUSH_MACROS
27506c3fb27SDimitry Andric#include <__undef_macros>
27606c3fb27SDimitry Andric
2770b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2800b57cec5SDimitry Andric
2810b57cec5SDimitry Andric// __tuple_leaf
2820b57cec5SDimitry Andric
283cb14a3feSDimitry Andrictemplate <size_t _Ip, class _Hp, bool = is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value >
2840b57cec5SDimitry Andricclass __tuple_leaf;
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep>
287cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
2880fca6ea1SDimitry Andricswap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<_Hp>) {
2890b57cec5SDimitry Andric  swap(__x.get(), __y.get());
2900b57cec5SDimitry Andric}
2910b57cec5SDimitry Andric
29281ad6265SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep>
293cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
2940fca6ea1SDimitry Andricswap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x,
2950fca6ea1SDimitry Andric     const __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<const _Hp>) {
29681ad6265SDimitry Andric  swap(__x.get(), __y.get());
29781ad6265SDimitry Andric}
29881ad6265SDimitry Andric
2990b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool>
300cb14a3feSDimitry Andricclass __tuple_leaf {
3010b57cec5SDimitry Andric  _Hp __value_;
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andric  template <class _Tp>
30406c3fb27SDimitry Andric  static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() {
305*dee76cf2SAlex Richardson#  if __has_keyword(__reference_constructs_from_temporary)
306*dee76cf2SAlex Richardson    return !__reference_constructs_from_temporary(_Hp, _Tp);
307*dee76cf2SAlex Richardson#  elif __has_keyword(__reference_binds_to_temporary)
3080b57cec5SDimitry Andric    return !__reference_binds_to_temporary(_Hp, _Tp);
3090b57cec5SDimitry Andric#  else
3100b57cec5SDimitry Andric    return true;
3110b57cec5SDimitry Andric#  endif
3120b57cec5SDimitry Andric  }
3130b57cec5SDimitry Andric
3140b57cec5SDimitry Andricpublic:
3150fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
3160fca6ea1SDimitry Andric
3170fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) : __value_() {
318cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
319cb14a3feSDimitry Andric  }
3200b57cec5SDimitry Andric
3210b57cec5SDimitry Andric  template <class _Alloc>
322cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) : __value_() {
323cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
324cb14a3feSDimitry Andric  }
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric  template <class _Alloc>
327cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
328cb14a3feSDimitry Andric      : __value_(allocator_arg_t(), __a) {
329cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
330cb14a3feSDimitry Andric  }
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andric  template <class _Alloc>
333cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : __value_(__a) {
334cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
335cb14a3feSDimitry Andric  }
3360b57cec5SDimitry Andric
3370fca6ea1SDimitry Andric  template <
3380fca6ea1SDimitry Andric      class _Tp,
3390fca6ea1SDimitry Andric      __enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int> = 0>
3400fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
3410fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
342cb14a3feSDimitry Andric      : __value_(std::forward<_Tp>(__t)) {
343cb14a3feSDimitry Andric    static_assert(__can_bind_reference<_Tp&&>(),
344cb14a3feSDimitry Andric                  "Attempted construction of reference element binds to a temporary whose lifetime has ended");
345cb14a3feSDimitry Andric  }
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
3480fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
3490fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
350cb14a3feSDimitry Andric      : __value_(std::forward<_Tp>(__t)) {
351cb14a3feSDimitry Andric    static_assert(__can_bind_reference<_Tp&&>(),
352cb14a3feSDimitry Andric                  "Attempted construction of reference element binds to a temporary whose lifetime has ended");
353cb14a3feSDimitry Andric  }
3540b57cec5SDimitry Andric
3550b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
3560fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
3570fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
358cb14a3feSDimitry Andric      : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {
359cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
360cb14a3feSDimitry Andric  }
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
3630fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
3640fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
365cb14a3feSDimitry Andric      : __value_(std::forward<_Tp>(__t), __a) {
366cb14a3feSDimitry Andric    static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
367cb14a3feSDimitry Andric  }
3680b57cec5SDimitry Andric
36906c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default;
37006c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t)      = default;
3710b57cec5SDimitry Andric
3720fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
3730fca6ea1SDimitry Andric  swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
3745f757f3fSDimitry Andric    std::swap(*this, __t);
3750b57cec5SDimitry Andric    return 0;
3760b57cec5SDimitry Andric  }
3770b57cec5SDimitry Andric
378cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __t) const
3790fca6ea1SDimitry Andric      noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
3805f757f3fSDimitry Andric    std::swap(*this, __t);
38181ad6265SDimitry Andric    return 0;
38281ad6265SDimitry Andric  }
38381ad6265SDimitry Andric
3845f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return __value_; }
3855f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT { return __value_; }
3860b57cec5SDimitry Andric};
3870b57cec5SDimitry Andric
3880b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp>
389cb14a3feSDimitry Andricclass __tuple_leaf<_Ip, _Hp, true> : private _Hp {
3900b57cec5SDimitry Andricpublic:
3910fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
3920fca6ea1SDimitry Andric
3930fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {}
3940b57cec5SDimitry Andric
3950b57cec5SDimitry Andric  template <class _Alloc>
396cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
3970b57cec5SDimitry Andric
3980b57cec5SDimitry Andric  template <class _Alloc>
399cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
4000b57cec5SDimitry Andric      : _Hp(allocator_arg_t(), __a) {}
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric  template <class _Alloc>
403cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : _Hp(__a) {}
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric  template <class _Tp,
4060fca6ea1SDimitry Andric            __enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value,
4070fca6ea1SDimitry Andric                           int> = 0>
4080fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
4090fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
4105f757f3fSDimitry Andric      : _Hp(std::forward<_Tp>(__t)) {}
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
413cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
4145f757f3fSDimitry Andric      : _Hp(std::forward<_Tp>(__t)) {}
4150b57cec5SDimitry Andric
4160b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
417cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
4185f757f3fSDimitry Andric      : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {}
4190b57cec5SDimitry Andric
4200b57cec5SDimitry Andric  template <class _Tp, class _Alloc>
421cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
4225f757f3fSDimitry Andric      : _Hp(std::forward<_Tp>(__t), __a) {}
4230b57cec5SDimitry Andric
4240b57cec5SDimitry Andric  __tuple_leaf(__tuple_leaf const&) = default;
4250b57cec5SDimitry Andric  __tuple_leaf(__tuple_leaf&&)      = default;
4260b57cec5SDimitry Andric
4270fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
4280fca6ea1SDimitry Andric  swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
4295f757f3fSDimitry Andric    std::swap(*this, __t);
4300b57cec5SDimitry Andric    return 0;
4310b57cec5SDimitry Andric  }
4320b57cec5SDimitry Andric
433cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __rhs) const
4340fca6ea1SDimitry Andric      noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
4355f757f3fSDimitry Andric    std::swap(*this, __rhs);
43681ad6265SDimitry Andric    return 0;
43781ad6265SDimitry Andric  }
43881ad6265SDimitry Andric
4395f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return static_cast<_Hp&>(*this); }
440cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT {
441cb14a3feSDimitry Andric    return static_cast<const _Hp&>(*this);
442cb14a3feSDimitry Andric  }
4430b57cec5SDimitry Andric};
4440b57cec5SDimitry Andric
4450b57cec5SDimitry Andrictemplate <class... _Tp>
446cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swallow(_Tp&&...) _NOEXCEPT {}
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andrictemplate <class _Tp>
4490b57cec5SDimitry Andricstruct __all_default_constructible;
4500b57cec5SDimitry Andric
4510b57cec5SDimitry Andrictemplate <class... _Tp>
452cb14a3feSDimitry Andricstruct __all_default_constructible<__tuple_types<_Tp...>> : __all<is_default_constructible<_Tp>::value...> {};
4530b57cec5SDimitry Andric
4540b57cec5SDimitry Andric// __tuple_impl
4550b57cec5SDimitry Andric
456cb14a3feSDimitry Andrictemplate <class _Indx, class... _Tp>
457cb14a3feSDimitry Andricstruct __tuple_impl;
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andrictemplate <size_t... _Indx, class... _Tp>
4600b57cec5SDimitry Andricstruct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
461cb14a3feSDimitry Andric    : public __tuple_leaf<_Indx, _Tp>... {
4620fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(
4630fca6ea1SDimitry Andric      __all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
4640b57cec5SDimitry Andric
465cb14a3feSDimitry Andric  template <size_t... _Uf, class... _Tf, size_t... _Ul, class... _Tl, class... _Up>
466cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(
4670fca6ea1SDimitry Andric      __tuple_indices<_Uf...>,
4680fca6ea1SDimitry Andric      __tuple_types<_Tf...>,
4690fca6ea1SDimitry Andric      __tuple_indices<_Ul...>,
4700fca6ea1SDimitry Andric      __tuple_types<_Tl...>,
4710fca6ea1SDimitry Andric      _Up&&... __u) noexcept(__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
4720fca6ea1SDimitry Andric                             __all<is_nothrow_default_constructible<_Tl>::value...>::value)
473cb14a3feSDimitry Andric      : __tuple_leaf<_Uf, _Tf>(std::forward<_Up>(__u))..., __tuple_leaf<_Ul, _Tl>()... {}
4740b57cec5SDimitry Andric
475cb14a3feSDimitry Andric  template <class _Alloc, size_t... _Uf, class... _Tf, size_t... _Ul, class... _Tl, class... _Up>
476cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(
477cb14a3feSDimitry Andric      allocator_arg_t,
478cb14a3feSDimitry Andric      const _Alloc& __a,
479cb14a3feSDimitry Andric      __tuple_indices<_Uf...>,
480cb14a3feSDimitry Andric      __tuple_types<_Tf...>,
481cb14a3feSDimitry Andric      __tuple_indices<_Ul...>,
482cb14a3feSDimitry Andric      __tuple_types<_Tl...>,
483cb14a3feSDimitry Andric      _Up&&... __u)
484cb14a3feSDimitry Andric      : __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, std::forward<_Up>(__u))...,
485cb14a3feSDimitry Andric        __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... {}
4860b57cec5SDimitry Andric
4870fca6ea1SDimitry Andric  template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
4880fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept(
489cb14a3feSDimitry Andric      (__all<is_nothrow_constructible<
490cb14a3feSDimitry Andric           _Tp,
491cb14a3feSDimitry Andric           typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
492cb14a3feSDimitry Andric      : __tuple_leaf<_Indx, _Tp>(
493cb14a3feSDimitry Andric            std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
494cb14a3feSDimitry Andric                std::get<_Indx>(__t)))... {}
4950b57cec5SDimitry Andric
4960fca6ea1SDimitry Andric  template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
497cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
498cb14a3feSDimitry Andric      : __tuple_leaf<_Indx, _Tp>(
499cb14a3feSDimitry Andric            __uses_alloc_ctor<_Tp,
500cb14a3feSDimitry Andric                              _Alloc,
501cb14a3feSDimitry Andric                              typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(),
502cb14a3feSDimitry Andric            __a,
503cb14a3feSDimitry Andric            std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
504cb14a3feSDimitry Andric                std::get<_Indx>(__t)))... {}
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andric  __tuple_impl(const __tuple_impl&) = default;
5070b57cec5SDimitry Andric  __tuple_impl(__tuple_impl&&)      = default;
5080b57cec5SDimitry Andric
5090fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
5100fca6ea1SDimitry Andric  swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
5115f757f3fSDimitry Andric    std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
5120b57cec5SDimitry Andric  }
51381ad6265SDimitry Andric
514cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(const __tuple_impl& __t) const
5150fca6ea1SDimitry Andric      noexcept(__all<__is_nothrow_swappable_v<const _Tp>...>::value) {
5165f757f3fSDimitry Andric    std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
51781ad6265SDimitry Andric  }
5180b57cec5SDimitry Andric};
5190b57cec5SDimitry Andric
520fe6060f1SDimitry Andrictemplate <class _Dest, class _Source, size_t... _Np>
521cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
522cb14a3feSDimitry Andric__memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
5235f757f3fSDimitry Andric  std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...);
524fe6060f1SDimitry Andric}
5250b57cec5SDimitry Andric
526fe6060f1SDimitry Andrictemplate <class _Dest, class _Source, class... _Up, size_t... _Np>
527cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
528cb14a3feSDimitry Andric__memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
529cb14a3feSDimitry Andric  std::__swallow(((std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source))), void(), 0)...);
530fe6060f1SDimitry Andric}
5310b57cec5SDimitry Andric
5320b57cec5SDimitry Andrictemplate <class... _Tp>
533cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple {
5340b57cec5SDimitry Andric  typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
5350b57cec5SDimitry Andric
5360b57cec5SDimitry Andric  _BaseT __base_;
5370b57cec5SDimitry Andric
538cb14a3feSDimitry Andric  template <size_t _Jp, class... _Up>
539cb14a3feSDimitry Andric  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
540cb14a3feSDimitry Andric  template <size_t _Jp, class... _Up>
541cb14a3feSDimitry Andric  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&
542cb14a3feSDimitry Andric  get(const tuple<_Up...>&) _NOEXCEPT;
543cb14a3feSDimitry Andric  template <size_t _Jp, class... _Up>
544cb14a3feSDimitry Andric  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type&&
545cb14a3feSDimitry Andric  get(tuple<_Up...>&&) _NOEXCEPT;
546cb14a3feSDimitry Andric  template <size_t _Jp, class... _Up>
547cb14a3feSDimitry Andric  friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&&
548cb14a3feSDimitry Andric  get(const tuple<_Up...>&&) _NOEXCEPT;
549cb14a3feSDimitry Andric
5500b57cec5SDimitry Andricpublic:
5510fca6ea1SDimitry Andric  using __trivially_relocatable = __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
5520b57cec5SDimitry Andric
5530fca6ea1SDimitry Andric  // [tuple.cnstr]
554e40139ffSDimitry Andric
5555f757f3fSDimitry Andric  // tuple() constructors (including allocator_arg_t variants)
556fe6060f1SDimitry Andric  template <template <class...> class _IsImpDefault                = __is_implicitly_default_constructible,
557cb14a3feSDimitry Andric            template <class...> class _IsDefault                   = is_default_constructible,
558cb14a3feSDimitry Andric            __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
5590fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)
5600fca6ea1SDimitry Andric      tuple() noexcept(_And<is_nothrow_default_constructible<_Tp>...>::value) {}
5610b57cec5SDimitry Andric
562fe6060f1SDimitry Andric  template <class _Alloc,
563fe6060f1SDimitry Andric            template <class...> class _IsImpDefault                = __is_implicitly_default_constructible,
564cb14a3feSDimitry Andric            template <class...> class _IsDefault                   = is_default_constructible,
565cb14a3feSDimitry Andric            __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
566cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)
567cb14a3feSDimitry Andric      tuple(allocator_arg_t, _Alloc const& __a)
568cb14a3feSDimitry Andric      : __base_(allocator_arg_t(),
569cb14a3feSDimitry Andric                __a,
570cb14a3feSDimitry Andric                __tuple_indices<>(),
571cb14a3feSDimitry Andric                __tuple_types<>(),
572fe6060f1SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
573fe6060f1SDimitry Andric                __tuple_types<_Tp...>()) {}
574fe6060f1SDimitry Andric
575fe6060f1SDimitry Andric  // tuple(const T&...) constructors (including allocator_arg_t variants)
576cb14a3feSDimitry Andric  template <template <class...> class _And = _And,
577cb14a3feSDimitry Andric            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
5780fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
5790fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)
5800fca6ea1SDimitry Andric      tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value)
581fe6060f1SDimitry Andric      : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
582fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
583fe6060f1SDimitry Andric                typename __make_tuple_indices<0>::type(),
584fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
585cb14a3feSDimitry Andric                __t...) {}
586fe6060f1SDimitry Andric
587cb14a3feSDimitry Andric  template <class _Alloc,
588cb14a3feSDimitry Andric            template <class...> class _And = _And,
589cb14a3feSDimitry Andric            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
5900fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
5910fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)
592cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t)
593cb14a3feSDimitry Andric      : __base_(allocator_arg_t(),
594cb14a3feSDimitry Andric                __a,
595fe6060f1SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
596fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
597fe6060f1SDimitry Andric                typename __make_tuple_indices<0>::type(),
598fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
599cb14a3feSDimitry Andric                __t...) {}
600fe6060f1SDimitry Andric
601fe6060f1SDimitry Andric  // tuple(U&& ...) constructors (including allocator_arg_t variants)
602cb14a3feSDimitry Andric  template <class... _Up>
603cb14a3feSDimitry Andric  struct _IsThisTuple : false_type {};
604cb14a3feSDimitry Andric  template <class _Up>
605cb14a3feSDimitry Andric  struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> {};
606fe6060f1SDimitry Andric
607fe6060f1SDimitry Andric  template <class... _Up>
608cb14a3feSDimitry Andric  struct _EnableUTypesCtor
609cb14a3feSDimitry Andric      : _And< _BoolConstant<sizeof...(_Tp) >= 1>,
610fe6060f1SDimitry Andric              _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
611cb14a3feSDimitry Andric              is_constructible<_Tp, _Up>... > {};
612fe6060f1SDimitry Andric
613cb14a3feSDimitry Andric  template <class... _Up,
614cb14a3feSDimitry Andric            __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
615cb14a3feSDimitry Andric                           int> = 0>
616cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
6170fca6ea1SDimitry Andric      tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
618fe6060f1SDimitry Andric      : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
619fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
620fe6060f1SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
621fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
6225f757f3fSDimitry Andric                std::forward<_Up>(__u)...) {}
623fe6060f1SDimitry Andric
624cb14a3feSDimitry Andric  template <class _Alloc,
625cb14a3feSDimitry Andric            class... _Up,
626cb14a3feSDimitry Andric            __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
627cb14a3feSDimitry Andric                           int> = 0>
628cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
629cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
630cb14a3feSDimitry Andric      : __base_(allocator_arg_t(),
631cb14a3feSDimitry Andric                __a,
632fe6060f1SDimitry Andric                typename __make_tuple_indices<sizeof...(_Up)>::type(),
633fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
634fe6060f1SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
635fe6060f1SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
6365f757f3fSDimitry Andric                std::forward<_Up>(__u)...) {}
637fe6060f1SDimitry Andric
638fe6060f1SDimitry Andric  // Copy and move constructors (including the allocator_arg_t variants)
639fe6060f1SDimitry Andric  tuple(const tuple&) = default;
6400b57cec5SDimitry Andric  tuple(tuple&&)      = default;
6410b57cec5SDimitry Andric
642cb14a3feSDimitry Andric  template <class _Alloc,
643cb14a3feSDimitry Andric            template <class...> class _And                                  = _And,
644cb14a3feSDimitry Andric            __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0>
645cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
646cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __alloc, __t) {}
6470b57cec5SDimitry Andric
648cb14a3feSDimitry Andric  template <class _Alloc,
649cb14a3feSDimitry Andric            template <class...> class _And                                  = _And,
650cb14a3feSDimitry Andric            __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0>
651cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
652cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
653e40139ffSDimitry Andric
654fe6060f1SDimitry Andric  // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
65581ad6265SDimitry Andric
656bdd1243dSDimitry Andric  template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>
65781ad6265SDimitry Andric  struct _EnableCtorFromUTypesTuple : false_type {};
65881ad6265SDimitry Andric
65981ad6265SDimitry Andric  template <class _OtherTuple, class... _Up>
660cb14a3feSDimitry Andric  struct _EnableCtorFromUTypesTuple<
661cb14a3feSDimitry Andric      _OtherTuple,
662cb14a3feSDimitry Andric      tuple<_Up...>,
66381ad6265SDimitry Andric      // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
664cb14a3feSDimitry Andric      __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>>
665cb14a3feSDimitry Andric      : _And<
666cb14a3feSDimitry Andric            // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor
667cb14a3feSDimitry Andric            // can work. Otherwise, is_constructible can trigger hard error in those cases
668cb14a3feSDimitry Andric            // https://godbolt.org/z/M94cGdKcE
66981ad6265SDimitry Andric            _Not<is_same<_OtherTuple, const tuple&> >,
67081ad6265SDimitry Andric            _Not<is_same<_OtherTuple, tuple&&> >,
67181ad6265SDimitry Andric            is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
672cb14a3feSDimitry Andric            _Lazy<_Or,
673cb14a3feSDimitry Andric                  _BoolConstant<sizeof...(_Tp) != 1>,
674fe6060f1SDimitry Andric                  // _Tp and _Up are 1-element packs - the pack expansions look
675fe6060f1SDimitry Andric                  // weird to avoid tripping up the type traits in degenerate cases
676fe6060f1SDimitry Andric                  _Lazy<_And,
67781ad6265SDimitry Andric                        _Not<is_same<_Tp, _Up> >...,
67881ad6265SDimitry Andric                        _Not<is_convertible<_OtherTuple, _Tp> >...,
679cb14a3feSDimitry Andric                        _Not<is_constructible<_Tp, _OtherTuple> >... > > > {};
6800b57cec5SDimitry Andric
681cb14a3feSDimitry Andric  template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
6820fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
6830fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)
6840fca6ea1SDimitry Andric      tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)
685cb14a3feSDimitry Andric      : __base_(__t) {}
6860b57cec5SDimitry Andric
687cb14a3feSDimitry Andric  template <class... _Up,
688cb14a3feSDimitry Andric            class _Alloc,
689cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
6900fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
6910fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)
692cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
693cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __a, __t) {}
6940b57cec5SDimitry Andric
69506c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
69681ad6265SDimitry Andric  // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
69781ad6265SDimitry Andric
698cb14a3feSDimitry Andric  template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
699cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t)
700cb14a3feSDimitry Andric      : __base_(__t) {}
70181ad6265SDimitry Andric
702cb14a3feSDimitry Andric  template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
703cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
704cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)
705cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __alloc, __t) {}
70606c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
70781ad6265SDimitry Andric
708fe6060f1SDimitry Andric  // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
709cb14a3feSDimitry Andric  template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
710cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
7110fca6ea1SDimitry Andric      tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
712cb14a3feSDimitry Andric      : __base_(std::move(__t)) {}
7130b57cec5SDimitry Andric
714cb14a3feSDimitry Andric  template <class _Alloc,
715cb14a3feSDimitry Andric            class... _Up,
716cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
717cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
718cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
719cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __a, std::move(__t)) {}
720fe6060f1SDimitry Andric
72106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
72281ad6265SDimitry Andric  // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
72381ad6265SDimitry Andric
724cb14a3feSDimitry Andric  template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
725cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
726cb14a3feSDimitry Andric      tuple(const tuple<_Up...>&& __t)
727cb14a3feSDimitry Andric      : __base_(std::move(__t)) {}
72881ad6265SDimitry Andric
729cb14a3feSDimitry Andric  template <class _Alloc,
730cb14a3feSDimitry Andric            class... _Up,
731cb14a3feSDimitry Andric            enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
732cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
73381ad6265SDimitry Andric      tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
73481ad6265SDimitry Andric      : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
73506c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
73681ad6265SDimitry Andric
737fe6060f1SDimitry Andric  // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
73881ad6265SDimitry Andric
739cb14a3feSDimitry Andric  template <template <class...> class _Pred,
740cb14a3feSDimitry Andric            class _Pair,
741cb14a3feSDimitry Andric            class _DecayedPair = __remove_cvref_t<_Pair>,
742cb14a3feSDimitry Andric            class _Tuple       = tuple>
74381ad6265SDimitry Andric  struct _CtorPredicateFromPair : false_type {};
74481ad6265SDimitry Andric
74506c3fb27SDimitry Andric  template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
746cb14a3feSDimitry Andric  struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
747cb14a3feSDimitry Andric      : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {};
748fe6060f1SDimitry Andric
74981ad6265SDimitry Andric  template <class _Pair>
75081ad6265SDimitry Andric  struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {};
75181ad6265SDimitry Andric
75281ad6265SDimitry Andric  template <class _Pair>
75381ad6265SDimitry Andric  struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {};
75481ad6265SDimitry Andric
755bdd1243dSDimitry Andric  template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
75681ad6265SDimitry Andric  struct _BothImplicitlyConvertible : false_type {};
75781ad6265SDimitry Andric
75881ad6265SDimitry Andric  template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
759cb14a3feSDimitry Andric  struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
760cb14a3feSDimitry Andric      : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {};
761fe6060f1SDimitry Andric
762cb14a3feSDimitry Andric  template <class _Up1,
763cb14a3feSDimitry Andric            class _Up2,
764cb14a3feSDimitry Andric            template <class...> class _And                                                   = _And,
765cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
7660fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
7670fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
7680fca6ea1SDimitry Andric      tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)
769cb14a3feSDimitry Andric      : __base_(__p) {}
770fe6060f1SDimitry Andric
771cb14a3feSDimitry Andric  template <class _Alloc,
772cb14a3feSDimitry Andric            class _Up1,
773cb14a3feSDimitry Andric            class _Up2,
774cb14a3feSDimitry Andric            template <class...> class _And                                                   = _And,
775cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
7760fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
7770fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
778cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
779cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __a, __p) {}
780fe6060f1SDimitry Andric
78106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
78281ad6265SDimitry Andric  // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
783fe6060f1SDimitry Andric
784cb14a3feSDimitry Andric  template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
785cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
786cb14a3feSDimitry Andric      tuple(pair<_U1, _U2>& __p)
787cb14a3feSDimitry Andric      : __base_(__p) {}
78881ad6265SDimitry Andric
789cb14a3feSDimitry Andric  template <class _Alloc,
790cb14a3feSDimitry Andric            class _U1,
791cb14a3feSDimitry Andric            class _U2,
792cb14a3feSDimitry Andric            enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
793cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
794cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)
795cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __alloc, __p) {}
79681ad6265SDimitry Andric#  endif
79781ad6265SDimitry Andric
79881ad6265SDimitry Andric  // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
799fe6060f1SDimitry Andric
800cb14a3feSDimitry Andric  template <class _Up1,
801cb14a3feSDimitry Andric            class _Up2,
802cb14a3feSDimitry Andric            template <class...> class _And                                              = _And,
803cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
8040fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
8050fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
8060fca6ea1SDimitry Andric      tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)
807cb14a3feSDimitry Andric      : __base_(std::move(__p)) {}
808fe6060f1SDimitry Andric
809cb14a3feSDimitry Andric  template <class _Alloc,
810cb14a3feSDimitry Andric            class _Up1,
811cb14a3feSDimitry Andric            class _Up2,
812cb14a3feSDimitry Andric            template <class...> class _And                                              = _And,
813cb14a3feSDimitry Andric            __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
8140fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
8150fca6ea1SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
816cb14a3feSDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
817cb14a3feSDimitry Andric      : __base_(allocator_arg_t(), __a, std::move(__p)) {}
818fe6060f1SDimitry Andric
81906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
82081ad6265SDimitry Andric  // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
82181ad6265SDimitry Andric
822cb14a3feSDimitry Andric  template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
823cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
824cb14a3feSDimitry Andric      tuple(const pair<_U1, _U2>&& __p)
825cb14a3feSDimitry Andric      : __base_(std::move(__p)) {}
82681ad6265SDimitry Andric
827cb14a3feSDimitry Andric  template <class _Alloc,
828cb14a3feSDimitry Andric            class _U1,
829cb14a3feSDimitry Andric            class _U2,
830cb14a3feSDimitry Andric            enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
831cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
83281ad6265SDimitry Andric      tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
83381ad6265SDimitry Andric      : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
83406c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
83581ad6265SDimitry Andric
836fe6060f1SDimitry Andric  // [tuple.assign]
837cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
838cb14a3feSDimitry Andric  operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
8390fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_copy_assignable<_Tp>...>::value) {
84081ad6265SDimitry Andric    std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
84181ad6265SDimitry Andric    return *this;
84281ad6265SDimitry Andric  }
84381ad6265SDimitry Andric
844cb14a3feSDimitry Andric#  if _LIBCPP_STD_VER >= 23
845cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
846cb14a3feSDimitry Andric    requires(_And<is_copy_assignable<const _Tp>...>::value)
847cb14a3feSDimitry Andric  {
848cb14a3feSDimitry Andric    std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
849cb14a3feSDimitry Andric    return *this;
850cb14a3feSDimitry Andric  }
851cb14a3feSDimitry Andric
852cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
853cb14a3feSDimitry Andric    requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
854cb14a3feSDimitry Andric  {
855cb14a3feSDimitry Andric    std::__memberwise_forward_assign(
856cb14a3feSDimitry Andric        *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
85781ad6265SDimitry Andric    return *this;
85881ad6265SDimitry Andric  }
85906c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
86081ad6265SDimitry Andric
861cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
862cb14a3feSDimitry Andric  operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
8630fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_move_assignable<_Tp>...>::value) {
864cb14a3feSDimitry Andric    std::__memberwise_forward_assign(
865cb14a3feSDimitry Andric        *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
8660b57cec5SDimitry Andric    return *this;
8670b57cec5SDimitry Andric  }
8680b57cec5SDimitry Andric
869cb14a3feSDimitry Andric  template <
870cb14a3feSDimitry Andric      class... _Up,
871cb14a3feSDimitry Andric      __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,
872cb14a3feSDimitry Andric                     int> = 0>
873cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...> const& __tuple)
8740fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
875cb14a3feSDimitry Andric    std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
8760b57cec5SDimitry Andric    return *this;
8770b57cec5SDimitry Andric  }
8780b57cec5SDimitry Andric
879cb14a3feSDimitry Andric  template <class... _Up,
880cb14a3feSDimitry Andric            __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,
881cb14a3feSDimitry Andric                           int> = 0>
882cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...>&& __tuple)
8830fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
884cb14a3feSDimitry Andric    std::__memberwise_forward_assign(
885cb14a3feSDimitry Andric        *this, std::move(__tuple), __tuple_types<_Up...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
886fe6060f1SDimitry Andric    return *this;
887fe6060f1SDimitry Andric  }
888fe6060f1SDimitry Andric
88906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
890cb14a3feSDimitry Andric  template <class... _UTypes,
891cb14a3feSDimitry Andric            enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
89281ad6265SDimitry Andric                              is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
893cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
894cb14a3feSDimitry Andric    std::__memberwise_copy_assign(*this, __u, typename __make_tuple_indices<sizeof...(_Tp)>::type());
89581ad6265SDimitry Andric    return *this;
89681ad6265SDimitry Andric  }
89781ad6265SDimitry Andric
898cb14a3feSDimitry Andric  template <class... _UTypes,
899cb14a3feSDimitry Andric            enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
90081ad6265SDimitry Andric                              is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
901cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
902cb14a3feSDimitry Andric    std::__memberwise_forward_assign(
903cb14a3feSDimitry Andric        *this, __u, __tuple_types<_UTypes...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
90481ad6265SDimitry Andric    return *this;
90581ad6265SDimitry Andric  }
90606c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
90781ad6265SDimitry Andric
908cb14a3feSDimitry Andric  template <template <class...> class _Pred,
909cb14a3feSDimitry Andric            bool _Const,
910cb14a3feSDimitry Andric            class _Pair,
911cb14a3feSDimitry Andric            class _DecayedPair = __remove_cvref_t<_Pair>,
912cb14a3feSDimitry Andric            class _Tuple       = tuple>
91381ad6265SDimitry Andric  struct _AssignPredicateFromPair : false_type {};
91481ad6265SDimitry Andric
915cb14a3feSDimitry Andric  template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
916cb14a3feSDimitry Andric  struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
917cb14a3feSDimitry Andric      : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
918cb14a3feSDimitry Andric             _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {};
91981ad6265SDimitry Andric
92081ad6265SDimitry Andric  template <bool _Const, class _Pair>
92181ad6265SDimitry Andric  struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
92281ad6265SDimitry Andric
92381ad6265SDimitry Andric  template <bool _Const, class _Pair>
92481ad6265SDimitry Andric  struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
92581ad6265SDimitry Andric
92606c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
927cb14a3feSDimitry Andric  template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
928cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const
92981ad6265SDimitry Andric      noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
93081ad6265SDimitry Andric    std::get<0>(*this) = __pair.first;
93181ad6265SDimitry Andric    std::get<1>(*this) = __pair.second;
93281ad6265SDimitry Andric    return *this;
93381ad6265SDimitry Andric  }
93481ad6265SDimitry Andric
935cb14a3feSDimitry Andric  template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
936cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const
93781ad6265SDimitry Andric      noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
93881ad6265SDimitry Andric    std::get<0>(*this) = std::move(__pair.first);
93981ad6265SDimitry Andric    std::get<1>(*this) = std::move(__pair.second);
94081ad6265SDimitry Andric    return *this;
94181ad6265SDimitry Andric  }
94206c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
94381ad6265SDimitry Andric
944cb14a3feSDimitry Andric  template <class _Up1,
945cb14a3feSDimitry Andric            class _Up2,
946cb14a3feSDimitry Andric            __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>
947cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2> const& __pair)
9480fca6ea1SDimitry Andric      noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
9495f757f3fSDimitry Andric    std::get<0>(*this) = __pair.first;
9505f757f3fSDimitry Andric    std::get<1>(*this) = __pair.second;
951fe6060f1SDimitry Andric    return *this;
952fe6060f1SDimitry Andric  }
953fe6060f1SDimitry Andric
954cb14a3feSDimitry Andric  template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>
955cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2>&& __pair)
9560fca6ea1SDimitry Andric      noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
9575f757f3fSDimitry Andric    std::get<0>(*this) = std::forward<_Up1>(__pair.first);
9585f757f3fSDimitry Andric    std::get<1>(*this) = std::forward<_Up2>(__pair.second);
959fe6060f1SDimitry Andric    return *this;
960fe6060f1SDimitry Andric  }
961fe6060f1SDimitry Andric
962fe6060f1SDimitry Andric  // EXTENSION
963cb14a3feSDimitry Andric  template <
964cb14a3feSDimitry Andric      class _Up,
965cb14a3feSDimitry Andric      size_t _Np,
9660fca6ea1SDimitry Andric      __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
967cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np> const& __array)
9680fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
969cb14a3feSDimitry Andric    std::__memberwise_copy_assign(*this, __array, typename __make_tuple_indices<sizeof...(_Tp)>::type());
970fe6060f1SDimitry Andric    return *this;
971fe6060f1SDimitry Andric  }
972fe6060f1SDimitry Andric
973fe6060f1SDimitry Andric  // EXTENSION
974cb14a3feSDimitry Andric  template <class _Up,
975cb14a3feSDimitry Andric            size_t _Np,
976cb14a3feSDimitry Andric            class = void,
9770fca6ea1SDimitry Andric            __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>
978cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np>&& __array)
9790fca6ea1SDimitry Andric      noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
980cb14a3feSDimitry Andric    std::__memberwise_forward_assign(
981cb14a3feSDimitry Andric        *this,
982cb14a3feSDimitry Andric        std::move(__array),
983fe6060f1SDimitry Andric        __tuple_types<_If<true, _Up, _Tp>...>(),
984fe6060f1SDimitry Andric        typename __make_tuple_indices<sizeof...(_Tp)>::type());
985fe6060f1SDimitry Andric    return *this;
986fe6060f1SDimitry Andric  }
987fe6060f1SDimitry Andric
988fe6060f1SDimitry Andric  // [tuple.swap]
989cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple& __t)
9900fca6ea1SDimitry Andric      noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
991cb14a3feSDimitry Andric    __base_.swap(__t.__base_);
992cb14a3feSDimitry Andric  }
99381ad6265SDimitry Andric
99406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
995cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const
996cb14a3feSDimitry Andric      noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
99781ad6265SDimitry Andric    __base_.swap(__t.__base_);
99881ad6265SDimitry Andric  }
99906c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
10000b57cec5SDimitry Andric};
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andrictemplate <>
1003cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple<> {
10040b57cec5SDimitry Andricpublic:
100506c3fb27SDimitry Andric  constexpr tuple() _NOEXCEPT = default;
10060b57cec5SDimitry Andric  template <class _Alloc>
1007cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
10080b57cec5SDimitry Andric  template <class _Alloc>
1009cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
10100b57cec5SDimitry Andric  template <class _Up>
1011cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) _NOEXCEPT {}
10120b57cec5SDimitry Andric  template <class _Alloc, class _Up>
1013cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
1014cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {}
101506c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
101681ad6265SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
101781ad6265SDimitry Andric#  endif
10180b57cec5SDimitry Andric};
10190b57cec5SDimitry Andric
102006c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
102104eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
102204eeddc0SDimitry Andric  requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
102304eeddc0SDimitry Andricstruct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
102404eeddc0SDimitry Andric  using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
102504eeddc0SDimitry Andric};
102604eeddc0SDimitry Andric
102704eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes>
102804eeddc0SDimitry Andric  requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
102904eeddc0SDimitry Andricstruct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
103004eeddc0SDimitry Andric  using type = tuple<common_type_t<_TTypes, _UTypes>...>;
103104eeddc0SDimitry Andric};
103206c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 23
103304eeddc0SDimitry Andric
103406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
1035e40139ffSDimitry Andrictemplate <class... _Tp>
1036e40139ffSDimitry Andrictuple(_Tp...) -> tuple<_Tp...>;
1037e40139ffSDimitry Andrictemplate <class _Tp1, class _Tp2>
1038e40139ffSDimitry Andrictuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1039e40139ffSDimitry Andrictemplate <class _Alloc, class... _Tp>
1040e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1041e40139ffSDimitry Andrictemplate <class _Alloc, class _Tp1, class _Tp2>
1042e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1043e40139ffSDimitry Andrictemplate <class _Alloc, class... _Tp>
1044e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
10450b57cec5SDimitry Andric#  endif
10460b57cec5SDimitry Andric
10470fca6ea1SDimitry Andrictemplate <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>
1048cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
10490fca6ea1SDimitry Andric    noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1050cb14a3feSDimitry Andric  __t.swap(__u);
1051cb14a3feSDimitry Andric}
10520b57cec5SDimitry Andric
105306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
105481ad6265SDimitry Andrictemplate <class... _Tp>
1055cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1056cb14a3feSDimitry Andricswap(const tuple<_Tp...>& __lhs,
1057cb14a3feSDimitry Andric     const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
105881ad6265SDimitry Andric  __lhs.swap(__rhs);
105981ad6265SDimitry Andric}
106081ad6265SDimitry Andric#  endif
106181ad6265SDimitry Andric
10620b57cec5SDimitry Andric// get
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp>
1065cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&
1066cb14a3feSDimitry Andricget(tuple<_Tp...>& __t) _NOEXCEPT {
1067349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10680b57cec5SDimitry Andric  return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
10690b57cec5SDimitry Andric}
10700b57cec5SDimitry Andric
10710b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp>
1072cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
1073cb14a3feSDimitry Andricget(const tuple<_Tp...>& __t) _NOEXCEPT {
1074349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10750b57cec5SDimitry Andric  return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
10760b57cec5SDimitry Andric}
10770b57cec5SDimitry Andric
10780b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp>
1079cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1080cb14a3feSDimitry Andricget(tuple<_Tp...>&& __t) _NOEXCEPT {
1081349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1082cb14a3feSDimitry Andric  return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10830b57cec5SDimitry Andric}
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp>
1086cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1087cb14a3feSDimitry Andricget(const tuple<_Tp...>&& __t) _NOEXCEPT {
1088349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1089cb14a3feSDimitry Andric  return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10900b57cec5SDimitry Andric}
10910b57cec5SDimitry Andric
109206c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
10930b57cec5SDimitry Andric
10940b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
1095cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {
10965f757f3fSDimitry Andric  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
10970b57cec5SDimitry Andric}
10980b57cec5SDimitry Andric
10990b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
1100cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept {
11015f757f3fSDimitry Andric  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
11020b57cec5SDimitry Andric}
11030b57cec5SDimitry Andric
11040b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
1105cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept {
11065f757f3fSDimitry Andric  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
11070b57cec5SDimitry Andric}
11080b57cec5SDimitry Andric
11090b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
1110cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept {
11115f757f3fSDimitry Andric  return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
11120b57cec5SDimitry Andric}
11130b57cec5SDimitry Andric
11140b57cec5SDimitry Andric#  endif
11150b57cec5SDimitry Andric
11160b57cec5SDimitry Andric// tie
11170b57cec5SDimitry Andric
11180b57cec5SDimitry Andrictemplate <class... _Tp>
1119cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) _NOEXCEPT {
11200b57cec5SDimitry Andric  return tuple<_Tp&...>(__t...);
11210b57cec5SDimitry Andric}
11220b57cec5SDimitry Andric
11230b57cec5SDimitry Andrictemplate <class... _Tp>
1124cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<typename __unwrap_ref_decay<_Tp>::type...>
1125cb14a3feSDimitry Andricmake_tuple(_Tp&&... __t) {
11265f757f3fSDimitry Andric  return tuple<typename __unwrap_ref_decay<_Tp>::type...>(std::forward<_Tp>(__t)...);
11270b57cec5SDimitry Andric}
11280b57cec5SDimitry Andric
11290b57cec5SDimitry Andrictemplate <class... _Tp>
1130cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) _NOEXCEPT {
11315f757f3fSDimitry Andric  return tuple<_Tp&&...>(std::forward<_Tp>(__t)...);
11320b57cec5SDimitry Andric}
11330b57cec5SDimitry Andric
11340b57cec5SDimitry Andrictemplate <size_t _Ip>
1135cb14a3feSDimitry Andricstruct __tuple_equal {
11360b57cec5SDimitry Andric  template <class _Tp, class _Up>
1137cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {
11385f757f3fSDimitry Andric    return __tuple_equal<_Ip - 1>()(__x, __y) && std::get<_Ip - 1>(__x) == std::get<_Ip - 1>(__y);
11390b57cec5SDimitry Andric  }
11400b57cec5SDimitry Andric};
11410b57cec5SDimitry Andric
11420b57cec5SDimitry Andrictemplate <>
1143cb14a3feSDimitry Andricstruct __tuple_equal<0> {
11440b57cec5SDimitry Andric  template <class _Tp, class _Up>
1145cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {
11460b57cec5SDimitry Andric    return true;
11470b57cec5SDimitry Andric  }
11480b57cec5SDimitry Andric};
11490b57cec5SDimitry Andric
11500b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1151cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1152cb14a3feSDimitry Andricoperator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11530b57cec5SDimitry Andric  static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
11540b57cec5SDimitry Andric  return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
11550b57cec5SDimitry Andric}
11560b57cec5SDimitry Andric
115706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
1158349cc55cSDimitry Andric
1159349cc55cSDimitry Andric// operator<=>
1160349cc55cSDimitry Andric
1161349cc55cSDimitry Andrictemplate <class... _Tp, class... _Up, size_t... _Is>
1162cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto
1163349cc55cSDimitry Andric__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1164349cc55cSDimitry Andric  common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1165cb14a3feSDimitry Andric  static_cast<void>(
1166cb14a3feSDimitry Andric      ((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...));
1167349cc55cSDimitry Andric  return __result;
1168349cc55cSDimitry Andric}
1169349cc55cSDimitry Andric
1170349cc55cSDimitry Andrictemplate <class... _Tp, class... _Up>
1171349cc55cSDimitry Andric  requires(sizeof...(_Tp) == sizeof...(_Up))
1172cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1173cb14a3feSDimitry Andricoperator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11745f757f3fSDimitry Andric  return std::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1175349cc55cSDimitry Andric}
1176349cc55cSDimitry Andric
117706c3fb27SDimitry Andric#  else // _LIBCPP_STD_VER >= 20
1178349cc55cSDimitry Andric
11790b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1180cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1181cb14a3feSDimitry Andricoperator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11820b57cec5SDimitry Andric  return !(__x == __y);
11830b57cec5SDimitry Andric}
11840b57cec5SDimitry Andric
11850b57cec5SDimitry Andrictemplate <size_t _Ip>
1186cb14a3feSDimitry Andricstruct __tuple_less {
11870b57cec5SDimitry Andric  template <class _Tp, class _Up>
1188cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {
11890b57cec5SDimitry Andric    const size_t __idx = tuple_size<_Tp>::value - _Ip;
11905f757f3fSDimitry Andric    if (std::get<__idx>(__x) < std::get<__idx>(__y))
11910b57cec5SDimitry Andric      return true;
11925f757f3fSDimitry Andric    if (std::get<__idx>(__y) < std::get<__idx>(__x))
11930b57cec5SDimitry Andric      return false;
11940b57cec5SDimitry Andric    return __tuple_less<_Ip - 1>()(__x, __y);
11950b57cec5SDimitry Andric  }
11960b57cec5SDimitry Andric};
11970b57cec5SDimitry Andric
11980b57cec5SDimitry Andrictemplate <>
1199cb14a3feSDimitry Andricstruct __tuple_less<0> {
12000b57cec5SDimitry Andric  template <class _Tp, class _Up>
1201cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {
12020b57cec5SDimitry Andric    return false;
12030b57cec5SDimitry Andric  }
12040b57cec5SDimitry Andric};
12050b57cec5SDimitry Andric
12060b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1207cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1208cb14a3feSDimitry Andricoperator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12090b57cec5SDimitry Andric  static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
12100b57cec5SDimitry Andric  return __tuple_less<sizeof...(_Tp)>()(__x, __y);
12110b57cec5SDimitry Andric}
12120b57cec5SDimitry Andric
12130b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1214cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1215cb14a3feSDimitry Andricoperator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12160b57cec5SDimitry Andric  return __y < __x;
12170b57cec5SDimitry Andric}
12180b57cec5SDimitry Andric
12190b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1220cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1221cb14a3feSDimitry Andricoperator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12220b57cec5SDimitry Andric  return !(__x < __y);
12230b57cec5SDimitry Andric}
12240b57cec5SDimitry Andric
12250b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up>
1226cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1227cb14a3feSDimitry Andricoperator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12280b57cec5SDimitry Andric  return !(__y < __x);
12290b57cec5SDimitry Andric}
12300b57cec5SDimitry Andric
123106c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 20
1232349cc55cSDimitry Andric
12330b57cec5SDimitry Andric// tuple_cat
12340b57cec5SDimitry Andric
1235cb14a3feSDimitry Andrictemplate <class _Tp, class _Up>
1236cb14a3feSDimitry Andricstruct __tuple_cat_type;
12370b57cec5SDimitry Andric
12380b57cec5SDimitry Andrictemplate <class... _Ttypes, class... _Utypes>
1239cb14a3feSDimitry Andricstruct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > {
1240349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
12410b57cec5SDimitry Andric};
12420b57cec5SDimitry Andric
12430b57cec5SDimitry Andrictemplate <class _ResultTuple, bool _Is_Tuple0TupleLike, class... _Tuples>
1244cb14a3feSDimitry Andricstruct __tuple_cat_return_1 {};
12450b57cec5SDimitry Andric
12460b57cec5SDimitry Andrictemplate <class... _Types, class _Tuple0>
1247cb14a3feSDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> {
1248cb14a3feSDimitry Andric  using type _LIBCPP_NODEBUG =
1249cb14a3feSDimitry Andric      typename __tuple_cat_type< tuple<_Types...>,
1250cb14a3feSDimitry Andric                                 typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type;
12510b57cec5SDimitry Andric};
12520b57cec5SDimitry Andric
12530b57cec5SDimitry Andrictemplate <class... _Types, class _Tuple0, class _Tuple1, class... _Tuples>
12540b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
12550b57cec5SDimitry Andric    : public __tuple_cat_return_1<
1256cb14a3feSDimitry Andric          typename __tuple_cat_type< tuple<_Types...>,
1257cb14a3feSDimitry Andric                                     typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type,
1258bdd1243dSDimitry Andric          __tuple_like_ext<__libcpp_remove_reference_t<_Tuple1> >::value,
1259cb14a3feSDimitry Andric          _Tuple1,
1260cb14a3feSDimitry Andric          _Tuples...> {};
12610b57cec5SDimitry Andric
1262cb14a3feSDimitry Andrictemplate <class... _Tuples>
1263cb14a3feSDimitry Andricstruct __tuple_cat_return;
12640b57cec5SDimitry Andric
12650b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples>
12660b57cec5SDimitry Andricstruct __tuple_cat_return<_Tuple0, _Tuples...>
12670b57cec5SDimitry Andric    : public __tuple_cat_return_1<tuple<>,
1268cb14a3feSDimitry Andric                                  __tuple_like_ext<__libcpp_remove_reference_t<_Tuple0> >::value,
1269cb14a3feSDimitry Andric                                  _Tuple0,
1270cb14a3feSDimitry Andric                                  _Tuples...> {};
12710b57cec5SDimitry Andric
12720b57cec5SDimitry Andrictemplate <>
1273cb14a3feSDimitry Andricstruct __tuple_cat_return<> {
1274349cc55cSDimitry Andric  typedef _LIBCPP_NODEBUG tuple<> type;
12750b57cec5SDimitry Andric};
12760b57cec5SDimitry Andric
1277cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
12780b57cec5SDimitry Andric
12790b57cec5SDimitry Andrictemplate <class _Rp, class _Indices, class _Tuple0, class... _Tuples>
12800b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp;
12810b57cec5SDimitry Andric
12820b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, class _Tuple0>
1283cb14a3feSDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> {
1284bdd1243dSDimitry Andric  typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
12850fca6ea1SDimitry Andric  typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
12860b57cec5SDimitry Andric};
12870b57cec5SDimitry Andric
12880b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>
1289cb14a3feSDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0, _Tuple1, _Tuples...>
12900b57cec5SDimitry Andric    : public __tuple_cat_return_ref_imp<
1291cb14a3feSDimitry Andric          tuple<_Types...,
12920fca6ea1SDimitry Andric                __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
1293bdd1243dSDimitry Andric          typename __make_tuple_indices<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>::type,
1294cb14a3feSDimitry Andric          _Tuple1,
1295cb14a3feSDimitry Andric          _Tuples...> {};
12960b57cec5SDimitry Andric
12970b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples>
12980b57cec5SDimitry Andricstruct __tuple_cat_return_ref
1299cb14a3feSDimitry Andric    : public __tuple_cat_return_ref_imp<
1300cb14a3feSDimitry Andric          tuple<>,
1301cb14a3feSDimitry Andric          typename __make_tuple_indices< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >::type,
1302cb14a3feSDimitry Andric          _Tuple0,
1303cb14a3feSDimitry Andric          _Tuples...> {};
13040b57cec5SDimitry Andric
13050b57cec5SDimitry Andrictemplate <class _Types, class _I0, class _J0>
13060b57cec5SDimitry Andricstruct __tuple_cat;
13070b57cec5SDimitry Andric
13080b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, size_t... _J0>
1309cb14a3feSDimitry Andricstruct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > {
13100b57cec5SDimitry Andric  template <class _Tuple0>
13115f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
13120b57cec5SDimitry Andric  typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1313cb14a3feSDimitry Andric  operator()(tuple<_Types...> __t, _Tuple0&& __t0) {
131481ad6265SDimitry Andric    (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
13155f757f3fSDimitry Andric    return std::forward_as_tuple(
1316cb14a3feSDimitry Andric        std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...);
13170b57cec5SDimitry Andric  }
13180b57cec5SDimitry Andric
13190b57cec5SDimitry Andric  template <class _Tuple0, class _Tuple1, class... _Tuples>
13205f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
13210b57cec5SDimitry Andric  typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1322cb14a3feSDimitry Andric  operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {
132381ad6265SDimitry Andric    (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1324bdd1243dSDimitry Andric    typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
1325bdd1243dSDimitry Andric    typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1;
13260fca6ea1SDimitry Andric    return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
132706c3fb27SDimitry Andric                       typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type,
1328480093f4SDimitry Andric                       typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
13295f757f3fSDimitry Andric        std::forward_as_tuple(
1330cb14a3feSDimitry Andric            std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...),
1331cb14a3feSDimitry Andric        std::forward<_Tuple1>(__t1),
1332cb14a3feSDimitry Andric        std::forward<_Tuples>(__tpls)...);
13330b57cec5SDimitry Andric  }
13340b57cec5SDimitry Andric};
13350b57cec5SDimitry Andric
13360b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples>
1337cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1338cb14a3feSDimitry Andrictuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
1339bdd1243dSDimitry Andric  typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
1340cb14a3feSDimitry Andric  return __tuple_cat<tuple<>, __tuple_indices<>, typename __make_tuple_indices<tuple_size<_T0>::value>::type>()(
1341cb14a3feSDimitry Andric      tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...);
13420b57cec5SDimitry Andric}
13430b57cec5SDimitry Andric
13440b57cec5SDimitry Andrictemplate <class... _Tp, class _Alloc>
1345cb14a3feSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
13460b57cec5SDimitry Andric
134706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
1348cb14a3feSDimitry Andric#    define _LIBCPP_NOEXCEPT_RETURN(...)                                                                               \
1349cb14a3feSDimitry Andric      noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
13500b57cec5SDimitry Andric
13511db9f3b2SDimitry Andric// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting.
13521db9f3b2SDimitry Andric// clang-format off
13530b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple, size_t... _Id>
1354cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto)
1355cb14a3feSDimitry Andric__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, __tuple_indices<_Id...>)
1356cb14a3feSDimitry Andric    _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...))
13570b57cec5SDimitry Andric
13580b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple>
13591db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t)
13601db9f3b2SDimitry Andric    _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl(
13611db9f3b2SDimitry Andric        std::forward<_Fn>(__f),
1362cb14a3feSDimitry Andric        std::forward<_Tuple>(__t),
1363cb14a3feSDimitry Andric        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}))
13640b57cec5SDimitry Andric
13650fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20
13660b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx>
13671db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
13680fca6ea1SDimitry Andric  noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
13690fca6ea1SDimitry Andric  requires is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> {
13700fca6ea1SDimitry Andric  return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
13710fca6ea1SDimitry Andric}
13720fca6ea1SDimitry Andric#else
13730fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx>
13740fca6ea1SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>,
13750fca6ea1SDimitry Andric    enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr)
1376cb14a3feSDimitry Andric    _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
13770fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
13780b57cec5SDimitry Andric
13790fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple,
13800fca6ea1SDimitry Andric          class _Seq = typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type, class = void>
13810fca6ea1SDimitry Andricinline constexpr bool __can_make_from_tuple = false;
13820fca6ea1SDimitry Andric
13830fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx>
13840fca6ea1SDimitry Andricinline constexpr bool __can_make_from_tuple<_Tp, _Tuple, __tuple_indices<_Idx...>,
13850fca6ea1SDimitry Andric    enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>>> = true;
13860fca6ea1SDimitry Andric
13870fca6ea1SDimitry Andric// Based on LWG3528(https://wg21.link/LWG3528) and http://eel.is/c++draft/description#structure.requirements-9,
13880fca6ea1SDimitry Andric// the standard allows to impose requirements, we constraint std::make_from_tuple to make std::make_from_tuple
13890fca6ea1SDimitry Andric// SFINAE friendly and also avoid worse diagnostic messages. We still keep the constraints of std::__make_from_tuple_impl
13900fca6ea1SDimitry Andric// so that std::__make_from_tuple_impl will have the same advantages when used alone.
13910fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20
13920b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple>
13930fca6ea1SDimitry Andric  requires __can_make_from_tuple<_Tp, _Tuple> // strengthen
13940fca6ea1SDimitry Andric#else
13950fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen
13960fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
13971db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)
13981db9f3b2SDimitry Andric    _LIBCPP_NOEXCEPT_RETURN(std::__make_from_tuple_impl<_Tp>(
1399cb14a3feSDimitry Andric        std::forward<_Tuple>(__t), typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}))
14000b57cec5SDimitry Andric#    undef _LIBCPP_NOEXCEPT_RETURN
14010b57cec5SDimitry Andric
140206c3fb27SDimitry Andric#  endif // _LIBCPP_STD_VER >= 17
14030b57cec5SDimitry Andric
14040b57cec5SDimitry Andric#endif // !defined(_LIBCPP_CXX03_LANG)
14050b57cec5SDimitry Andric
14060b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
14070b57cec5SDimitry Andric
140806c3fb27SDimitry Andric_LIBCPP_POP_MACROS
140906c3fb27SDimitry Andric
14101db9f3b2SDimitry Andric// clang-format on
14111db9f3b2SDimitry Andric
1412bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1413bdd1243dSDimitry Andric#  include <exception>
1414bdd1243dSDimitry Andric#  include <iosfwd>
1415bdd1243dSDimitry Andric#  include <new>
1416bdd1243dSDimitry Andric#  include <type_traits>
1417bdd1243dSDimitry Andric#  include <typeinfo>
1418bdd1243dSDimitry Andric#  include <utility>
1419bdd1243dSDimitry Andric#endif
1420bdd1243dSDimitry Andric
14210b57cec5SDimitry Andric#endif // _LIBCPP_TUPLE
1422