2 //===--------------------------- tuple ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
24 explicit tuple(const T&...); // constexpr in C++14
26 explicit tuple(U&&...); // constexpr in C++14
27 tuple(const tuple&) = default;
28 tuple(tuple&&) = default;
30 tuple(const tuple<U...>&); // constexpr in C++14
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
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>&&);
58 tuple& operator=(const tuple&);
60 operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
62 tuple& operator=(const tuple<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
70 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
73 const unspecified ignore;
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
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
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
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
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
114 template <class... Types, class Alloc>
115 struct uses_allocator<tuple<Types...>, Alloc>;
117 template <class... Types>
119 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
128 #include <type_traits>
129 #include <__functional_base>
132 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
133 #pragma GCC system_header
136 _LIBCPP_BEGIN_NAMESPACE_STD
138 #ifndef _LIBCPP_HAS_NO_VARIADICS
142 template <class ..._Tp>
143 class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
144 : public integral_constant<size_t, sizeof...(_Tp)>
150 template <size_t _Ip, class ..._Tp>
151 class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
154 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
157 #if _LIBCPP_STD_VER > 11
158 template <size_t _Ip, class ..._Tp>
159 using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
164 template <size_t _Ip, class _Hp,
165 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
169 template <size_t _Ip, class _Hp, bool _Ep>
170 inline _LIBCPP_INLINE_VISIBILITY
171 void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
172 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
174 swap(__x.get(), __y.get());
177 template <size_t _Ip, class _Hp, bool>
182 __tuple_leaf& operator=(const __tuple_leaf&);
184 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
185 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
186 {static_assert(!is_reference<_Hp>::value,
187 "Attempted to default construct a reference element in a tuple");}
189 template <class _Alloc>
190 _LIBCPP_INLINE_VISIBILITY
191 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
193 {static_assert(!is_reference<_Hp>::value,
194 "Attempted to default construct a reference element in a tuple");}
196 template <class _Alloc>
197 _LIBCPP_INLINE_VISIBILITY
198 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
199 : value(allocator_arg_t(), __a)
200 {static_assert(!is_reference<_Hp>::value,
201 "Attempted to default construct a reference element in a tuple");}
203 template <class _Alloc>
204 _LIBCPP_INLINE_VISIBILITY
205 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
207 {static_assert(!is_reference<_Hp>::value,
208 "Attempted to default construct a reference element in a tuple");}
211 class = typename enable_if<
213 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
214 , is_constructible<_Hp, _Tp>
218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
219 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
220 : value(_VSTD::forward<_Tp>(__t))
221 {static_assert(!is_reference<_Hp>::value ||
222 (is_lvalue_reference<_Hp>::value &&
223 (is_lvalue_reference<_Tp>::value ||
224 is_same<typename remove_reference<_Tp>::type,
226 typename remove_reference<_Hp>::type
229 (is_rvalue_reference<_Hp>::value &&
230 !is_lvalue_reference<_Tp>::value),
231 "Attempted to construct a reference element in a tuple with an rvalue");}
233 template <class _Tp, class _Alloc>
234 _LIBCPP_INLINE_VISIBILITY
235 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
236 : value(_VSTD::forward<_Tp>(__t))
237 {static_assert(!is_lvalue_reference<_Hp>::value ||
238 (is_lvalue_reference<_Hp>::value &&
239 (is_lvalue_reference<_Tp>::value ||
240 is_same<typename remove_reference<_Tp>::type,
242 typename remove_reference<_Hp>::type
245 "Attempted to construct a reference element in a tuple with an rvalue");}
247 template <class _Tp, class _Alloc>
248 _LIBCPP_INLINE_VISIBILITY
249 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
250 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
251 {static_assert(!is_lvalue_reference<_Hp>::value ||
252 (is_lvalue_reference<_Hp>::value &&
253 (is_lvalue_reference<_Tp>::value ||
254 is_same<typename remove_reference<_Tp>::type,
256 typename remove_reference<_Hp>::type
259 "Attempted to construct a reference element in a tuple with an rvalue");}
261 template <class _Tp, class _Alloc>
262 _LIBCPP_INLINE_VISIBILITY
263 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
264 : value(_VSTD::forward<_Tp>(__t), __a)
265 {static_assert(!is_lvalue_reference<_Hp>::value ||
266 (is_lvalue_reference<_Hp>::value &&
267 (is_lvalue_reference<_Tp>::value ||
268 is_same<typename remove_reference<_Tp>::type,
270 typename remove_reference<_Hp>::type
273 "Attempted to construct a reference element in a tuple with an rvalue");}
275 __tuple_leaf(const __tuple_leaf& __t) = default;
276 __tuple_leaf(__tuple_leaf&& __t) = default;
279 _LIBCPP_INLINE_VISIBILITY
281 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
283 value = _VSTD::forward<_Tp>(__t);
287 _LIBCPP_INLINE_VISIBILITY
288 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
290 _VSTD::swap(*this, __t);
294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
298 template <size_t _Ip, class _Hp>
299 class __tuple_leaf<_Ip, _Hp, true>
303 __tuple_leaf& operator=(const __tuple_leaf&);
305 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
306 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
308 template <class _Alloc>
309 _LIBCPP_INLINE_VISIBILITY
310 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
312 template <class _Alloc>
313 _LIBCPP_INLINE_VISIBILITY
314 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
315 : _Hp(allocator_arg_t(), __a) {}
317 template <class _Alloc>
318 _LIBCPP_INLINE_VISIBILITY
319 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
323 class = typename enable_if<
325 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
326 , is_constructible<_Hp, _Tp>
330 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
331 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
332 : _Hp(_VSTD::forward<_Tp>(__t)) {}
334 template <class _Tp, class _Alloc>
335 _LIBCPP_INLINE_VISIBILITY
336 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
337 : _Hp(_VSTD::forward<_Tp>(__t)) {}
339 template <class _Tp, class _Alloc>
340 _LIBCPP_INLINE_VISIBILITY
341 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
342 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
344 template <class _Tp, class _Alloc>
345 _LIBCPP_INLINE_VISIBILITY
346 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
347 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
349 __tuple_leaf(__tuple_leaf const &) = default;
350 __tuple_leaf(__tuple_leaf &&) = default;
353 _LIBCPP_INLINE_VISIBILITY
355 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
357 _Hp::operator=(_VSTD::forward<_Tp>(__t));
361 _LIBCPP_INLINE_VISIBILITY
363 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
365 _VSTD::swap(*this, __t);
369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
373 template <class ..._Tp>
374 _LIBCPP_INLINE_VISIBILITY
375 void __swallow(_Tp&&...) _NOEXCEPT {}
377 template <bool ..._Pred>
379 : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
383 struct __all_default_constructible;
385 template <class ..._Tp>
386 struct __all_default_constructible<__tuple_types<_Tp...>>
387 : __all<is_default_constructible<_Tp>::value...>
392 template<class _Indx, class ..._Tp> struct __tuple_impl;
394 template<size_t ..._Indx, class ..._Tp>
395 struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
396 : public __tuple_leaf<_Indx, _Tp>...
398 _LIBCPP_INLINE_VISIBILITY
399 _LIBCPP_CONSTEXPR __tuple_impl()
400 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
402 template <size_t ..._Uf, class ..._Tf,
403 size_t ..._Ul, class ..._Tl, class ..._Up>
404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
406 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
407 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
409 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
410 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
411 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
412 __tuple_leaf<_Ul, _Tl>()...
415 template <class _Alloc, size_t ..._Uf, class ..._Tf,
416 size_t ..._Ul, class ..._Tl, class ..._Up>
417 _LIBCPP_INLINE_VISIBILITY
419 __tuple_impl(allocator_arg_t, const _Alloc& __a,
420 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
421 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
423 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
424 _VSTD::forward<_Up>(__u))...,
425 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
428 template <class _Tuple,
429 class = typename enable_if
431 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
434 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
435 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
436 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
437 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
438 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
441 template <class _Alloc, class _Tuple,
442 class = typename enable_if
444 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
447 _LIBCPP_INLINE_VISIBILITY
448 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
449 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
450 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
451 _VSTD::forward<typename tuple_element<_Indx,
452 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
455 template <class _Tuple>
456 _LIBCPP_INLINE_VISIBILITY
459 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
462 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
463 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
465 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
466 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
470 __tuple_impl(const __tuple_impl&) = default;
471 __tuple_impl(__tuple_impl&&) = default;
473 _LIBCPP_INLINE_VISIBILITY
475 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
477 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
481 _LIBCPP_INLINE_VISIBILITY
483 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
485 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
489 _LIBCPP_INLINE_VISIBILITY
490 void swap(__tuple_impl& __t)
491 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
493 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
497 template <class ..._Tp>
498 class _LIBCPP_TYPE_VIS_ONLY tuple
500 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
504 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
505 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
506 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
507 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
508 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
509 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
512 template <bool _Dummy = true, class = typename enable_if<
513 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
515 _LIBCPP_INLINE_VISIBILITY
516 _LIBCPP_CONSTEXPR tuple()
517 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
519 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
520 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
521 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
522 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
523 typename __make_tuple_indices<0>::type(),
524 typename __make_tuple_types<tuple, 0>::type(),
528 template <class _Alloc>
529 _LIBCPP_INLINE_VISIBILITY
530 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
531 : base_(allocator_arg_t(), __a,
532 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
533 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
534 typename __make_tuple_indices<0>::type(),
535 typename __make_tuple_types<tuple, 0>::type(),
539 template <class ..._Up,
542 sizeof...(_Up) <= sizeof...(_Tp) &&
546 typename __make_tuple_types<tuple,
547 sizeof...(_Up) < sizeof...(_Tp) ?
549 sizeof...(_Tp)>::type
551 __all_default_constructible<
552 typename __make_tuple_types<tuple, sizeof...(_Tp),
553 sizeof...(_Up) < sizeof...(_Tp) ?
555 sizeof...(_Tp)>::type
560 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
563 is_nothrow_constructible<base,
564 typename __make_tuple_indices<sizeof...(_Up)>::type,
565 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
566 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
567 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
571 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
572 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
573 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
574 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
575 _VSTD::forward<_Up>(__u)...) {}
577 template <class ..._Up,
580 sizeof...(_Up) <= sizeof...(_Tp) &&
581 __tuple_constructible
584 typename __make_tuple_types<tuple,
585 sizeof...(_Up) < sizeof...(_Tp) ?
587 sizeof...(_Tp)>::type
592 typename __make_tuple_types<tuple,
593 sizeof...(_Up) < sizeof...(_Tp) ?
595 sizeof...(_Tp)>::type
597 __all_default_constructible<
598 typename __make_tuple_types<tuple, sizeof...(_Tp),
599 sizeof...(_Up) < sizeof...(_Tp) ?
601 sizeof...(_Tp)>::type
606 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
610 is_nothrow_constructible<base,
611 typename __make_tuple_indices<sizeof...(_Up)>::type,
612 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
613 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
614 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
618 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
619 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
620 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
621 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
622 _VSTD::forward<_Up>(__u)...) {}
624 template <class _Alloc, class ..._Up,
625 class = typename enable_if
627 sizeof...(_Up) <= sizeof...(_Tp) &&
631 typename __make_tuple_types<tuple,
632 sizeof...(_Up) < sizeof...(_Tp) ?
634 sizeof...(_Tp)>::type
636 __all_default_constructible<
637 typename __make_tuple_types<tuple, sizeof...(_Tp),
638 sizeof...(_Up) < sizeof...(_Tp) ?
640 sizeof...(_Tp)>::type
644 _LIBCPP_INLINE_VISIBILITY
645 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
646 : base_(allocator_arg_t(), __a,
647 typename __make_tuple_indices<sizeof...(_Up)>::type(),
648 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
649 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
650 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
651 _VSTD::forward<_Up>(__u)...) {}
653 template <class _Tuple,
656 __tuple_convertible<_Tuple, tuple>::value,
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
661 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
662 : base_(_VSTD::forward<_Tuple>(__t)) {}
664 template <class _Tuple,
667 __tuple_constructible<_Tuple, tuple>::value &&
668 !__tuple_convertible<_Tuple, tuple>::value,
672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
674 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
675 : base_(_VSTD::forward<_Tuple>(__t)) {}
677 template <class _Alloc, class _Tuple,
678 class = typename enable_if
680 __tuple_convertible<_Tuple, tuple>::value
683 _LIBCPP_INLINE_VISIBILITY
684 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
685 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
687 template <class _Tuple,
688 class = typename enable_if
690 __tuple_assignable<_Tuple, tuple>::value
693 _LIBCPP_INLINE_VISIBILITY
695 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
697 base_.operator=(_VSTD::forward<_Tuple>(__t));
701 _LIBCPP_INLINE_VISIBILITY
702 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
703 {base_.swap(__t.base_);}
707 class _LIBCPP_TYPE_VIS_ONLY tuple<>
710 _LIBCPP_INLINE_VISIBILITY
711 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
712 template <class _Alloc>
713 _LIBCPP_INLINE_VISIBILITY
714 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
715 template <class _Alloc>
716 _LIBCPP_INLINE_VISIBILITY
717 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
719 _LIBCPP_INLINE_VISIBILITY
720 tuple(array<_Up, 0>) _NOEXCEPT {}
721 template <class _Alloc, class _Up>
722 _LIBCPP_INLINE_VISIBILITY
723 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
724 _LIBCPP_INLINE_VISIBILITY
725 void swap(tuple&) _NOEXCEPT {}
728 template <class ..._Tp>
729 inline _LIBCPP_INLINE_VISIBILITY
732 __all<__is_swappable<_Tp>::value...>::value,
735 swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
736 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
741 template <size_t _Ip, class ..._Tp>
742 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
743 typename tuple_element<_Ip, tuple<_Tp...> >::type&
744 get(tuple<_Tp...>& __t) _NOEXCEPT
746 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
747 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
750 template <size_t _Ip, class ..._Tp>
751 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
752 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
753 get(const tuple<_Tp...>& __t) _NOEXCEPT
755 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
756 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
759 template <size_t _Ip, class ..._Tp>
760 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
761 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
762 get(tuple<_Tp...>&& __t) _NOEXCEPT
764 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
765 return static_cast<type&&>(
766 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
769 #if _LIBCPP_STD_VER > 11
771 template <typename _T1, size_t _Idx, typename... _Args>
772 struct __find_exactly_one_t_helper;
774 // -- find exactly one
775 template <typename _T1, size_t _Idx, typename... _Args>
776 struct __find_exactly_one_t_checker {
777 static constexpr size_t value = _Idx;
778 // Check the rest of the list to make sure there's only one
779 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
783 template <typename _T1, size_t _Idx>
784 struct __find_exactly_one_t_helper <_T1, _Idx> {
785 static constexpr size_t value = -1;
788 template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
789 struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
790 static constexpr size_t value =
792 std::is_same<_T1, _Head>::value,
793 __find_exactly_one_t_checker<_T1, _Idx, _Args...>,
794 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
798 template <typename _T1, typename... _Args>
799 struct __find_exactly_one_t {
800 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
801 static_assert ( value != -1, "type not found in type list" );
804 template <class _T1, class... _Args>
805 inline _LIBCPP_INLINE_VISIBILITY
806 constexpr _T1& get(tuple<_Args...>& __tup) noexcept
808 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
811 template <class _T1, class... _Args>
812 inline _LIBCPP_INLINE_VISIBILITY
813 constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
815 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
818 template <class _T1, class... _Args>
819 inline _LIBCPP_INLINE_VISIBILITY
820 constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
822 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
829 template <class ..._Tp>
830 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
832 tie(_Tp&... __t) _NOEXCEPT
834 return tuple<_Tp&...>(__t...);
841 _LIBCPP_INLINE_VISIBILITY
842 const __ignore_t& operator=(_Tp&&) const {return *this;}
845 namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
848 struct __make_tuple_return_impl
854 struct __make_tuple_return_impl<reference_wrapper<_Tp> >
860 struct __make_tuple_return
862 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
865 template <class... _Tp>
866 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
867 tuple<typename __make_tuple_return<_Tp>::type...>
868 make_tuple(_Tp&&... __t)
870 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
873 template <class... _Tp>
874 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
876 forward_as_tuple(_Tp&&... __t) _NOEXCEPT
878 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
881 template <size_t _Ip>
884 template <class _Tp, class _Up>
885 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
886 bool operator()(const _Tp& __x, const _Up& __y)
888 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
893 struct __tuple_equal<0>
895 template <class _Tp, class _Up>
896 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
897 bool operator()(const _Tp&, const _Up&)
903 template <class ..._Tp, class ..._Up>
904 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
906 operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
908 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
911 template <class ..._Tp, class ..._Up>
912 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
914 operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
916 return !(__x == __y);
919 template <size_t _Ip>
922 template <class _Tp, class _Up>
923 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
924 bool operator()(const _Tp& __x, const _Up& __y)
926 const size_t __idx = tuple_size<_Tp>::value - _Ip;
927 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
929 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
931 return __tuple_less<_Ip-1>()(__x, __y);
936 struct __tuple_less<0>
938 template <class _Tp, class _Up>
939 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
940 bool operator()(const _Tp&, const _Up&)
946 template <class ..._Tp, class ..._Up>
947 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
949 operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
951 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
954 template <class ..._Tp, class ..._Up>
955 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
957 operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
962 template <class ..._Tp, class ..._Up>
963 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
965 operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
970 template <class ..._Tp, class ..._Up>
971 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
973 operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
980 template <class _Tp, class _Up> struct __tuple_cat_type;
982 template <class ..._Ttypes, class ..._Utypes>
983 struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
985 typedef tuple<_Ttypes..., _Utypes...> type;
988 template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
989 struct __tuple_cat_return_1
993 template <class ..._Types, class _Tuple0>
994 struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
996 typedef typename __tuple_cat_type<tuple<_Types...>,
997 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
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<
1006 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1008 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1009 _Tuple1, _Tuples...>
1013 template <class ..._Tuples> struct __tuple_cat_return;
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,
1024 struct __tuple_cat_return<>
1026 typedef tuple<> type;
1029 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1036 template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
1037 struct __tuple_cat_return_ref_imp;
1039 template <class ..._Types, size_t ..._I0, class _Tuple0>
1040 struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
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;
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...>
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...>
1069 template <class _Types, class _I0, class _J0>
1072 template <class ..._Types, size_t ..._I0, size_t ..._J0>
1073 struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
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)
1080 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1081 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
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)
1089 typedef typename remove_reference<_Tuple0>::type _T0;
1090 typedef typename remove_reference<_Tuple1>::type _T1;
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>()
1096 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1097 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
1099 _VSTD::forward<_Tuple1>(__t1),
1100 _VSTD::forward<_Tuples>(__tpls)...);
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)
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)...);
1116 template <class ..._Tp, class _Alloc>
1117 struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
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))...)
1131 #endif // _LIBCPP_HAS_NO_VARIADICS
1133 _LIBCPP_END_NAMESPACE_STD
1135 #endif // _LIBCPP_TUPLE