blob: 5ec0f819c15d0fc35cd6fb18b49c4745e3f32197 [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
130template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000131class _LIBCPP_VISIBLE tuple_size<const tuple<_Tp...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132 : public integral_constant<size_t, sizeof...(_Tp)>
133{
134};
135
136// tuple_element
137
138template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000139class _LIBCPP_VISIBLE tuple_element<_Ip, tuple<_Tp...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140{
141public:
142 typedef typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
143};
144
145template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000146class _LIBCPP_VISIBLE tuple_element<_Ip, const tuple<_Tp...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000147{
148public:
149 typedef const typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
150};
151
152// __tuple_leaf
153
154template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value>
155class __tuple_leaf;
156
157template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000158inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
160{
161 swap(__x.get(), __y.get());
162}
163
164template <size_t _Ip, class _Hp, bool>
165class __tuple_leaf
166{
167 _Hp value;
168
169 __tuple_leaf& operator=(const __tuple_leaf&);
170public:
171 _LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value()
172 {static_assert(!is_reference<_Hp>::value,
173 "Attempted to default construct a reference element in a tuple");}
174
175 template <class _Alloc>
176 _LIBCPP_INLINE_VISIBILITY
177 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
178 : value()
179 {static_assert(!is_reference<_Hp>::value,
180 "Attempted to default construct a reference element in a tuple");}
181
182 template <class _Alloc>
183 _LIBCPP_INLINE_VISIBILITY
184 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
185 : value(allocator_arg_t(), __a)
186 {static_assert(!is_reference<_Hp>::value,
187 "Attempted to default construct a reference element in a tuple");}
188
189 template <class _Alloc>
190 _LIBCPP_INLINE_VISIBILITY
191 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
192 : value(__a)
193 {static_assert(!is_reference<_Hp>::value,
194 "Attempted to default construct a reference element in a tuple");}
195
196 template <class _Tp>
197 _LIBCPP_INLINE_VISIBILITY
198 explicit __tuple_leaf(_Tp&& __t)
199 : value(_STD::forward<_Tp>(__t))
200 {static_assert(!is_lvalue_reference<_Hp>::value ||
201 is_lvalue_reference<_Hp>::value &&
202 (is_lvalue_reference<_Tp>::value ||
203 is_same<typename remove_reference<_Tp>::type,
204 reference_wrapper<
205 typename remove_reference<_Hp>::type
206 >
207 >::value),
208 "Attempted to construct a reference element in a tuple with an rvalue");}
209
210 template <class _Tp, class _Alloc>
211 _LIBCPP_INLINE_VISIBILITY
212 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
213 : value(_STD::forward<_Tp>(__t))
214 {static_assert(!is_lvalue_reference<_Hp>::value ||
215 is_lvalue_reference<_Hp>::value &&
216 (is_lvalue_reference<_Tp>::value ||
217 is_same<typename remove_reference<_Tp>::type,
218 reference_wrapper<
219 typename remove_reference<_Hp>::type
220 >
221 >::value),
222 "Attempted to construct a reference element in a tuple with an rvalue");}
223
224 template <class _Tp, class _Alloc>
225 _LIBCPP_INLINE_VISIBILITY
226 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
227 : value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t))
228 {static_assert(!is_lvalue_reference<_Hp>::value ||
229 is_lvalue_reference<_Hp>::value &&
230 (is_lvalue_reference<_Tp>::value ||
231 is_same<typename remove_reference<_Tp>::type,
232 reference_wrapper<
233 typename remove_reference<_Hp>::type
234 >
235 >::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, 2>, const _Alloc& __a, _Tp&& __t)
241 : value(_STD::forward<_Tp>(__t), __a)
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>
253 _LIBCPP_INLINE_VISIBILITY
254 explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
255 : value(__t.get()) {}
256
257 template <class _Tp>
258 _LIBCPP_INLINE_VISIBILITY
259 __tuple_leaf&
260 operator=(_Tp&& __t)
261 {
262 value = _STD::forward<_Tp>(__t);
263 return *this;
264 }
265
266 _LIBCPP_INLINE_VISIBILITY
267 int swap(__tuple_leaf& __t)
268 {
269 _STD::swap(*this, __t);
270 return 0;
271 }
272
273 _LIBCPP_INLINE_VISIBILITY _Hp& get() {return value;}
274 _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;}
275};
276
277template <size_t _Ip, class _Hp>
278class __tuple_leaf<_Ip, _Hp, true>
279 : private _Hp
280{
281
282 __tuple_leaf& operator=(const __tuple_leaf&);
283public:
284 _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {}
285
286 template <class _Alloc>
287 _LIBCPP_INLINE_VISIBILITY
288 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
289
290 template <class _Alloc>
291 _LIBCPP_INLINE_VISIBILITY
292 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
293 : _Hp(allocator_arg_t(), __a) {}
294
295 template <class _Alloc>
296 _LIBCPP_INLINE_VISIBILITY
297 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
298 : _Hp(__a) {}
299
300 template <class _Tp>
301 _LIBCPP_INLINE_VISIBILITY
302 explicit __tuple_leaf(_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, 0>, const _Alloc&, _Tp&& __t)
308 : _Hp(_STD::forward<_Tp>(__t)) {}
309
310 template <class _Tp, class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
313 : _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {}
314
315 template <class _Tp, class _Alloc>
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
318 : _Hp(_STD::forward<_Tp>(__t), __a) {}
319
320 template <class _Tp>
321 _LIBCPP_INLINE_VISIBILITY
322 explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
323 : _Hp(__t.get()) {}
324
325 template <class _Tp>
326 _LIBCPP_INLINE_VISIBILITY
327 __tuple_leaf&
328 operator=(_Tp&& __t)
329 {
330 _Hp::operator=(_STD::forward<_Tp>(__t));
331 return *this;
332 }
333
334 _LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t)
335 {
336 _STD::swap(*this, __t);
337 return 0;
338 }
339
340 _LIBCPP_INLINE_VISIBILITY _Hp& get() {return static_cast<_Hp&>(*this);}
341 _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);}
342};
343
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000344template <class ..._Tp>
345_LIBCPP_INLINE_VISIBILITY
346void __swallow(_Tp&&...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347
348// __tuple_impl
349
350template<class _Indx, class ..._Tp> struct __tuple_impl;
351
352template<size_t ..._Indx, class ..._Tp>
353struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
354 : public __tuple_leaf<_Indx, _Tp>...
355{
356 template <size_t ..._Uf, class ..._Tf,
357 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000358 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359 explicit
360 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
361 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
362 _Up&&... __u) :
363 __tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))...,
364 __tuple_leaf<_Ul, _Tl>()...
365 {}
366
367 template <class _Alloc, size_t ..._Uf, class ..._Tf,
368 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370 explicit
371 __tuple_impl(allocator_arg_t, const _Alloc& __a,
372 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
373 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
374 _Up&&... __u) :
375 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
376 _STD::forward<_Up>(__u))...,
377 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
378 {}
379
380 template <class _Tuple,
381 class = typename enable_if
382 <
383 __tuple_convertible<_Tuple, tuple<_Tp...>>::value
384 >::type
385 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387 __tuple_impl(_Tuple&& __t)
388 : __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx,
389 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
390 {}
391
392 template <class _Alloc, class _Tuple,
393 class = typename enable_if
394 <
395 __tuple_convertible<_Tuple, tuple<_Tp...>>::value
396 >::type
397 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
400 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000401 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 _STD::forward<typename tuple_element<_Indx,
403 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
404 {}
405
406 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 typename enable_if
409 <
410 __tuple_assignable<_Tuple, tuple<_Tp...>>::value,
411 __tuple_impl&
412 >::type
413 operator=(_Tuple&& __t)
414 {
415 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx,
416 typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...);
417 return *this;
418 }
419
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 void swap(__tuple_impl& __t)
422 {
423 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
424 }
425};
426
427template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428class _LIBCPP_VISIBLE tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429{
430 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
431
432 base base_;
433
434 template <size_t _Jp, class ..._Up> friend
435 typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&);
436 template <size_t _Jp, class ..._Up> friend
437 const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&);
438public:
439
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 explicit tuple(const _Tp& ... __t)
442 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
443 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
444 typename __make_tuple_indices<0>::type(),
445 typename __make_tuple_types<tuple, 0>::type(),
446 __t...
447 ) {}
448
449 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
452 : base_(allocator_arg_t(), __a,
453 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
454 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
455 typename __make_tuple_indices<0>::type(),
456 typename __make_tuple_types<tuple, 0>::type(),
457 __t...
458 ) {}
459
460 template <class ..._Up,
461 class = typename enable_if
462 <
463 sizeof...(_Up) <= sizeof...(_Tp) &&
464 __tuple_convertible
465 <
466 tuple<_Up...>,
467 typename __make_tuple_types<tuple,
468 sizeof...(_Up) < sizeof...(_Tp) ?
469 sizeof...(_Up) :
470 sizeof...(_Tp)>::type
471 >::value
472 >::type
473 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 explicit
476 tuple(_Up&&... __u)
477 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
478 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
479 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
480 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
481 _STD::forward<_Up>(__u)...) {}
482
483 template <class _Alloc, class ..._Up,
484 class = typename enable_if
485 <
486 sizeof...(_Up) <= sizeof...(_Tp) &&
487 __tuple_convertible
488 <
489 tuple<_Up...>,
490 typename __make_tuple_types<tuple,
491 sizeof...(_Up) < sizeof...(_Tp) ?
492 sizeof...(_Up) :
493 sizeof...(_Tp)>::type
494 >::value
495 >::type
496 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
499 : base_(allocator_arg_t(), __a,
500 typename __make_tuple_indices<sizeof...(_Up)>::type(),
501 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
502 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
503 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
504 _STD::forward<_Up>(__u)...) {}
505
506 template <class _Tuple,
507 class = typename enable_if
508 <
509 __tuple_convertible<_Tuple, tuple>::value
510 >::type
511 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 tuple(_Tuple&& __t)
514 : base_(_STD::forward<_Tuple>(__t)) {}
515
516 template <class _Alloc, class _Tuple,
517 class = typename enable_if
518 <
519 __tuple_convertible<_Tuple, tuple>::value
520 >::type
521 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
524 : base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {}
525
526 template <class _Tuple,
527 class = typename enable_if
528 <
529 __tuple_assignable<_Tuple, tuple>::value
530 >::type
531 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 tuple&
534 operator=(_Tuple&& __t)
535 {
536 base_.operator=(_STD::forward<_Tuple>(__t));
537 return *this;
538 }
539
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 void swap(tuple& __t) {base_.swap(__t.base_);}
542};
543
544template <>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000545class _LIBCPP_VISIBLE tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546{
547public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 tuple() {}
550 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 tuple(allocator_arg_t, const _Alloc&) {}
553 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555 tuple(allocator_arg_t, const _Alloc&, const tuple&) {}
556 template <class _U>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 tuple(array<_U, 0>) {}
559 template <class _Alloc, class _U>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561 tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563 void swap(tuple&) {}
564};
565
566template <class ..._Tp>
567inline _LIBCPP_INLINE_VISIBILITY
568void
569swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);}
570
571// get
572
573template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575typename tuple_element<_Ip, tuple<_Tp...>>::type&
576get(tuple<_Tp...>& __t)
577{
578 typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
579 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
580}
581
582template <size_t _Ip, class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584const typename tuple_element<_Ip, tuple<_Tp...>>::type&
585get(const tuple<_Tp...>& __t)
586{
587 typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
588 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
589}
590
591// tie
592
593template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000594inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595tuple<_Tp&...>
596tie(_Tp&... __t)
597{
598 return tuple<_Tp&...>(__t...);
599}
600
601template <class _Up>
602struct __ignore_t
603{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 __ignore_t() {}
606 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 __ignore_t(_Tp&&) {}
609 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611 const __ignore_t& operator=(_Tp&&) const {return *this;}
612};
613
614namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
615
616template <class _Tp> class reference_wrapper;
617
618template <class _Tp>
619struct ___make_tuple_return
620{
621 typedef _Tp type;
622};
623
624template <class _Tp>
625struct ___make_tuple_return<reference_wrapper<_Tp>>
626{
627 typedef _Tp& type;
628};
629
630template <class _Tp>
631struct __make_tuple_return
632{
633 typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
634};
635
636template <class... _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000637inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638tuple<typename __make_tuple_return<_Tp>::type...>
639make_tuple(_Tp&&... __t)
640{
641 return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...);
642}
643
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000644template <class... _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000646tuple<_Tp&&...>
647forward_as_tuple(_Tp&&... __t)
648{
649 return tuple<_Tp&&...>(_STD::forward<_Tp>(__t)...);
650}
651
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652template <size_t _I>
653struct __tuple_equal
654{
655 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 bool operator()(const _Tp& __x, const _Up& __y)
658 {
659 return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y);
660 }
661};
662
663template <>
664struct __tuple_equal<0>
665{
666 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 bool operator()(const _Tp&, const _Up&)
669 {
670 return true;
671 }
672};
673
674template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676bool
677operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
678{
679 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
680}
681
682template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000683inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684bool
685operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
686{
687 return !(__x == __y);
688}
689
690template <size_t _I>
691struct __tuple_less
692{
693 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 bool operator()(const _Tp& __x, const _Up& __y)
696 {
697 return __tuple_less<_I-1>()(__x, __y) ||
698 (!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y));
699 }
700};
701
702template <>
703struct __tuple_less<0>
704{
705 template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 bool operator()(const _Tp&, const _Up&)
708 {
709 return false;
710 }
711};
712
713template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715bool
716operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
717{
718 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
719}
720
721template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723bool
724operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
725{
726 return __y < __x;
727}
728
729template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731bool
732operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
733{
734 return !(__x < __y);
735}
736
737template <class ..._Tp, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739bool
740operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
741{
742 return !(__y < __x);
743}
744
745// tuple_cat
746
747template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749tuple<_Tp..., _Up...>
750__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
751{
752 return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...);
753}
754
755template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757tuple<_Tp..., _Up...>
758tuple_cat(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
759{
760 return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
761 __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
762}
763
764template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766tuple<_Tp..., _Up...>
767__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
768{
769 return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...);
770}
771
772template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774tuple<_Tp..., _Up...>
775tuple_cat(tuple<_Tp...>&& __x, const tuple<_Up...>& __y)
776{
777 return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
778 __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
779}
780
781template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000782inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783tuple<_Tp..., _Up...>
784__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
785{
786 return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...);
787}
788
789template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791tuple<_Tp..., _Up...>
792tuple_cat(const tuple<_Tp...>& __x, tuple<_Up...>&& __y)
793{
794 return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
795 _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
796}
797
798template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800tuple<_Tp..., _Up...>
801__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
802{
803 return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...);
804}
805
806template <class... _Tp, class... _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000807inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808tuple<_Tp..., _Up...>
809tuple_cat(tuple<_Tp...>&& __x, tuple<_Up...>&& __y)
810{
811 return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
812 _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
813}
814
815template <class ..._Tp, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000816struct _LIBCPP_VISIBLE uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 : true_type {};
818
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819template <class _T1, class _T2>
820template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
821inline _LIBCPP_INLINE_VISIBILITY
822pair<_T1, _T2>::pair(piecewise_construct_t,
823 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
824 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
825 : first(_STD::forward<_Args1>(get<_I1>( __first_args))...),
826 second(_STD::forward<_Args2>(get<_I2>(__second_args))...)
827{
828}
829
Howard Hinnant324bb032010-08-22 00:02:43 +0000830#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831
832_LIBCPP_END_NAMESPACE_STD
833
834#endif // _LIBCPP_TUPLE