xref: /llvm-project-15.0.7/libcxx/include/tuple (revision d2c87699)
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14    tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
22    explicit(see-below) constexpr tuple();
23    explicit(see-below) tuple(const T&...);  // constexpr in C++14
24    template <class... U>
25        explicit(see-below) tuple(U&&...);  // constexpr in C++14
26    tuple(const tuple&) = default;
27    tuple(tuple&&) = default;
28    template <class... U>
29        explicit(see-below) tuple(const tuple<U...>&);  // constexpr in C++14
30    template <class... U>
31        explicit(see-below) tuple(tuple<U...>&&);  // constexpr in C++14
32    template <class U1, class U2>
33        explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
34    template <class U1, class U2>
35        explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++14
36
37    // allocator-extended constructors
38    template <class Alloc>
39        tuple(allocator_arg_t, const Alloc& a);
40    template <class Alloc>
41        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);          // constexpr in C++20
42    template <class Alloc, class... U>
43        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);               // constexpr in C++20
44    template <class Alloc>
45        tuple(allocator_arg_t, const Alloc& a, const tuple&);                             // constexpr in C++20
46    template <class Alloc>
47        tuple(allocator_arg_t, const Alloc& a, tuple&&);                                  // constexpr in C++20
48    template <class Alloc, class... U>
49        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);   // constexpr in C++20
50    template <class Alloc, class... U>
51        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);        // constexpr in C++20
52    template <class Alloc, class U1, class U2>
53        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);  // constexpr in C++20
54    template <class Alloc, class U1, class U2>
55        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);       // constexpr in C++20
56
57    tuple& operator=(const tuple&);                                                       // constexpr in C++20
58    tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...);           // constexpr in C++20
59    template <class... U>
60        tuple& operator=(const tuple<U...>&);                                             // constexpr in C++20
61    template <class... U>
62        tuple& operator=(tuple<U...>&&);                                                  // constexpr in C++20
63    template <class U1, class U2>
64        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2                   // constexpr in C++20
65    template <class U1, class U2>
66        tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2                        // constexpr in C++20
67
68    template<class U, size_t N>
69        tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70    template<class U, size_t N>
71        tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
73    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));               // constexpr in C++20
74};
75
76
77template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
78  requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
79struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
80  using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
81};
82
83template<class... TTypes, class... UTypes>                                // since C++23
84  requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
85struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
86  using type = tuple<common_type_t<TTypes, UTypes>...>;
87};
88
89template <class ...T>
90tuple(T...) -> tuple<T...>;                                         // since C++17
91template <class T1, class T2>
92tuple(pair<T1, T2>) -> tuple<T1, T2>;                               // since C++17
93template <class Alloc, class ...T>
94tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>;                 // since C++17
95template <class Alloc, class T1, class T2>
96tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>;       // since C++17
97template <class Alloc, class ...T>
98tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>;          // since C++17
99
100inline constexpr unspecified ignore;
101
102template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
103template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
104template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
105template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
106
107// [tuple.apply], calling a function with a tuple of arguments:
108template <class F, class Tuple>
109  constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
110template <class T, class Tuple>
111  constexpr T make_from_tuple(Tuple&& t); // C++17
112
113// 20.4.1.4, tuple helper classes:
114template <class T> struct tuple_size; // undefined
115template <class... T> struct tuple_size<tuple<T...>>;
116template <class T>
117 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
118template <size_t I, class T> struct tuple_element; // undefined
119template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
120template <size_t I, class T>
121  using tuple_element_t = typename tuple_element <I, T>::type; // C++14
122
123// 20.4.1.5, element access:
124template <size_t I, class... T>
125    typename tuple_element<I, tuple<T...>>::type&
126    get(tuple<T...>&) noexcept; // constexpr in C++14
127template <size_t I, class... T>
128    const typename tuple_element<I, tuple<T...>>::type&
129    get(const tuple<T...>&) noexcept; // constexpr in C++14
130template <size_t I, class... T>
131    typename tuple_element<I, tuple<T...>>::type&&
132    get(tuple<T...>&&) noexcept; // constexpr in C++14
133template <size_t I, class... T>
134    const typename tuple_element<I, tuple<T...>>::type&&
135    get(const tuple<T...>&&) noexcept; // constexpr in C++14
136
137template <class T1, class... T>
138    constexpr T1& get(tuple<T...>&) noexcept;  // C++14
139template <class T1, class... T>
140    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
141template <class T1, class... T>
142    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
143template <class T1, class... T>
144    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
145
146// 20.4.1.6, relational operators:
147template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
148template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
149template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
150template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
151template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
152template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
153template<class... T, class... U>
154  constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
155    operator<=>(const tuple<T...>&, const tuple<U...>&);                                  // since C++20
156
157template <class... Types, class Alloc>
158  struct uses_allocator<tuple<Types...>, Alloc>;
159
160template <class... Types>
161  void
162  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
163
164}  // std
165
166*/
167
168#include <__assert> // all public C++ headers provide the assertion handler
169#include <__compare/common_comparison_category.h>
170#include <__compare/synth_three_way.h>
171#include <__config>
172#include <__functional/unwrap_ref.h>
173#include <__memory/allocator_arg_t.h>
174#include <__memory/uses_allocator.h>
175#include <__tuple>
176#include <__utility/forward.h>
177#include <__utility/integer_sequence.h>
178#include <__utility/move.h>
179#include <__utility/pair.h>
180#include <__utility/piecewise_construct.h>
181#include <__utility/swap.h>
182#include <cstddef>
183#include <type_traits>
184#include <version>
185
186// standard-mandated includes
187#include <compare>
188
189#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
190#  pragma GCC system_header
191#endif
192
193_LIBCPP_BEGIN_NAMESPACE_STD
194
195#ifndef _LIBCPP_CXX03_LANG
196
197
198// __tuple_leaf
199
200template <size_t _Ip, class _Hp,
201          bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
202         >
203class __tuple_leaf;
204
205template <size_t _Ip, class _Hp, bool _Ep>
206inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
207void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
208    _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
209{
210    swap(__x.get(), __y.get());
211}
212
213template <size_t _Ip, class _Hp, bool>
214class __tuple_leaf
215{
216    _Hp __value_;
217
218    template <class _Tp>
219    static constexpr bool __can_bind_reference() {
220#if __has_keyword(__reference_binds_to_temporary)
221      return !__reference_binds_to_temporary(_Hp, _Tp);
222#else
223      return true;
224#endif
225    }
226
227    _LIBCPP_CONSTEXPR_AFTER_CXX11
228    __tuple_leaf& operator=(const __tuple_leaf&);
229public:
230    _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
231             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
232       {static_assert(!is_reference<_Hp>::value,
233              "Attempted to default construct a reference element in a tuple");}
234
235    template <class _Alloc>
236        _LIBCPP_INLINE_VISIBILITY constexpr
237        __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
238            : __value_()
239        {static_assert(!is_reference<_Hp>::value,
240              "Attempted to default construct a reference element in a tuple");}
241
242    template <class _Alloc>
243        _LIBCPP_INLINE_VISIBILITY constexpr
244        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
245            : __value_(allocator_arg_t(), __a)
246        {static_assert(!is_reference<_Hp>::value,
247              "Attempted to default construct a reference element in a tuple");}
248
249    template <class _Alloc>
250        _LIBCPP_INLINE_VISIBILITY constexpr
251        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
252            : __value_(__a)
253        {static_assert(!is_reference<_Hp>::value,
254              "Attempted to default construct a reference element in a tuple");}
255
256    template <class _Tp,
257              class = __enable_if_t<
258                  _And<
259                      _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
260                      is_constructible<_Hp, _Tp>
261                    >::value
262                >
263            >
264        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
265        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
266            : __value_(_VSTD::forward<_Tp>(__t))
267        {static_assert(__can_bind_reference<_Tp&&>(),
268       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
269
270    template <class _Tp, class _Alloc>
271        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
272        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
273            : __value_(_VSTD::forward<_Tp>(__t))
274        {static_assert(__can_bind_reference<_Tp&&>(),
275       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
276
277    template <class _Tp, class _Alloc>
278        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
279        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
280            : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
281        {static_assert(!is_reference<_Hp>::value,
282            "Attempted to uses-allocator construct a reference element in a tuple");}
283
284    template <class _Tp, class _Alloc>
285        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
286        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
287            : __value_(_VSTD::forward<_Tp>(__t), __a)
288        {static_assert(!is_reference<_Hp>::value,
289           "Attempted to uses-allocator construct a reference element in a tuple");}
290
291    __tuple_leaf(const __tuple_leaf& __t) = default;
292    __tuple_leaf(__tuple_leaf&& __t) = default;
293
294    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
295    int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
296    {
297        _VSTD::swap(*this, __t);
298        return 0;
299    }
300
301    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return __value_;}
302    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
303};
304
305template <size_t _Ip, class _Hp>
306class __tuple_leaf<_Ip, _Hp, true>
307    : private _Hp
308{
309    _LIBCPP_CONSTEXPR_AFTER_CXX11
310    __tuple_leaf& operator=(const __tuple_leaf&);
311public:
312    _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
313             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
314
315    template <class _Alloc>
316        _LIBCPP_INLINE_VISIBILITY constexpr
317        __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
318
319    template <class _Alloc>
320        _LIBCPP_INLINE_VISIBILITY constexpr
321        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
322            : _Hp(allocator_arg_t(), __a) {}
323
324    template <class _Alloc>
325        _LIBCPP_INLINE_VISIBILITY constexpr
326        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
327            : _Hp(__a) {}
328
329    template <class _Tp,
330              class = __enable_if_t<
331                  _And<
332                    _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
333                    is_constructible<_Hp, _Tp>
334                  >::value
335                >
336            >
337        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
338        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
339            : _Hp(_VSTD::forward<_Tp>(__t)) {}
340
341    template <class _Tp, class _Alloc>
342        _LIBCPP_INLINE_VISIBILITY constexpr
343        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
344            : _Hp(_VSTD::forward<_Tp>(__t)) {}
345
346    template <class _Tp, class _Alloc>
347        _LIBCPP_INLINE_VISIBILITY constexpr
348        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
349            : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
350
351    template <class _Tp, class _Alloc>
352        _LIBCPP_INLINE_VISIBILITY constexpr
353        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
354            : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
355
356    __tuple_leaf(__tuple_leaf const &) = default;
357    __tuple_leaf(__tuple_leaf &&) = default;
358
359    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
360    int
361    swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
362    {
363        _VSTD::swap(*this, __t);
364        return 0;
365    }
366
367    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
368    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
369};
370
371template <class ..._Tp>
372_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
373void __swallow(_Tp&&...) _NOEXCEPT {}
374
375template <class _Tp>
376struct __all_default_constructible;
377
378template <class ..._Tp>
379struct __all_default_constructible<__tuple_types<_Tp...>>
380    : __all<is_default_constructible<_Tp>::value...>
381{ };
382
383// __tuple_impl
384
385template<class _Indx, class ..._Tp> struct __tuple_impl;
386
387template<size_t ..._Indx, class ..._Tp>
388struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
389    : public __tuple_leaf<_Indx, _Tp>...
390{
391    _LIBCPP_INLINE_VISIBILITY
392    constexpr __tuple_impl()
393        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
394
395    template <size_t ..._Uf, class ..._Tf,
396              size_t ..._Ul, class ..._Tl, class ..._Up>
397        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
398        explicit
399        __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
400                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
401                     _Up&&... __u)
402                     _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
403                                 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
404            __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
405            __tuple_leaf<_Ul, _Tl>()...
406            {}
407
408    template <class _Alloc, size_t ..._Uf, class ..._Tf,
409              size_t ..._Ul, class ..._Tl, class ..._Up>
410        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
411        explicit
412        __tuple_impl(allocator_arg_t, const _Alloc& __a,
413                     __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
414                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
415                     _Up&&... __u) :
416            __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
417            _VSTD::forward<_Up>(__u))...,
418            __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
419            {}
420
421    template <class _Tuple,
422              class = typename enable_if
423                      <
424                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
425                      >::type
426             >
427        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
428        __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
429                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
430            : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
431                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
432            {}
433
434    template <class _Alloc, class _Tuple,
435              class = typename enable_if
436                      <
437                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
438                      >::type
439             >
440        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
441        __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
442            : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
443                                       typename __make_tuple_types<_Tuple>::type>::type>(), __a,
444                                       _VSTD::forward<typename tuple_element<_Indx,
445                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
446            {}
447
448    __tuple_impl(const __tuple_impl&) = default;
449    __tuple_impl(__tuple_impl&&) = default;
450
451    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
452    void swap(__tuple_impl& __t)
453        _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
454    {
455        _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
456    }
457};
458
459template<class _Dest, class _Source, size_t ..._Np>
460_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
461void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
462    _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
463}
464
465template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
466_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
467void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
468    _VSTD::__swallow(((
469        _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
470    ), void(), 0)...);
471}
472
473template <class ..._Tp>
474class _LIBCPP_TEMPLATE_VIS tuple
475{
476    typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
477
478    _BaseT __base_;
479
480    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
481        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
482    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
483        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
484    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
485        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
486    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
487        const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
488public:
489    // [tuple.cnstr]
490
491    // tuple() constructors (including allocator_arg_t variants)
492    template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
493        _And<
494            _IsImpDefault<_Tp>... // explicit check
495        >::value
496    , int> = 0>
497    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
498    tuple()
499        _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
500    { }
501
502    template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
503              template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
504        _And<
505            _IsDefault<_Tp>...,
506            _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
507        >::value
508    , int> = 0>
509    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
510    explicit tuple()
511        _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
512    { }
513
514    template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
515        _And<
516            _IsImpDefault<_Tp>... // explicit check
517        >::value
518    , int> = 0>
519    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
520    tuple(allocator_arg_t, _Alloc const& __a)
521      : __base_(allocator_arg_t(), __a,
522                    __tuple_indices<>(), __tuple_types<>(),
523                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
524                    __tuple_types<_Tp...>()) {}
525
526    template <class _Alloc,
527              template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
528              template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
529        _And<
530            _IsDefault<_Tp>...,
531            _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
532        >::value
533    , int> = 0>
534    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
535    explicit tuple(allocator_arg_t, _Alloc const& __a)
536      : __base_(allocator_arg_t(), __a,
537                    __tuple_indices<>(), __tuple_types<>(),
538                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
539                    __tuple_types<_Tp...>()) {}
540
541    // tuple(const T&...) constructors (including allocator_arg_t variants)
542    template <template<class...> class _And = _And, __enable_if_t<
543        _And<
544            _BoolConstant<sizeof...(_Tp) >= 1>,
545            is_copy_constructible<_Tp>...,
546            is_convertible<const _Tp&, _Tp>... // explicit check
547        >::value
548    , int> = 0>
549    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
550    tuple(const _Tp& ... __t)
551        _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
552        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
553                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
554                typename __make_tuple_indices<0>::type(),
555                typename __make_tuple_types<tuple, 0>::type(),
556                __t...
557               ) {}
558
559    template <template<class...> class _And = _And, __enable_if_t<
560        _And<
561            _BoolConstant<sizeof...(_Tp) >= 1>,
562            is_copy_constructible<_Tp>...,
563            _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
564        >::value
565    , int> = 0>
566    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
567    explicit tuple(const _Tp& ... __t)
568        _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
569        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
570                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
571                typename __make_tuple_indices<0>::type(),
572                typename __make_tuple_types<tuple, 0>::type(),
573                __t...
574               ) {}
575
576    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
577        _And<
578            _BoolConstant<sizeof...(_Tp) >= 1>,
579            is_copy_constructible<_Tp>...,
580            is_convertible<const _Tp&, _Tp>... // explicit check
581        >::value
582    , int> = 0>
583    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
584    tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
585        : __base_(allocator_arg_t(), __a,
586                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
587                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
588                typename __make_tuple_indices<0>::type(),
589                typename __make_tuple_types<tuple, 0>::type(),
590                __t...
591               ) {}
592
593    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
594        _And<
595            _BoolConstant<sizeof...(_Tp) >= 1>,
596            is_copy_constructible<_Tp>...,
597            _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
598        >::value
599    , int> = 0>
600    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
601    explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
602        : __base_(allocator_arg_t(), __a,
603                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
604                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
605                typename __make_tuple_indices<0>::type(),
606                typename __make_tuple_types<tuple, 0>::type(),
607                __t...
608               ) {}
609
610    // tuple(U&& ...) constructors (including allocator_arg_t variants)
611    template <class ..._Up> struct _IsThisTuple : false_type { };
612    template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
613
614    template <class ..._Up>
615    struct _EnableUTypesCtor : _And<
616        _BoolConstant<sizeof...(_Tp) >= 1>,
617        _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
618        is_constructible<_Tp, _Up>...
619    > { };
620
621    template <class ..._Up, __enable_if_t<
622        _And<
623            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
624            _EnableUTypesCtor<_Up...>,
625            is_convertible<_Up, _Tp>... // explicit check
626        >::value
627    , int> = 0>
628    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
629    tuple(_Up&&... __u)
630        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
631        : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
632                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
633                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
634                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
635                    _VSTD::forward<_Up>(__u)...) {}
636
637    template <class ..._Up, __enable_if_t<
638        _And<
639            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
640            _EnableUTypesCtor<_Up...>,
641            _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
642        >::value
643    , int> = 0>
644    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
645    explicit tuple(_Up&&... __u)
646        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
647        : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
648                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
649                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
650                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
651                    _VSTD::forward<_Up>(__u)...) {}
652
653    template <class _Alloc, class ..._Up, __enable_if_t<
654        _And<
655            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
656            _EnableUTypesCtor<_Up...>,
657            is_convertible<_Up, _Tp>... // explicit check
658        >::value
659    , int> = 0>
660    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
661    tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
662        : __base_(allocator_arg_t(), __a,
663                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
664                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
665                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
666                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
667                    _VSTD::forward<_Up>(__u)...) {}
668
669    template <class _Alloc, class ..._Up, __enable_if_t<
670        _And<
671            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
672            _EnableUTypesCtor<_Up...>,
673            _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
674        >::value
675    , int> = 0>
676    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
677    explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
678        : __base_(allocator_arg_t(), __a,
679                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
680                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
681                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
682                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
683                    _VSTD::forward<_Up>(__u)...) {}
684
685    // Copy and move constructors (including the allocator_arg_t variants)
686    tuple(const tuple&) = default;
687    tuple(tuple&&) = default;
688
689    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
690        _And<is_copy_constructible<_Tp>...>::value
691    , int> = 0>
692    tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
693        : __base_(allocator_arg_t(), __alloc, __t)
694    { }
695
696    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
697        _And<is_move_constructible<_Tp>...>::value
698    , int> = 0>
699    tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
700        : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
701    { }
702
703    // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
704    template <class ..._Up>
705    struct _EnableCopyFromOtherTuple : _And<
706        _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
707        _Lazy<_Or,
708            _BoolConstant<sizeof...(_Tp) != 1>,
709            // _Tp and _Up are 1-element packs - the pack expansions look
710            // weird to avoid tripping up the type traits in degenerate cases
711            _Lazy<_And,
712                _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
713                _Not<is_constructible<_Tp, const tuple<_Up>&> >...
714            >
715        >,
716        is_constructible<_Tp, const _Up&>...
717    > { };
718
719    template <class ..._Up, __enable_if_t<
720        _And<
721            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
722            _EnableCopyFromOtherTuple<_Up...>,
723            is_convertible<const _Up&, _Tp>... // explicit check
724        >::value
725    , int> = 0>
726    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
727    tuple(const tuple<_Up...>& __t)
728        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
729        : __base_(__t)
730    { }
731
732    template <class ..._Up, __enable_if_t<
733        _And<
734            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
735            _EnableCopyFromOtherTuple<_Up...>,
736            _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
737        >::value
738    , int> = 0>
739    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
740    explicit tuple(const tuple<_Up...>& __t)
741        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
742        : __base_(__t)
743    { }
744
745    template <class ..._Up, class _Alloc, __enable_if_t<
746        _And<
747            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
748            _EnableCopyFromOtherTuple<_Up...>,
749            is_convertible<const _Up&, _Tp>... // explicit check
750        >::value
751    , int> = 0>
752    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
753    tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
754        : __base_(allocator_arg_t(), __a, __t)
755    { }
756
757    template <class ..._Up, class _Alloc, __enable_if_t<
758        _And<
759            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
760            _EnableCopyFromOtherTuple<_Up...>,
761            _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
762        >::value
763    , int> = 0>
764    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
765    explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
766        : __base_(allocator_arg_t(), __a, __t)
767    { }
768
769    // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
770    template <class ..._Up>
771    struct _EnableMoveFromOtherTuple : _And<
772        _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
773        _Lazy<_Or,
774            _BoolConstant<sizeof...(_Tp) != 1>,
775            // _Tp and _Up are 1-element packs - the pack expansions look
776            // weird to avoid tripping up the type traits in degenerate cases
777            _Lazy<_And,
778                _Not<is_convertible<tuple<_Up>, _Tp> >...,
779                _Not<is_constructible<_Tp, tuple<_Up> > >...
780            >
781        >,
782        is_constructible<_Tp, _Up>...
783    > { };
784
785    template <class ..._Up, __enable_if_t<
786        _And<
787            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
788            _EnableMoveFromOtherTuple<_Up...>,
789            is_convertible<_Up, _Tp>... // explicit check
790        >::value
791    , int> = 0>
792    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
793    tuple(tuple<_Up...>&& __t)
794        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
795        : __base_(_VSTD::move(__t))
796    { }
797
798    template <class ..._Up, __enable_if_t<
799        _And<
800            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
801            _EnableMoveFromOtherTuple<_Up...>,
802            _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
803        >::value
804    , int> = 0>
805    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
806    explicit tuple(tuple<_Up...>&& __t)
807        _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
808        : __base_(_VSTD::move(__t))
809    { }
810
811    template <class _Alloc, class ..._Up, __enable_if_t<
812        _And<
813            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
814            _EnableMoveFromOtherTuple<_Up...>,
815            is_convertible<_Up, _Tp>... // explicit check
816        >::value
817    , int> = 0>
818    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
819    tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
820        : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
821    { }
822
823    template <class _Alloc, class ..._Up, __enable_if_t<
824        _And<
825            _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
826            _EnableMoveFromOtherTuple<_Up...>,
827            _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
828        >::value
829    , int> = 0>
830    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
831    explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
832        : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
833    { }
834
835    // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
836    template <class _Up1, class _Up2, class ..._DependentTp>
837    struct _EnableImplicitCopyFromPair : _And<
838        is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
839        is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
840        is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
841        is_convertible<const _Up2&, _SecondType<_DependentTp...> >
842    > { };
843
844    template <class _Up1, class _Up2, class ..._DependentTp>
845    struct _EnableExplicitCopyFromPair : _And<
846        is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
847        is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
848        _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
849        _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
850    > { };
851
852    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
853        _And<
854            _BoolConstant<sizeof...(_Tp) == 2>,
855            _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
856        >::value
857    , int> = 0>
858    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
859    tuple(const pair<_Up1, _Up2>& __p)
860        _NOEXCEPT_((_And<
861            is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
862            is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
863        >::value))
864        : __base_(__p)
865    { }
866
867    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
868        _And<
869            _BoolConstant<sizeof...(_Tp) == 2>,
870            _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
871        >::value
872    , int> = 0>
873    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
874    explicit tuple(const pair<_Up1, _Up2>& __p)
875        _NOEXCEPT_((_And<
876            is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
877            is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
878        >::value))
879        : __base_(__p)
880    { }
881
882    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
883        _And<
884            _BoolConstant<sizeof...(_Tp) == 2>,
885            _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
886        >::value
887    , int> = 0>
888    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
889    tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
890        : __base_(allocator_arg_t(), __a, __p)
891    { }
892
893    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
894        _And<
895            _BoolConstant<sizeof...(_Tp) == 2>,
896            _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
897        >::value
898    , int> = 0>
899    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
900    explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
901        : __base_(allocator_arg_t(), __a, __p)
902    { }
903
904    // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
905    template <class _Up1, class _Up2, class ..._DependentTp>
906    struct _EnableImplicitMoveFromPair : _And<
907        is_constructible<_FirstType<_DependentTp...>, _Up1>,
908        is_constructible<_SecondType<_DependentTp...>, _Up2>,
909        is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
910        is_convertible<_Up2, _SecondType<_DependentTp...> >
911    > { };
912
913    template <class _Up1, class _Up2, class ..._DependentTp>
914    struct _EnableExplicitMoveFromPair : _And<
915        is_constructible<_FirstType<_DependentTp...>, _Up1>,
916        is_constructible<_SecondType<_DependentTp...>, _Up2>,
917        _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
918        _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
919    > { };
920
921    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
922        _And<
923            _BoolConstant<sizeof...(_Tp) == 2>,
924            _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
925        >::value
926    , int> = 0>
927    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
928    tuple(pair<_Up1, _Up2>&& __p)
929        _NOEXCEPT_((_And<
930            is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
931            is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
932        >::value))
933        : __base_(_VSTD::move(__p))
934    { }
935
936    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
937        _And<
938            _BoolConstant<sizeof...(_Tp) == 2>,
939            _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
940        >::value
941    , int> = 0>
942    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
943    explicit tuple(pair<_Up1, _Up2>&& __p)
944        _NOEXCEPT_((_And<
945            is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
946            is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
947        >::value))
948        : __base_(_VSTD::move(__p))
949    { }
950
951    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
952        _And<
953            _BoolConstant<sizeof...(_Tp) == 2>,
954            _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
955        >::value
956    , int> = 0>
957    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
958    tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
959        : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
960    { }
961
962    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
963        _And<
964            _BoolConstant<sizeof...(_Tp) == 2>,
965            _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
966        >::value
967    , int> = 0>
968    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
969    explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
970        : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
971    { }
972
973    // [tuple.assign]
974    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
975    tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
976        _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
977    {
978        _VSTD::__memberwise_copy_assign(*this, __tuple,
979            typename __make_tuple_indices<sizeof...(_Tp)>::type());
980        return *this;
981    }
982
983    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
984    tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
985        _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
986    {
987        _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
988            __tuple_types<_Tp...>(),
989            typename __make_tuple_indices<sizeof...(_Tp)>::type());
990        return *this;
991    }
992
993    template<class... _Up, __enable_if_t<
994        _And<
995            _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
996            is_assignable<_Tp&, _Up const&>...
997        >::value
998    ,int> = 0>
999    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1000    tuple& operator=(tuple<_Up...> const& __tuple)
1001        _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1002    {
1003        _VSTD::__memberwise_copy_assign(*this, __tuple,
1004            typename __make_tuple_indices<sizeof...(_Tp)>::type());
1005        return *this;
1006    }
1007
1008    template<class... _Up, __enable_if_t<
1009        _And<
1010            _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1011            is_assignable<_Tp&, _Up>...
1012        >::value
1013    ,int> = 0>
1014    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1015    tuple& operator=(tuple<_Up...>&& __tuple)
1016        _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1017    {
1018        _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1019            __tuple_types<_Up...>(),
1020            typename __make_tuple_indices<sizeof...(_Tp)>::type());
1021        return *this;
1022    }
1023
1024    template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
1025        _And<_Dep,
1026            _BoolConstant<sizeof...(_Tp) == 2>,
1027            is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1028            is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1029        >::value
1030    ,int> = 0>
1031    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1032    tuple& operator=(pair<_Up1, _Up2> const& __pair)
1033        _NOEXCEPT_((_And<
1034            is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1035            is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1036        >::value))
1037    {
1038        _VSTD::get<0>(*this) = __pair.first;
1039        _VSTD::get<1>(*this) = __pair.second;
1040        return *this;
1041    }
1042
1043    template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
1044        _And<_Dep,
1045            _BoolConstant<sizeof...(_Tp) == 2>,
1046            is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1047            is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1048        >::value
1049    ,int> = 0>
1050    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1051    tuple& operator=(pair<_Up1, _Up2>&& __pair)
1052        _NOEXCEPT_((_And<
1053            is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1054            is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1055        >::value))
1056    {
1057        _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1058        _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
1059        return *this;
1060    }
1061
1062    // EXTENSION
1063    template<class _Up, size_t _Np, class = __enable_if_t<
1064        _And<
1065            _BoolConstant<_Np == sizeof...(_Tp)>,
1066            is_assignable<_Tp&, _Up const&>...
1067        >::value
1068    > >
1069    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1070    tuple& operator=(array<_Up, _Np> const& __array)
1071        _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1072    {
1073        _VSTD::__memberwise_copy_assign(*this, __array,
1074            typename __make_tuple_indices<sizeof...(_Tp)>::type());
1075        return *this;
1076    }
1077
1078    // EXTENSION
1079    template<class _Up, size_t _Np, class = void, class = __enable_if_t<
1080        _And<
1081            _BoolConstant<_Np == sizeof...(_Tp)>,
1082            is_assignable<_Tp&, _Up>...
1083        >::value
1084    > >
1085    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1086    tuple& operator=(array<_Up, _Np>&& __array)
1087        _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1088    {
1089        _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1090            __tuple_types<_If<true, _Up, _Tp>...>(),
1091            typename __make_tuple_indices<sizeof...(_Tp)>::type());
1092        return *this;
1093    }
1094
1095    // [tuple.swap]
1096    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1097    void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1098        {__base_.swap(__t.__base_);}
1099};
1100
1101template <>
1102class _LIBCPP_TEMPLATE_VIS tuple<>
1103{
1104public:
1105    _LIBCPP_INLINE_VISIBILITY constexpr
1106        tuple() _NOEXCEPT = default;
1107    template <class _Alloc>
1108    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1109        tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
1110    template <class _Alloc>
1111    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1112        tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
1113    template <class _Up>
1114    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1115        tuple(array<_Up, 0>) _NOEXCEPT {}
1116    template <class _Alloc, class _Up>
1117    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1118        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
1119    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1120    void swap(tuple&) _NOEXCEPT {}
1121};
1122
1123#if _LIBCPP_STD_VER > 20
1124template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1125    requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1126struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1127    using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1128};
1129
1130template <class... _TTypes, class... _UTypes>
1131    requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1132struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1133    using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1134};
1135#endif // _LIBCPP_STD_VER > 20
1136
1137#if _LIBCPP_STD_VER > 14
1138template <class ..._Tp>
1139tuple(_Tp...) -> tuple<_Tp...>;
1140template <class _Tp1, class _Tp2>
1141tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1142template <class _Alloc, class ..._Tp>
1143tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1144template <class _Alloc, class _Tp1, class _Tp2>
1145tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1146template <class _Alloc, class ..._Tp>
1147tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
1148#endif
1149
1150template <class ..._Tp>
1151inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1152typename enable_if
1153<
1154    __all<__is_swappable<_Tp>::value...>::value,
1155    void
1156>::type
1157swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1158                 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1159    {__t.swap(__u);}
1160
1161// get
1162
1163template <size_t _Ip, class ..._Tp>
1164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1165typename tuple_element<_Ip, tuple<_Tp...> >::type&
1166get(tuple<_Tp...>& __t) _NOEXCEPT
1167{
1168    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1169    return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
1170}
1171
1172template <size_t _Ip, class ..._Tp>
1173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1174const typename tuple_element<_Ip, tuple<_Tp...> >::type&
1175get(const tuple<_Tp...>& __t) _NOEXCEPT
1176{
1177    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1178    return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
1179}
1180
1181template <size_t _Ip, class ..._Tp>
1182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1183typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1184get(tuple<_Tp...>&& __t) _NOEXCEPT
1185{
1186    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1187    return static_cast<type&&>(
1188             static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1189}
1190
1191template <size_t _Ip, class ..._Tp>
1192inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1193const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1194get(const tuple<_Tp...>&& __t) _NOEXCEPT
1195{
1196    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1197    return static_cast<const type&&>(
1198             static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1199}
1200
1201#if _LIBCPP_STD_VER > 11
1202
1203namespace __find_detail {
1204
1205static constexpr size_t __not_found = static_cast<size_t>(-1);
1206static constexpr size_t __ambiguous = __not_found - 1;
1207
1208inline _LIBCPP_INLINE_VISIBILITY
1209constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1210    return !__matches ? __res :
1211        (__res == __not_found ? __curr_i : __ambiguous);
1212}
1213
1214template <size_t _Nx>
1215inline _LIBCPP_INLINE_VISIBILITY
1216constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1217  return __i == _Nx ? __not_found :
1218      __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1219}
1220
1221template <class _T1, class ..._Args>
1222struct __find_exactly_one_checked {
1223    static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
1224    static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1225    static_assert(value != __not_found, "type not found in type list" );
1226    static_assert(value != __ambiguous, "type occurs more than once in type list");
1227};
1228
1229template <class _T1>
1230struct __find_exactly_one_checked<_T1> {
1231    static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1232};
1233
1234} // namespace __find_detail
1235
1236template <typename _T1, typename... _Args>
1237struct __find_exactly_one_t
1238    : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1239};
1240
1241template <class _T1, class... _Args>
1242inline _LIBCPP_INLINE_VISIBILITY
1243constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1244{
1245    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1246}
1247
1248template <class _T1, class... _Args>
1249inline _LIBCPP_INLINE_VISIBILITY
1250constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1251{
1252    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1253}
1254
1255template <class _T1, class... _Args>
1256inline _LIBCPP_INLINE_VISIBILITY
1257constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1258{
1259    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1260}
1261
1262template <class _T1, class... _Args>
1263inline _LIBCPP_INLINE_VISIBILITY
1264constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1265{
1266    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1267}
1268
1269#endif
1270
1271// tie
1272
1273template <class ..._Tp>
1274inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1275tuple<_Tp&...>
1276tie(_Tp&... __t) _NOEXCEPT
1277{
1278    return tuple<_Tp&...>(__t...);
1279}
1280
1281template <class _Up>
1282struct __ignore_t
1283{
1284    template <class _Tp>
1285    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1286    const __ignore_t& operator=(_Tp&&) const {return *this;}
1287};
1288
1289namespace {
1290  constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
1291} // namespace
1292
1293template <class... _Tp>
1294inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1295tuple<typename __unwrap_ref_decay<_Tp>::type...>
1296make_tuple(_Tp&&... __t)
1297{
1298    return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
1299}
1300
1301template <class... _Tp>
1302inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1303tuple<_Tp&&...>
1304forward_as_tuple(_Tp&&... __t) _NOEXCEPT
1305{
1306    return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
1307}
1308
1309template <size_t _Ip>
1310struct __tuple_equal
1311{
1312    template <class _Tp, class _Up>
1313    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1314    bool operator()(const _Tp& __x, const _Up& __y)
1315    {
1316        return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
1317    }
1318};
1319
1320template <>
1321struct __tuple_equal<0>
1322{
1323    template <class _Tp, class _Up>
1324    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1325    bool operator()(const _Tp&, const _Up&)
1326    {
1327        return true;
1328    }
1329};
1330
1331template <class ..._Tp, class ..._Up>
1332inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1333bool
1334operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1335{
1336    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1337    return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1338}
1339
1340#if _LIBCPP_STD_VER > 17
1341
1342// operator<=>
1343
1344template <class ..._Tp, class ..._Up, size_t ..._Is>
1345_LIBCPP_HIDE_FROM_ABI constexpr
1346auto
1347__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1348    common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1349    static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1350    return __result;
1351}
1352
1353template <class ..._Tp, class ..._Up>
1354requires (sizeof...(_Tp) == sizeof...(_Up))
1355_LIBCPP_HIDE_FROM_ABI constexpr
1356common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1357operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1358{
1359    return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1360}
1361
1362#else // _LIBCPP_STD_VER > 17
1363
1364template <class ..._Tp, class ..._Up>
1365inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1366bool
1367operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1368{
1369    return !(__x == __y);
1370}
1371
1372template <size_t _Ip>
1373struct __tuple_less
1374{
1375    template <class _Tp, class _Up>
1376    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1377    bool operator()(const _Tp& __x, const _Up& __y)
1378    {
1379        const size_t __idx = tuple_size<_Tp>::value - _Ip;
1380        if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1381            return true;
1382        if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1383            return false;
1384        return __tuple_less<_Ip-1>()(__x, __y);
1385    }
1386};
1387
1388template <>
1389struct __tuple_less<0>
1390{
1391    template <class _Tp, class _Up>
1392    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1393    bool operator()(const _Tp&, const _Up&)
1394    {
1395        return false;
1396    }
1397};
1398
1399template <class ..._Tp, class ..._Up>
1400inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1401bool
1402operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1403{
1404    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1405    return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1406}
1407
1408template <class ..._Tp, class ..._Up>
1409inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1410bool
1411operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1412{
1413    return __y < __x;
1414}
1415
1416template <class ..._Tp, class ..._Up>
1417inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1418bool
1419operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1420{
1421    return !(__x < __y);
1422}
1423
1424template <class ..._Tp, class ..._Up>
1425inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1426bool
1427operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1428{
1429    return !(__y < __x);
1430}
1431
1432#endif // _LIBCPP_STD_VER > 17
1433
1434// tuple_cat
1435
1436template <class _Tp, class _Up> struct __tuple_cat_type;
1437
1438template <class ..._Ttypes, class ..._Utypes>
1439struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
1440{
1441    typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
1442};
1443
1444template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1445struct __tuple_cat_return_1
1446{
1447};
1448
1449template <class ..._Types, class _Tuple0>
1450struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1451{
1452  using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1453      tuple<_Types...>,
1454      typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1455    >::type;
1456};
1457
1458template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1459struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1460    : public __tuple_cat_return_1<
1461                 typename __tuple_cat_type<
1462                     tuple<_Types...>,
1463                     typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1464                 >::type,
1465                 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1466                 _Tuple1, _Tuples...>
1467{
1468};
1469
1470template <class ..._Tuples> struct __tuple_cat_return;
1471
1472template <class _Tuple0, class ..._Tuples>
1473struct __tuple_cat_return<_Tuple0, _Tuples...>
1474    : public __tuple_cat_return_1<tuple<>,
1475         __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1476                                                                     _Tuples...>
1477{
1478};
1479
1480template <>
1481struct __tuple_cat_return<>
1482{
1483    typedef _LIBCPP_NODEBUG tuple<> type;
1484};
1485
1486inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1487tuple<>
1488tuple_cat()
1489{
1490    return tuple<>();
1491}
1492
1493template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
1494struct __tuple_cat_return_ref_imp;
1495
1496template <class ..._Types, size_t ..._I0, class _Tuple0>
1497struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
1498{
1499    typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1500    typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1501                          typename tuple_element<_I0, _T0>::type>::type&&...> type;
1502};
1503
1504template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1505struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1506                                  _Tuple0, _Tuple1, _Tuples...>
1507    : public __tuple_cat_return_ref_imp<
1508         tuple<_Types..., typename __apply_cv<_Tuple0,
1509               typename tuple_element<_I0,
1510                  typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1511         typename __make_tuple_indices<tuple_size<typename
1512                                 remove_reference<_Tuple1>::type>::value>::type,
1513         _Tuple1, _Tuples...>
1514{
1515};
1516
1517template <class _Tuple0, class ..._Tuples>
1518struct __tuple_cat_return_ref
1519    : public __tuple_cat_return_ref_imp<tuple<>,
1520               typename __make_tuple_indices<
1521                        tuple_size<typename remove_reference<_Tuple0>::type>::value
1522               >::type, _Tuple0, _Tuples...>
1523{
1524};
1525
1526template <class _Types, class _I0, class _J0>
1527struct __tuple_cat;
1528
1529template <class ..._Types, size_t ..._I0, size_t ..._J0>
1530struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
1531{
1532    template <class _Tuple0>
1533    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1534    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1535    operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1536    {
1537        (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1538        return _VSTD::forward_as_tuple(
1539            _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1540            _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
1541    }
1542
1543    template <class _Tuple0, class _Tuple1, class ..._Tuples>
1544    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1545    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1546    operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1547    {
1548        (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1549        typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1550        typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
1551        return __tuple_cat<
1552            tuple<_Types...,
1553                  typename __apply_cv<_Tuple0, typename tuple_element<
1554                                                   _J0, _T0>::type>::type&&...>,
1555            typename __make_tuple_indices<sizeof...(_Types) +
1556                                          tuple_size<_T0>::value>::type,
1557            typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1558            _VSTD::forward_as_tuple(
1559                _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1560                _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1561            _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
1562    }
1563};
1564
1565template <class _Tuple0, class... _Tuples>
1566inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1567typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1568tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1569{
1570    typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1571    return __tuple_cat<tuple<>, __tuple_indices<>,
1572                  typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
1573                  (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1574                                            _VSTD::forward<_Tuples>(__tpls)...);
1575}
1576
1577template <class ..._Tp, class _Alloc>
1578struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
1579    : true_type {};
1580
1581template <class _T1, class _T2>
1582template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1583inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1584pair<_T1, _T2>::pair(piecewise_construct_t,
1585                     tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1586                     __tuple_indices<_I1...>, __tuple_indices<_I2...>)
1587    :  first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1588      second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
1589{
1590}
1591
1592#if _LIBCPP_STD_VER > 14
1593template <class _Tp>
1594inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1595
1596#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1597
1598template <class _Fn, class _Tuple, size_t ..._Id>
1599inline _LIBCPP_INLINE_VISIBILITY
1600constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1601                                            __tuple_indices<_Id...>)
1602_LIBCPP_NOEXCEPT_RETURN(
1603    _VSTD::__invoke(
1604        _VSTD::forward<_Fn>(__f),
1605        _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1606)
1607
1608template <class _Fn, class _Tuple>
1609inline _LIBCPP_INLINE_VISIBILITY
1610constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1611_LIBCPP_NOEXCEPT_RETURN(
1612    _VSTD::__apply_tuple_impl(
1613        _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1614        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
1615)
1616
1617template <class _Tp, class _Tuple, size_t... _Idx>
1618inline _LIBCPP_INLINE_VISIBILITY
1619constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1620_LIBCPP_NOEXCEPT_RETURN(
1621    _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1622)
1623
1624template <class _Tp, class _Tuple>
1625inline _LIBCPP_INLINE_VISIBILITY
1626constexpr _Tp make_from_tuple(_Tuple&& __t)
1627_LIBCPP_NOEXCEPT_RETURN(
1628    _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1629        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
1630)
1631
1632#undef _LIBCPP_NOEXCEPT_RETURN
1633
1634#endif // _LIBCPP_STD_VER > 14
1635
1636#endif // !defined(_LIBCPP_CXX03_LANG)
1637
1638_LIBCPP_END_NAMESPACE_STD
1639
1640#endif // _LIBCPP_TUPLE
1641