xref: /llvm-project-15.0.7/libcxx/include/tuple (revision 303c9861)
1// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
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    constexpr tuple();
23    explicit tuple(const T&...);  // constexpr in C++14
24    template <class... U>
25        explicit tuple(U&&...);  // constexpr in C++14
26    tuple(const tuple&) = default;
27    tuple(tuple&&) = default;
28    template <class... U>
29        tuple(const tuple<U...>&);  // constexpr in C++14
30    template <class... U>
31        tuple(tuple<U...>&&);  // constexpr in C++14
32    template <class U1, class U2>
33        tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
34    template <class U1, class U2>
35        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        tuple(allocator_arg_t, const Alloc& a, const T&...);
42    template <class Alloc, class... U>
43        tuple(allocator_arg_t, const Alloc& a, U&&...);
44    template <class Alloc>
45        tuple(allocator_arg_t, const Alloc& a, const tuple&);
46    template <class Alloc>
47        tuple(allocator_arg_t, const Alloc& a, tuple&&);
48    template <class Alloc, class... U>
49        tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
50    template <class Alloc, class... U>
51        tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
52    template <class Alloc, class U1, class U2>
53        tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
54    template <class Alloc, class U1, class U2>
55        tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
56
57    tuple& operator=(const tuple&);
58    tuple&
59        operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
60    template <class... U>
61        tuple& operator=(const tuple<U...>&);
62    template <class... U>
63        tuple& operator=(tuple<U...>&&);
64    template <class U1, class U2>
65        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
66    template <class U1, class U2>
67        tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
68
69    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
70};
71
72inline constexpr unspecified ignore;
73
74template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
75template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
76template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
77template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
78
79// [tuple.apply], calling a function with a tuple of arguments:
80template <class F, class Tuple>
81  constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
82template <class T, class Tuple>
83  constexpr T make_from_tuple(Tuple&& t); // C++17
84
85// 20.4.1.4, tuple helper classes:
86template <class T> struct tuple_size; // undefined
87template <class... T> struct tuple_size<tuple<T...>>;
88template <class T>
89 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
90template <size_t I, class T> struct tuple_element; // undefined
91template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
92template <size_t I, class T>
93  using tuple_element_t = typename tuple_element <I, T>::type; // C++14
94
95// 20.4.1.5, element access:
96template <size_t I, class... T>
97    typename tuple_element<I, tuple<T...>>::type&
98    get(tuple<T...>&) noexcept; // constexpr in C++14
99template <size_t I, class... T>
100    const typename tuple_element<I, tuple<T...>>::type&
101    get(const tuple<T...>&) noexcept; // constexpr in C++14
102template <size_t I, class... T>
103    typename tuple_element<I, tuple<T...>>::type&&
104    get(tuple<T...>&&) noexcept; // constexpr in C++14
105template <size_t I, class... T>
106    const typename tuple_element<I, tuple<T...>>::type&&
107    get(const tuple<T...>&&) noexcept; // constexpr in C++14
108
109template <class T1, class... T>
110    constexpr T1& get(tuple<T...>&) noexcept;  // C++14
111template <class T1, class... T>
112    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
113template <class T1, class... T>
114    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
115template <class T1, class... T>
116    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
117
118// 20.4.1.6, relational operators:
119template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
120template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
121template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
122template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
123template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
124template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
125
126template <class... Types, class Alloc>
127  struct uses_allocator<tuple<Types...>, Alloc>;
128
129template <class... Types>
130  void
131  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
132
133}  // std
134
135*/
136
137#include <__config>
138#include <__tuple>
139#include <cstddef>
140#include <type_traits>
141#include <__functional_base>
142#include <utility>
143#include <version>
144
145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
146#pragma GCC system_header
147#endif
148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
151#ifndef _LIBCPP_CXX03_LANG
152
153
154// __tuple_leaf
155
156template <size_t _Ip, class _Hp,
157          bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
158         >
159class __tuple_leaf;
160
161template <size_t _Ip, class _Hp, bool _Ep>
162inline _LIBCPP_INLINE_VISIBILITY
163void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
164    _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
165{
166    swap(__x.get(), __y.get());
167}
168
169template <size_t _Ip, class _Hp, bool>
170class __tuple_leaf
171{
172    _Hp __value_;
173
174    template <class _Tp>
175    static constexpr bool __can_bind_reference() {
176#if __has_keyword(__reference_binds_to_temporary)
177      return !__reference_binds_to_temporary(_Hp, _Tp);
178#else
179      return true;
180#endif
181    }
182
183    __tuple_leaf& operator=(const __tuple_leaf&);
184public:
185    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
186             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
187       {static_assert(!is_reference<_Hp>::value,
188              "Attempted to default construct a reference element in a tuple");}
189
190    template <class _Alloc>
191        _LIBCPP_INLINE_VISIBILITY
192        __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
193            : __value_()
194        {static_assert(!is_reference<_Hp>::value,
195              "Attempted to default construct a reference element in a tuple");}
196
197    template <class _Alloc>
198        _LIBCPP_INLINE_VISIBILITY
199        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
200            : __value_(allocator_arg_t(), __a)
201        {static_assert(!is_reference<_Hp>::value,
202              "Attempted to default construct a reference element in a tuple");}
203
204    template <class _Alloc>
205        _LIBCPP_INLINE_VISIBILITY
206        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
207            : __value_(__a)
208        {static_assert(!is_reference<_Hp>::value,
209              "Attempted to default construct a reference element in a tuple");}
210
211    template <class _Tp,
212              class = _EnableIf<
213                  _And<
214                      _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
215                      is_constructible<_Hp, _Tp>
216                    >::value
217                >
218            >
219        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
220        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
221            : __value_(_VSTD::forward<_Tp>(__t))
222        {static_assert(__can_bind_reference<_Tp&&>(),
223       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
224
225    template <class _Tp, class _Alloc>
226        _LIBCPP_INLINE_VISIBILITY
227        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
228            : __value_(_VSTD::forward<_Tp>(__t))
229        {static_assert(__can_bind_reference<_Tp&&>(),
230       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
231
232    template <class _Tp, class _Alloc>
233        _LIBCPP_INLINE_VISIBILITY
234        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
235            : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
236        {static_assert(!is_reference<_Hp>::value,
237            "Attempted to uses-allocator construct a reference element in a tuple");}
238
239    template <class _Tp, class _Alloc>
240        _LIBCPP_INLINE_VISIBILITY
241        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
242            : __value_(_VSTD::forward<_Tp>(__t), __a)
243        {static_assert(!is_reference<_Hp>::value,
244           "Attempted to uses-allocator construct a reference element in a tuple");}
245
246    __tuple_leaf(const __tuple_leaf& __t) = default;
247    __tuple_leaf(__tuple_leaf&& __t) = default;
248
249    template <class _Tp>
250        _LIBCPP_INLINE_VISIBILITY
251        __tuple_leaf&
252        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
253        {
254            __value_ = _VSTD::forward<_Tp>(__t);
255            return *this;
256        }
257
258    _LIBCPP_INLINE_VISIBILITY
259    int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
260    {
261        _VSTD::swap(*this, __t);
262        return 0;
263    }
264
265    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return __value_;}
266    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
267};
268
269template <size_t _Ip, class _Hp>
270class __tuple_leaf<_Ip, _Hp, true>
271    : private _Hp
272{
273
274    __tuple_leaf& operator=(const __tuple_leaf&);
275public:
276    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
277             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
278
279    template <class _Alloc>
280        _LIBCPP_INLINE_VISIBILITY
281        __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
282
283    template <class _Alloc>
284        _LIBCPP_INLINE_VISIBILITY
285        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
286            : _Hp(allocator_arg_t(), __a) {}
287
288    template <class _Alloc>
289        _LIBCPP_INLINE_VISIBILITY
290        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
291            : _Hp(__a) {}
292
293    template <class _Tp,
294              class = _EnableIf<
295                  _And<
296                    _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
297                    is_constructible<_Hp, _Tp>
298                  >::value
299                >
300            >
301        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
302        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
303            : _Hp(_VSTD::forward<_Tp>(__t)) {}
304
305    template <class _Tp, class _Alloc>
306        _LIBCPP_INLINE_VISIBILITY
307        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
308            : _Hp(_VSTD::forward<_Tp>(__t)) {}
309
310    template <class _Tp, class _Alloc>
311        _LIBCPP_INLINE_VISIBILITY
312        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
313            : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
314
315    template <class _Tp, class _Alloc>
316        _LIBCPP_INLINE_VISIBILITY
317        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
318            : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
319
320    __tuple_leaf(__tuple_leaf const &) = default;
321    __tuple_leaf(__tuple_leaf &&) = default;
322
323    template <class _Tp>
324        _LIBCPP_INLINE_VISIBILITY
325        __tuple_leaf&
326        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
327        {
328            _Hp::operator=(_VSTD::forward<_Tp>(__t));
329            return *this;
330        }
331
332    _LIBCPP_INLINE_VISIBILITY
333    int
334    swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
335    {
336        _VSTD::swap(*this, __t);
337        return 0;
338    }
339
340    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
341    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
342};
343
344template <class ..._Tp>
345_LIBCPP_INLINE_VISIBILITY
346void __swallow(_Tp&&...) _NOEXCEPT {}
347
348template <class _Tp>
349struct __all_default_constructible;
350
351template <class ..._Tp>
352struct __all_default_constructible<__tuple_types<_Tp...>>
353    : __all<is_default_constructible<_Tp>::value...>
354{ };
355
356// __tuple_impl
357
358template<class _Indx, class ..._Tp> struct __tuple_impl;
359
360template<size_t ..._Indx, class ..._Tp>
361struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
362    : public __tuple_leaf<_Indx, _Tp>...
363{
364    _LIBCPP_INLINE_VISIBILITY
365    _LIBCPP_CONSTEXPR __tuple_impl()
366        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
367
368    template <size_t ..._Uf, class ..._Tf,
369              size_t ..._Ul, class ..._Tl, class ..._Up>
370        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
371        explicit
372        __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
373                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
374                     _Up&&... __u)
375                     _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
376                                 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
377            __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
378            __tuple_leaf<_Ul, _Tl>()...
379            {}
380
381    template <class _Alloc, size_t ..._Uf, class ..._Tf,
382              size_t ..._Ul, class ..._Tl, class ..._Up>
383        _LIBCPP_INLINE_VISIBILITY
384        explicit
385        __tuple_impl(allocator_arg_t, const _Alloc& __a,
386                     __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
387                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
388                     _Up&&... __u) :
389            __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
390            _VSTD::forward<_Up>(__u))...,
391            __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
392            {}
393
394    template <class _Tuple,
395              class = typename enable_if
396                      <
397                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
398                      >::type
399             >
400        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
401        __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
402                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
403            : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
404                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
405            {}
406
407    template <class _Alloc, class _Tuple,
408              class = typename enable_if
409                      <
410                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
411                      >::type
412             >
413        _LIBCPP_INLINE_VISIBILITY
414        __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
415            : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
416                                       typename __make_tuple_types<_Tuple>::type>::type>(), __a,
417                                       _VSTD::forward<typename tuple_element<_Indx,
418                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
419            {}
420
421    template <class _Tuple>
422        _LIBCPP_INLINE_VISIBILITY
423        typename enable_if
424        <
425            __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
426            __tuple_impl&
427        >::type
428        operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
429                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
430        {
431            __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
432                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
433            return *this;
434        }
435
436    __tuple_impl(const __tuple_impl&) = default;
437    __tuple_impl(__tuple_impl&&) = default;
438
439    _LIBCPP_INLINE_VISIBILITY
440    __tuple_impl&
441    operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
442    {
443        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
444        return *this;
445    }
446
447    _LIBCPP_INLINE_VISIBILITY
448    __tuple_impl&
449    operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
450    {
451        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
452        return *this;
453    }
454
455    _LIBCPP_INLINE_VISIBILITY
456    void swap(__tuple_impl& __t)
457        _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
458    {
459        __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
460    }
461};
462
463
464
465template <class ..._Tp>
466class _LIBCPP_TEMPLATE_VIS tuple
467{
468    typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
469
470    _BaseT __base_;
471
472#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
473    static constexpr bool _EnableImplicitReducedArityExtension = true;
474#else
475    static constexpr bool _EnableImplicitReducedArityExtension = false;
476#endif
477
478    template <class ..._Args>
479    struct _PackExpandsToThisTuple : false_type {};
480
481    template <class _Arg>
482    struct _PackExpandsToThisTuple<_Arg>
483        : is_same<typename __uncvref<_Arg>::type, tuple> {};
484
485    template <bool _MaybeEnable, class _Dummy = void>
486    struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
487
488    template <class _Dummy>
489    struct _CheckArgsConstructor<true, _Dummy>
490    {
491        template <class ..._Args>
492        static constexpr bool __enable_default() {
493            return __all<is_default_constructible<_Args>::value...>::value;
494        }
495
496        template <class ..._Args>
497        static constexpr bool __enable_explicit() {
498            return
499                __tuple_constructible<
500                    tuple<_Args...>,
501                    typename __make_tuple_types<tuple,
502                             sizeof...(_Args) < sizeof...(_Tp) ?
503                                 sizeof...(_Args) :
504                                 sizeof...(_Tp)>::type
505                >::value &&
506                !__tuple_convertible<
507                    tuple<_Args...>,
508                    typename __make_tuple_types<tuple,
509                             sizeof...(_Args) < sizeof...(_Tp) ?
510                                 sizeof...(_Args) :
511                                 sizeof...(_Tp)>::type
512                >::value &&
513                __all_default_constructible<
514                    typename __make_tuple_types<tuple, sizeof...(_Tp),
515                             sizeof...(_Args) < sizeof...(_Tp) ?
516                                 sizeof...(_Args) :
517                                 sizeof...(_Tp)>::type
518                >::value;
519        }
520
521        template <class ..._Args>
522        static constexpr bool __enable_implicit() {
523            return
524                __tuple_convertible<
525                    tuple<_Args...>,
526                    typename __make_tuple_types<tuple,
527                             sizeof...(_Args) < sizeof...(_Tp) ?
528                                 sizeof...(_Args) :
529                                 sizeof...(_Tp)>::type
530                >::value &&
531                __all_default_constructible<
532                    typename __make_tuple_types<tuple, sizeof...(_Tp),
533                             sizeof...(_Args) < sizeof...(_Tp) ?
534                                 sizeof...(_Args) :
535                                 sizeof...(_Tp)>::type
536                >::value;
537        }
538    };
539
540    template <bool _MaybeEnable,
541              bool = sizeof...(_Tp) == 1,
542              class _Dummy = void>
543    struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
544
545    template <class _Dummy>
546    struct _CheckTupleLikeConstructor<true, false, _Dummy>
547    {
548        template <class _Tuple>
549        static constexpr bool __enable_implicit() {
550            return __tuple_convertible<_Tuple, tuple>::value;
551        }
552
553        template <class _Tuple>
554        static constexpr bool __enable_explicit() {
555            return __tuple_constructible<_Tuple, tuple>::value
556               && !__tuple_convertible<_Tuple, tuple>::value;
557        }
558    };
559
560    template <class _Dummy>
561    struct _CheckTupleLikeConstructor<true, true, _Dummy>
562    {
563        // This trait is used to disable the tuple-like constructor when
564        // the UTypes... constructor should be selected instead.
565        // See LWG issue #2549.
566        template <class _Tuple>
567        using _PreferTupleLikeConstructor = _Or<
568            // Don't attempt the two checks below if the tuple we are given
569            // has the same type as this tuple.
570            _IsSame<__uncvref_t<_Tuple>, tuple>,
571            _Lazy<_And,
572                _Not<is_constructible<_Tp..., _Tuple>>,
573                _Not<is_convertible<_Tuple, _Tp...>>
574            >
575        >;
576
577        template <class _Tuple>
578        static constexpr bool __enable_implicit() {
579            return _And<
580                __tuple_convertible<_Tuple, tuple>,
581                _PreferTupleLikeConstructor<_Tuple>
582            >::value;
583        }
584
585        template <class _Tuple>
586        static constexpr bool __enable_explicit() {
587            return _And<
588                __tuple_constructible<_Tuple, tuple>,
589                _PreferTupleLikeConstructor<_Tuple>,
590                _Not<__tuple_convertible<_Tuple, tuple>>
591            >::value;
592        }
593    };
594
595    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
596        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
597    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
598        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
599    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
600        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
601    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
602        const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
603public:
604
605    template <bool _Dummy = true, class = typename enable_if<
606        _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
607    >::type>
608    _LIBCPP_INLINE_VISIBILITY
609    _LIBCPP_CONSTEXPR tuple()
610        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
611
612    tuple(tuple const&) = default;
613    tuple(tuple&&) = default;
614
615    template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf<
616        _And<
617            _IsSame<allocator_arg_t, _AllocArgT>,
618           __dependent_type<is_default_constructible<_Tp>, _Dummy>...
619       >::value
620      >
621    >
622    _LIBCPP_INLINE_VISIBILITY
623    tuple(_AllocArgT, _Alloc const& __a)
624      : __base_(allocator_arg_t(), __a,
625                    __tuple_indices<>(), __tuple_types<>(),
626                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
627                    __tuple_types<_Tp...>()) {}
628
629    template <bool _Dummy = true,
630              typename enable_if
631                      <
632                         _CheckArgsConstructor<
633                            _Dummy
634                         >::template __enable_implicit<_Tp const&...>(),
635                         bool
636                      >::type = false
637        >
638    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
639    tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
640        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
641                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
642                typename __make_tuple_indices<0>::type(),
643                typename __make_tuple_types<tuple, 0>::type(),
644                __t...
645               ) {}
646
647    template <bool _Dummy = true,
648              typename enable_if
649                      <
650                         _CheckArgsConstructor<
651                            _Dummy
652                         >::template __enable_explicit<_Tp const&...>(),
653                         bool
654                      >::type = false
655        >
656    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
657    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
658        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
659                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
660                typename __make_tuple_indices<0>::type(),
661                typename __make_tuple_types<tuple, 0>::type(),
662                __t...
663               ) {}
664
665    template <class _Alloc, bool _Dummy = true,
666              typename enable_if
667                      <
668                         _CheckArgsConstructor<
669                            _Dummy
670                         >::template __enable_implicit<_Tp const&...>(),
671                         bool
672                      >::type = false
673        >
674      _LIBCPP_INLINE_VISIBILITY
675      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
676        : __base_(allocator_arg_t(), __a,
677                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
678                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
679                typename __make_tuple_indices<0>::type(),
680                typename __make_tuple_types<tuple, 0>::type(),
681                __t...
682               ) {}
683
684    template <class _Alloc, bool _Dummy = true,
685              typename enable_if
686                      <
687                         _CheckArgsConstructor<
688                            _Dummy
689                         >::template __enable_explicit<_Tp const&...>(),
690                         bool
691                      >::type = false
692        >
693      _LIBCPP_INLINE_VISIBILITY
694      explicit
695      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
696        : __base_(allocator_arg_t(), __a,
697                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
698                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
699                typename __make_tuple_indices<0>::type(),
700                typename __make_tuple_types<tuple, 0>::type(),
701                __t...
702               ) {}
703
704    template <class ..._Up,
705              bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
706              typename enable_if
707                      <
708                         _CheckArgsConstructor<
709                             sizeof...(_Up) == sizeof...(_Tp)
710                             && !_PackIsTuple
711                         >::template __enable_implicit<_Up...>() ||
712                        _CheckArgsConstructor<
713                            _EnableImplicitReducedArityExtension
714                            && sizeof...(_Up) < sizeof...(_Tp)
715                            && !_PackIsTuple
716                         >::template __enable_implicit<_Up...>(),
717                         bool
718                      >::type = false
719             >
720        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
721        tuple(_Up&&... __u)
722            _NOEXCEPT_((
723                is_nothrow_constructible<_BaseT,
724                    typename __make_tuple_indices<sizeof...(_Up)>::type,
725                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
726                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
727                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
728                    _Up...
729                >::value
730            ))
731            : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
732                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
733                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
734                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
735                    _VSTD::forward<_Up>(__u)...) {}
736
737    template <class ..._Up,
738              typename enable_if
739                      <
740                         _CheckArgsConstructor<
741                             sizeof...(_Up) <= sizeof...(_Tp)
742                             && !_PackExpandsToThisTuple<_Up...>::value
743                         >::template __enable_explicit<_Up...>() ||
744                         _CheckArgsConstructor<
745                            !_EnableImplicitReducedArityExtension
746                            && sizeof...(_Up) < sizeof...(_Tp)
747                            && !_PackExpandsToThisTuple<_Up...>::value
748                         >::template __enable_implicit<_Up...>(),
749                         bool
750                      >::type = false
751             >
752        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
753        explicit
754        tuple(_Up&&... __u)
755            _NOEXCEPT_((
756                is_nothrow_constructible<_BaseT,
757                    typename __make_tuple_indices<sizeof...(_Up)>::type,
758                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
759                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
760                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
761                    _Up...
762                >::value
763            ))
764            : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
765                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
766                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
767                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
768                    _VSTD::forward<_Up>(__u)...) {}
769
770    template <class _Alloc, class ..._Up,
771              typename enable_if
772                      <
773                         _CheckArgsConstructor<
774                             sizeof...(_Up) == sizeof...(_Tp) &&
775                             !_PackExpandsToThisTuple<_Up...>::value
776                         >::template __enable_implicit<_Up...>(),
777                         bool
778                      >::type = false
779             >
780        _LIBCPP_INLINE_VISIBILITY
781        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
782            : __base_(allocator_arg_t(), __a,
783                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
784                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
785                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
786                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
787                    _VSTD::forward<_Up>(__u)...) {}
788
789    template <class _Alloc, class ..._Up,
790              typename enable_if
791                      <
792                         _CheckArgsConstructor<
793                             sizeof...(_Up) == sizeof...(_Tp) &&
794                             !_PackExpandsToThisTuple<_Up...>::value
795                         >::template __enable_explicit<_Up...>(),
796                         bool
797                      >::type = false
798             >
799        _LIBCPP_INLINE_VISIBILITY
800        explicit
801        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
802            : __base_(allocator_arg_t(), __a,
803                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
804                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
805                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
806                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
807                    _VSTD::forward<_Up>(__u)...) {}
808
809    template <class _Tuple,
810              typename enable_if
811                      <
812                         _CheckTupleLikeConstructor<
813                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
814                             && !_PackExpandsToThisTuple<_Tuple>::value
815                         >::template __enable_implicit<_Tuple>(),
816                         bool
817                      >::type = false
818             >
819        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
820        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
821            : __base_(_VSTD::forward<_Tuple>(__t)) {}
822
823    template <class _Tuple,
824              typename enable_if
825                      <
826                         _CheckTupleLikeConstructor<
827                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
828                             && !_PackExpandsToThisTuple<_Tuple>::value
829                         >::template __enable_explicit<_Tuple>(),
830                         bool
831                      >::type = false
832             >
833        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
834        explicit
835        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
836            : __base_(_VSTD::forward<_Tuple>(__t)) {}
837
838    template <class _Alloc, class _Tuple,
839              typename enable_if
840                      <
841                         _CheckTupleLikeConstructor<
842                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
843                         >::template __enable_implicit<_Tuple>(),
844                         bool
845                      >::type = false
846             >
847        _LIBCPP_INLINE_VISIBILITY
848        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
849            : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
850
851    template <class _Alloc, class _Tuple,
852              typename enable_if
853                      <
854                         _CheckTupleLikeConstructor<
855                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
856                         >::template __enable_explicit<_Tuple>(),
857                         bool
858                      >::type = false
859             >
860        _LIBCPP_INLINE_VISIBILITY
861        explicit
862        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
863            : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
864
865    using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
866    using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
867
868    _LIBCPP_INLINE_VISIBILITY
869    tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
870        _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
871    {
872        __base_.operator=(__t.__base_);
873        return *this;
874    }
875
876    _LIBCPP_INLINE_VISIBILITY
877    tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
878        _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
879    {
880        __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
881        return *this;
882    }
883
884    template <class _Tuple,
885              class = typename enable_if
886                      <
887                         __tuple_assignable<_Tuple, tuple>::value
888                      >::type
889             >
890        _LIBCPP_INLINE_VISIBILITY
891        tuple&
892        operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
893        {
894            __base_.operator=(_VSTD::forward<_Tuple>(__t));
895            return *this;
896        }
897
898    _LIBCPP_INLINE_VISIBILITY
899    void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
900        {__base_.swap(__t.__base_);}
901};
902
903template <>
904class _LIBCPP_TEMPLATE_VIS tuple<>
905{
906public:
907    _LIBCPP_INLINE_VISIBILITY
908    _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
909    template <class _Alloc>
910    _LIBCPP_INLINE_VISIBILITY
911        tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
912    template <class _Alloc>
913    _LIBCPP_INLINE_VISIBILITY
914        tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
915    template <class _Up>
916    _LIBCPP_INLINE_VISIBILITY
917        tuple(array<_Up, 0>) _NOEXCEPT {}
918    template <class _Alloc, class _Up>
919    _LIBCPP_INLINE_VISIBILITY
920        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
921    _LIBCPP_INLINE_VISIBILITY
922    void swap(tuple&) _NOEXCEPT {}
923};
924
925#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
926// NOTE: These are not yet standardized, but are required to simulate the
927// implicit deduction guide that should be generated had libc++ declared the
928// tuple-like constructors "correctly"
929template <class _Alloc, class ..._Args>
930tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
931template <class _Alloc, class ..._Args>
932tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
933#endif
934
935template <class ..._Tp>
936inline _LIBCPP_INLINE_VISIBILITY
937typename enable_if
938<
939    __all<__is_swappable<_Tp>::value...>::value,
940    void
941>::type
942swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
943                 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
944    {__t.swap(__u);}
945
946// get
947
948template <size_t _Ip, class ..._Tp>
949inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
950typename tuple_element<_Ip, tuple<_Tp...> >::type&
951get(tuple<_Tp...>& __t) _NOEXCEPT
952{
953    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
954    return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
955}
956
957template <size_t _Ip, class ..._Tp>
958inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
959const typename tuple_element<_Ip, tuple<_Tp...> >::type&
960get(const tuple<_Tp...>& __t) _NOEXCEPT
961{
962    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
963    return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
964}
965
966template <size_t _Ip, class ..._Tp>
967inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
968typename tuple_element<_Ip, tuple<_Tp...> >::type&&
969get(tuple<_Tp...>&& __t) _NOEXCEPT
970{
971    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
972    return static_cast<type&&>(
973             static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
974}
975
976template <size_t _Ip, class ..._Tp>
977inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
978const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
979get(const tuple<_Tp...>&& __t) _NOEXCEPT
980{
981    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
982    return static_cast<const type&&>(
983             static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
984}
985
986#if _LIBCPP_STD_VER > 11
987
988namespace __find_detail {
989
990static constexpr size_t __not_found = -1;
991static constexpr size_t __ambiguous = __not_found - 1;
992
993inline _LIBCPP_INLINE_VISIBILITY
994constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
995    return !__matches ? __res :
996        (__res == __not_found ? __curr_i : __ambiguous);
997}
998
999template <size_t _Nx>
1000inline _LIBCPP_INLINE_VISIBILITY
1001constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1002  return __i == _Nx ? __not_found :
1003      __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1004}
1005
1006template <class _T1, class ..._Args>
1007struct __find_exactly_one_checked {
1008    static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
1009    static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1010    static_assert(value != __not_found, "type not found in type list" );
1011    static_assert(value != __ambiguous, "type occurs more than once in type list");
1012};
1013
1014template <class _T1>
1015struct __find_exactly_one_checked<_T1> {
1016    static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1017};
1018
1019} // namespace __find_detail;
1020
1021template <typename _T1, typename... _Args>
1022struct __find_exactly_one_t
1023    : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1024};
1025
1026template <class _T1, class... _Args>
1027inline _LIBCPP_INLINE_VISIBILITY
1028constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1029{
1030    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1031}
1032
1033template <class _T1, class... _Args>
1034inline _LIBCPP_INLINE_VISIBILITY
1035constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1036{
1037    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1038}
1039
1040template <class _T1, class... _Args>
1041inline _LIBCPP_INLINE_VISIBILITY
1042constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1043{
1044    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1045}
1046
1047template <class _T1, class... _Args>
1048inline _LIBCPP_INLINE_VISIBILITY
1049constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1050{
1051    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1052}
1053
1054#endif
1055
1056// tie
1057
1058template <class ..._Tp>
1059inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1060tuple<_Tp&...>
1061tie(_Tp&... __t) _NOEXCEPT
1062{
1063    return tuple<_Tp&...>(__t...);
1064}
1065
1066template <class _Up>
1067struct __ignore_t
1068{
1069    template <class _Tp>
1070    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1071    const __ignore_t& operator=(_Tp&&) const {return *this;}
1072};
1073
1074namespace {
1075  _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
1076}
1077
1078template <class... _Tp>
1079inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1080tuple<typename __unwrap_ref_decay<_Tp>::type...>
1081make_tuple(_Tp&&... __t)
1082{
1083    return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
1084}
1085
1086template <class... _Tp>
1087inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1088tuple<_Tp&&...>
1089forward_as_tuple(_Tp&&... __t) _NOEXCEPT
1090{
1091    return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
1092}
1093
1094template <size_t _Ip>
1095struct __tuple_equal
1096{
1097    template <class _Tp, class _Up>
1098    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1099    bool operator()(const _Tp& __x, const _Up& __y)
1100    {
1101        return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
1102    }
1103};
1104
1105template <>
1106struct __tuple_equal<0>
1107{
1108    template <class _Tp, class _Up>
1109    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1110    bool operator()(const _Tp&, const _Up&)
1111    {
1112        return true;
1113    }
1114};
1115
1116template <class ..._Tp, class ..._Up>
1117inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1118bool
1119operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1120{
1121    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1122    return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1123}
1124
1125template <class ..._Tp, class ..._Up>
1126inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1127bool
1128operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1129{
1130    return !(__x == __y);
1131}
1132
1133template <size_t _Ip>
1134struct __tuple_less
1135{
1136    template <class _Tp, class _Up>
1137    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1138    bool operator()(const _Tp& __x, const _Up& __y)
1139    {
1140        const size_t __idx = tuple_size<_Tp>::value - _Ip;
1141        if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1142            return true;
1143        if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1144            return false;
1145        return __tuple_less<_Ip-1>()(__x, __y);
1146    }
1147};
1148
1149template <>
1150struct __tuple_less<0>
1151{
1152    template <class _Tp, class _Up>
1153    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1154    bool operator()(const _Tp&, const _Up&)
1155    {
1156        return false;
1157    }
1158};
1159
1160template <class ..._Tp, class ..._Up>
1161inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1162bool
1163operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1164{
1165    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1166    return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1167}
1168
1169template <class ..._Tp, class ..._Up>
1170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1171bool
1172operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1173{
1174    return __y < __x;
1175}
1176
1177template <class ..._Tp, class ..._Up>
1178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1179bool
1180operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1181{
1182    return !(__x < __y);
1183}
1184
1185template <class ..._Tp, class ..._Up>
1186inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1187bool
1188operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1189{
1190    return !(__y < __x);
1191}
1192
1193// tuple_cat
1194
1195template <class _Tp, class _Up> struct __tuple_cat_type;
1196
1197template <class ..._Ttypes, class ..._Utypes>
1198struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
1199{
1200    typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
1201};
1202
1203template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1204struct __tuple_cat_return_1
1205{
1206};
1207
1208template <class ..._Types, class _Tuple0>
1209struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1210{
1211    typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
1212            typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
1213                                                                           type;
1214};
1215
1216template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1217struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1218    : public __tuple_cat_return_1<
1219                 typename __tuple_cat_type<
1220                     tuple<_Types...>,
1221                     typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
1222                 >::type,
1223                 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1224                 _Tuple1, _Tuples...>
1225{
1226};
1227
1228template <class ..._Tuples> struct __tuple_cat_return;
1229
1230template <class _Tuple0, class ..._Tuples>
1231struct __tuple_cat_return<_Tuple0, _Tuples...>
1232    : public __tuple_cat_return_1<tuple<>,
1233         __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1234                                                                     _Tuples...>
1235{
1236};
1237
1238template <>
1239struct __tuple_cat_return<>
1240{
1241    typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
1242};
1243
1244inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1245tuple<>
1246tuple_cat()
1247{
1248    return tuple<>();
1249}
1250
1251template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
1252struct __tuple_cat_return_ref_imp;
1253
1254template <class ..._Types, size_t ..._I0, class _Tuple0>
1255struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
1256{
1257    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1258    typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1259                          typename tuple_element<_I0, _T0>::type>::type&&...> type;
1260};
1261
1262template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1263struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1264                                  _Tuple0, _Tuple1, _Tuples...>
1265    : public __tuple_cat_return_ref_imp<
1266         tuple<_Types..., typename __apply_cv<_Tuple0,
1267               typename tuple_element<_I0,
1268                  typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1269         typename __make_tuple_indices<tuple_size<typename
1270                                 remove_reference<_Tuple1>::type>::value>::type,
1271         _Tuple1, _Tuples...>
1272{
1273};
1274
1275template <class _Tuple0, class ..._Tuples>
1276struct __tuple_cat_return_ref
1277    : public __tuple_cat_return_ref_imp<tuple<>,
1278               typename __make_tuple_indices<
1279                        tuple_size<typename remove_reference<_Tuple0>::type>::value
1280               >::type, _Tuple0, _Tuples...>
1281{
1282};
1283
1284template <class _Types, class _I0, class _J0>
1285struct __tuple_cat;
1286
1287template <class ..._Types, size_t ..._I0, size_t ..._J0>
1288struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
1289{
1290    template <class _Tuple0>
1291    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1292    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1293    operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1294    {
1295        return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1296                                      _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
1297    }
1298
1299    template <class _Tuple0, class _Tuple1, class ..._Tuples>
1300    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1301    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1302    operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1303    {
1304        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1305        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
1306        return __tuple_cat<
1307           tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1308           typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1309           typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
1310                           (forward_as_tuple(
1311                              _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1312                              _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
1313                            ),
1314                            _VSTD::forward<_Tuple1>(__t1),
1315                            _VSTD::forward<_Tuples>(__tpls)...);
1316    }
1317};
1318
1319template <class _Tuple0, class... _Tuples>
1320inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1321typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1322tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1323{
1324    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1325    return __tuple_cat<tuple<>, __tuple_indices<>,
1326                  typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
1327                  (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1328                                            _VSTD::forward<_Tuples>(__tpls)...);
1329}
1330
1331template <class ..._Tp, class _Alloc>
1332struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
1333    : true_type {};
1334
1335template <class _T1, class _T2>
1336template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1337inline _LIBCPP_INLINE_VISIBILITY
1338pair<_T1, _T2>::pair(piecewise_construct_t,
1339                     tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1340                     __tuple_indices<_I1...>, __tuple_indices<_I2...>)
1341    :  first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1342      second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
1343{
1344}
1345
1346#if _LIBCPP_STD_VER > 14
1347template <class _Tp>
1348_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1349
1350#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1351
1352template <class _Fn, class _Tuple, size_t ..._Id>
1353inline _LIBCPP_INLINE_VISIBILITY
1354constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1355                                            __tuple_indices<_Id...>)
1356_LIBCPP_NOEXCEPT_RETURN(
1357    _VSTD::__invoke_constexpr(
1358        _VSTD::forward<_Fn>(__f),
1359        _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1360)
1361
1362template <class _Fn, class _Tuple>
1363inline _LIBCPP_INLINE_VISIBILITY
1364constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1365_LIBCPP_NOEXCEPT_RETURN(
1366    _VSTD::__apply_tuple_impl(
1367        _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1368        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
1369)
1370
1371template <class _Tp, class _Tuple, size_t... _Idx>
1372inline _LIBCPP_INLINE_VISIBILITY
1373constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1374_LIBCPP_NOEXCEPT_RETURN(
1375    _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1376)
1377
1378template <class _Tp, class _Tuple>
1379inline _LIBCPP_INLINE_VISIBILITY
1380constexpr _Tp make_from_tuple(_Tuple&& __t)
1381_LIBCPP_NOEXCEPT_RETURN(
1382    _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1383        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
1384)
1385
1386#undef _LIBCPP_NOEXCEPT_RETURN
1387
1388#endif // _LIBCPP_STD_VER > 14
1389
1390#endif // !defined(_LIBCPP_CXX03_LANG)
1391
1392_LIBCPP_END_NAMESPACE_STD
1393
1394#endif  // _LIBCPP_TUPLE
1395