tuple revision 261272
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===--------------------------- tuple ------------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is distributed under the University of Illinois Open Source
7227825Stheraven// License. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_TUPLE
12227825Stheraven#define _LIBCPP_TUPLE
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    tuple synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraventemplate <class... T>
21227825Stheravenclass tuple {
22227825Stheravenpublic:
23227825Stheraven    constexpr tuple();
24261272Sdim    explicit tuple(const T&...);  // constexpr in C++14
25227825Stheraven    template <class... U>
26261272Sdim        explicit tuple(U&&...);  // constexpr in C++14
27227825Stheraven    tuple(const tuple&) = default;
28227825Stheraven    tuple(tuple&&) = default;
29227825Stheraven    template <class... U>
30261272Sdim        tuple(const tuple<U...>&);  // constexpr in C++14
31227825Stheraven    template <class... U>
32261272Sdim        tuple(tuple<U...>&&);  // constexpr in C++14
33227825Stheraven    template <class U1, class U2>
34261272Sdim        tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
35227825Stheraven    template <class U1, class U2>
36261272Sdim        tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++14
37227825Stheraven
38227825Stheraven    // allocator-extended constructors
39227825Stheraven    template <class Alloc>
40227825Stheraven        tuple(allocator_arg_t, const Alloc& a);
41227825Stheraven    template <class Alloc>
42227825Stheraven        tuple(allocator_arg_t, const Alloc& a, const T&...);
43227825Stheraven    template <class Alloc, class... U>
44227825Stheraven        tuple(allocator_arg_t, const Alloc& a, U&&...);
45227825Stheraven    template <class Alloc>
46227825Stheraven        tuple(allocator_arg_t, const Alloc& a, const tuple&);
47227825Stheraven    template <class Alloc>
48227825Stheraven        tuple(allocator_arg_t, const Alloc& a, tuple&&);
49227825Stheraven    template <class Alloc, class... U>
50227825Stheraven        tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
51227825Stheraven    template <class Alloc, class... U>
52227825Stheraven        tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
53227825Stheraven    template <class Alloc, class U1, class U2>
54227825Stheraven        tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
55227825Stheraven    template <class Alloc, class U1, class U2>
56227825Stheraven        tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
57227825Stheraven
58227825Stheraven    tuple& operator=(const tuple&);
59227825Stheraven    tuple&
60227825Stheraven        operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
61227825Stheraven    template <class... U>
62227825Stheraven        tuple& operator=(const tuple<U...>&);
63227825Stheraven    template <class... U>
64227825Stheraven        tuple& operator=(tuple<U...>&&);
65227825Stheraven    template <class U1, class U2>
66227825Stheraven        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
67227825Stheraven    template <class U1, class U2>
68227825Stheraven        tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
69227825Stheraven
70227825Stheraven    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
71227825Stheraven};
72227825Stheraven
73227825Stheravenconst unspecified ignore;
74227825Stheraven
75261272Sdimtemplate <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
76261272Sdimtemplate <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
77227825Stheraventemplate <class... T> tuple<T&...> tie(T&...) noexcept;
78261272Sdimtemplate <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
79227825Stheraven  
80227825Stheraven// 20.4.1.4, tuple helper classes:
81227825Stheraventemplate <class T> class tuple_size; // undefined
82227825Stheraventemplate <class... T> class tuple_size<tuple<T...>>;
83227825Stheraventemplate <intsize_t I, class T> class tuple_element; // undefined
84227825Stheraventemplate <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
85227825Stheraven
86227825Stheraven// 20.4.1.5, element access:
87227825Stheraventemplate <intsize_t I, class... T>
88227825Stheraven    typename tuple_element<I, tuple<T...>>::type&
89261272Sdim    get(tuple<T...>&) noexcept; // constexpr in C++14
90227825Stheraventemplate <intsize_t I, class... T>
91227825Stheraven    typename tuple_element<I, tuple<T...>>::type const&
92261272Sdim    get(const tuple<T...>&) noexcept; // constexpr in C++14
93227825Stheraventemplate <intsize_t I, class... T>
94227825Stheraven    typename tuple_element<I, tuple<T...>>::type&&
95261272Sdim    get(tuple<T...>&&) noexcept; // constexpr in C++14
96227825Stheraven
97261272Sdimtemplate <class T1, class... T>
98261272Sdim    constexpr T1& get(tuple<T...>&) noexcept;  // C++14
99261272Sdimtemplate <class T1, class... T>
100261272Sdim    constexpr T1 const& get(const tuple<T...>&) noexcept;   // C++14
101261272Sdimtemplate <class T1, class... T>
102261272Sdim    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
103261272Sdim
104227825Stheraven// 20.4.1.6, relational operators:
105261272Sdimtemplate<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
106261272Sdimtemplate<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
107261272Sdimtemplate<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
108261272Sdimtemplate<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
109261272Sdimtemplate<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
110261272Sdimtemplate<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
111227825Stheraven
112227825Stheraventemplate <class... Types, class Alloc>
113227825Stheraven  struct uses_allocator<tuple<Types...>, Alloc>;
114227825Stheraven
115227825Stheraventemplate <class... Types>
116227825Stheraven  void
117227825Stheraven  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
118227825Stheraven
119227825Stheraven}  // std
120227825Stheraven
121227825Stheraven*/
122227825Stheraven
123227825Stheraven#include <__config>
124227825Stheraven#include <__tuple>
125227825Stheraven#include <cstddef>
126227825Stheraven#include <type_traits>
127232924Stheraven#include <__functional_base>
128232924Stheraven#include <utility>
129227825Stheraven
130227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
131227825Stheraven#pragma GCC system_header
132227825Stheraven#endif
133227825Stheraven
134227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
135227825Stheraven
136227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
137227825Stheraven
138227825Stheraven// tuple_size
139227825Stheraven
140227825Stheraventemplate <class ..._Tp>
141261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
142227825Stheraven    : public integral_constant<size_t, sizeof...(_Tp)>
143227825Stheraven{
144227825Stheraven};
145227825Stheraven
146227825Stheraven// tuple_element
147227825Stheraven
148227825Stheraventemplate <size_t _Ip, class ..._Tp>
149261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
150227825Stheraven{
151227825Stheravenpublic:
152227825Stheraven    typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
153227825Stheraven};
154227825Stheraven
155227825Stheraven// __tuple_leaf
156227825Stheraven
157232924Stheraventemplate <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value
158232924Stheraven#if __has_feature(is_final)
159232924Stheraven                                 && !__is_final(_Hp)
160232924Stheraven#endif
161232924Stheraven         >
162227825Stheravenclass __tuple_leaf;
163227825Stheraven
164227825Stheraventemplate <size_t _Ip, class _Hp, bool _Ep>
165227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
166227825Stheravenvoid swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
167227825Stheraven    _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
168227825Stheraven{
169227825Stheraven    swap(__x.get(), __y.get());
170227825Stheraven}
171227825Stheraven
172227825Stheraventemplate <size_t _Ip, class _Hp, bool>
173227825Stheravenclass __tuple_leaf
174227825Stheraven{
175227825Stheraven    _Hp value;
176227825Stheraven
177227825Stheraven    __tuple_leaf& operator=(const __tuple_leaf&);
178227825Stheravenpublic:
179241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
180241900Sdim             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
181227825Stheraven       {static_assert(!is_reference<_Hp>::value,
182227825Stheraven              "Attempted to default construct a reference element in a tuple");}
183227825Stheraven
184227825Stheraven    template <class _Alloc>
185227825Stheraven        _LIBCPP_INLINE_VISIBILITY
186227825Stheraven        __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
187227825Stheraven            : value()
188227825Stheraven        {static_assert(!is_reference<_Hp>::value,
189227825Stheraven              "Attempted to default construct a reference element in a tuple");}
190227825Stheraven
191227825Stheraven    template <class _Alloc>
192227825Stheraven        _LIBCPP_INLINE_VISIBILITY
193227825Stheraven        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
194227825Stheraven            : value(allocator_arg_t(), __a)
195227825Stheraven        {static_assert(!is_reference<_Hp>::value,
196227825Stheraven              "Attempted to default construct a reference element in a tuple");}
197227825Stheraven
198227825Stheraven    template <class _Alloc>
199227825Stheraven        _LIBCPP_INLINE_VISIBILITY
200227825Stheraven        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
201227825Stheraven            : value(__a)
202227825Stheraven        {static_assert(!is_reference<_Hp>::value,
203227825Stheraven              "Attempted to default construct a reference element in a tuple");}
204227825Stheraven
205227825Stheraven    template <class _Tp,
206227825Stheraven              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
207261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
208241900Sdim        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
209227825Stheraven            : value(_VSTD::forward<_Tp>(__t))
210227825Stheraven        {static_assert(!is_reference<_Hp>::value ||
211232924Stheraven                       (is_lvalue_reference<_Hp>::value &&
212227825Stheraven                        (is_lvalue_reference<_Tp>::value ||
213227825Stheraven                         is_same<typename remove_reference<_Tp>::type,
214227825Stheraven                                 reference_wrapper<
215227825Stheraven                                    typename remove_reference<_Hp>::type
216227825Stheraven                                 >
217232924Stheraven                                >::value)) ||
218227825Stheraven                        (is_rvalue_reference<_Hp>::value &&
219227825Stheraven                         !is_lvalue_reference<_Tp>::value),
220227825Stheraven       "Attempted to construct a reference element in a tuple with an rvalue");}
221227825Stheraven
222227825Stheraven    template <class _Tp, class _Alloc>
223227825Stheraven        _LIBCPP_INLINE_VISIBILITY
224227825Stheraven        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
225227825Stheraven            : value(_VSTD::forward<_Tp>(__t))
226227825Stheraven        {static_assert(!is_lvalue_reference<_Hp>::value ||
227232924Stheraven                       (is_lvalue_reference<_Hp>::value &&
228227825Stheraven                        (is_lvalue_reference<_Tp>::value ||
229227825Stheraven                         is_same<typename remove_reference<_Tp>::type,
230227825Stheraven                                 reference_wrapper<
231227825Stheraven                                    typename remove_reference<_Hp>::type
232227825Stheraven                                 >
233232924Stheraven                                >::value)),
234227825Stheraven       "Attempted to construct a reference element in a tuple with an rvalue");}
235227825Stheraven
236227825Stheraven    template <class _Tp, class _Alloc>
237227825Stheraven        _LIBCPP_INLINE_VISIBILITY
238227825Stheraven        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
239227825Stheraven            : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
240227825Stheraven        {static_assert(!is_lvalue_reference<_Hp>::value ||
241232924Stheraven                       (is_lvalue_reference<_Hp>::value &&
242227825Stheraven                        (is_lvalue_reference<_Tp>::value ||
243227825Stheraven                         is_same<typename remove_reference<_Tp>::type,
244227825Stheraven                                 reference_wrapper<
245227825Stheraven                                    typename remove_reference<_Hp>::type
246227825Stheraven                                 >
247232924Stheraven                                >::value)),
248227825Stheraven       "Attempted to construct a reference element in a tuple with an rvalue");}
249227825Stheraven
250227825Stheraven    template <class _Tp, class _Alloc>
251227825Stheraven        _LIBCPP_INLINE_VISIBILITY
252227825Stheraven        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
253227825Stheraven            : value(_VSTD::forward<_Tp>(__t), __a)
254227825Stheraven        {static_assert(!is_lvalue_reference<_Hp>::value ||
255232924Stheraven                       (is_lvalue_reference<_Hp>::value &&
256227825Stheraven                        (is_lvalue_reference<_Tp>::value ||
257227825Stheraven                         is_same<typename remove_reference<_Tp>::type,
258227825Stheraven                                 reference_wrapper<
259227825Stheraven                                    typename remove_reference<_Hp>::type
260227825Stheraven                                 >
261232924Stheraven                                >::value)),
262227825Stheraven       "Attempted to construct a reference element in a tuple with an rvalue");}
263227825Stheraven
264261272Sdim    _LIBCPP_INLINE_VISIBILITY
265261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11
266241900Sdim    __tuple_leaf(const __tuple_leaf& __t) _NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value)
267227825Stheraven        : value(__t.get())
268227825Stheraven        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
269227825Stheraven
270261272Sdim    _LIBCPP_INLINE_VISIBILITY
271261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11
272261272Sdim    __tuple_leaf(__tuple_leaf&& __t) _NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value)
273261272Sdim        : value(_VSTD::forward<_Hp>(__t.get()))
274261272Sdim        {}
275227825Stheraven
276227825Stheraven    template <class _Tp>
277227825Stheraven        _LIBCPP_INLINE_VISIBILITY
278227825Stheraven        __tuple_leaf&
279241900Sdim        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
280227825Stheraven        {
281227825Stheraven            value = _VSTD::forward<_Tp>(__t);
282227825Stheraven            return *this;
283227825Stheraven        }
284227825Stheraven
285227825Stheraven    _LIBCPP_INLINE_VISIBILITY
286227825Stheraven    int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
287227825Stheraven    {
288227825Stheraven        _VSTD::swap(*this, __t);
289227825Stheraven        return 0;
290227825Stheraven    }
291227825Stheraven
292261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return value;}
293261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
294227825Stheraven};
295227825Stheraven
296227825Stheraventemplate <size_t _Ip, class _Hp>
297227825Stheravenclass __tuple_leaf<_Ip, _Hp, true>
298227825Stheraven    : private _Hp
299227825Stheraven{
300227825Stheraven
301227825Stheraven    __tuple_leaf& operator=(const __tuple_leaf&);
302227825Stheravenpublic:
303241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
304241900Sdim             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
305227825Stheraven
306227825Stheraven    template <class _Alloc>
307227825Stheraven        _LIBCPP_INLINE_VISIBILITY
308227825Stheraven        __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
309227825Stheraven
310227825Stheraven    template <class _Alloc>
311227825Stheraven        _LIBCPP_INLINE_VISIBILITY
312227825Stheraven        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
313227825Stheraven            : _Hp(allocator_arg_t(), __a) {}
314227825Stheraven
315227825Stheraven    template <class _Alloc>
316227825Stheraven        _LIBCPP_INLINE_VISIBILITY
317227825Stheraven        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
318227825Stheraven            : _Hp(__a) {}
319227825Stheraven
320227825Stheraven    template <class _Tp,
321227825Stheraven              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
322261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
323241900Sdim        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
324227825Stheraven            : _Hp(_VSTD::forward<_Tp>(__t)) {}
325227825Stheraven
326227825Stheraven    template <class _Tp, class _Alloc>
327227825Stheraven        _LIBCPP_INLINE_VISIBILITY
328227825Stheraven        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
329227825Stheraven            : _Hp(_VSTD::forward<_Tp>(__t)) {}
330227825Stheraven
331227825Stheraven    template <class _Tp, class _Alloc>
332227825Stheraven        _LIBCPP_INLINE_VISIBILITY
333227825Stheraven        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
334227825Stheraven            : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
335227825Stheraven
336227825Stheraven    template <class _Tp, class _Alloc>
337227825Stheraven        _LIBCPP_INLINE_VISIBILITY
338227825Stheraven        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
339227825Stheraven            : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
340227825Stheraven
341227825Stheraven    template <class _Tp>
342227825Stheraven        _LIBCPP_INLINE_VISIBILITY
343227825Stheraven        __tuple_leaf&
344241900Sdim        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
345227825Stheraven        {
346227825Stheraven            _Hp::operator=(_VSTD::forward<_Tp>(__t));
347227825Stheraven            return *this;
348227825Stheraven        }
349227825Stheraven
350227825Stheraven    _LIBCPP_INLINE_VISIBILITY
351227825Stheraven    int
352227825Stheraven    swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
353227825Stheraven    {
354227825Stheraven        _VSTD::swap(*this, __t);
355227825Stheraven        return 0;
356227825Stheraven    }
357227825Stheraven
358261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
359261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
360227825Stheraven};
361227825Stheraven
362227825Stheraventemplate <class ..._Tp>
363227825Stheraven_LIBCPP_INLINE_VISIBILITY
364241900Sdimvoid __swallow(_Tp&&...) _NOEXCEPT {}
365227825Stheraven
366227825Stheraventemplate <bool ...> struct __all;
367227825Stheraven
368227825Stheraventemplate <>
369227825Stheravenstruct __all<>
370227825Stheraven{
371227825Stheraven    static const bool value = true;
372227825Stheraven};
373227825Stheraven
374232924Stheraventemplate <bool _B0, bool ... _Bp>
375232924Stheravenstruct __all<_B0, _Bp...>
376227825Stheraven{
377232924Stheraven    static const bool value = _B0 && __all<_Bp...>::value;
378227825Stheraven};
379227825Stheraven
380227825Stheraven// __tuple_impl
381227825Stheraven
382227825Stheraventemplate<class _Indx, class ..._Tp> struct __tuple_impl;
383227825Stheraven
384227825Stheraventemplate<size_t ..._Indx, class ..._Tp>
385227825Stheravenstruct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
386227825Stheraven    : public __tuple_leaf<_Indx, _Tp>...
387227825Stheraven{
388241900Sdim    _LIBCPP_INLINE_VISIBILITY
389241900Sdim    _LIBCPP_CONSTEXPR __tuple_impl()
390241900Sdim        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
391241900Sdim
392227825Stheraven    template <size_t ..._Uf, class ..._Tf,
393227825Stheraven              size_t ..._Ul, class ..._Tl, class ..._Up>
394261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
395227825Stheraven        explicit
396227825Stheraven        __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
397227825Stheraven                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
398241900Sdim                     _Up&&... __u)
399241900Sdim                     _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
400241900Sdim                                 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
401227825Stheraven            __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
402227825Stheraven            __tuple_leaf<_Ul, _Tl>()...
403227825Stheraven            {}
404227825Stheraven
405227825Stheraven    template <class _Alloc, size_t ..._Uf, class ..._Tf,
406227825Stheraven              size_t ..._Ul, class ..._Tl, class ..._Up>
407227825Stheraven        _LIBCPP_INLINE_VISIBILITY
408227825Stheraven        explicit
409227825Stheraven        __tuple_impl(allocator_arg_t, const _Alloc& __a,
410227825Stheraven                     __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
411227825Stheraven                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
412227825Stheraven                     _Up&&... __u) :
413227825Stheraven            __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
414227825Stheraven            _VSTD::forward<_Up>(__u))...,
415227825Stheraven            __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
416227825Stheraven            {}
417227825Stheraven
418227825Stheraven    template <class _Tuple,
419227825Stheraven              class = typename enable_if
420227825Stheraven                      <
421249989Sdim                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
422227825Stheraven                      >::type
423227825Stheraven             >
424261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
425241900Sdim        __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
426241900Sdim                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
427227825Stheraven            : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
428227825Stheraven                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
429227825Stheraven            {}
430227825Stheraven
431227825Stheraven    template <class _Alloc, class _Tuple,
432227825Stheraven              class = typename enable_if
433227825Stheraven                      <
434227825Stheraven                         __tuple_convertible<_Tuple, tuple<_Tp...> >::value
435227825Stheraven                      >::type
436227825Stheraven             >
437227825Stheraven        _LIBCPP_INLINE_VISIBILITY
438227825Stheraven        __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
439227825Stheraven            : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
440227825Stheraven                                       typename __make_tuple_types<_Tuple>::type>::type>(), __a,
441227825Stheraven                                       _VSTD::forward<typename tuple_element<_Indx,
442227825Stheraven                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
443227825Stheraven            {}
444227825Stheraven
445227825Stheraven    template <class _Tuple>
446227825Stheraven        _LIBCPP_INLINE_VISIBILITY
447227825Stheraven        typename enable_if
448227825Stheraven        <
449227825Stheraven            __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
450227825Stheraven            __tuple_impl&
451227825Stheraven        >::type
452241900Sdim        operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
453241900Sdim                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
454227825Stheraven        {
455227825Stheraven            __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
456227825Stheraven                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
457227825Stheraven            return *this;
458227825Stheraven        }
459227825Stheraven
460261272Sdim    __tuple_impl(const __tuple_impl&) = default;
461261272Sdim    __tuple_impl(__tuple_impl&&) = default;
462232924Stheraven
463227825Stheraven    _LIBCPP_INLINE_VISIBILITY
464261272Sdim    __tuple_impl&
465261272Sdim    operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
466261272Sdim    {
467261272Sdim        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
468261272Sdim        return *this;
469261272Sdim    }
470261272Sdim
471261272Sdim    _LIBCPP_INLINE_VISIBILITY
472261272Sdim    __tuple_impl&
473261272Sdim    operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
474261272Sdim    {
475261272Sdim        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
476261272Sdim        return *this;
477261272Sdim    }
478261272Sdim
479261272Sdim    _LIBCPP_INLINE_VISIBILITY
480227825Stheraven    void swap(__tuple_impl& __t)
481227825Stheraven        _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
482227825Stheraven    {
483227825Stheraven        __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
484227825Stheraven    }
485227825Stheraven};
486227825Stheraven
487227825Stheraventemplate <class ..._Tp>
488261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple
489227825Stheraven{
490227825Stheraven    typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
491227825Stheraven
492227825Stheraven    base base_;
493227825Stheraven
494261272Sdim    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
495232924Stheraven        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
496261272Sdim    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
497232924Stheraven        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
498261272Sdim    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
499232924Stheraven        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
500227825Stheravenpublic:
501227825Stheraven
502227825Stheraven    _LIBCPP_INLINE_VISIBILITY
503241900Sdim    _LIBCPP_CONSTEXPR tuple()
504241900Sdim        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
505241900Sdim
506261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
507241900Sdim    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) 
508227825Stheraven        : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
509227825Stheraven                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
510227825Stheraven                typename __make_tuple_indices<0>::type(),
511227825Stheraven                typename __make_tuple_types<tuple, 0>::type(),
512227825Stheraven                __t...
513227825Stheraven               ) {}
514227825Stheraven
515227825Stheraven    template <class _Alloc>
516227825Stheraven      _LIBCPP_INLINE_VISIBILITY
517227825Stheraven      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
518227825Stheraven        : base_(allocator_arg_t(), __a,
519227825Stheraven                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
520227825Stheraven                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
521227825Stheraven                typename __make_tuple_indices<0>::type(),
522227825Stheraven                typename __make_tuple_types<tuple, 0>::type(),
523227825Stheraven                __t...
524227825Stheraven               ) {}
525227825Stheraven
526227825Stheraven    template <class ..._Up,
527234959Stheraven              typename enable_if
528227825Stheraven                      <
529227825Stheraven                         sizeof...(_Up) <= sizeof...(_Tp) &&
530227825Stheraven                         __tuple_convertible
531227825Stheraven                         <
532227825Stheraven                            tuple<_Up...>,
533227825Stheraven                            typename __make_tuple_types<tuple,
534227825Stheraven                                     sizeof...(_Up) < sizeof...(_Tp) ?
535227825Stheraven                                        sizeof...(_Up) :
536227825Stheraven                                        sizeof...(_Tp)>::type
537234959Stheraven                         >::value,
538234959Stheraven                         bool
539234959Stheraven                      >::type = false
540227825Stheraven             >
541261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
542234959Stheraven        tuple(_Up&&... __u)
543241900Sdim            _NOEXCEPT_((
544241900Sdim                is_nothrow_constructible<
545241900Sdim                    typename __make_tuple_indices<sizeof...(_Up)>::type,
546241900Sdim                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
547241900Sdim                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
548241900Sdim                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
549241900Sdim                    _Up...
550241900Sdim                >::value
551241900Sdim            ))
552234959Stheraven            : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
553234959Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
554234959Stheraven                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
555234959Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
556234959Stheraven                    _VSTD::forward<_Up>(__u)...) {}
557234959Stheraven
558234959Stheraven    template <class ..._Up,
559234959Stheraven              typename enable_if
560234959Stheraven                      <
561234959Stheraven                         sizeof...(_Up) <= sizeof...(_Tp) &&
562234959Stheraven                         __tuple_constructible
563234959Stheraven                         <
564234959Stheraven                            tuple<_Up...>,
565234959Stheraven                            typename __make_tuple_types<tuple,
566234959Stheraven                                     sizeof...(_Up) < sizeof...(_Tp) ?
567234959Stheraven                                        sizeof...(_Up) :
568234959Stheraven                                        sizeof...(_Tp)>::type
569234959Stheraven                         >::value &&
570234959Stheraven                         !__tuple_convertible
571234959Stheraven                         <
572234959Stheraven                            tuple<_Up...>,
573234959Stheraven                            typename __make_tuple_types<tuple,
574234959Stheraven                                     sizeof...(_Up) < sizeof...(_Tp) ?
575234959Stheraven                                        sizeof...(_Up) :
576234959Stheraven                                        sizeof...(_Tp)>::type
577234959Stheraven                         >::value,
578234959Stheraven                         bool
579234959Stheraven                      >::type =false
580234959Stheraven             >
581261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
582227825Stheraven        explicit
583227825Stheraven        tuple(_Up&&... __u)
584241900Sdim            _NOEXCEPT_((
585241900Sdim                is_nothrow_constructible<
586241900Sdim                    typename __make_tuple_indices<sizeof...(_Up)>::type,
587241900Sdim                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
588241900Sdim                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
589241900Sdim                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
590241900Sdim                    _Up...
591241900Sdim                >::value
592241900Sdim            ))
593227825Stheraven            : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
594227825Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
595227825Stheraven                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
596227825Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
597227825Stheraven                    _VSTD::forward<_Up>(__u)...) {}
598227825Stheraven
599227825Stheraven    template <class _Alloc, class ..._Up,
600227825Stheraven              class = typename enable_if
601227825Stheraven                      <
602227825Stheraven                         sizeof...(_Up) <= sizeof...(_Tp) &&
603227825Stheraven                         __tuple_convertible
604227825Stheraven                         <
605227825Stheraven                            tuple<_Up...>,
606227825Stheraven                            typename __make_tuple_types<tuple,
607227825Stheraven                                     sizeof...(_Up) < sizeof...(_Tp) ?
608227825Stheraven                                        sizeof...(_Up) :
609227825Stheraven                                        sizeof...(_Tp)>::type
610227825Stheraven                         >::value
611227825Stheraven                      >::type
612227825Stheraven             >
613227825Stheraven        _LIBCPP_INLINE_VISIBILITY
614227825Stheraven        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
615227825Stheraven            : base_(allocator_arg_t(), __a,
616227825Stheraven                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
617227825Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
618227825Stheraven                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
619227825Stheraven                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
620227825Stheraven                    _VSTD::forward<_Up>(__u)...) {}
621227825Stheraven
622227825Stheraven    template <class _Tuple,
623234959Stheraven              typename enable_if
624227825Stheraven                      <
625234959Stheraven                         __tuple_convertible<_Tuple, tuple>::value,
626234959Stheraven                         bool
627234959Stheraven                      >::type = false
628227825Stheraven             >
629261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
630241900Sdim        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
631227825Stheraven            : base_(_VSTD::forward<_Tuple>(__t)) {}
632227825Stheraven
633234959Stheraven    template <class _Tuple,
634234959Stheraven              typename enable_if
635234959Stheraven                      <
636234959Stheraven                         __tuple_constructible<_Tuple, tuple>::value &&
637234959Stheraven                         !__tuple_convertible<_Tuple, tuple>::value,
638234959Stheraven                         bool
639234959Stheraven                      >::type = false
640234959Stheraven             >
641261272Sdim        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
642234959Stheraven        explicit
643241900Sdim        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
644234959Stheraven            : base_(_VSTD::forward<_Tuple>(__t)) {}
645234959Stheraven
646227825Stheraven    template <class _Alloc, class _Tuple,
647227825Stheraven              class = typename enable_if
648227825Stheraven                      <
649227825Stheraven                         __tuple_convertible<_Tuple, tuple>::value
650227825Stheraven                      >::type
651227825Stheraven             >
652227825Stheraven        _LIBCPP_INLINE_VISIBILITY
653227825Stheraven        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
654227825Stheraven            : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
655227825Stheraven
656227825Stheraven    template <class _Tuple,
657227825Stheraven              class = typename enable_if
658227825Stheraven                      <
659227825Stheraven                         __tuple_assignable<_Tuple, tuple>::value
660227825Stheraven                      >::type
661227825Stheraven             >
662227825Stheraven        _LIBCPP_INLINE_VISIBILITY
663227825Stheraven        tuple&
664241900Sdim        operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
665227825Stheraven        {
666227825Stheraven            base_.operator=(_VSTD::forward<_Tuple>(__t));
667227825Stheraven            return *this;
668227825Stheraven        }
669227825Stheraven
670227825Stheraven    _LIBCPP_INLINE_VISIBILITY
671227825Stheraven    void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
672227825Stheraven        {base_.swap(__t.base_);}
673227825Stheraven};
674227825Stheraven
675227825Stheraventemplate <>
676261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple<>
677227825Stheraven{
678227825Stheravenpublic:
679227825Stheraven    _LIBCPP_INLINE_VISIBILITY
680241900Sdim    _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
681227825Stheraven    template <class _Alloc>
682227825Stheraven    _LIBCPP_INLINE_VISIBILITY
683241900Sdim        tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
684227825Stheraven    template <class _Alloc>
685227825Stheraven    _LIBCPP_INLINE_VISIBILITY
686241900Sdim        tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
687232924Stheraven    template <class _Up>
688227825Stheraven    _LIBCPP_INLINE_VISIBILITY
689241900Sdim        tuple(array<_Up, 0>) _NOEXCEPT {}
690232924Stheraven    template <class _Alloc, class _Up>
691227825Stheraven    _LIBCPP_INLINE_VISIBILITY
692241900Sdim        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
693227825Stheraven    _LIBCPP_INLINE_VISIBILITY
694227825Stheraven    void swap(tuple&) _NOEXCEPT {}
695227825Stheraven};
696227825Stheraven
697227825Stheraventemplate <class ..._Tp>
698227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
699227825Stheraventypename enable_if
700227825Stheraven<
701227825Stheraven    __all<__is_swappable<_Tp>::value...>::value,
702227825Stheraven    void
703227825Stheraven>::type
704227825Stheravenswap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
705227825Stheraven                 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
706227825Stheraven    {__t.swap(__u);}
707227825Stheraven
708227825Stheraven// get
709227825Stheraven
710227825Stheraventemplate <size_t _Ip, class ..._Tp>
711261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
712227825Stheraventypename tuple_element<_Ip, tuple<_Tp...> >::type&
713232924Stheravenget(tuple<_Tp...>& __t) _NOEXCEPT
714227825Stheraven{
715227825Stheraven    typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
716227825Stheraven    return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
717227825Stheraven}
718227825Stheraven
719227825Stheraventemplate <size_t _Ip, class ..._Tp>
720261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
721227825Stheravenconst typename tuple_element<_Ip, tuple<_Tp...> >::type&
722232924Stheravenget(const tuple<_Tp...>& __t) _NOEXCEPT
723227825Stheraven{
724227825Stheraven    typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
725227825Stheraven    return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
726227825Stheraven}
727227825Stheraven
728227825Stheraventemplate <size_t _Ip, class ..._Tp>
729261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
730227825Stheraventypename tuple_element<_Ip, tuple<_Tp...> >::type&&
731232924Stheravenget(tuple<_Tp...>&& __t) _NOEXCEPT
732227825Stheraven{
733227825Stheraven    typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
734227825Stheraven    return static_cast<type&&>(
735227825Stheraven             static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
736227825Stheraven}
737227825Stheraven
738261272Sdim#if _LIBCPP_STD_VER > 11
739261272Sdim// get by type
740261272Sdimtemplate <typename _T1, size_t _Idx, typename... _Args>
741261272Sdimstruct __find_exactly_one_t_helper;
742261272Sdim
743261272Sdim// -- find exactly one
744261272Sdimtemplate <typename _T1, size_t _Idx, typename... _Args>
745261272Sdimstruct __find_exactly_one_t_checker {
746261272Sdim    static constexpr size_t value = _Idx;
747261272Sdim//  Check the rest of the list to make sure there's only one
748261272Sdim    static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
749261272Sdim    };
750261272Sdim
751261272Sdim
752261272Sdimtemplate <typename _T1, size_t _Idx>
753261272Sdimstruct __find_exactly_one_t_helper <_T1, _Idx> {
754261272Sdim    static constexpr size_t value = -1;
755261272Sdim    };
756261272Sdim
757261272Sdimtemplate <typename _T1, size_t _Idx, typename _Head, typename... _Args>
758261272Sdimstruct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
759261272Sdim    static constexpr size_t value =
760261272Sdim        std::conditional<
761261272Sdim            std::is_same<_T1, _Head>::value,
762261272Sdim            __find_exactly_one_t_checker<_T1, _Idx,   _Args...>,
763261272Sdim            __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
764261272Sdim        >::type::value;
765261272Sdim    };
766261272Sdim
767261272Sdimtemplate <typename _T1, typename... _Args>
768261272Sdimstruct __find_exactly_one_t {
769261272Sdim    static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
770261272Sdim    static_assert ( value != -1, "type not found in type list" );
771261272Sdim    };
772261272Sdim
773261272Sdimtemplate <class _T1, class... _Args>
774261272Sdiminline _LIBCPP_INLINE_VISIBILITY
775261272Sdimconstexpr _T1& get(tuple<_Args...>& __tup) noexcept
776261272Sdim{
777261272Sdim    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
778261272Sdim}
779261272Sdim
780261272Sdimtemplate <class _T1, class... _Args>
781261272Sdiminline _LIBCPP_INLINE_VISIBILITY
782261272Sdimconstexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
783261272Sdim{
784261272Sdim    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
785261272Sdim}
786261272Sdim
787261272Sdimtemplate <class _T1, class... _Args>
788261272Sdiminline _LIBCPP_INLINE_VISIBILITY
789261272Sdimconstexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
790261272Sdim{
791261272Sdim    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
792261272Sdim}
793261272Sdim
794261272Sdim#endif
795261272Sdim
796227825Stheraven// tie
797227825Stheraven
798227825Stheraventemplate <class ..._Tp>
799227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
800227825Stheraventuple<_Tp&...>
801241900Sdimtie(_Tp&... __t) _NOEXCEPT
802227825Stheraven{
803227825Stheraven    return tuple<_Tp&...>(__t...);
804227825Stheraven}
805227825Stheraven
806227825Stheraventemplate <class _Up>
807227825Stheravenstruct __ignore_t
808227825Stheraven{
809227825Stheraven    template <class _Tp>
810227825Stheraven        _LIBCPP_INLINE_VISIBILITY
811227825Stheraven        const __ignore_t& operator=(_Tp&&) const {return *this;}
812227825Stheraven};
813227825Stheraven
814227825Stheravennamespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
815227825Stheraven
816261272Sdimtemplate <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
817227825Stheraven
818227825Stheraventemplate <class _Tp>
819227825Stheravenstruct ___make_tuple_return
820227825Stheraven{
821227825Stheraven    typedef _Tp type;
822227825Stheraven};
823227825Stheraven
824227825Stheraventemplate <class _Tp>
825227825Stheravenstruct ___make_tuple_return<reference_wrapper<_Tp> >
826227825Stheraven{
827227825Stheraven    typedef _Tp& type;
828227825Stheraven};
829227825Stheraven
830227825Stheraventemplate <class _Tp>
831227825Stheravenstruct __make_tuple_return
832227825Stheraven{
833227825Stheraven    typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
834227825Stheraven};
835227825Stheraven
836227825Stheraventemplate <class... _Tp>
837261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
838227825Stheraventuple<typename __make_tuple_return<_Tp>::type...>
839227825Stheravenmake_tuple(_Tp&&... __t)
840227825Stheraven{
841227825Stheraven    return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
842227825Stheraven}
843227825Stheraven
844227825Stheraventemplate <class... _Tp>
845261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
846227825Stheraventuple<_Tp&&...>
847241900Sdimforward_as_tuple(_Tp&&... __t) _NOEXCEPT
848227825Stheraven{
849227825Stheraven    return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
850227825Stheraven}
851227825Stheraven
852232924Stheraventemplate <size_t _Ip>
853227825Stheravenstruct __tuple_equal
854227825Stheraven{
855227825Stheraven    template <class _Tp, class _Up>
856261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
857227825Stheraven    bool operator()(const _Tp& __x, const _Up& __y)
858227825Stheraven    {
859232924Stheraven        return __tuple_equal<_Ip - 1>()(__x, __y) && get<_Ip-1>(__x) == get<_Ip-1>(__y);
860227825Stheraven    }
861227825Stheraven};
862227825Stheraven
863227825Stheraventemplate <>
864227825Stheravenstruct __tuple_equal<0>
865227825Stheraven{
866227825Stheraven    template <class _Tp, class _Up>
867261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
868227825Stheraven    bool operator()(const _Tp&, const _Up&)
869227825Stheraven    {
870227825Stheraven        return true;
871227825Stheraven    }
872227825Stheraven};
873227825Stheraven
874227825Stheraventemplate <class ..._Tp, class ..._Up>
875261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
876227825Stheravenbool
877227825Stheravenoperator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
878227825Stheraven{
879227825Stheraven    return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
880227825Stheraven}
881227825Stheraven
882227825Stheraventemplate <class ..._Tp, class ..._Up>
883261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
884227825Stheravenbool
885227825Stheravenoperator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
886227825Stheraven{
887227825Stheraven    return !(__x == __y);
888227825Stheraven}
889227825Stheraven
890232924Stheraventemplate <size_t _Ip>
891227825Stheravenstruct __tuple_less
892227825Stheraven{
893227825Stheraven    template <class _Tp, class _Up>
894261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
895227825Stheraven    bool operator()(const _Tp& __x, const _Up& __y)
896227825Stheraven    {
897232924Stheraven        return __tuple_less<_Ip-1>()(__x, __y) ||
898232924Stheraven             (!__tuple_less<_Ip-1>()(__y, __x) && get<_Ip-1>(__x) < get<_Ip-1>(__y));
899227825Stheraven    }
900227825Stheraven};
901227825Stheraven
902227825Stheraventemplate <>
903227825Stheravenstruct __tuple_less<0>
904227825Stheraven{
905227825Stheraven    template <class _Tp, class _Up>
906261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
907227825Stheraven    bool operator()(const _Tp&, const _Up&)
908227825Stheraven    {
909227825Stheraven        return false;
910227825Stheraven    }
911227825Stheraven};
912227825Stheraven
913227825Stheraventemplate <class ..._Tp, class ..._Up>
914261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
915227825Stheravenbool
916227825Stheravenoperator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
917227825Stheraven{
918227825Stheraven    return __tuple_less<sizeof...(_Tp)>()(__x, __y);
919227825Stheraven}
920227825Stheraven
921227825Stheraventemplate <class ..._Tp, class ..._Up>
922261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
923227825Stheravenbool
924227825Stheravenoperator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
925227825Stheraven{
926227825Stheraven    return __y < __x;
927227825Stheraven}
928227825Stheraven
929227825Stheraventemplate <class ..._Tp, class ..._Up>
930261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
931227825Stheravenbool
932227825Stheravenoperator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
933227825Stheraven{
934227825Stheraven    return !(__x < __y);
935227825Stheraven}
936227825Stheraven
937227825Stheraventemplate <class ..._Tp, class ..._Up>
938261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
939227825Stheravenbool
940227825Stheravenoperator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
941227825Stheraven{
942227825Stheraven    return !(__y < __x);
943227825Stheraven}
944227825Stheraven
945227825Stheraven// tuple_cat
946227825Stheraven
947227825Stheraventemplate <class _Tp, class _Up> struct __tuple_cat_type;
948227825Stheraven
949227825Stheraventemplate <class ..._Ttypes, class ..._Utypes>
950227825Stheravenstruct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
951227825Stheraven{
952227825Stheraven    typedef tuple<_Ttypes..., _Utypes...> type;
953227825Stheraven};
954227825Stheraven
955227825Stheraventemplate <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
956227825Stheravenstruct __tuple_cat_return_1
957227825Stheraven{
958227825Stheraven};
959227825Stheraven
960227825Stheraventemplate <class ..._Types, class _Tuple0>
961227825Stheravenstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
962227825Stheraven{
963227825Stheraven    typedef typename __tuple_cat_type<tuple<_Types...>,
964227825Stheraven            typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
965227825Stheraven                                                                           type;
966227825Stheraven};
967227825Stheraven
968227825Stheraventemplate <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
969227825Stheravenstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
970227825Stheraven    : public __tuple_cat_return_1<
971227825Stheraven                 typename __tuple_cat_type<
972227825Stheraven                     tuple<_Types...>,
973227825Stheraven                     typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
974227825Stheraven                 >::type,
975227825Stheraven                 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
976227825Stheraven                 _Tuple1, _Tuples...>
977227825Stheraven{
978227825Stheraven};
979227825Stheraven
980227825Stheraventemplate <class ..._Tuples> struct __tuple_cat_return;
981227825Stheraven
982227825Stheraventemplate <class _Tuple0, class ..._Tuples>
983227825Stheravenstruct __tuple_cat_return<_Tuple0, _Tuples...>
984227825Stheraven    : public __tuple_cat_return_1<tuple<>,
985227825Stheraven         __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
986227825Stheraven                                                                     _Tuples...>
987227825Stheraven{
988227825Stheraven};
989227825Stheraven
990227825Stheraventemplate <>
991227825Stheravenstruct __tuple_cat_return<>
992227825Stheraven{
993227825Stheraven    typedef tuple<> type;
994227825Stheraven};
995227825Stheraven
996261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
997227825Stheraventuple<>
998227825Stheraventuple_cat()
999227825Stheraven{
1000227825Stheraven    return tuple<>();
1001227825Stheraven}
1002227825Stheraven
1003232924Stheraventemplate <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
1004227825Stheravenstruct __tuple_cat_return_ref_imp;
1005227825Stheraven
1006227825Stheraventemplate <class ..._Types, size_t ..._I0, class _Tuple0>
1007227825Stheravenstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
1008227825Stheraven{
1009227825Stheraven    typedef typename remove_reference<_Tuple0>::type _T0;
1010227825Stheraven    typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1011227825Stheraven                          typename tuple_element<_I0, _T0>::type>::type&&...> type;
1012227825Stheraven};
1013227825Stheraven
1014227825Stheraventemplate <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1015227825Stheravenstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1016227825Stheraven                                  _Tuple0, _Tuple1, _Tuples...>
1017227825Stheraven    : public __tuple_cat_return_ref_imp<
1018227825Stheraven         tuple<_Types..., typename __apply_cv<_Tuple0,
1019227825Stheraven               typename tuple_element<_I0,
1020227825Stheraven                  typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1021227825Stheraven         typename __make_tuple_indices<tuple_size<typename
1022227825Stheraven                                 remove_reference<_Tuple1>::type>::value>::type,
1023227825Stheraven         _Tuple1, _Tuples...>
1024227825Stheraven{
1025227825Stheraven};
1026227825Stheraven
1027227825Stheraventemplate <class _Tuple0, class ..._Tuples>
1028227825Stheravenstruct __tuple_cat_return_ref
1029227825Stheraven    : public __tuple_cat_return_ref_imp<tuple<>,
1030227825Stheraven               typename __make_tuple_indices<
1031227825Stheraven                        tuple_size<typename remove_reference<_Tuple0>::type>::value
1032227825Stheraven               >::type, _Tuple0, _Tuples...>
1033227825Stheraven{
1034227825Stheraven};
1035227825Stheraven
1036227825Stheraventemplate <class _Types, class _I0, class _J0>
1037227825Stheravenstruct __tuple_cat;
1038227825Stheraven
1039227825Stheraventemplate <class ..._Types, size_t ..._I0, size_t ..._J0>
1040227825Stheravenstruct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
1041227825Stheraven{
1042227825Stheraven    template <class _Tuple0>
1043261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1044227825Stheraven    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1045227825Stheraven    operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1046227825Stheraven    {
1047261272Sdim        return forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))...,
1048227825Stheraven                                      get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
1049227825Stheraven    }
1050227825Stheraven
1051227825Stheraven    template <class _Tuple0, class _Tuple1, class ..._Tuples>
1052261272Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1053227825Stheraven    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1054227825Stheraven    operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1055227825Stheraven    {
1056227825Stheraven        typedef typename remove_reference<_Tuple0>::type _T0;
1057227825Stheraven        typedef typename remove_reference<_Tuple1>::type _T1;
1058227825Stheraven        return __tuple_cat<
1059227825Stheraven           tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1060227825Stheraven           typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1061227825Stheraven           typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
1062261272Sdim                           (forward_as_tuple(
1063227825Stheraven                              _VSTD::forward<_Types>(get<_I0>(__t))...,
1064227825Stheraven                              get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
1065227825Stheraven                            ),
1066227825Stheraven                            _VSTD::forward<_Tuple1>(__t1),
1067227825Stheraven                            _VSTD::forward<_Tuples>(__tpls)...);
1068227825Stheraven    }
1069227825Stheraven};
1070227825Stheraven
1071227825Stheraventemplate <class _Tuple0, class... _Tuples>
1072261272Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1073227825Stheraventypename __tuple_cat_return<_Tuple0, _Tuples...>::type
1074227825Stheraventuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1075227825Stheraven{
1076227825Stheraven    typedef typename remove_reference<_Tuple0>::type _T0;
1077227825Stheraven    return __tuple_cat<tuple<>, __tuple_indices<>,
1078227825Stheraven                  typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
1079227825Stheraven                  (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1080227825Stheraven                                            _VSTD::forward<_Tuples>(__tpls)...);
1081227825Stheraven}
1082227825Stheraven
1083227825Stheraventemplate <class ..._Tp, class _Alloc>
1084261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
1085227825Stheraven    : true_type {};
1086227825Stheraven
1087227825Stheraventemplate <class _T1, class _T2>
1088227825Stheraventemplate <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1089227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1090227825Stheravenpair<_T1, _T2>::pair(piecewise_construct_t,
1091227825Stheraven                     tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1092227825Stheraven                     __tuple_indices<_I1...>, __tuple_indices<_I2...>)
1093227825Stheraven    :  first(_VSTD::forward<_Args1>(get<_I1>( __first_args))...),
1094227825Stheraven      second(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
1095227825Stheraven{
1096227825Stheraven}
1097227825Stheraven
1098227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1099227825Stheraven
1100227825Stheraven_LIBCPP_END_NAMESPACE_STD
1101227825Stheraven
1102227825Stheraven#endif  // _LIBCPP_TUPLE
1103