]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/tuple
Import libucl 20160812
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / tuple
1 // -*- C++ -*-
2 //===--------------------------- tuple ------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _LIBCPP_TUPLE
12 #define _LIBCPP_TUPLE
13
14 /*
15     tuple synopsis
16
17 namespace std
18 {
19
20 template <class... T>
21 class tuple {
22 public:
23     constexpr tuple();
24     explicit tuple(const T&...);  // constexpr in C++14
25     template <class... U>
26         explicit tuple(U&&...);  // constexpr in C++14
27     tuple(const tuple&) = default;
28     tuple(tuple&&) = default;
29     template <class... U>
30         tuple(const tuple<U...>&);  // constexpr in C++14
31     template <class... U>
32         tuple(tuple<U...>&&);  // constexpr in C++14
33     template <class U1, class U2>
34         tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
35     template <class U1, class U2>
36         tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++14
37
38     // allocator-extended constructors
39     template <class Alloc>
40         tuple(allocator_arg_t, const Alloc& a);
41     template <class Alloc>
42         tuple(allocator_arg_t, const Alloc& a, const T&...);
43     template <class Alloc, class... U>
44         tuple(allocator_arg_t, const Alloc& a, U&&...);
45     template <class Alloc>
46         tuple(allocator_arg_t, const Alloc& a, const tuple&);
47     template <class Alloc>
48         tuple(allocator_arg_t, const Alloc& a, tuple&&);
49     template <class Alloc, class... U>
50         tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
51     template <class Alloc, class... U>
52         tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
53     template <class Alloc, class U1, class U2>
54         tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
55     template <class Alloc, class U1, class U2>
56         tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
57
58     tuple& operator=(const tuple&);
59     tuple&
60         operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
61     template <class... U>
62         tuple& operator=(const tuple<U...>&);
63     template <class... U>
64         tuple& operator=(tuple<U...>&&);
65     template <class U1, class U2>
66         tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
67     template <class U1, class U2>
68         tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
69
70     void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
71 };
72
73 const unspecified ignore;
74
75 template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
76 template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
77 template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
78 template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
79   
80 // 20.4.1.4, tuple helper classes:
81 template <class T> class tuple_size; // undefined
82 template <class... T> class tuple_size<tuple<T...>>;
83 template <size_t I, class T> class tuple_element; // undefined
84 template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
85 template <size_t I, class T>
86   using tuple_element_t = typename tuple_element <I, T>::type; // C++14
87
88 // 20.4.1.5, element access:
89 template <size_t I, class... T>
90     typename tuple_element<I, tuple<T...>>::type&
91     get(tuple<T...>&) noexcept; // constexpr in C++14
92 template <size_t I, class... T>
93     const typename tuple_element<I, tuple<T...>>::type&
94     get(const tuple<T...>&) noexcept; // constexpr in C++14
95 template <size_t I, class... T>
96     typename tuple_element<I, tuple<T...>>::type&&
97     get(tuple<T...>&&) noexcept; // constexpr in C++14
98 template <size_t I, class... T>
99     const typename tuple_element<I, tuple<T...>>::type&&
100     get(const tuple<T...>&&) noexcept; // constexpr in C++14
101
102 template <class T1, class... T>
103     constexpr T1& get(tuple<T...>&) noexcept;  // C++14
104 template <class T1, class... T>
105     constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
106 template <class T1, class... T>
107     constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
108 template <class T1, class... T>
109     constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
110
111 // 20.4.1.6, relational operators:
112 template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
113 template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
114 template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
115 template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
116 template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
117 template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
118
119 template <class... Types, class Alloc>
120   struct uses_allocator<tuple<Types...>, Alloc>;
121
122 template <class... Types>
123   void
124   swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
125
126 }  // std
127
128 */
129
130 #include <__config>
131 #include <__tuple>
132 #include <cstddef>
133 #include <type_traits>
134 #include <__functional_base>
135 #include <utility>
136
137 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138 #pragma GCC system_header
139 #endif
140
141 _LIBCPP_BEGIN_NAMESPACE_STD
142
143 #ifndef _LIBCPP_HAS_NO_VARIADICS
144
145 // tuple_size
146
147 template <class ..._Tp>
148 class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
149     : public integral_constant<size_t, sizeof...(_Tp)>
150 {
151 };
152
153 // tuple_element
154
155 template <size_t _Ip, class ..._Tp>
156 class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
157 {
158 public:
159     typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
160 };
161
162 #if _LIBCPP_STD_VER > 11
163 template <size_t _Ip, class ..._Tp>
164 using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
165 #endif
166
167 // __tuple_leaf
168
169 template <size_t _Ip, class _Hp,
170           bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
171          >
172 class __tuple_leaf;
173
174 template <size_t _Ip, class _Hp, bool _Ep>
175 inline _LIBCPP_INLINE_VISIBILITY
176 void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
177     _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
178 {
179     swap(__x.get(), __y.get());
180 }
181
182 template <size_t _Ip, class _Hp, bool>
183 class __tuple_leaf
184 {
185     _Hp value;
186
187     __tuple_leaf& operator=(const __tuple_leaf&);
188 public:
189     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
190              _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
191        {static_assert(!is_reference<_Hp>::value,
192               "Attempted to default construct a reference element in a tuple");}
193
194     template <class _Alloc>
195         _LIBCPP_INLINE_VISIBILITY
196         __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
197             : value()
198         {static_assert(!is_reference<_Hp>::value,
199               "Attempted to default construct a reference element in a tuple");}
200
201     template <class _Alloc>
202         _LIBCPP_INLINE_VISIBILITY
203         __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
204             : value(allocator_arg_t(), __a)
205         {static_assert(!is_reference<_Hp>::value,
206               "Attempted to default construct a reference element in a tuple");}
207
208     template <class _Alloc>
209         _LIBCPP_INLINE_VISIBILITY
210         __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
211             : value(__a)
212         {static_assert(!is_reference<_Hp>::value,
213               "Attempted to default construct a reference element in a tuple");}
214
215     template <class _Tp,
216               class = typename enable_if<
217                   __lazy_and<
218                       __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
219                     , is_constructible<_Hp, _Tp>
220                     >::value
221                 >::type
222             >
223         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
224         explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
225             : value(_VSTD::forward<_Tp>(__t))
226         {static_assert(!is_reference<_Hp>::value ||
227                        (is_lvalue_reference<_Hp>::value &&
228                         (is_lvalue_reference<_Tp>::value ||
229                          is_same<typename remove_reference<_Tp>::type,
230                                  reference_wrapper<
231                                     typename remove_reference<_Hp>::type
232                                  >
233                                 >::value)) ||
234                         (is_rvalue_reference<_Hp>::value &&
235                          !is_lvalue_reference<_Tp>::value),
236        "Attempted to construct a reference element in a tuple with an rvalue");}
237
238     template <class _Tp, class _Alloc>
239         _LIBCPP_INLINE_VISIBILITY
240         explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
241             : value(_VSTD::forward<_Tp>(__t))
242         {static_assert(!is_lvalue_reference<_Hp>::value ||
243                        (is_lvalue_reference<_Hp>::value &&
244                         (is_lvalue_reference<_Tp>::value ||
245                          is_same<typename remove_reference<_Tp>::type,
246                                  reference_wrapper<
247                                     typename remove_reference<_Hp>::type
248                                  >
249                                 >::value)),
250        "Attempted to construct a reference element in a tuple with an rvalue");}
251
252     template <class _Tp, class _Alloc>
253         _LIBCPP_INLINE_VISIBILITY
254         explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
255             : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
256         {static_assert(!is_lvalue_reference<_Hp>::value ||
257                        (is_lvalue_reference<_Hp>::value &&
258                         (is_lvalue_reference<_Tp>::value ||
259                          is_same<typename remove_reference<_Tp>::type,
260                                  reference_wrapper<
261                                     typename remove_reference<_Hp>::type
262                                  >
263                                 >::value)),
264        "Attempted to construct a reference element in a tuple with an rvalue");}
265
266     template <class _Tp, class _Alloc>
267         _LIBCPP_INLINE_VISIBILITY
268         explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
269             : value(_VSTD::forward<_Tp>(__t), __a)
270         {static_assert(!is_lvalue_reference<_Hp>::value ||
271                        (is_lvalue_reference<_Hp>::value &&
272                         (is_lvalue_reference<_Tp>::value ||
273                          is_same<typename remove_reference<_Tp>::type,
274                                  reference_wrapper<
275                                     typename remove_reference<_Hp>::type
276                                  >
277                                 >::value)),
278        "Attempted to construct a reference element in a tuple with an rvalue");}
279
280     __tuple_leaf(const __tuple_leaf& __t) = default;
281     __tuple_leaf(__tuple_leaf&& __t) = default;
282
283     template <class _Tp>
284         _LIBCPP_INLINE_VISIBILITY
285         __tuple_leaf&
286         operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
287         {
288             value = _VSTD::forward<_Tp>(__t);
289             return *this;
290         }
291
292     _LIBCPP_INLINE_VISIBILITY
293     int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
294     {
295         _VSTD::swap(*this, __t);
296         return 0;
297     }
298
299     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return value;}
300     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
301 };
302
303 template <size_t _Ip, class _Hp>
304 class __tuple_leaf<_Ip, _Hp, true>
305     : private _Hp
306 {
307
308     __tuple_leaf& operator=(const __tuple_leaf&);
309 public:
310     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
311              _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
312
313     template <class _Alloc>
314         _LIBCPP_INLINE_VISIBILITY
315         __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
316
317     template <class _Alloc>
318         _LIBCPP_INLINE_VISIBILITY
319         __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
320             : _Hp(allocator_arg_t(), __a) {}
321
322     template <class _Alloc>
323         _LIBCPP_INLINE_VISIBILITY
324         __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
325             : _Hp(__a) {}
326
327     template <class _Tp,
328               class = typename enable_if<
329                   __lazy_and<
330                         __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
331                       , is_constructible<_Hp, _Tp>
332                     >::value
333                 >::type
334             >
335         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
336         explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
337             : _Hp(_VSTD::forward<_Tp>(__t)) {}
338
339     template <class _Tp, class _Alloc>
340         _LIBCPP_INLINE_VISIBILITY
341         explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
342             : _Hp(_VSTD::forward<_Tp>(__t)) {}
343
344     template <class _Tp, class _Alloc>
345         _LIBCPP_INLINE_VISIBILITY
346         explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
347             : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
348
349     template <class _Tp, class _Alloc>
350         _LIBCPP_INLINE_VISIBILITY
351         explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
352             : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
353
354     __tuple_leaf(__tuple_leaf const &) = default;
355     __tuple_leaf(__tuple_leaf &&) = default;
356
357     template <class _Tp>
358         _LIBCPP_INLINE_VISIBILITY
359         __tuple_leaf&
360         operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
361         {
362             _Hp::operator=(_VSTD::forward<_Tp>(__t));
363             return *this;
364         }
365
366     _LIBCPP_INLINE_VISIBILITY
367     int
368     swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
369     {
370         _VSTD::swap(*this, __t);
371         return 0;
372     }
373
374     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
375     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
376 };
377
378 template <class ..._Tp>
379 _LIBCPP_INLINE_VISIBILITY
380 void __swallow(_Tp&&...) _NOEXCEPT {}
381
382 template <bool ..._Pred>
383 struct __all
384     : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
385 { };
386
387 template <class _Tp>
388 struct __all_default_constructible;
389
390 template <class ..._Tp>
391 struct __all_default_constructible<__tuple_types<_Tp...>>
392     : __all<is_default_constructible<_Tp>::value...>
393 { };
394
395 // __tuple_impl
396
397 template<class _Indx, class ..._Tp> struct __tuple_impl;
398
399 template<size_t ..._Indx, class ..._Tp>
400 struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
401     : public __tuple_leaf<_Indx, _Tp>...
402 {
403     _LIBCPP_INLINE_VISIBILITY
404     _LIBCPP_CONSTEXPR __tuple_impl()
405         _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
406
407     template <size_t ..._Uf, class ..._Tf,
408               size_t ..._Ul, class ..._Tl, class ..._Up>
409         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
410         explicit
411         __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
412                      __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
413                      _Up&&... __u)
414                      _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
415                                  __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
416             __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
417             __tuple_leaf<_Ul, _Tl>()...
418             {}
419
420     template <class _Alloc, size_t ..._Uf, class ..._Tf,
421               size_t ..._Ul, class ..._Tl, class ..._Up>
422         _LIBCPP_INLINE_VISIBILITY
423         explicit
424         __tuple_impl(allocator_arg_t, const _Alloc& __a,
425                      __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
426                      __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
427                      _Up&&... __u) :
428             __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
429             _VSTD::forward<_Up>(__u))...,
430             __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
431             {}
432
433     template <class _Tuple,
434               class = typename enable_if
435                       <
436                          __tuple_constructible<_Tuple, tuple<_Tp...> >::value
437                       >::type
438              >
439         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
440         __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
441                                        typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
442             : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
443                                        typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
444             {}
445
446     template <class _Alloc, class _Tuple,
447               class = typename enable_if
448                       <
449                          __tuple_convertible<_Tuple, tuple<_Tp...> >::value
450                       >::type
451              >
452         _LIBCPP_INLINE_VISIBILITY
453         __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
454             : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
455                                        typename __make_tuple_types<_Tuple>::type>::type>(), __a,
456                                        _VSTD::forward<typename tuple_element<_Indx,
457                                        typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
458             {}
459
460     template <class _Tuple>
461         _LIBCPP_INLINE_VISIBILITY
462         typename enable_if
463         <
464             __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
465             __tuple_impl&
466         >::type
467         operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
468                                        typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
469         {
470             __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
471                                        typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
472             return *this;
473         }
474
475     __tuple_impl(const __tuple_impl&) = default;
476     __tuple_impl(__tuple_impl&&) = default;
477
478     _LIBCPP_INLINE_VISIBILITY
479     __tuple_impl&
480     operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
481     {
482         __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
483         return *this;
484     }
485
486     _LIBCPP_INLINE_VISIBILITY
487     __tuple_impl&
488     operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
489     {
490         __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
491         return *this;
492     }
493
494     _LIBCPP_INLINE_VISIBILITY
495     void swap(__tuple_impl& __t)
496         _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
497     {
498         __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
499     }
500 };
501
502 template <class ..._Tp>
503 class _LIBCPP_TYPE_VIS_ONLY tuple
504 {
505     typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
506
507     base base_;
508
509     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
510         typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
511     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
512         const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
513     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
514         typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
515     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
516         const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
517 public:
518
519     template <bool _Dummy = true, class = typename enable_if<
520         __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
521     >::type>
522     _LIBCPP_INLINE_VISIBILITY
523     _LIBCPP_CONSTEXPR tuple()
524         _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
525
526     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
527     explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) 
528         : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
529                 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
530                 typename __make_tuple_indices<0>::type(),
531                 typename __make_tuple_types<tuple, 0>::type(),
532                 __t...
533                ) {}
534
535     template <class _Alloc>
536       _LIBCPP_INLINE_VISIBILITY
537       tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
538         : base_(allocator_arg_t(), __a,
539                 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
540                 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
541                 typename __make_tuple_indices<0>::type(),
542                 typename __make_tuple_types<tuple, 0>::type(),
543                 __t...
544                ) {}
545
546     template <class ..._Up,
547               typename enable_if
548                       <
549                          sizeof...(_Up) <= sizeof...(_Tp) &&
550                          __tuple_convertible
551                          <
552                             tuple<_Up...>,
553                             typename __make_tuple_types<tuple,
554                                      sizeof...(_Up) < sizeof...(_Tp) ?
555                                         sizeof...(_Up) :
556                                         sizeof...(_Tp)>::type
557                          >::value &&
558                          __all_default_constructible<
559                             typename __make_tuple_types<tuple, sizeof...(_Tp),
560                                 sizeof...(_Up) < sizeof...(_Tp) ?
561                                     sizeof...(_Up) :
562                                     sizeof...(_Tp)>::type
563                          >::value,
564                          bool
565                       >::type = false
566              >
567         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
568         tuple(_Up&&... __u)
569             _NOEXCEPT_((
570                 is_nothrow_constructible<base,
571                     typename __make_tuple_indices<sizeof...(_Up)>::type,
572                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
573                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
574                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
575                     _Up...
576                 >::value
577             ))
578             : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
579                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
580                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
581                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
582                     _VSTD::forward<_Up>(__u)...) {}
583
584     template <class ..._Up,
585               typename enable_if
586                       <
587                          sizeof...(_Up) <= sizeof...(_Tp) &&
588                          __tuple_constructible
589                          <
590                             tuple<_Up...>,
591                             typename __make_tuple_types<tuple,
592                                      sizeof...(_Up) < sizeof...(_Tp) ?
593                                         sizeof...(_Up) :
594                                         sizeof...(_Tp)>::type
595                          >::value &&
596                          !__tuple_convertible
597                          <
598                             tuple<_Up...>,
599                             typename __make_tuple_types<tuple,
600                                      sizeof...(_Up) < sizeof...(_Tp) ?
601                                         sizeof...(_Up) :
602                                         sizeof...(_Tp)>::type
603                          >::value &&
604                          __all_default_constructible<
605                             typename __make_tuple_types<tuple, sizeof...(_Tp),
606                                 sizeof...(_Up) < sizeof...(_Tp) ?
607                                     sizeof...(_Up) :
608                                     sizeof...(_Tp)>::type
609                          >::value,
610                          bool
611                       >::type =false
612              >
613         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
614         explicit
615         tuple(_Up&&... __u)
616             _NOEXCEPT_((
617                 is_nothrow_constructible<base,
618                     typename __make_tuple_indices<sizeof...(_Up)>::type,
619                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
620                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
621                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
622                     _Up...
623                 >::value
624             ))
625             : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
626                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
627                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
628                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
629                     _VSTD::forward<_Up>(__u)...) {}
630
631     template <class _Alloc, class ..._Up,
632               class = typename enable_if
633                       <
634                          sizeof...(_Up) <= sizeof...(_Tp) &&
635                          __tuple_convertible
636                          <
637                             tuple<_Up...>,
638                             typename __make_tuple_types<tuple,
639                                      sizeof...(_Up) < sizeof...(_Tp) ?
640                                         sizeof...(_Up) :
641                                         sizeof...(_Tp)>::type
642                          >::value &&
643                          __all_default_constructible<
644                             typename __make_tuple_types<tuple, sizeof...(_Tp),
645                                 sizeof...(_Up) < sizeof...(_Tp) ?
646                                     sizeof...(_Up) :
647                                     sizeof...(_Tp)>::type
648                          >::value
649                       >::type
650              >
651         _LIBCPP_INLINE_VISIBILITY
652         tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
653             : base_(allocator_arg_t(), __a,
654                     typename __make_tuple_indices<sizeof...(_Up)>::type(),
655                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
656                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
657                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
658                     _VSTD::forward<_Up>(__u)...) {}
659
660     template <class _Tuple,
661               typename enable_if
662                       <
663                          __tuple_convertible<_Tuple, tuple>::value,
664                          bool
665                       >::type = false
666              >
667         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
668         tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
669             : base_(_VSTD::forward<_Tuple>(__t)) {}
670
671     template <class _Tuple,
672               typename enable_if
673                       <
674                          __tuple_constructible<_Tuple, tuple>::value &&
675                          !__tuple_convertible<_Tuple, tuple>::value,
676                          bool
677                       >::type = false
678              >
679         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
680         explicit
681         tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
682             : base_(_VSTD::forward<_Tuple>(__t)) {}
683
684     template <class _Alloc, class _Tuple,
685               class = typename enable_if
686                       <
687                          __tuple_convertible<_Tuple, tuple>::value
688                       >::type
689              >
690         _LIBCPP_INLINE_VISIBILITY
691         tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
692             : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
693
694     template <class _Tuple,
695               class = typename enable_if
696                       <
697                          __tuple_assignable<_Tuple, tuple>::value
698                       >::type
699              >
700         _LIBCPP_INLINE_VISIBILITY
701         tuple&
702         operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
703         {
704             base_.operator=(_VSTD::forward<_Tuple>(__t));
705             return *this;
706         }
707
708     _LIBCPP_INLINE_VISIBILITY
709     void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
710         {base_.swap(__t.base_);}
711 };
712
713 template <>
714 class _LIBCPP_TYPE_VIS_ONLY tuple<>
715 {
716 public:
717     _LIBCPP_INLINE_VISIBILITY
718     _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
719     template <class _Alloc>
720     _LIBCPP_INLINE_VISIBILITY
721         tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
722     template <class _Alloc>
723     _LIBCPP_INLINE_VISIBILITY
724         tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
725     template <class _Up>
726     _LIBCPP_INLINE_VISIBILITY
727         tuple(array<_Up, 0>) _NOEXCEPT {}
728     template <class _Alloc, class _Up>
729     _LIBCPP_INLINE_VISIBILITY
730         tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
731     _LIBCPP_INLINE_VISIBILITY
732     void swap(tuple&) _NOEXCEPT {}
733 };
734
735 template <class ..._Tp>
736 inline _LIBCPP_INLINE_VISIBILITY
737 typename enable_if
738 <
739     __all<__is_swappable<_Tp>::value...>::value,
740     void
741 >::type
742 swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
743                  _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
744     {__t.swap(__u);}
745
746 // get
747
748 template <size_t _Ip, class ..._Tp>
749 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
750 typename tuple_element<_Ip, tuple<_Tp...> >::type&
751 get(tuple<_Tp...>& __t) _NOEXCEPT
752 {
753     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
754     return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
755 }
756
757 template <size_t _Ip, class ..._Tp>
758 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
759 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
760 get(const tuple<_Tp...>& __t) _NOEXCEPT
761 {
762     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
763     return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
764 }
765
766 template <size_t _Ip, class ..._Tp>
767 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
768 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
769 get(tuple<_Tp...>&& __t) _NOEXCEPT
770 {
771     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
772     return static_cast<type&&>(
773              static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
774 }
775
776 template <size_t _Ip, class ..._Tp>
777 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
778 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
779 get(const tuple<_Tp...>&& __t) _NOEXCEPT
780 {
781     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
782     return static_cast<const type&&>(
783              static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
784 }
785
786 #if _LIBCPP_STD_VER > 11
787 // get by type
788 template <typename _T1, size_t _Idx, typename... _Args>
789 struct __find_exactly_one_t_helper;
790
791 // -- find exactly one
792 template <typename _T1, size_t _Idx, typename... _Args>
793 struct __find_exactly_one_t_checker {
794     static constexpr size_t value = _Idx;
795 //  Check the rest of the list to make sure there's only one
796     static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
797     };
798
799
800 template <typename _T1, size_t _Idx>
801 struct __find_exactly_one_t_helper <_T1, _Idx> {
802     static constexpr size_t value = -1;
803     };
804
805 template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
806 struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
807     static constexpr size_t value =
808         std::conditional<
809             std::is_same<_T1, _Head>::value,
810             __find_exactly_one_t_checker<_T1, _Idx,   _Args...>,
811             __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
812         >::type::value;
813     };
814
815 template <typename _T1, typename... _Args>
816 struct __find_exactly_one_t {
817     static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
818     static_assert ( value != -1, "type not found in type list" );
819     };
820
821 template <class _T1, class... _Args>
822 inline _LIBCPP_INLINE_VISIBILITY
823 constexpr _T1& get(tuple<_Args...>& __tup) noexcept
824 {
825     return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
826 }
827
828 template <class _T1, class... _Args>
829 inline _LIBCPP_INLINE_VISIBILITY
830 constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
831 {
832     return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
833 }
834
835 template <class _T1, class... _Args>
836 inline _LIBCPP_INLINE_VISIBILITY
837 constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
838 {
839     return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
840 }
841
842 template <class _T1, class... _Args>
843 inline _LIBCPP_INLINE_VISIBILITY
844 constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
845 {
846     return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
847 }
848
849 #endif
850
851 // tie
852
853 template <class ..._Tp>
854 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855 tuple<_Tp&...>
856 tie(_Tp&... __t) _NOEXCEPT
857 {
858     return tuple<_Tp&...>(__t...);
859 }
860
861 template <class _Up>
862 struct __ignore_t
863 {
864     template <class _Tp>
865         _LIBCPP_INLINE_VISIBILITY
866         const __ignore_t& operator=(_Tp&&) const {return *this;}
867 };
868
869 namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
870
871 template <class _Tp>
872 struct __make_tuple_return_impl
873 {
874     typedef _Tp type;
875 };
876
877 template <class _Tp>
878 struct __make_tuple_return_impl<reference_wrapper<_Tp> >
879 {
880     typedef _Tp& type;
881 };
882
883 template <class _Tp>
884 struct __make_tuple_return
885 {
886     typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
887 };
888
889 template <class... _Tp>
890 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
891 tuple<typename __make_tuple_return<_Tp>::type...>
892 make_tuple(_Tp&&... __t)
893 {
894     return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
895 }
896
897 template <class... _Tp>
898 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
899 tuple<_Tp&&...>
900 forward_as_tuple(_Tp&&... __t) _NOEXCEPT
901 {
902     return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
903 }
904
905 template <size_t _Ip>
906 struct __tuple_equal
907 {
908     template <class _Tp, class _Up>
909     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
910     bool operator()(const _Tp& __x, const _Up& __y)
911     {
912         return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
913     }
914 };
915
916 template <>
917 struct __tuple_equal<0>
918 {
919     template <class _Tp, class _Up>
920     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
921     bool operator()(const _Tp&, const _Up&)
922     {
923         return true;
924     }
925 };
926
927 template <class ..._Tp, class ..._Up>
928 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
929 bool
930 operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
931 {
932     return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
933 }
934
935 template <class ..._Tp, class ..._Up>
936 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
937 bool
938 operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
939 {
940     return !(__x == __y);
941 }
942
943 template <size_t _Ip>
944 struct __tuple_less
945 {
946     template <class _Tp, class _Up>
947     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
948     bool operator()(const _Tp& __x, const _Up& __y)
949     {
950         const size_t __idx = tuple_size<_Tp>::value - _Ip;
951         if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
952             return true;
953         if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
954             return false;
955         return __tuple_less<_Ip-1>()(__x, __y);
956     }
957 };
958
959 template <>
960 struct __tuple_less<0>
961 {
962     template <class _Tp, class _Up>
963     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
964     bool operator()(const _Tp&, const _Up&)
965     {
966         return false;
967     }
968 };
969
970 template <class ..._Tp, class ..._Up>
971 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
972 bool
973 operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
974 {
975     return __tuple_less<sizeof...(_Tp)>()(__x, __y);
976 }
977
978 template <class ..._Tp, class ..._Up>
979 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
980 bool
981 operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
982 {
983     return __y < __x;
984 }
985
986 template <class ..._Tp, class ..._Up>
987 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
988 bool
989 operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
990 {
991     return !(__x < __y);
992 }
993
994 template <class ..._Tp, class ..._Up>
995 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
996 bool
997 operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
998 {
999     return !(__y < __x);
1000 }
1001
1002 // tuple_cat
1003
1004 template <class _Tp, class _Up> struct __tuple_cat_type;
1005
1006 template <class ..._Ttypes, class ..._Utypes>
1007 struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
1008 {
1009     typedef tuple<_Ttypes..., _Utypes...> type;
1010 };
1011
1012 template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1013 struct __tuple_cat_return_1
1014 {
1015 };
1016
1017 template <class ..._Types, class _Tuple0>
1018 struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1019 {
1020     typedef typename __tuple_cat_type<tuple<_Types...>,
1021             typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1022                                                                            type;
1023 };
1024
1025 template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1026 struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1027     : public __tuple_cat_return_1<
1028                  typename __tuple_cat_type<
1029                      tuple<_Types...>,
1030                      typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1031                  >::type,
1032                  __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1033                  _Tuple1, _Tuples...>
1034 {
1035 };
1036
1037 template <class ..._Tuples> struct __tuple_cat_return;
1038
1039 template <class _Tuple0, class ..._Tuples>
1040 struct __tuple_cat_return<_Tuple0, _Tuples...>
1041     : public __tuple_cat_return_1<tuple<>,
1042          __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1043                                                                      _Tuples...>
1044 {
1045 };
1046
1047 template <>
1048 struct __tuple_cat_return<>
1049 {
1050     typedef tuple<> type;
1051 };
1052
1053 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1054 tuple<>
1055 tuple_cat()
1056 {
1057     return tuple<>();
1058 }
1059
1060 template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
1061 struct __tuple_cat_return_ref_imp;
1062
1063 template <class ..._Types, size_t ..._I0, class _Tuple0>
1064 struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
1065 {
1066     typedef typename remove_reference<_Tuple0>::type _T0;
1067     typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1068                           typename tuple_element<_I0, _T0>::type>::type&&...> type;
1069 };
1070
1071 template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1072 struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1073                                   _Tuple0, _Tuple1, _Tuples...>
1074     : public __tuple_cat_return_ref_imp<
1075          tuple<_Types..., typename __apply_cv<_Tuple0,
1076                typename tuple_element<_I0,
1077                   typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1078          typename __make_tuple_indices<tuple_size<typename
1079                                  remove_reference<_Tuple1>::type>::value>::type,
1080          _Tuple1, _Tuples...>
1081 {
1082 };
1083
1084 template <class _Tuple0, class ..._Tuples>
1085 struct __tuple_cat_return_ref
1086     : public __tuple_cat_return_ref_imp<tuple<>,
1087                typename __make_tuple_indices<
1088                         tuple_size<typename remove_reference<_Tuple0>::type>::value
1089                >::type, _Tuple0, _Tuples...>
1090 {
1091 };
1092
1093 template <class _Types, class _I0, class _J0>
1094 struct __tuple_cat;
1095
1096 template <class ..._Types, size_t ..._I0, size_t ..._J0>
1097 struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
1098 {
1099     template <class _Tuple0>
1100     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1101     typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1102     operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1103     {
1104         return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1105                                       _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
1106     }
1107
1108     template <class _Tuple0, class _Tuple1, class ..._Tuples>
1109     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1110     typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1111     operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1112     {
1113         typedef typename remove_reference<_Tuple0>::type _T0;
1114         typedef typename remove_reference<_Tuple1>::type _T1;
1115         return __tuple_cat<
1116            tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1117            typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1118            typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
1119                            (forward_as_tuple(
1120                               _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1121                               _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
1122                             ),
1123                             _VSTD::forward<_Tuple1>(__t1),
1124                             _VSTD::forward<_Tuples>(__tpls)...);
1125     }
1126 };
1127
1128 template <class _Tuple0, class... _Tuples>
1129 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1130 typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1131 tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1132 {
1133     typedef typename remove_reference<_Tuple0>::type _T0;
1134     return __tuple_cat<tuple<>, __tuple_indices<>,
1135                   typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
1136                   (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1137                                             _VSTD::forward<_Tuples>(__tpls)...);
1138 }
1139
1140 template <class ..._Tp, class _Alloc>
1141 struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
1142     : true_type {};
1143
1144 template <class _T1, class _T2>
1145 template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1146 inline _LIBCPP_INLINE_VISIBILITY
1147 pair<_T1, _T2>::pair(piecewise_construct_t,
1148                      tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1149                      __tuple_indices<_I1...>, __tuple_indices<_I2...>)
1150     :  first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1151       second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
1152 {
1153 }
1154
1155 #endif  // _LIBCPP_HAS_NO_VARIADICS
1156
1157 _LIBCPP_END_NAMESPACE_STD
1158
1159 #endif  // _LIBCPP_TUPLE