blob: 31613d2b94f0ce7d56c1ebc20c41fe046b33b4ee [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_TUPLE
12#define _LIBCPP_TUPLE
13
14/*
15 tuple synopsis
16
17namespace std
18{
19
20template <class... T>
21class tuple {
22public:
23 constexpr tuple();
Marshall Clowda0a0e82013-07-22 16:02:19 +000024 explicit tuple(const T&...); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:19 +000026 explicit tuple(U&&...); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027 tuple(const tuple&) = default;
Howard Hinnanta5e01212011-05-27 19:08:18 +000028 tuple(tuple&&) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:19 +000030 tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:19 +000032 tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 template <class U1, class U2>
Marshall Clowda0a0e82013-07-22 16:02:19 +000034 tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035 template <class U1, class U2>
Marshall Clowda0a0e82013-07-22 16:02:19 +000036 tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037
38 // allocator-extended constructors
39 template <class Alloc>
40 tuple(allocator_arg_t, const Alloc& a);
41 template <class Alloc>
42 tuple(allocator_arg_t, const Alloc& a, const T&...);
43 template <class Alloc, class... U>
44 tuple(allocator_arg_t, const Alloc& a, U&&...);
45 template <class Alloc>
46 tuple(allocator_arg_t, const Alloc& a, const tuple&);
47 template <class Alloc>
48 tuple(allocator_arg_t, const Alloc& a, tuple&&);
49 template <class Alloc, class... U>
50 tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
51 template <class Alloc, class... U>
52 tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
53 template <class Alloc, class U1, class U2>
54 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
55 template <class Alloc, class U1, class U2>
56 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
57
58 tuple& operator=(const tuple&);
Howard Hinnanta5e01212011-05-27 19:08:18 +000059 tuple&
60 operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000061 template <class... U>
62 tuple& operator=(const tuple<U...>&);
63 template <class... U>
64 tuple& operator=(tuple<U...>&&);
65 template <class U1, class U2>
66 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
67 template <class U1, class U2>
68 tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
69
Howard Hinnanta5e01212011-05-27 19:08:18 +000070 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071};
72
73const unspecified ignore;
74
Marshall Clowda0a0e82013-07-22 16:02:19 +000075template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clow1d927e32013-10-05 18:46:37 +000076template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clow8e554d92014-02-25 16:11:46 +000077template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clowda0a0e82013-07-22 16:02:19 +000078template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier5839fed2016-07-18 00:35:56 +000079
80// [tuple.apply], calling a function with a tuple of arguments:
81template <class F, class Tuple>
82 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
83template <class T, class Tuple>
84 constexpr T make_from_tuple(Tuple&& t); // C++17
85
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086// 20.4.1.4, tuple helper classes:
87template <class T> class tuple_size; // undefined
88template <class... T> class tuple_size<tuple<T...>>;
Eric Fiselier5839fed2016-07-18 00:35:56 +000089template <class T>
90 constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Marshall Clowa6607572015-11-19 19:45:29 +000091template <size_t I, class T> class tuple_element; // undefined
92template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
93template <size_t I, class T>
94 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095
96// 20.4.1.5, element access:
Marshall Clowa6607572015-11-19 19:45:29 +000097template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +000098 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000099 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +0000100template <size_t I, class... T>
101 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000102 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +0000103template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000104 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000105 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000106template <size_t I, class... T>
107 const typename tuple_element<I, tuple<T...>>::type&&
108 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109
Marshall Clowe8029e52013-07-13 02:54:05 +0000110template <class T1, class... T>
111 constexpr T1& get(tuple<T...>&) noexcept; // C++14
112template <class T1, class... T>
Marshall Clowa6607572015-11-19 19:45:29 +0000113 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000114template <class T1, class... T>
115 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000116template <class T1, class... T>
117 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000118
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000119// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19 +0000120template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
121template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
122template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
123template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
124template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
125template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126
127template <class... Types, class Alloc>
128 struct uses_allocator<tuple<Types...>, Alloc>;
129
130template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000131 void
132 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134} // std
135
136*/
137
138#include <__config>
139#include <__tuple>
140#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000142#include <__functional_base>
143#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
Howard Hinnant08e17472011-10-17 20:05:10 +0000145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000147#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
151#ifndef _LIBCPP_HAS_NO_VARIADICS
152
153// tuple_size
154
155template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000156class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157 : public integral_constant<size_t, sizeof...(_Tp)>
158{
159};
160
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161// tuple_element
162
163template <size_t _Ip, class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000164class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165{
166public:
Howard Hinnantf83417b2011-01-24 16:07:25 +0000167 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000168};
169
Marshall Clow50fe0c72014-03-03 06:18:11 +0000170#if _LIBCPP_STD_VER > 11
171template <size_t _Ip, class ..._Tp>
172using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
173#endif
174
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175// __tuple_leaf
176
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000177template <size_t _Ip, class _Hp,
178 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000179 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180class __tuple_leaf;
181
182template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000185 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186{
187 swap(__x.get(), __y.get());
188}
189
190template <size_t _Ip, class _Hp, bool>
191class __tuple_leaf
192{
193 _Hp value;
194
Eric Fiselier9c747b92016-07-20 02:57:39 +0000195 template <class _Tp>
196 static constexpr bool __can_bind_reference() {
197 using _RawTp = typename remove_reference<_Tp>::type;
198 using _RawHp = typename remove_reference<_Hp>::type;
199 using _CheckLValueArg = integral_constant<bool,
200 is_lvalue_reference<_Tp>::value
201 || is_same<_RawTp, reference_wrapper<_RawHp>>::value
202 || is_same<_RawTp, reference_wrapper<typename remove_const<_RawHp>::type>>::value
203 >;
204 return !is_reference<_Hp>::value
205 || (is_lvalue_reference<_Hp>::value && _CheckLValueArg::value)
206 || (is_rvalue_reference<_Hp>::value && !is_lvalue_reference<_Tp>::value);
207 }
208
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209 __tuple_leaf& operator=(const __tuple_leaf&);
210public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
212 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213 {static_assert(!is_reference<_Hp>::value,
214 "Attempted to default construct a reference element in a tuple");}
215
216 template <class _Alloc>
217 _LIBCPP_INLINE_VISIBILITY
218 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
219 : value()
220 {static_assert(!is_reference<_Hp>::value,
221 "Attempted to default construct a reference element in a tuple");}
222
223 template <class _Alloc>
224 _LIBCPP_INLINE_VISIBILITY
225 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
226 : value(allocator_arg_t(), __a)
227 {static_assert(!is_reference<_Hp>::value,
228 "Attempted to default construct a reference element in a tuple");}
229
230 template <class _Alloc>
231 _LIBCPP_INLINE_VISIBILITY
232 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
233 : value(__a)
234 {static_assert(!is_reference<_Hp>::value,
235 "Attempted to default construct a reference element in a tuple");}
236
Howard Hinnante049cc52010-09-27 17:54:17 +0000237 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000238 class = typename enable_if<
239 __lazy_and<
240 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
241 , is_constructible<_Hp, _Tp>
242 >::value
243 >::type
244 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000246 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000247 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000248 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249 "Attempted to construct a reference element in a tuple with an rvalue");}
250
251 template <class _Tp, class _Alloc>
252 _LIBCPP_INLINE_VISIBILITY
253 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000254 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000255 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 "Attempted to construct a reference element in a tuple with an rvalue");}
257
258 template <class _Tp, class _Alloc>
259 _LIBCPP_INLINE_VISIBILITY
260 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000261 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000262 {static_assert(!is_reference<_Hp>::value,
263 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264
265 template <class _Tp, class _Alloc>
266 _LIBCPP_INLINE_VISIBILITY
267 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000268 : value(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselier9c747b92016-07-20 02:57:39 +0000269 {static_assert(!is_reference<_Hp>::value,
270 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271
Marshall Clow398c9d82014-04-21 23:48:09 +0000272 __tuple_leaf(const __tuple_leaf& __t) = default;
273 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274
275 template <class _Tp>
276 _LIBCPP_INLINE_VISIBILITY
277 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000278 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000280 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 return *this;
282 }
283
284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000285 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000287 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 return 0;
289 }
290
Marshall Clowda0a0e82013-07-22 16:02:19 +0000291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293};
294
295template <size_t _Ip, class _Hp>
296class __tuple_leaf<_Ip, _Hp, true>
297 : private _Hp
298{
299
300 __tuple_leaf& operator=(const __tuple_leaf&);
301public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000302 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
303 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
305 template <class _Alloc>
306 _LIBCPP_INLINE_VISIBILITY
307 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
308
309 template <class _Alloc>
310 _LIBCPP_INLINE_VISIBILITY
311 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
312 : _Hp(allocator_arg_t(), __a) {}
313
314 template <class _Alloc>
315 _LIBCPP_INLINE_VISIBILITY
316 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
317 : _Hp(__a) {}
318
Howard Hinnante049cc52010-09-27 17:54:17 +0000319 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000320 class = typename enable_if<
321 __lazy_and<
322 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
323 , is_constructible<_Hp, _Tp>
324 >::value
325 >::type
326 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000327 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000328 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000329 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330
331 template <class _Tp, class _Alloc>
332 _LIBCPP_INLINE_VISIBILITY
333 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000334 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336 template <class _Tp, class _Alloc>
337 _LIBCPP_INLINE_VISIBILITY
338 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000339 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
341 template <class _Tp, class _Alloc>
342 _LIBCPP_INLINE_VISIBILITY
343 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000344 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
Eric Fiselier9020c082014-07-24 18:48:34 +0000346 __tuple_leaf(__tuple_leaf const &) = default;
347 __tuple_leaf(__tuple_leaf &&) = default;
348
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349 template <class _Tp>
350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000352 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000354 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355 return *this;
356 }
357
Howard Hinnanta5e01212011-05-27 19:08:18 +0000358 _LIBCPP_INLINE_VISIBILITY
359 int
360 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000362 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 return 0;
364 }
365
Marshall Clowda0a0e82013-07-22 16:02:19 +0000366 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368};
369
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000370template <class ..._Tp>
371_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000372void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000374template <class ..._Tp>
375struct __lazy_all : __all<_Tp::value...> {};
376
Marshall Clowbbc7c742014-10-15 10:33:02 +0000377template <class _Tp>
378struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000379
Marshall Clowbbc7c742014-10-15 10:33:02 +0000380template <class ..._Tp>
381struct __all_default_constructible<__tuple_types<_Tp...>>
382 : __all<is_default_constructible<_Tp>::value...>
383{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000384
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385// __tuple_impl
386
387template<class _Indx, class ..._Tp> struct __tuple_impl;
388
389template<size_t ..._Indx, class ..._Tp>
390struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
391 : public __tuple_leaf<_Indx, _Tp>...
392{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000394 _LIBCPP_CONSTEXPR __tuple_impl()
395 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000396
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 template <size_t ..._Uf, class ..._Tf,
398 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000399 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 explicit
401 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
402 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000403 _Up&&... __u)
404 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
405 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000406 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407 __tuple_leaf<_Ul, _Tl>()...
408 {}
409
410 template <class _Alloc, size_t ..._Uf, class ..._Tf,
411 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 explicit
414 __tuple_impl(allocator_arg_t, const _Alloc& __a,
415 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
416 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
417 _Up&&... __u) :
418 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000419 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
421 {}
422
423 template <class _Tuple,
424 class = typename enable_if
425 <
Howard Hinnant99324892013-04-14 00:01:13 +0000426 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 >::type
428 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000429 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000430 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
431 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000432 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
433 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 {}
435
436 template <class _Alloc, class _Tuple,
437 class = typename enable_if
438 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000439 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 >::type
441 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
444 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000445 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000446 _VSTD::forward<typename tuple_element<_Indx,
447 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 {}
449
450 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452 typename enable_if
453 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000454 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 __tuple_impl&
456 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000457 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
458 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000460 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
461 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 return *this;
463 }
464
Howard Hinnant3de50862013-11-06 17:45:43 +0000465 __tuple_impl(const __tuple_impl&) = default;
466 __tuple_impl(__tuple_impl&&) = default;
467
468 _LIBCPP_INLINE_VISIBILITY
469 __tuple_impl&
470 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
471 {
472 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
473 return *this;
474 }
475
476 _LIBCPP_INLINE_VISIBILITY
477 __tuple_impl&
478 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
479 {
480 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
481 return *this;
482 }
Howard Hinnant28484442012-02-15 20:13:52 +0000483
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000486 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487 {
488 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
489 }
490};
491
Eric Fiselierd5019332016-04-15 18:05:59 +0000492template <bool _IsTuple, class _SizeTrait, size_t _Expected>
493struct __tuple_like_with_size_imp : false_type {};
494
495template <class _SizeTrait, size_t _Expected>
496struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
497 : integral_constant<bool, _SizeTrait::value == _Expected> {};
498
499template <class _Tuple, size_t _ExpectedSize,
500 class _RawTuple = typename __uncvref<_Tuple>::type>
501using __tuple_like_with_size = __tuple_like_with_size_imp<
502 __tuple_like<_RawTuple>::value,
503 tuple_size<_RawTuple>, _ExpectedSize
504 >;
505
506
507struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
508 template <class ...>
509 static constexpr bool __enable_explicit() { return false; }
510 template <class ...>
511 static constexpr bool __enable_implicit() { return false; }
512};
513
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000515class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516{
517 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
518
519 base base_;
520
Eric Fiselierd5019332016-04-15 18:05:59 +0000521 template <class ..._Args>
522 struct _PackExpandsToThisTuple : false_type {};
523
524 template <class _Arg>
525 struct _PackExpandsToThisTuple<_Arg>
526 : is_same<typename __uncvref<_Arg>::type, tuple> {};
527
528 template <bool _MaybeEnable, class _Dummy = void>
529 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
530
531 template <class _Dummy>
532 struct _CheckArgsConstructor<true, _Dummy>
533 {
534 template <class ..._Args>
535 static constexpr bool __enable_explicit() {
536 return
537 __tuple_constructible<
538 tuple<_Args...>,
539 typename __make_tuple_types<tuple,
540 sizeof...(_Args) < sizeof...(_Tp) ?
541 sizeof...(_Args) :
542 sizeof...(_Tp)>::type
543 >::value &&
544 !__tuple_convertible<
545 tuple<_Args...>,
546 typename __make_tuple_types<tuple,
547 sizeof...(_Args) < sizeof...(_Tp) ?
548 sizeof...(_Args) :
549 sizeof...(_Tp)>::type
550 >::value &&
551 __all_default_constructible<
552 typename __make_tuple_types<tuple, sizeof...(_Tp),
553 sizeof...(_Args) < sizeof...(_Tp) ?
554 sizeof...(_Args) :
555 sizeof...(_Tp)>::type
556 >::value;
557 }
558
559 template <class ..._Args>
560 static constexpr bool __enable_implicit() {
561 return
562 __tuple_convertible<
563 tuple<_Args...>,
564 typename __make_tuple_types<tuple,
565 sizeof...(_Args) < sizeof...(_Tp) ?
566 sizeof...(_Args) :
567 sizeof...(_Tp)>::type
568 >::value &&
569 __all_default_constructible<
570 typename __make_tuple_types<tuple, sizeof...(_Tp),
571 sizeof...(_Args) < sizeof...(_Tp) ?
572 sizeof...(_Args) :
573 sizeof...(_Tp)>::type
574 >::value;
575 }
576 };
577
578 template <bool _MaybeEnable,
579 bool = sizeof...(_Tp) == 1,
580 class _Dummy = void>
581 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
582
583 template <class _Dummy>
584 struct _CheckTupleLikeConstructor<true, false, _Dummy>
585 {
586 template <class _Tuple>
587 static constexpr bool __enable_implicit() {
588 return __tuple_convertible<_Tuple, tuple>::value;
589 }
590
591 template <class _Tuple>
592 static constexpr bool __enable_explicit() {
593 return __tuple_constructible<_Tuple, tuple>::value
594 && !__tuple_convertible<_Tuple, tuple>::value;
595 }
596 };
597
598 template <class _Dummy>
599 struct _CheckTupleLikeConstructor<true, true, _Dummy>
600 {
601 // This trait is used to disable the tuple-like constructor when
602 // the UTypes... constructor should be selected instead.
603 // See LWG issue #2549.
604 template <class _Tuple>
605 using _PreferTupleLikeConstructor = __lazy_or<
606 // Don't attempt the two checks below if the tuple we are given
607 // has the same type as this tuple.
608 is_same<typename __uncvref<_Tuple>::type, tuple>,
609 __lazy_and<
610 __lazy_not<is_constructible<_Tp..., _Tuple>>,
611 __lazy_not<is_convertible<_Tuple, _Tp...>>
612 >
613 >;
614
615 template <class _Tuple>
616 static constexpr bool __enable_implicit() {
617 return __lazy_and<
618 __tuple_convertible<_Tuple, tuple>,
619 _PreferTupleLikeConstructor<_Tuple>
620 >::value;
621 }
622
623 template <class _Tuple>
624 static constexpr bool __enable_explicit() {
625 return __lazy_and<
626 __tuple_constructible<_Tuple, tuple>,
627 _PreferTupleLikeConstructor<_Tuple>,
628 __lazy_not<__tuple_convertible<_Tuple, tuple>>
629 >::value;
630 }
631 };
632
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000633 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000634 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000635 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000636 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000637 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000638 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000639 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
640 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641public:
642
Eric Fiselierda1818a2015-02-21 02:30:41 +0000643 template <bool _Dummy = true, class = typename enable_if<
644 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
Marshall Clowbbc7c742014-10-15 10:33:02 +0000645 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000647 _LIBCPP_CONSTEXPR tuple()
648 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000649
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000650 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
651 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000652 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000653 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
654 >::value
655 >::type>
656 _LIBCPP_INLINE_VISIBILITY
657 tuple(_AllocArgT, _Alloc const& __a)
658 : base_(allocator_arg_t(), __a,
659 __tuple_indices<>(), __tuple_types<>(),
660 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
661 __tuple_types<_Tp...>()) {}
662
Eric Fiselier95526d32016-04-19 01:19:25 +0000663 template <bool _Dummy = true,
664 typename enable_if
665 <
666 _CheckArgsConstructor<
667 _Dummy
668 >::template __enable_implicit<_Tp...>(),
669 bool
670 >::type = false
671 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000673 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
675 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
676 typename __make_tuple_indices<0>::type(),
677 typename __make_tuple_types<tuple, 0>::type(),
678 __t...
679 ) {}
680
Eric Fiselier95526d32016-04-19 01:19:25 +0000681 template <bool _Dummy = true,
682 typename enable_if
683 <
684 _CheckArgsConstructor<
685 _Dummy
686 >::template __enable_explicit<_Tp...>(),
687 bool
688 >::type = false
689 >
690 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
691 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
692 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
693 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
694 typename __make_tuple_indices<0>::type(),
695 typename __make_tuple_types<tuple, 0>::type(),
696 __t...
697 ) {}
698
699 template <class _Alloc, bool _Dummy = true,
700 typename enable_if
701 <
702 _CheckArgsConstructor<
703 _Dummy
704 >::template __enable_implicit<_Tp...>(),
705 bool
706 >::type = false
707 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
710 : base_(allocator_arg_t(), __a,
711 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
712 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
713 typename __make_tuple_indices<0>::type(),
714 typename __make_tuple_types<tuple, 0>::type(),
715 __t...
716 ) {}
717
Eric Fiselier95526d32016-04-19 01:19:25 +0000718 template <class _Alloc, bool _Dummy = true,
719 typename enable_if
720 <
721 _CheckArgsConstructor<
722 _Dummy
723 >::template __enable_explicit<_Tp...>(),
724 bool
725 >::type = false
726 >
727 _LIBCPP_INLINE_VISIBILITY
728 explicit
729 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
730 : base_(allocator_arg_t(), __a,
731 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
732 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
733 typename __make_tuple_indices<0>::type(),
734 typename __make_tuple_types<tuple, 0>::type(),
735 __t...
736 ) {}
737
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000739 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000741 _CheckArgsConstructor<
742 sizeof...(_Up) <= sizeof...(_Tp)
743 && !_PackExpandsToThisTuple<_Up...>::value
744 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000745 bool
746 >::type = false
747 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000748 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000749 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000750 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000751 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000752 typename __make_tuple_indices<sizeof...(_Up)>::type,
753 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
754 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
755 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000756 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000757 >::value
758 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000759 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
760 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
761 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
762 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
763 _VSTD::forward<_Up>(__u)...) {}
764
765 template <class ..._Up,
766 typename enable_if
767 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000768 _CheckArgsConstructor<
769 sizeof...(_Up) <= sizeof...(_Tp)
770 && !_PackExpandsToThisTuple<_Up...>::value
771 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000772 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000773 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000775 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 explicit
777 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000778 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000779 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000780 typename __make_tuple_indices<sizeof...(_Up)>::type,
781 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
782 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
783 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
784 _Up...
785 >::value
786 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
788 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
789 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
790 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000791 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792
793 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000794 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000796 _CheckArgsConstructor<
797 sizeof...(_Up) == sizeof...(_Tp) &&
798 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000799 >::template __enable_implicit<_Up...>(),
800 bool
801 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000802 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
805 : base_(allocator_arg_t(), __a,
806 typename __make_tuple_indices<sizeof...(_Up)>::type(),
807 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
808 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
809 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000810 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811
Eric Fiselier95526d32016-04-19 01:19:25 +0000812 template <class _Alloc, class ..._Up,
813 typename enable_if
814 <
815 _CheckArgsConstructor<
816 sizeof...(_Up) == sizeof...(_Tp) &&
817 !_PackExpandsToThisTuple<_Up...>::value
818 >::template __enable_explicit<_Up...>(),
819 bool
820 >::type = false
821 >
822 _LIBCPP_INLINE_VISIBILITY
823 explicit
824 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
825 : base_(allocator_arg_t(), __a,
826 typename __make_tuple_indices<sizeof...(_Up)>::type(),
827 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
828 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
829 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
830 _VSTD::forward<_Up>(__u)...) {}
831
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000832 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000833 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000835 _CheckTupleLikeConstructor<
836 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
837 && !_PackExpandsToThisTuple<_Tuple>::value
838 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000839 bool
840 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000842 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000843 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000844 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000846 template <class _Tuple,
847 typename enable_if
848 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000849 _CheckTupleLikeConstructor<
850 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
851 && !_PackExpandsToThisTuple<_Tuple>::value
852 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000853 bool
854 >::type = false
855 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000856 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000857 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000858 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000859 : base_(_VSTD::forward<_Tuple>(__t)) {}
860
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000862 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000864 _CheckTupleLikeConstructor<
865 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000866 >::template __enable_implicit<_Tuple>(),
867 bool
868 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000872 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
Eric Fiselier95526d32016-04-19 01:19:25 +0000874 template <class _Alloc, class _Tuple,
875 typename enable_if
876 <
877 _CheckTupleLikeConstructor<
878 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
879 >::template __enable_explicit<_Tuple>(),
880 bool
881 >::type = false
882 >
883 _LIBCPP_INLINE_VISIBILITY
884 explicit
885 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
886 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
887
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 template <class _Tuple,
889 class = typename enable_if
890 <
891 __tuple_assignable<_Tuple, tuple>::value
892 >::type
893 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000896 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000898 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 return *this;
900 }
901
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000903 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
904 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905};
906
907template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000908class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909{
910public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000912 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000915 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000918 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000919 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000921 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000922 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000924 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000926 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927};
928
929template <class ..._Tp>
930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000931typename enable_if
932<
933 __all<__is_swappable<_Tp>::value...>::value,
934 void
935>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000936swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
937 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
938 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939
940// get
941
942template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000943inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000944typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000945get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000947 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
949}
950
951template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000952inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000953const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000954get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000956 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
958}
959
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000960template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000961inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000962typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000963get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000964{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000965 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000966 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000967 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000968}
969
Eric Fiselier199bee02015-12-18 00:36:55 +0000970template <size_t _Ip, class ..._Tp>
971inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
972const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
973get(const tuple<_Tp...>&& __t) _NOEXCEPT
974{
975 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
976 return static_cast<const type&&>(
977 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
978}
979
Marshall Clowe8029e52013-07-13 02:54:05 +0000980#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000981
Eric Fiselier22c3e762016-07-02 03:18:30 +0000982namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000983
Eric Fiselier22c3e762016-07-02 03:18:30 +0000984static constexpr size_t __not_found = -1;
985static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000986
Eric Fiselier22c3e762016-07-02 03:18:30 +0000987inline _LIBCPP_INLINE_VISIBILITY
988constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
989 return !__matches ? __res :
990 (__res == __not_found ? __curr_i : __ambiguous);
991}
Marshall Clowe8029e52013-07-13 02:54:05 +0000992
Eric Fiselier22c3e762016-07-02 03:18:30 +0000993template <size_t _Nx>
994inline _LIBCPP_INLINE_VISIBILITY
995constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
996 return __i == _Nx ? __not_found :
997 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
998}
999
1000template <class _T1, class ..._Args>
1001struct __find_exactly_one_checked {
1002 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
1003 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1004 static_assert (value != __not_found, "type not found in type list" );
1005 static_assert(value != __ambiguous,"type occurs more than once in type list");
1006};
1007
Eric Fiselier990090f2016-07-02 03:46:08 +00001008template <class _T1>
1009struct __find_exactly_one_checked<_T1> {
1010 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1011};
1012
Eric Fiselier22c3e762016-07-02 03:18:30 +00001013} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001014
1015template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001016struct __find_exactly_one_t
1017 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1018};
Marshall Clowe8029e52013-07-13 02:54:05 +00001019
1020template <class _T1, class... _Args>
1021inline _LIBCPP_INLINE_VISIBILITY
1022constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1023{
1024 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1025}
1026
1027template <class _T1, class... _Args>
1028inline _LIBCPP_INLINE_VISIBILITY
1029constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1030{
1031 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1032}
1033
1034template <class _T1, class... _Args>
1035inline _LIBCPP_INLINE_VISIBILITY
1036constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1037{
Marshall Clow01a0e902013-07-15 20:46:11 +00001038 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001039}
1040
Eric Fiselier199bee02015-12-18 00:36:55 +00001041template <class _T1, class... _Args>
1042inline _LIBCPP_INLINE_VISIBILITY
1043constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1044{
1045 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1046}
1047
Marshall Clowe8029e52013-07-13 02:54:05 +00001048#endif
1049
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050// tie
1051
1052template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001053inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001055tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056{
1057 return tuple<_Tp&...>(__t...);
1058}
1059
1060template <class _Up>
1061struct __ignore_t
1062{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 const __ignore_t& operator=(_Tp&&) const {return *this;}
1066};
1067
1068namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1069
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001071struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072{
1073 typedef _Tp type;
1074};
1075
1076template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001077struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078{
1079 typedef _Tp& type;
1080};
1081
1082template <class _Tp>
1083struct __make_tuple_return
1084{
Marshall Clowa71f9562014-01-03 22:55:49 +00001085 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086};
1087
1088template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001089inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090tuple<typename __make_tuple_return<_Tp>::type...>
1091make_tuple(_Tp&&... __t)
1092{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001093 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094}
1095
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001096template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001097inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1098tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001099forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001100{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001101 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001102}
1103
Howard Hinnant99968442011-11-29 18:15:50 +00001104template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105struct __tuple_equal
1106{
1107 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 bool operator()(const _Tp& __x, const _Up& __y)
1110 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001111 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 }
1113};
1114
1115template <>
1116struct __tuple_equal<0>
1117{
1118 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 bool operator()(const _Tp&, const _Up&)
1121 {
1122 return true;
1123 }
1124};
1125
1126template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001127inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128bool
1129operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1130{
1131 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1132}
1133
1134template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001135inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136bool
1137operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1138{
1139 return !(__x == __y);
1140}
1141
Howard Hinnant99968442011-11-29 18:15:50 +00001142template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143struct __tuple_less
1144{
1145 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001146 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 bool operator()(const _Tp& __x, const _Up& __y)
1148 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001149 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1150 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1151 return true;
1152 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1153 return false;
1154 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 }
1156};
1157
1158template <>
1159struct __tuple_less<0>
1160{
1161 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 bool operator()(const _Tp&, const _Up&)
1164 {
1165 return false;
1166 }
1167};
1168
1169template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171bool
1172operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1173{
1174 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1175}
1176
1177template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179bool
1180operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1181{
1182 return __y < __x;
1183}
1184
1185template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001186inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187bool
1188operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1189{
1190 return !(__x < __y);
1191}
1192
1193template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195bool
1196operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1197{
1198 return !(__y < __x);
1199}
1200
1201// tuple_cat
1202
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001203template <class _Tp, class _Up> struct __tuple_cat_type;
1204
1205template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001206struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001208 typedef tuple<_Ttypes..., _Utypes...> type;
1209};
1210
1211template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1212struct __tuple_cat_return_1
1213{
1214};
1215
1216template <class ..._Types, class _Tuple0>
1217struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1218{
1219 typedef typename __tuple_cat_type<tuple<_Types...>,
1220 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1221 type;
1222};
1223
1224template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1225struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1226 : public __tuple_cat_return_1<
1227 typename __tuple_cat_type<
1228 tuple<_Types...>,
1229 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1230 >::type,
1231 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1232 _Tuple1, _Tuples...>
1233{
1234};
1235
1236template <class ..._Tuples> struct __tuple_cat_return;
1237
1238template <class _Tuple0, class ..._Tuples>
1239struct __tuple_cat_return<_Tuple0, _Tuples...>
1240 : public __tuple_cat_return_1<tuple<>,
1241 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1242 _Tuples...>
1243{
1244};
1245
1246template <>
1247struct __tuple_cat_return<>
1248{
1249 typedef tuple<> type;
1250};
1251
Marshall Clowda0a0e82013-07-22 16:02:19 +00001252inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001253tuple<>
1254tuple_cat()
1255{
1256 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257}
1258
Howard Hinnant99968442011-11-29 18:15:50 +00001259template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001260struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261
Howard Hinnante48e3662010-12-12 23:04:37 +00001262template <class ..._Types, size_t ..._I0, class _Tuple0>
1263struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001265 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001266 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1267 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1268};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269
Howard Hinnante48e3662010-12-12 23:04:37 +00001270template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1271struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1272 _Tuple0, _Tuple1, _Tuples...>
1273 : public __tuple_cat_return_ref_imp<
1274 tuple<_Types..., typename __apply_cv<_Tuple0,
1275 typename tuple_element<_I0,
1276 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1277 typename __make_tuple_indices<tuple_size<typename
1278 remove_reference<_Tuple1>::type>::value>::type,
1279 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280{
Howard Hinnante48e3662010-12-12 23:04:37 +00001281};
1282
1283template <class _Tuple0, class ..._Tuples>
1284struct __tuple_cat_return_ref
1285 : public __tuple_cat_return_ref_imp<tuple<>,
1286 typename __make_tuple_indices<
1287 tuple_size<typename remove_reference<_Tuple0>::type>::value
1288 >::type, _Tuple0, _Tuples...>
1289{
1290};
1291
1292template <class _Types, class _I0, class _J0>
1293struct __tuple_cat;
1294
1295template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001296struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001297{
1298 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001299 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001300 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1301 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1302 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001303 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1304 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001305 }
1306
1307 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001309 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1310 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1311 {
1312 typedef typename remove_reference<_Tuple0>::type _T0;
1313 typedef typename remove_reference<_Tuple1>::type _T1;
1314 return __tuple_cat<
1315 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1316 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1317 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001318 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001319 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1320 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001321 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001322 _VSTD::forward<_Tuple1>(__t1),
1323 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001324 }
1325};
1326
1327template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001328inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001329typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1330tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1331{
1332 typedef typename remove_reference<_Tuple0>::type _T0;
1333 return __tuple_cat<tuple<>, __tuple_indices<>,
1334 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001335 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1336 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337}
1338
1339template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001340struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341 : true_type {};
1342
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343template <class _T1, class _T2>
1344template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1345inline _LIBCPP_INLINE_VISIBILITY
1346pair<_T1, _T2>::pair(piecewise_construct_t,
1347 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1348 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001349 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1350 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351{
1352}
1353
Howard Hinnant324bb032010-08-22 00:02:43 +00001354#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355
Eric Fiselier5839fed2016-07-18 00:35:56 +00001356#if _LIBCPP_STD_VER > 14
1357template <class _Tp>
1358constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1359
1360#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1361
1362template <class _Fn, class _Tuple, size_t ..._Id>
1363inline _LIBCPP_INLINE_VISIBILITY
1364constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1365 __tuple_indices<_Id...>)
1366_LIBCPP_NOEXCEPT_RETURN(
1367 _VSTD::__invoke_constexpr(
1368 _VSTD::forward<_Fn>(__f),
1369 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1370)
1371
1372template <class _Fn, class _Tuple>
1373inline _LIBCPP_INLINE_VISIBILITY
1374constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1375_LIBCPP_NOEXCEPT_RETURN(
1376 _VSTD::__apply_tuple_impl(
1377 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1378 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1379)
1380
1381template <class _Tp, class _Tuple, size_t... _Idx>
1382inline _LIBCPP_INLINE_VISIBILITY
1383constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1384_LIBCPP_NOEXCEPT_RETURN(
1385 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1386)
1387
1388template <class _Tp, class _Tuple>
1389inline _LIBCPP_INLINE_VISIBILITY
1390constexpr _Tp make_from_tuple(_Tuple&& __t)
1391_LIBCPP_NOEXCEPT_RETURN(
1392 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1393 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1394)
1395
1396#undef _LIBCPP_NOEXCEPT_RETURN
1397
1398#endif // _LIBCPP_STD_VER > 14
1399
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400_LIBCPP_END_NAMESPACE_STD
1401
1402#endif // _LIBCPP_TUPLE