blob: 32bc86913aaa89d722fa01f7c17e6f2066badd8a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
22 constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
Louis Dionne1afad1d2019-07-22 20:45:23 +000041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
45 tuple(allocator_arg_t, const Alloc& a, const tuple&);
46 template <class Alloc>
47 tuple(allocator_arg_t, const Alloc& a, tuple&&);
48 template <class Alloc, class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
57 tuple& operator=(const tuple&);
Howard Hinnant89ef1212011-05-27 19:08:18 +000058 tuple&
59 operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 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>
Louis Dionnea6316ed2018-11-12 01:28:07 +000067 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
Howard Hinnantc51e1022010-05-11 19:42:16 +000068
Howard Hinnant89ef1212011-05-27 19:08:18 +000069 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
Howard Hinnantc51e1022010-05-11 19:42:16 +000070};
71
Louis Dionne616da2a2019-08-12 18:30:31 +000072template <class ...T>
73tuple(T...) -> tuple<T...>; // since C++17
74template <class T1, class T2>
75tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
76template <class Alloc, class ...T>
77tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
78template <class Alloc, class T1, class T2>
79tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
80template <class Alloc, class ...T>
81tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
82
Marshall Clowf1bf62f2018-01-02 17:17:01 +000083inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000084
Marshall Clow2229cee2013-07-22 16:02:19 +000085template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000086template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000087template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000088template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000089
90// [tuple.apply], calling a function with a tuple of arguments:
91template <class F, class Tuple>
92 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
93template <class T, class Tuple>
94 constexpr T make_from_tuple(Tuple&& t); // C++17
95
Howard Hinnantc51e1022010-05-11 19:42:16 +000096// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +000097template <class T> struct tuple_size; // undefined
98template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +000099template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000100 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000101template <size_t I, class T> struct tuple_element; // undefined
102template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000103template <size_t I, class T>
104 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000107template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000108 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000109 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000110template <size_t I, class... T>
111 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000112 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000113template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000114 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000115 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000116template <size_t I, class... T>
117 const typename tuple_element<I, tuple<T...>>::type&&
118 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119
Marshall Clow15b02e02013-07-13 02:54:05 +0000120template <class T1, class... T>
121 constexpr T1& get(tuple<T...>&) noexcept; // C++14
122template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000123 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000124template <class T1, class... T>
125 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000126template <class T1, class... T>
127 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000128
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000130template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
131template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
132template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
133template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
134template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
135template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
137template <class... Types, class Alloc>
138 struct uses_allocator<tuple<Types...>, Alloc>;
139
140template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000141 void
142 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144} // std
145
146*/
147
148#include <__config>
149#include <__tuple>
150#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000152#include <__functional_base>
153#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000154#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000156#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000158#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159
160_LIBCPP_BEGIN_NAMESPACE_STD
161
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000162#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Marshall Clowf50d66f2014-03-03 06:18:11 +0000164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165// __tuple_leaf
166
Eric Fiselierf7394302015-06-13 07:08:02 +0000167template <size_t _Ip, class _Hp,
168 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000169 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170class __tuple_leaf;
171
172template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000175 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176{
177 swap(__x.get(), __y.get());
178}
179
180template <size_t _Ip, class _Hp, bool>
181class __tuple_leaf
182{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000183 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184
Eric Fiselierca8bba12016-07-20 02:57:39 +0000185 template <class _Tp>
186 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000187#if __has_keyword(__reference_binds_to_temporary)
188 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000189#else
190 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000191#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000192 }
193
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194 __tuple_leaf& operator=(const __tuple_leaf&);
195public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000197 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 {static_assert(!is_reference<_Hp>::value,
199 "Attempted to default construct a reference element in a tuple");}
200
201 template <class _Alloc>
202 _LIBCPP_INLINE_VISIBILITY
203 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000204 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205 {static_assert(!is_reference<_Hp>::value,
206 "Attempted to default construct a reference element in a tuple");}
207
208 template <class _Alloc>
209 _LIBCPP_INLINE_VISIBILITY
210 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000211 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 {static_assert(!is_reference<_Hp>::value,
213 "Attempted to default construct a reference element in a tuple");}
214
215 template <class _Alloc>
216 _LIBCPP_INLINE_VISIBILITY
217 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000218 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 {static_assert(!is_reference<_Hp>::value,
220 "Attempted to default construct a reference element in a tuple");}
221
Howard Hinnant693fc212010-09-27 17:54:17 +0000222 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000223 class = _EnableIf<
224 _And<
225 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
226 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000227 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000228 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000229 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000231 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000232 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000233 {static_assert(__can_bind_reference<_Tp&&>(),
234 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235
236 template <class _Tp, class _Alloc>
237 _LIBCPP_INLINE_VISIBILITY
238 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000239 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000240 {static_assert(__can_bind_reference<_Tp&&>(),
241 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242
243 template <class _Tp, class _Alloc>
244 _LIBCPP_INLINE_VISIBILITY
245 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000246 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000247 {static_assert(!is_reference<_Hp>::value,
248 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249
250 template <class _Tp, class _Alloc>
251 _LIBCPP_INLINE_VISIBILITY
252 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000253 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000254 {static_assert(!is_reference<_Hp>::value,
255 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256
Marshall Clow47fcee52014-04-21 23:48:09 +0000257 __tuple_leaf(const __tuple_leaf& __t) = default;
258 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259
260 template <class _Tp>
261 _LIBCPP_INLINE_VISIBILITY
262 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000263 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000265 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 return *this;
267 }
268
269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000270 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000272 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 return 0;
274 }
275
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278};
279
280template <size_t _Ip, class _Hp>
281class __tuple_leaf<_Ip, _Hp, true>
282 : private _Hp
283{
284
285 __tuple_leaf& operator=(const __tuple_leaf&);
286public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
288 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290 template <class _Alloc>
291 _LIBCPP_INLINE_VISIBILITY
292 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
293
294 template <class _Alloc>
295 _LIBCPP_INLINE_VISIBILITY
296 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
297 : _Hp(allocator_arg_t(), __a) {}
298
299 template <class _Alloc>
300 _LIBCPP_INLINE_VISIBILITY
301 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
302 : _Hp(__a) {}
303
Howard Hinnant693fc212010-09-27 17:54:17 +0000304 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000305 class = _EnableIf<
306 _And<
307 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
308 is_constructible<_Hp, _Tp>
309 >::value
310 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000311 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000313 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000314 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315
316 template <class _Tp, class _Alloc>
317 _LIBCPP_INLINE_VISIBILITY
318 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000319 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
321 template <class _Tp, class _Alloc>
322 _LIBCPP_INLINE_VISIBILITY
323 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000324 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325
326 template <class _Tp, class _Alloc>
327 _LIBCPP_INLINE_VISIBILITY
328 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000329 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000331 __tuple_leaf(__tuple_leaf const &) = default;
332 __tuple_leaf(__tuple_leaf &&) = default;
333
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 template <class _Tp>
335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000337 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000339 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 return *this;
341 }
342
Howard Hinnant89ef1212011-05-27 19:08:18 +0000343 _LIBCPP_INLINE_VISIBILITY
344 int
345 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000347 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 return 0;
349 }
350
Marshall Clow2229cee2013-07-22 16:02:19 +0000351 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353};
354
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000355template <class ..._Tp>
356_LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000357void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358
Marshall Clowc470eae2014-10-15 10:33:02 +0000359template <class _Tp>
360struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000361
Marshall Clowc470eae2014-10-15 10:33:02 +0000362template <class ..._Tp>
363struct __all_default_constructible<__tuple_types<_Tp...>>
364 : __all<is_default_constructible<_Tp>::value...>
365{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000366
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367// __tuple_impl
368
369template<class _Indx, class ..._Tp> struct __tuple_impl;
370
371template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000372struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 : public __tuple_leaf<_Indx, _Tp>...
374{
Howard Hinnant38469632012-07-06 20:39:45 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000376 _LIBCPP_CONSTEXPR __tuple_impl()
377 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000378
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379 template <size_t ..._Uf, class ..._Tf,
380 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000381 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 explicit
383 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
384 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000385 _Up&&... __u)
386 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
387 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000388 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389 __tuple_leaf<_Ul, _Tl>()...
390 {}
391
392 template <class _Alloc, size_t ..._Uf, class ..._Tf,
393 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 explicit
396 __tuple_impl(allocator_arg_t, const _Alloc& __a,
397 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
398 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
399 _Up&&... __u) :
400 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000401 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
403 {}
404
405 template <class _Tuple,
406 class = typename enable_if
407 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000408 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 >::type
410 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000412 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
413 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000414 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
415 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 {}
417
418 template <class _Alloc, class _Tuple,
419 class = typename enable_if
420 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000421 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 >::type
423 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
426 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000427 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000428 _VSTD::forward<typename tuple_element<_Indx,
429 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 {}
431
432 template <class _Tuple>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 typename enable_if
435 <
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000436 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 __tuple_impl&
438 >::type
Howard Hinnant62751642012-07-06 21:53:48 +0000439 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000442 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
443 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 return *this;
445 }
446
Howard Hinnant0d032d12013-11-06 17:45:43 +0000447 __tuple_impl(const __tuple_impl&) = default;
448 __tuple_impl(__tuple_impl&&) = default;
449
450 _LIBCPP_INLINE_VISIBILITY
451 __tuple_impl&
452 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
453 {
454 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
455 return *this;
456 }
457
458 _LIBCPP_INLINE_VISIBILITY
459 __tuple_impl&
460 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
461 {
462 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
463 return *this;
464 }
Howard Hinnantbcb62c62012-02-15 20:13:52 +0000465
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000468 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 {
470 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
471 }
472};
473
Eric Fiselier264d04a2016-04-15 18:05:59 +0000474
Eric Fiselier264d04a2016-04-15 18:05:59 +0000475
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000477class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000479 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000481 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482
Eric Fiselier41b686e2016-12-08 23:57:08 +0000483#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
484 static constexpr bool _EnableImplicitReducedArityExtension = true;
485#else
486 static constexpr bool _EnableImplicitReducedArityExtension = false;
487#endif
488
Eric Fiselier264d04a2016-04-15 18:05:59 +0000489 template <class ..._Args>
490 struct _PackExpandsToThisTuple : false_type {};
491
492 template <class _Arg>
493 struct _PackExpandsToThisTuple<_Arg>
494 : is_same<typename __uncvref<_Arg>::type, tuple> {};
495
496 template <bool _MaybeEnable, class _Dummy = void>
497 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
498
499 template <class _Dummy>
500 struct _CheckArgsConstructor<true, _Dummy>
501 {
502 template <class ..._Args>
Eric Fiseliere61db632016-07-25 04:32:07 +0000503 static constexpr bool __enable_default() {
504 return __all<is_default_constructible<_Args>::value...>::value;
505 }
506
507 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000508 static constexpr bool __enable_explicit() {
509 return
510 __tuple_constructible<
511 tuple<_Args...>,
512 typename __make_tuple_types<tuple,
513 sizeof...(_Args) < sizeof...(_Tp) ?
514 sizeof...(_Args) :
515 sizeof...(_Tp)>::type
516 >::value &&
517 !__tuple_convertible<
518 tuple<_Args...>,
519 typename __make_tuple_types<tuple,
520 sizeof...(_Args) < sizeof...(_Tp) ?
521 sizeof...(_Args) :
522 sizeof...(_Tp)>::type
523 >::value &&
524 __all_default_constructible<
525 typename __make_tuple_types<tuple, sizeof...(_Tp),
526 sizeof...(_Args) < sizeof...(_Tp) ?
527 sizeof...(_Args) :
528 sizeof...(_Tp)>::type
529 >::value;
530 }
531
532 template <class ..._Args>
533 static constexpr bool __enable_implicit() {
534 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000535 __tuple_constructible<
536 tuple<_Args...>,
537 typename __make_tuple_types<tuple,
538 sizeof...(_Args) < sizeof...(_Tp) ?
539 sizeof...(_Args) :
540 sizeof...(_Tp)>::type
541 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000542 __tuple_convertible<
543 tuple<_Args...>,
544 typename __make_tuple_types<tuple,
545 sizeof...(_Args) < sizeof...(_Tp) ?
546 sizeof...(_Args) :
547 sizeof...(_Tp)>::type
548 >::value &&
549 __all_default_constructible<
550 typename __make_tuple_types<tuple, sizeof...(_Tp),
551 sizeof...(_Args) < sizeof...(_Tp) ?
552 sizeof...(_Args) :
553 sizeof...(_Tp)>::type
554 >::value;
555 }
556 };
557
558 template <bool _MaybeEnable,
559 bool = sizeof...(_Tp) == 1,
560 class _Dummy = void>
561 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
562
563 template <class _Dummy>
564 struct _CheckTupleLikeConstructor<true, false, _Dummy>
565 {
566 template <class _Tuple>
567 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000568 return __tuple_constructible<_Tuple, tuple>::value
569 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000570 }
571
572 template <class _Tuple>
573 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000574 return __tuple_constructible<_Tuple, tuple>::value
575 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000576 }
577 };
578
579 template <class _Dummy>
580 struct _CheckTupleLikeConstructor<true, true, _Dummy>
581 {
582 // This trait is used to disable the tuple-like constructor when
583 // the UTypes... constructor should be selected instead.
584 // See LWG issue #2549.
585 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000586 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000587 // Don't attempt the two checks below if the tuple we are given
588 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000589 _IsSame<__uncvref_t<_Tuple>, tuple>,
590 _Lazy<_And,
591 _Not<is_constructible<_Tp..., _Tuple>>,
592 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000593 >
594 >;
595
596 template <class _Tuple>
597 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000598 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000599 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000600 __tuple_convertible<_Tuple, tuple>,
601 _PreferTupleLikeConstructor<_Tuple>
602 >::value;
603 }
604
605 template <class _Tuple>
606 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000607 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000608 __tuple_constructible<_Tuple, tuple>,
609 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000610 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000611 >::value;
612 }
613 };
614
Eric Fiselierec5a2102019-07-12 23:01:48 +0000615 template <class _Tuple, bool _DisableIfLValue>
616 using _EnableImplicitTupleLikeConstructor = _EnableIf<
617 _CheckTupleLikeConstructor<
618 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
619 && !_PackExpandsToThisTuple<_Tuple>::value
620 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
621 >::template __enable_implicit<_Tuple>(),
622 bool
623 >;
624
625 template <class _Tuple, bool _DisableIfLValue>
626 using _EnableExplicitTupleLikeConstructor = _EnableIf<
627 _CheckTupleLikeConstructor<
628 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
629 && !_PackExpandsToThisTuple<_Tuple>::value
630 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
631 >::template __enable_explicit<_Tuple>(),
632 bool
633 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000634 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000635 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000636 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000637 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000638 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000639 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000640 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
641 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642public:
643
Eric Fiseliercba58302015-02-21 02:30:41 +0000644 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere61db632016-07-25 04:32:07 +0000645 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowc470eae2014-10-15 10:33:02 +0000646 >::type>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000648 _LIBCPP_CONSTEXPR tuple()
649 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000650
Eric Fiselier737a16d2016-07-25 02:36:42 +0000651 tuple(tuple const&) = default;
652 tuple(tuple&&) = default;
653
Eric Fiselier3906a132019-06-23 20:28:29 +0000654 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf<
655 _And<
656 _IsSame<allocator_arg_t, _AllocArgT>,
657 __dependent_type<is_default_constructible<_Tp>, _Dummy>...
Eric Fiselierc170df52016-04-15 03:29:40 +0000658 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000659 >
660 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000661 _LIBCPP_INLINE_VISIBILITY
662 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000663 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000664 __tuple_indices<>(), __tuple_types<>(),
665 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
666 __tuple_types<_Tp...>()) {}
667
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000668 template <bool _Dummy = true,
669 typename enable_if
670 <
671 _CheckArgsConstructor<
672 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000673 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000674 bool
675 >::type = false
676 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000677 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000678 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000679 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
681 typename __make_tuple_indices<0>::type(),
682 typename __make_tuple_types<tuple, 0>::type(),
683 __t...
684 ) {}
685
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000686 template <bool _Dummy = true,
687 typename enable_if
688 <
689 _CheckArgsConstructor<
690 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000691 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000692 bool
693 >::type = false
694 >
695 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
696 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000697 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000698 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
699 typename __make_tuple_indices<0>::type(),
700 typename __make_tuple_types<tuple, 0>::type(),
701 __t...
702 ) {}
703
704 template <class _Alloc, bool _Dummy = true,
705 typename enable_if
706 <
707 _CheckArgsConstructor<
708 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000709 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000710 bool
711 >::type = false
712 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000715 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
717 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
718 typename __make_tuple_indices<0>::type(),
719 typename __make_tuple_types<tuple, 0>::type(),
720 __t...
721 ) {}
722
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000723 template <class _Alloc, bool _Dummy = true,
724 typename enable_if
725 <
726 _CheckArgsConstructor<
727 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000728 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000729 bool
730 >::type = false
731 >
732 _LIBCPP_INLINE_VISIBILITY
733 explicit
734 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000735 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000736 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
737 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
738 typename __make_tuple_indices<0>::type(),
739 typename __make_tuple_types<tuple, 0>::type(),
740 __t...
741 ) {}
742
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000744 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000745 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000747 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000748 sizeof...(_Up) == sizeof...(_Tp)
749 && !_PackIsTuple
750 >::template __enable_implicit<_Up...>() ||
751 _CheckArgsConstructor<
752 _EnableImplicitReducedArityExtension
753 && sizeof...(_Up) < sizeof...(_Tp)
754 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000755 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000756 bool
757 >::type = false
758 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000759 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000760 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000761 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000762 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000763 typename __make_tuple_indices<sizeof...(_Up)>::type,
764 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
765 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
766 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000767 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000768 >::value
769 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000770 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000771 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
772 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
773 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
774 _VSTD::forward<_Up>(__u)...) {}
775
776 template <class ..._Up,
777 typename enable_if
778 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000779 _CheckArgsConstructor<
780 sizeof...(_Up) <= sizeof...(_Tp)
781 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000782 >::template __enable_explicit<_Up...>() ||
783 _CheckArgsConstructor<
784 !_EnableImplicitReducedArityExtension
785 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000786 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000787 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000788 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000789 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000791 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792 explicit
793 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000794 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000795 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000796 typename __make_tuple_indices<sizeof...(_Up)>::type,
797 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
798 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
799 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
800 _Up...
801 >::value
802 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000803 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
805 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
806 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000807 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808
809 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000810 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000812 _CheckArgsConstructor<
813 sizeof...(_Up) == sizeof...(_Tp) &&
814 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000815 >::template __enable_implicit<_Up...>(),
816 bool
817 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000821 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 typename __make_tuple_indices<sizeof...(_Up)>::type(),
823 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
824 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
825 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000826 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000828 template <class _Alloc, class ..._Up,
829 typename enable_if
830 <
831 _CheckArgsConstructor<
832 sizeof...(_Up) == sizeof...(_Tp) &&
833 !_PackExpandsToThisTuple<_Up...>::value
834 >::template __enable_explicit<_Up...>(),
835 bool
836 >::type = false
837 >
838 _LIBCPP_INLINE_VISIBILITY
839 explicit
840 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000841 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000842 typename __make_tuple_indices<sizeof...(_Up)>::type(),
843 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
844 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
845 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
846 _VSTD::forward<_Up>(__u)...) {}
847
Eric Fiselierec5a2102019-07-12 23:01:48 +0000848 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000849 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000850 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
851 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Eric Fiselierec5a2102019-07-12 23:01:48 +0000853 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
854 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
856 : __base_(__t) {}
857 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000859 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000860 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
861 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000862
Eric Fiselierec5a2102019-07-12 23:01:48 +0000863 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
865 explicit
866 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
867 : __base_(__t) {}
868
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000870 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000872 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000873 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
874 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000875 bool
876 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000880 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000882 template <class _Alloc, class _Tuple,
883 typename enable_if
884 <
885 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000886 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
887 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000888 bool
889 >::type = false
890 >
891 _LIBCPP_INLINE_VISIBILITY
892 explicit
893 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000894 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000895
Eric Fiselier737a16d2016-07-25 02:36:42 +0000896 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
897 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
898
899 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000900 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000901 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
902 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000903 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000904 return *this;
905 }
906
907 _LIBCPP_INLINE_VISIBILITY
908 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
909 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
910 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000911 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000912 return *this;
913 }
914
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 template <class _Tuple,
916 class = typename enable_if
917 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000918 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 >::type
920 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000923 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000925 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926 return *this;
927 }
928
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000930 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000931 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932};
933
934template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000935class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936{
937public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000938 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000939 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000942 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000945 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000946 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000948 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000949 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000951 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000953 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954};
955
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000956#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +0000957template <class ..._Tp>
958tuple(_Tp...) -> tuple<_Tp...>;
959template <class _Tp1, class _Tp2>
960tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
961template <class _Alloc, class ..._Tp>
962tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
963template <class _Alloc, class _Tp1, class _Tp2>
964tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
965template <class _Alloc, class ..._Tp>
966tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +0000967#endif
968
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969template <class ..._Tp>
970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000971typename enable_if
972<
973 __all<__is_swappable<_Tp>::value...>::value,
974 void
975>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +0000976swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
977 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
978 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
980// get
981
982template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000983inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000984typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000985get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000987 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000988 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989}
990
991template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000992inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000993const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000994get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000996 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000997 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998}
999
Howard Hinnant22e97242010-11-17 19:52:17 +00001000template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001001inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001002typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001003get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001004{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001005 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001006 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001007 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001008}
1009
Eric Fiselier6dea8092015-12-18 00:36:55 +00001010template <size_t _Ip, class ..._Tp>
1011inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1012const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1013get(const tuple<_Tp...>&& __t) _NOEXCEPT
1014{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001015 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001016 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001017 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001018}
1019
Marshall Clow15b02e02013-07-13 02:54:05 +00001020#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001021
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001022namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001023
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001024static constexpr size_t __not_found = -1;
1025static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001026
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001027inline _LIBCPP_INLINE_VISIBILITY
1028constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1029 return !__matches ? __res :
1030 (__res == __not_found ? __curr_i : __ambiguous);
1031}
Marshall Clow15b02e02013-07-13 02:54:05 +00001032
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001033template <size_t _Nx>
1034inline _LIBCPP_INLINE_VISIBILITY
1035constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1036 return __i == _Nx ? __not_found :
1037 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1038}
1039
1040template <class _T1, class ..._Args>
1041struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001042 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001043 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001044 static_assert(value != __not_found, "type not found in type list" );
1045 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001046};
1047
Eric Fiselier8087d302016-07-02 03:46:08 +00001048template <class _T1>
1049struct __find_exactly_one_checked<_T1> {
1050 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1051};
1052
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001053} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001054
1055template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001056struct __find_exactly_one_t
1057 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1058};
Marshall Clow15b02e02013-07-13 02:54:05 +00001059
1060template <class _T1, class... _Args>
1061inline _LIBCPP_INLINE_VISIBILITY
1062constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1063{
1064 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1065}
1066
1067template <class _T1, class... _Args>
1068inline _LIBCPP_INLINE_VISIBILITY
1069constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1070{
1071 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1072}
1073
1074template <class _T1, class... _Args>
1075inline _LIBCPP_INLINE_VISIBILITY
1076constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1077{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001078 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001079}
1080
Eric Fiselier6dea8092015-12-18 00:36:55 +00001081template <class _T1, class... _Args>
1082inline _LIBCPP_INLINE_VISIBILITY
1083constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1084{
1085 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1086}
1087
Marshall Clow15b02e02013-07-13 02:54:05 +00001088#endif
1089
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090// tie
1091
1092template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001093inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001095tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096{
1097 return tuple<_Tp&...>(__t...);
1098}
1099
1100template <class _Up>
1101struct __ignore_t
1102{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1105 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106};
1107
Eric Fiselier24e70262017-02-06 01:25:31 +00001108namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001109 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001110}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001113inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001114tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115make_tuple(_Tp&&... __t)
1116{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001117 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118}
1119
Howard Hinnant3d203a32010-08-19 18:59:38 +00001120template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001121inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1122tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001123forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001124{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001125 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001126}
1127
Howard Hinnantc834c512011-11-29 18:15:50 +00001128template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129struct __tuple_equal
1130{
1131 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 bool operator()(const _Tp& __x, const _Up& __y)
1134 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001135 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 }
1137};
1138
1139template <>
1140struct __tuple_equal<0>
1141{
1142 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 bool operator()(const _Tp&, const _Up&)
1145 {
1146 return true;
1147 }
1148};
1149
1150template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001151inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152bool
1153operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1154{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001155 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1157}
1158
1159template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001160inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161bool
1162operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1163{
1164 return !(__x == __y);
1165}
1166
Howard Hinnantc834c512011-11-29 18:15:50 +00001167template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168struct __tuple_less
1169{
1170 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001171 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172 bool operator()(const _Tp& __x, const _Up& __y)
1173 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001174 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1175 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1176 return true;
1177 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1178 return false;
1179 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 }
1181};
1182
1183template <>
1184struct __tuple_less<0>
1185{
1186 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001187 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188 bool operator()(const _Tp&, const _Up&)
1189 {
1190 return false;
1191 }
1192};
1193
1194template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001195inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196bool
1197operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1198{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001199 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1201}
1202
1203template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001204inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205bool
1206operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1207{
1208 return __y < __x;
1209}
1210
1211template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001212inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213bool
1214operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1215{
1216 return !(__x < __y);
1217}
1218
1219template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001220inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221bool
1222operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1223{
1224 return !(__y < __x);
1225}
1226
1227// tuple_cat
1228
Howard Hinnant6256ee72010-12-11 20:47:50 +00001229template <class _Tp, class _Up> struct __tuple_cat_type;
1230
1231template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001232struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001234 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001235};
1236
1237template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1238struct __tuple_cat_return_1
1239{
1240};
1241
1242template <class ..._Types, class _Tuple0>
1243struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1244{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001245 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001246 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001247 type;
1248};
1249
1250template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1251struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1252 : public __tuple_cat_return_1<
1253 typename __tuple_cat_type<
1254 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001255 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001256 >::type,
1257 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1258 _Tuple1, _Tuples...>
1259{
1260};
1261
1262template <class ..._Tuples> struct __tuple_cat_return;
1263
1264template <class _Tuple0, class ..._Tuples>
1265struct __tuple_cat_return<_Tuple0, _Tuples...>
1266 : public __tuple_cat_return_1<tuple<>,
1267 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1268 _Tuples...>
1269{
1270};
1271
1272template <>
1273struct __tuple_cat_return<>
1274{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001275 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001276};
1277
Marshall Clow2229cee2013-07-22 16:02:19 +00001278inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001279tuple<>
1280tuple_cat()
1281{
1282 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283}
1284
Howard Hinnantc834c512011-11-29 18:15:50 +00001285template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001286struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287
Howard Hinnant21376f62010-12-12 23:04:37 +00001288template <class ..._Types, size_t ..._I0, class _Tuple0>
1289struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001291 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001292 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1293 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1294};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295
Howard Hinnant21376f62010-12-12 23:04:37 +00001296template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1297struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1298 _Tuple0, _Tuple1, _Tuples...>
1299 : public __tuple_cat_return_ref_imp<
1300 tuple<_Types..., typename __apply_cv<_Tuple0,
1301 typename tuple_element<_I0,
1302 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1303 typename __make_tuple_indices<tuple_size<typename
1304 remove_reference<_Tuple1>::type>::value>::type,
1305 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306{
Howard Hinnant21376f62010-12-12 23:04:37 +00001307};
1308
1309template <class _Tuple0, class ..._Tuples>
1310struct __tuple_cat_return_ref
1311 : public __tuple_cat_return_ref_imp<tuple<>,
1312 typename __make_tuple_indices<
1313 tuple_size<typename remove_reference<_Tuple0>::type>::value
1314 >::type, _Tuple0, _Tuples...>
1315{
1316};
1317
1318template <class _Types, class _I0, class _J0>
1319struct __tuple_cat;
1320
1321template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001322struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001323{
1324 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001325 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001326 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1327 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1328 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001329 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1330 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001331 }
1332
1333 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001335 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1336 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1337 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001338 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1339 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001340 return __tuple_cat<
1341 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1342 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1343 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowded420b2013-10-05 18:46:37 +00001344 (forward_as_tuple(
Marshall Clow60e4aa72014-06-24 00:46:19 +00001345 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1346 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnant21376f62010-12-12 23:04:37 +00001347 ),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001348 _VSTD::forward<_Tuple1>(__t1),
1349 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001350 }
1351};
1352
1353template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001354inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001355typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1356tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1357{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001358 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001359 return __tuple_cat<tuple<>, __tuple_indices<>,
1360 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001361 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1362 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363}
1364
1365template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001366struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367 : true_type {};
1368
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369template <class _T1, class _T2>
1370template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1371inline _LIBCPP_INLINE_VISIBILITY
1372pair<_T1, _T2>::pair(piecewise_construct_t,
1373 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1374 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001375 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1376 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377{
1378}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379
Eric Fiselier8e892c52016-07-18 00:35:56 +00001380#if _LIBCPP_STD_VER > 14
1381template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001382_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001383
1384#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1385
1386template <class _Fn, class _Tuple, size_t ..._Id>
1387inline _LIBCPP_INLINE_VISIBILITY
1388constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1389 __tuple_indices<_Id...>)
1390_LIBCPP_NOEXCEPT_RETURN(
1391 _VSTD::__invoke_constexpr(
1392 _VSTD::forward<_Fn>(__f),
1393 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1394)
1395
1396template <class _Fn, class _Tuple>
1397inline _LIBCPP_INLINE_VISIBILITY
1398constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1399_LIBCPP_NOEXCEPT_RETURN(
1400 _VSTD::__apply_tuple_impl(
1401 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001402 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001403)
1404
1405template <class _Tp, class _Tuple, size_t... _Idx>
1406inline _LIBCPP_INLINE_VISIBILITY
1407constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1408_LIBCPP_NOEXCEPT_RETURN(
1409 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1410)
1411
1412template <class _Tp, class _Tuple>
1413inline _LIBCPP_INLINE_VISIBILITY
1414constexpr _Tp make_from_tuple(_Tuple&& __t)
1415_LIBCPP_NOEXCEPT_RETURN(
1416 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001417 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001418)
1419
1420#undef _LIBCPP_NOEXCEPT_RETURN
1421
1422#endif // _LIBCPP_STD_VER > 14
1423
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001424#endif // !defined(_LIBCPP_CXX03_LANG)
1425
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426_LIBCPP_END_NAMESPACE_STD
1427
1428#endif // _LIBCPP_TUPLE