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