blob: e134bdff5a60661c0793e408ea14d7c9667857ee [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
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
17namespace std
18{
19
20template <class... T>
21class tuple {
22public:
23 constexpr tuple();
24 explicit tuple(const T&...);
25 template <class... U>
26 explicit tuple(U&&...);
27 tuple(const tuple&) = default;
28 tuple(tuple&&);
29 template <class... U>
30 tuple(const tuple<U...>&);
31 template <class... U>
32 tuple(tuple<U...>&&);
33 template <class U1, class U2>
34 tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2
35 template <class U1, class U2>
36 tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2
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& operator=(tuple&&);
60 template <class... U>
61 tuple& operator=(const tuple<U...>&);
62 template <class... U>
63 tuple& operator=(tuple<U...>&&);
64 template <class U1, class U2>
65 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
66 template <class U1, class U2>
67 tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
68
69 void swap(tuple&);
70};
71
72const unspecified ignore;
73
74template <class... T> tuple<V...> make_tuple(T&&...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +000075template <class... T> tuple<ATypes...> forward_as_tuple(T&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000076template <class... T> tuple<T&...> tie(T&...);
77template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, const tuple<U...>&);
78template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, const tuple<U...>&);
79template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, tuple<U...>&&);
80template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, tuple<U...>&&);
81
82// 20.4.1.4, tuple helper classes:
83template <class T> class tuple_size; // undefined
84template <class... T> class tuple_size<tuple<T...>>;
85template <intsize_t I, class T> class tuple_element; // undefined
86template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
87
88// 20.4.1.5, element access:
89template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& get(tuple<T...>&);
90template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& get(const tuple<T...>&);
91
92// 20.4.1.6, relational operators:
93template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&);
94template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);
95template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&);
96template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);
97template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&);
98template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&);
99
100template <class... Types, class Alloc>
101 struct uses_allocator<tuple<Types...>, Alloc>;
102
103template <class... Types>
104 void swap(tuple<Types...>& x, tuple<Types...>& y);
105
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000106} // std
107
108*/
109
110#include <__config>
111#include <__tuple>
112#include <cstddef>
113#include <memory>
114#include <type_traits>
115
116#pragma GCC system_header
117
118_LIBCPP_BEGIN_NAMESPACE_STD
119
120#ifndef _LIBCPP_HAS_NO_VARIADICS
121
122// tuple_size
123
124template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000125class _LIBCPP_VISIBLE tuple_size<tuple<_Tp...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126 : public integral_constant<size_t, sizeof...(_Tp)>
127{
128};
129
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130// tuple_element
131
132template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000133class _LIBCPP_VISIBLE tuple_element<_Ip, tuple<_Tp...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134{
135public:
136 typedef typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
137};
138
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000139// __tuple_leaf
140
141template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value>
142class __tuple_leaf;
143
144template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000145inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
147{
148 swap(__x.get(), __y.get());
149}
150
151template <size_t _Ip, class _Hp, bool>
152class __tuple_leaf
153{
154 _Hp value;
155
156 __tuple_leaf& operator=(const __tuple_leaf&);
157public:
158 _LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value()
159 {static_assert(!is_reference<_Hp>::value,
160 "Attempted to default construct a reference element in a tuple");}
161
162 template <class _Alloc>
163 _LIBCPP_INLINE_VISIBILITY
164 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
165 : value()
166 {static_assert(!is_reference<_Hp>::value,
167 "Attempted to default construct a reference element in a tuple");}
168
169 template <class _Alloc>
170 _LIBCPP_INLINE_VISIBILITY
171 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
172 : value(allocator_arg_t(), __a)
173 {static_assert(!is_reference<_Hp>::value,
174 "Attempted to default construct a reference element in a tuple");}
175
176 template <class _Alloc>
177 _LIBCPP_INLINE_VISIBILITY
178 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
179 : value(__a)
180 {static_assert(!is_reference<_Hp>::value,
181 "Attempted to default construct a reference element in a tuple");}
182
Howard Hinnante049cc52010-09-27 17:54:17 +0000183 template <class _Tp,
184 class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185 _LIBCPP_INLINE_VISIBILITY
186 explicit __tuple_leaf(_Tp&& __t)
187 : value(_STD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000188 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000189 is_lvalue_reference<_Hp>::value &&
190 (is_lvalue_reference<_Tp>::value ||
191 is_same<typename remove_reference<_Tp>::type,
192 reference_wrapper<
193 typename remove_reference<_Hp>::type
194 >
Howard Hinnante049cc52010-09-27 17:54:17 +0000195 >::value) ||
196 (is_rvalue_reference<_Hp>::value &&
197 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 "Attempted to construct a reference element in a tuple with an rvalue");}
199
200 template <class _Tp, class _Alloc>
201 _LIBCPP_INLINE_VISIBILITY
202 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
203 : value(_STD::forward<_Tp>(__t))
204 {static_assert(!is_lvalue_reference<_Hp>::value ||
205 is_lvalue_reference<_Hp>::value &&
206 (is_lvalue_reference<_Tp>::value ||
207 is_same<typename remove_reference<_Tp>::type,
208 reference_wrapper<
209 typename remove_reference<_Hp>::type
210 >
211 >::value),
212 "Attempted to construct a reference element in a tuple with an rvalue");}
213
214 template <class _Tp, class _Alloc>
215 _LIBCPP_INLINE_VISIBILITY
216 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
217 : value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t))
218 {static_assert(!is_lvalue_reference<_Hp>::value ||
219 is_lvalue_reference<_Hp>::value &&
220 (is_lvalue_reference<_Tp>::value ||
221 is_same<typename remove_reference<_Tp>::type,
222 reference_wrapper<
223 typename remove_reference<_Hp>::type
224 >
225 >::value),
226 "Attempted to construct a reference element in a tuple with an rvalue");}
227
228 template <class _Tp, class _Alloc>
229 _LIBCPP_INLINE_VISIBILITY
230 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
231 : value(_STD::forward<_Tp>(__t), __a)
232 {static_assert(!is_lvalue_reference<_Hp>::value ||
233 is_lvalue_reference<_Hp>::value &&
234 (is_lvalue_reference<_Tp>::value ||
235 is_same<typename remove_reference<_Tp>::type,
236 reference_wrapper<
237 typename remove_reference<_Hp>::type
238 >
239 >::value),
240 "Attempted to construct a reference element in a tuple with an rvalue");}
241
Howard Hinnante049cc52010-09-27 17:54:17 +0000242 __tuple_leaf(const __tuple_leaf& __t)
243 : value(__t.get())
244 {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
245
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246 template <class _Tp>
247 _LIBCPP_INLINE_VISIBILITY
248 explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
249 : value(__t.get()) {}
250
251 template <class _Tp>
252 _LIBCPP_INLINE_VISIBILITY
253 __tuple_leaf&
254 operator=(_Tp&& __t)
255 {
256 value = _STD::forward<_Tp>(__t);
257 return *this;
258 }
259
260 _LIBCPP_INLINE_VISIBILITY
261 int swap(__tuple_leaf& __t)
262 {
263 _STD::swap(*this, __t);
264 return 0;
265 }
266
267 _LIBCPP_INLINE_VISIBILITY _Hp& get() {return value;}
268 _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;}
269};
270
271template <size_t _Ip, class _Hp>
272class __tuple_leaf<_Ip, _Hp, true>
273 : private _Hp
274{
275
276 __tuple_leaf& operator=(const __tuple_leaf&);
277public:
278 _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {}
279
280 template <class _Alloc>
281 _LIBCPP_INLINE_VISIBILITY
282 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
283
284 template <class _Alloc>
285 _LIBCPP_INLINE_VISIBILITY
286 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
287 : _Hp(allocator_arg_t(), __a) {}
288
289 template <class _Alloc>
290 _LIBCPP_INLINE_VISIBILITY
291 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
292 : _Hp(__a) {}
293
Howard Hinnante049cc52010-09-27 17:54:17 +0000294 template <class _Tp,
295 class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296 _LIBCPP_INLINE_VISIBILITY
297 explicit __tuple_leaf(_Tp&& __t)
298 : _Hp(_STD::forward<_Tp>(__t)) {}
299
300 template <class _Tp, class _Alloc>
301 _LIBCPP_INLINE_VISIBILITY
302 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
303 : _Hp(_STD::forward<_Tp>(__t)) {}
304
305 template <class _Tp, class _Alloc>
306 _LIBCPP_INLINE_VISIBILITY
307 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
308 : _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {}
309
310 template <class _Tp, class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
313 : _Hp(_STD::forward<_Tp>(__t), __a) {}
314
315 template <class _Tp>
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
318 : _Hp(__t.get()) {}
319
320 template <class _Tp>
321 _LIBCPP_INLINE_VISIBILITY
322 __tuple_leaf&
323 operator=(_Tp&& __t)
324 {
325 _Hp::operator=(_STD::forward<_Tp>(__t));
326 return *this;
327 }
328
329 _LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t)
330 {
331 _STD::swap(*this, __t);
332 return 0;
333 }
334
335 _LIBCPP_INLINE_VISIBILITY _Hp& get() {return static_cast<_Hp&>(*this);}
336 _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);}
337};
338
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000339template <class ..._Tp>
340_LIBCPP_INLINE_VISIBILITY
341void __swallow(_Tp&&...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343// __tuple_impl
344
345template<class _Indx, class ..._Tp> struct __tuple_impl;
346
347template<size_t ..._Indx, class ..._Tp>
348struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
349 : public __tuple_leaf<_Indx, _Tp>...
350{
351 template <size_t ..._Uf, class ..._Tf,
352 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 explicit
355 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
356 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
357 _Up&&... __u) :
358 __tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))...,
359 __tuple_leaf<_Ul, _Tl>()...
360 {}
361
362 template <class _Alloc, size_t ..._Uf, class ..._Tf,
363 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 explicit
366 __tuple_impl(allocator_arg_t, const _Alloc& __a,
367 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
368 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
369 _Up&&... __u) :
370 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
371 _STD::forward<_Up>(__u))...,
372 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
373 {}
374
375 template <class _Tuple,
376 class = typename enable_if
377 <
378 __tuple_convertible<_Tuple, tuple<_Tp...>>::value
379 >::type
380 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 __tuple_impl(_Tuple&& __t)
383 : __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx,
384 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
385 {}
386
387 template <class _Alloc, class _Tuple,
388 class = typename enable_if
389 <
390 __tuple_convertible<_Tuple, tuple<_Tp...>>::value
391 >::type
392 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
395 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000396 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 _STD::forward<typename tuple_element<_Indx,
398 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
399 {}
400
401 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403 typename enable_if
404 <
405 __tuple_assignable<_Tuple, tuple<_Tp...>>::value,
406 __tuple_impl&
407 >::type
408 operator=(_Tuple&& __t)
409 {
410 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx,
411 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...);
412 return *this;
413 }
414
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 void swap(__tuple_impl& __t)
417 {
418 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
419 }
420};
421
422template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000423class _LIBCPP_VISIBLE tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424{
425 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
426
427 base base_;
428
429 template <size_t _Jp, class ..._Up> friend
430 typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&);
431 template <size_t _Jp, class ..._Up> friend
432 const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&);
433public:
434
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436 explicit tuple(const _Tp& ... __t)
437 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
438 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
439 typename __make_tuple_indices<0>::type(),
440 typename __make_tuple_types<tuple, 0>::type(),
441 __t...
442 ) {}
443
444 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
447 : base_(allocator_arg_t(), __a,
448 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
449 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
450 typename __make_tuple_indices<0>::type(),
451 typename __make_tuple_types<tuple, 0>::type(),
452 __t...
453 ) {}
454
455 template <class ..._Up,
456 class = typename enable_if
457 <
458 sizeof...(_Up) <= sizeof...(_Tp) &&
459 __tuple_convertible
460 <
461 tuple<_Up...>,
462 typename __make_tuple_types<tuple,
463 sizeof...(_Up) < sizeof...(_Tp) ?
464 sizeof...(_Up) :
465 sizeof...(_Tp)>::type
466 >::value
467 >::type
468 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 explicit
471 tuple(_Up&&... __u)
472 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
473 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
474 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
475 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
476 _STD::forward<_Up>(__u)...) {}
477
478 template <class _Alloc, class ..._Up,
479 class = typename enable_if
480 <
481 sizeof...(_Up) <= sizeof...(_Tp) &&
482 __tuple_convertible
483 <
484 tuple<_Up...>,
485 typename __make_tuple_types<tuple,
486 sizeof...(_Up) < sizeof...(_Tp) ?
487 sizeof...(_Up) :
488 sizeof...(_Tp)>::type
489 >::value
490 >::type
491 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
494 : base_(allocator_arg_t(), __a,
495 typename __make_tuple_indices<sizeof...(_Up)>::type(),
496 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
497 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
498 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
499 _STD::forward<_Up>(__u)...) {}
500
501 template <class _Tuple,
502 class = typename enable_if
503 <
504 __tuple_convertible<_Tuple, tuple>::value
505 >::type
506 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508 tuple(_Tuple&& __t)
509 : base_(_STD::forward<_Tuple>(__t)) {}
510
511 template <class _Alloc, class _Tuple,
512 class = typename enable_if
513 <
514 __tuple_convertible<_Tuple, tuple>::value
515 >::type
516 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
519 : base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {}
520
521 template <class _Tuple,
522 class = typename enable_if
523 <
524 __tuple_assignable<_Tuple, tuple>::value
525 >::type
526 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 tuple&
529 operator=(_Tuple&& __t)
530 {
531 base_.operator=(_STD::forward<_Tuple>(__t));
532 return *this;
533 }
534
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 void swap(tuple& __t) {base_.swap(__t.base_);}
537};
538
539template <>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000540class _LIBCPP_VISIBLE tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541{
542public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 tuple() {}
545 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 tuple(allocator_arg_t, const _Alloc&) {}
548 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550 tuple(allocator_arg_t, const _Alloc&, const tuple&) {}
551 template <class _U>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 tuple(array<_U, 0>) {}
554 template <class _Alloc, class _U>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556 tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 void swap(tuple&) {}
559};
560
561template <class ..._Tp>
562inline _LIBCPP_INLINE_VISIBILITY
563void
564swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);}
565
566// get
567
568template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570typename tuple_element<_Ip, tuple<_Tp...>>::type&
571get(tuple<_Tp...>& __t)
572{
573 typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
574 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
575}
576
577template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579const typename tuple_element<_Ip, tuple<_Tp...>>::type&
580get(const tuple<_Tp...>& __t)
581{
582 typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
583 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
584}
585
586// tie
587
588template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590tuple<_Tp&...>
591tie(_Tp&... __t)
592{
593 return tuple<_Tp&...>(__t...);
594}
595
596template <class _Up>
597struct __ignore_t
598{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 __ignore_t() {}
601 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603 __ignore_t(_Tp&&) {}
604 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606 const __ignore_t& operator=(_Tp&&) const {return *this;}
607};
608
609namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
610
611template <class _Tp> class reference_wrapper;
612
613template <class _Tp>
614struct ___make_tuple_return
615{
616 typedef _Tp type;
617};
618
619template <class _Tp>
620struct ___make_tuple_return<reference_wrapper<_Tp>>
621{
622 typedef _Tp& type;
623};
624
625template <class _Tp>
626struct __make_tuple_return
627{
628 typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
629};
630
631template <class... _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633tuple<typename __make_tuple_return<_Tp>::type...>
634make_tuple(_Tp&&... __t)
635{
636 return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...);
637}
638
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000639template <class... _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000641tuple<_Tp&&...>
642forward_as_tuple(_Tp&&... __t)
643{
644 return tuple<_Tp&&...>(_STD::forward<_Tp>(__t)...);
645}
646
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647template <size_t _I>
648struct __tuple_equal
649{
650 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652 bool operator()(const _Tp& __x, const _Up& __y)
653 {
654 return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y);
655 }
656};
657
658template <>
659struct __tuple_equal<0>
660{
661 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 bool operator()(const _Tp&, const _Up&)
664 {
665 return true;
666 }
667};
668
669template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671bool
672operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
673{
674 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
675}
676
677template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000678inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679bool
680operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
681{
682 return !(__x == __y);
683}
684
685template <size_t _I>
686struct __tuple_less
687{
688 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690 bool operator()(const _Tp& __x, const _Up& __y)
691 {
692 return __tuple_less<_I-1>()(__x, __y) ||
693 (!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y));
694 }
695};
696
697template <>
698struct __tuple_less<0>
699{
700 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 bool operator()(const _Tp&, const _Up&)
703 {
704 return false;
705 }
706};
707
708template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710bool
711operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
712{
713 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
714}
715
716template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000717inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718bool
719operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
720{
721 return __y < __x;
722}
723
724template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000725inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726bool
727operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
728{
729 return !(__x < __y);
730}
731
732template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000733inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734bool
735operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
736{
737 return !(__y < __x);
738}
739
740// tuple_cat
741
742template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000743inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744tuple<_Tp..., _Up...>
745__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
746{
747 return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...);
748}
749
750template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000751inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752tuple<_Tp..., _Up...>
753tuple_cat(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
754{
755 return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
756 __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
757}
758
759template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761tuple<_Tp..., _Up...>
762__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
763{
764 return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...);
765}
766
767template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000768inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769tuple<_Tp..., _Up...>
770tuple_cat(tuple<_Tp...>&& __x, const tuple<_Up...>& __y)
771{
772 return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
773 __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
774}
775
776template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000777inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778tuple<_Tp..., _Up...>
779__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
780{
781 return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...);
782}
783
784template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000785inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786tuple<_Tp..., _Up...>
787tuple_cat(const tuple<_Tp...>& __x, tuple<_Up...>&& __y)
788{
789 return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
790 _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
791}
792
793template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000794inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795tuple<_Tp..., _Up...>
796__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
797{
798 return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...);
799}
800
801template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803tuple<_Tp..., _Up...>
804tuple_cat(tuple<_Tp...>&& __x, tuple<_Up...>&& __y)
805{
806 return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
807 _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
808}
809
810template <class ..._Tp, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000811struct _LIBCPP_VISIBLE uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 : true_type {};
813
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814template <class _T1, class _T2>
815template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
816inline _LIBCPP_INLINE_VISIBILITY
817pair<_T1, _T2>::pair(piecewise_construct_t,
818 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
819 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
820 : first(_STD::forward<_Args1>(get<_I1>( __first_args))...),
821 second(_STD::forward<_Args2>(get<_I2>(__second_args))...)
822{
823}
824
Howard Hinnant324bb032010-08-22 00:02:43 +0000825#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826
827_LIBCPP_END_NAMESPACE_STD
828
829#endif // _LIBCPP_TUPLE