blob: 6805d8c7635b74332959a6fcd3745fda89767fba [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
195 __tuple_leaf& operator=(const __tuple_leaf&);
196public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
198 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 {static_assert(!is_reference<_Hp>::value,
200 "Attempted to default construct a reference element in a tuple");}
201
202 template <class _Alloc>
203 _LIBCPP_INLINE_VISIBILITY
204 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
205 : value()
206 {static_assert(!is_reference<_Hp>::value,
207 "Attempted to default construct a reference element in a tuple");}
208
209 template <class _Alloc>
210 _LIBCPP_INLINE_VISIBILITY
211 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
212 : value(allocator_arg_t(), __a)
213 {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, 2>, const _Alloc& __a)
219 : value(__a)
220 {static_assert(!is_reference<_Hp>::value,
221 "Attempted to default construct a reference element in a tuple");}
222
Howard Hinnante049cc52010-09-27 17:54:17 +0000223 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000224 class = typename enable_if<
225 __lazy_and<
226 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
227 , is_constructible<_Hp, _Tp>
228 >::value
229 >::type
230 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000231 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000232 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000233 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000234 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000235 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236 (is_lvalue_reference<_Tp>::value ||
237 is_same<typename remove_reference<_Tp>::type,
238 reference_wrapper<
239 typename remove_reference<_Hp>::type
240 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000241 >::value)) ||
Howard Hinnante049cc52010-09-27 17:54:17 +0000242 (is_rvalue_reference<_Hp>::value &&
243 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244 "Attempted to construct a reference element in a tuple with an rvalue");}
245
246 template <class _Tp, class _Alloc>
247 _LIBCPP_INLINE_VISIBILITY
248 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000249 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000251 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252 (is_lvalue_reference<_Tp>::value ||
253 is_same<typename remove_reference<_Tp>::type,
254 reference_wrapper<
255 typename remove_reference<_Hp>::type
256 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000257 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 "Attempted to construct a reference element in a tuple with an rvalue");}
259
260 template <class _Tp, class _Alloc>
261 _LIBCPP_INLINE_VISIBILITY
262 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000263 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000265 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266 (is_lvalue_reference<_Tp>::value ||
267 is_same<typename remove_reference<_Tp>::type,
268 reference_wrapper<
269 typename remove_reference<_Hp>::type
270 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000271 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 "Attempted to construct a reference element in a tuple with an rvalue");}
273
274 template <class _Tp, class _Alloc>
275 _LIBCPP_INLINE_VISIBILITY
276 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000277 : value(_VSTD::forward<_Tp>(__t), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000279 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280 (is_lvalue_reference<_Tp>::value ||
281 is_same<typename remove_reference<_Tp>::type,
282 reference_wrapper<
283 typename remove_reference<_Hp>::type
284 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000285 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 "Attempted to construct a reference element in a tuple with an rvalue");}
287
Marshall Clow398c9d82014-04-21 23:48:09 +0000288 __tuple_leaf(const __tuple_leaf& __t) = default;
289 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
291 template <class _Tp>
292 _LIBCPP_INLINE_VISIBILITY
293 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000294 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000296 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297 return *this;
298 }
299
300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000301 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000303 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304 return 0;
305 }
306
Marshall Clowda0a0e82013-07-22 16:02:19 +0000307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309};
310
311template <size_t _Ip, class _Hp>
312class __tuple_leaf<_Ip, _Hp, true>
313 : private _Hp
314{
315
316 __tuple_leaf& operator=(const __tuple_leaf&);
317public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000318 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
319 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
321 template <class _Alloc>
322 _LIBCPP_INLINE_VISIBILITY
323 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
324
325 template <class _Alloc>
326 _LIBCPP_INLINE_VISIBILITY
327 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
328 : _Hp(allocator_arg_t(), __a) {}
329
330 template <class _Alloc>
331 _LIBCPP_INLINE_VISIBILITY
332 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
333 : _Hp(__a) {}
334
Howard Hinnante049cc52010-09-27 17:54:17 +0000335 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000336 class = typename enable_if<
337 __lazy_and<
338 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
339 , is_constructible<_Hp, _Tp>
340 >::value
341 >::type
342 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000344 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000345 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347 template <class _Tp, class _Alloc>
348 _LIBCPP_INLINE_VISIBILITY
349 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000350 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
352 template <class _Tp, class _Alloc>
353 _LIBCPP_INLINE_VISIBILITY
354 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000355 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356
357 template <class _Tp, class _Alloc>
358 _LIBCPP_INLINE_VISIBILITY
359 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000360 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
Eric Fiselier9020c082014-07-24 18:48:34 +0000362 __tuple_leaf(__tuple_leaf const &) = default;
363 __tuple_leaf(__tuple_leaf &&) = default;
364
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 template <class _Tp>
366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000368 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000370 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 return *this;
372 }
373
Howard Hinnanta5e01212011-05-27 19:08:18 +0000374 _LIBCPP_INLINE_VISIBILITY
375 int
376 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000378 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379 return 0;
380 }
381
Marshall Clowda0a0e82013-07-22 16:02:19 +0000382 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
383 _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 +0000384};
385
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000386template <class ..._Tp>
387_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000388void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000390template <class ..._Tp>
391struct __lazy_all : __all<_Tp::value...> {};
392
Marshall Clowbbc7c742014-10-15 10:33:02 +0000393template <class _Tp>
394struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000395
Marshall Clowbbc7c742014-10-15 10:33:02 +0000396template <class ..._Tp>
397struct __all_default_constructible<__tuple_types<_Tp...>>
398 : __all<is_default_constructible<_Tp>::value...>
399{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000400
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401// __tuple_impl
402
403template<class _Indx, class ..._Tp> struct __tuple_impl;
404
405template<size_t ..._Indx, class ..._Tp>
406struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
407 : public __tuple_leaf<_Indx, _Tp>...
408{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000410 _LIBCPP_CONSTEXPR __tuple_impl()
411 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000412
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 template <size_t ..._Uf, class ..._Tf,
414 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000415 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 explicit
417 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
418 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000419 _Up&&... __u)
420 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
421 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000422 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 __tuple_leaf<_Ul, _Tl>()...
424 {}
425
426 template <class _Alloc, size_t ..._Uf, class ..._Tf,
427 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 explicit
430 __tuple_impl(allocator_arg_t, const _Alloc& __a,
431 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
432 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
433 _Up&&... __u) :
434 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000435 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
437 {}
438
439 template <class _Tuple,
440 class = typename enable_if
441 <
Howard Hinnant99324892013-04-14 00:01:13 +0000442 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443 >::type
444 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000445 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000446 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
447 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000448 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
449 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 {}
451
452 template <class _Alloc, class _Tuple,
453 class = typename enable_if
454 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000455 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 >::type
457 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
460 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000461 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000462 _VSTD::forward<typename tuple_element<_Indx,
463 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 {}
465
466 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 typename enable_if
469 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000470 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 __tuple_impl&
472 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000473 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
474 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000476 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
477 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 return *this;
479 }
480
Howard Hinnant3de50862013-11-06 17:45:43 +0000481 __tuple_impl(const __tuple_impl&) = default;
482 __tuple_impl(__tuple_impl&&) = default;
483
484 _LIBCPP_INLINE_VISIBILITY
485 __tuple_impl&
486 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
487 {
488 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
489 return *this;
490 }
491
492 _LIBCPP_INLINE_VISIBILITY
493 __tuple_impl&
494 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
495 {
496 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
497 return *this;
498 }
Howard Hinnant28484442012-02-15 20:13:52 +0000499
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000502 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503 {
504 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
505 }
506};
507
Eric Fiselierd5019332016-04-15 18:05:59 +0000508template <bool _IsTuple, class _SizeTrait, size_t _Expected>
509struct __tuple_like_with_size_imp : false_type {};
510
511template <class _SizeTrait, size_t _Expected>
512struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
513 : integral_constant<bool, _SizeTrait::value == _Expected> {};
514
515template <class _Tuple, size_t _ExpectedSize,
516 class _RawTuple = typename __uncvref<_Tuple>::type>
517using __tuple_like_with_size = __tuple_like_with_size_imp<
518 __tuple_like<_RawTuple>::value,
519 tuple_size<_RawTuple>, _ExpectedSize
520 >;
521
522
523struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
524 template <class ...>
525 static constexpr bool __enable_explicit() { return false; }
526 template <class ...>
527 static constexpr bool __enable_implicit() { return false; }
528};
529
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000531class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532{
533 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
534
535 base base_;
536
Eric Fiselierd5019332016-04-15 18:05:59 +0000537 template <class ..._Args>
538 struct _PackExpandsToThisTuple : false_type {};
539
540 template <class _Arg>
541 struct _PackExpandsToThisTuple<_Arg>
542 : is_same<typename __uncvref<_Arg>::type, tuple> {};
543
544 template <bool _MaybeEnable, class _Dummy = void>
545 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
546
547 template <class _Dummy>
548 struct _CheckArgsConstructor<true, _Dummy>
549 {
550 template <class ..._Args>
551 static constexpr bool __enable_explicit() {
552 return
553 __tuple_constructible<
554 tuple<_Args...>,
555 typename __make_tuple_types<tuple,
556 sizeof...(_Args) < sizeof...(_Tp) ?
557 sizeof...(_Args) :
558 sizeof...(_Tp)>::type
559 >::value &&
560 !__tuple_convertible<
561 tuple<_Args...>,
562 typename __make_tuple_types<tuple,
563 sizeof...(_Args) < sizeof...(_Tp) ?
564 sizeof...(_Args) :
565 sizeof...(_Tp)>::type
566 >::value &&
567 __all_default_constructible<
568 typename __make_tuple_types<tuple, sizeof...(_Tp),
569 sizeof...(_Args) < sizeof...(_Tp) ?
570 sizeof...(_Args) :
571 sizeof...(_Tp)>::type
572 >::value;
573 }
574
575 template <class ..._Args>
576 static constexpr bool __enable_implicit() {
577 return
578 __tuple_convertible<
579 tuple<_Args...>,
580 typename __make_tuple_types<tuple,
581 sizeof...(_Args) < sizeof...(_Tp) ?
582 sizeof...(_Args) :
583 sizeof...(_Tp)>::type
584 >::value &&
585 __all_default_constructible<
586 typename __make_tuple_types<tuple, sizeof...(_Tp),
587 sizeof...(_Args) < sizeof...(_Tp) ?
588 sizeof...(_Args) :
589 sizeof...(_Tp)>::type
590 >::value;
591 }
592 };
593
594 template <bool _MaybeEnable,
595 bool = sizeof...(_Tp) == 1,
596 class _Dummy = void>
597 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
598
599 template <class _Dummy>
600 struct _CheckTupleLikeConstructor<true, false, _Dummy>
601 {
602 template <class _Tuple>
603 static constexpr bool __enable_implicit() {
604 return __tuple_convertible<_Tuple, tuple>::value;
605 }
606
607 template <class _Tuple>
608 static constexpr bool __enable_explicit() {
609 return __tuple_constructible<_Tuple, tuple>::value
610 && !__tuple_convertible<_Tuple, tuple>::value;
611 }
612 };
613
614 template <class _Dummy>
615 struct _CheckTupleLikeConstructor<true, true, _Dummy>
616 {
617 // This trait is used to disable the tuple-like constructor when
618 // the UTypes... constructor should be selected instead.
619 // See LWG issue #2549.
620 template <class _Tuple>
621 using _PreferTupleLikeConstructor = __lazy_or<
622 // Don't attempt the two checks below if the tuple we are given
623 // has the same type as this tuple.
624 is_same<typename __uncvref<_Tuple>::type, tuple>,
625 __lazy_and<
626 __lazy_not<is_constructible<_Tp..., _Tuple>>,
627 __lazy_not<is_convertible<_Tuple, _Tp...>>
628 >
629 >;
630
631 template <class _Tuple>
632 static constexpr bool __enable_implicit() {
633 return __lazy_and<
634 __tuple_convertible<_Tuple, tuple>,
635 _PreferTupleLikeConstructor<_Tuple>
636 >::value;
637 }
638
639 template <class _Tuple>
640 static constexpr bool __enable_explicit() {
641 return __lazy_and<
642 __tuple_constructible<_Tuple, tuple>,
643 _PreferTupleLikeConstructor<_Tuple>,
644 __lazy_not<__tuple_convertible<_Tuple, tuple>>
645 >::value;
646 }
647 };
648
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000649 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000650 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000651 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000652 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000653 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000654 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000655 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
656 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657public:
658
Eric Fiselierda1818a2015-02-21 02:30:41 +0000659 template <bool _Dummy = true, class = typename enable_if<
660 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
Marshall Clowbbc7c742014-10-15 10:33:02 +0000661 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000663 _LIBCPP_CONSTEXPR tuple()
664 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000665
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000666 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
667 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000668 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000669 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
670 >::value
671 >::type>
672 _LIBCPP_INLINE_VISIBILITY
673 tuple(_AllocArgT, _Alloc const& __a)
674 : base_(allocator_arg_t(), __a,
675 __tuple_indices<>(), __tuple_types<>(),
676 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
677 __tuple_types<_Tp...>()) {}
678
Eric Fiselier95526d32016-04-19 01:19:25 +0000679 template <bool _Dummy = true,
680 typename enable_if
681 <
682 _CheckArgsConstructor<
683 _Dummy
684 >::template __enable_implicit<_Tp...>(),
685 bool
686 >::type = false
687 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000688 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000689 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
691 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
692 typename __make_tuple_indices<0>::type(),
693 typename __make_tuple_types<tuple, 0>::type(),
694 __t...
695 ) {}
696
Eric Fiselier95526d32016-04-19 01:19:25 +0000697 template <bool _Dummy = true,
698 typename enable_if
699 <
700 _CheckArgsConstructor<
701 _Dummy
702 >::template __enable_explicit<_Tp...>(),
703 bool
704 >::type = false
705 >
706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
707 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
708 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
709 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
710 typename __make_tuple_indices<0>::type(),
711 typename __make_tuple_types<tuple, 0>::type(),
712 __t...
713 ) {}
714
715 template <class _Alloc, bool _Dummy = true,
716 typename enable_if
717 <
718 _CheckArgsConstructor<
719 _Dummy
720 >::template __enable_implicit<_Tp...>(),
721 bool
722 >::type = false
723 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
726 : base_(allocator_arg_t(), __a,
727 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
728 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
729 typename __make_tuple_indices<0>::type(),
730 typename __make_tuple_types<tuple, 0>::type(),
731 __t...
732 ) {}
733
Eric Fiselier95526d32016-04-19 01:19:25 +0000734 template <class _Alloc, bool _Dummy = true,
735 typename enable_if
736 <
737 _CheckArgsConstructor<
738 _Dummy
739 >::template __enable_explicit<_Tp...>(),
740 bool
741 >::type = false
742 >
743 _LIBCPP_INLINE_VISIBILITY
744 explicit
745 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
746 : base_(allocator_arg_t(), __a,
747 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
748 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
749 typename __make_tuple_indices<0>::type(),
750 typename __make_tuple_types<tuple, 0>::type(),
751 __t...
752 ) {}
753
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000755 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000757 _CheckArgsConstructor<
758 sizeof...(_Up) <= sizeof...(_Tp)
759 && !_PackExpandsToThisTuple<_Up...>::value
760 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000761 bool
762 >::type = false
763 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000765 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000766 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000767 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000768 typename __make_tuple_indices<sizeof...(_Up)>::type,
769 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
770 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
771 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000772 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000773 >::value
774 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000775 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
776 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
777 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
778 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
779 _VSTD::forward<_Up>(__u)...) {}
780
781 template <class ..._Up,
782 typename enable_if
783 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000784 _CheckArgsConstructor<
785 sizeof...(_Up) <= sizeof...(_Tp)
786 && !_PackExpandsToThisTuple<_Up...>::value
787 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000788 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000789 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000791 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 explicit
793 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000794 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000795 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-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 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
804 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 Hinnant0949eed2011-06-30 21:18:19 +0000807 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808
809 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000810 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000812 _CheckArgsConstructor<
813 sizeof...(_Up) == sizeof...(_Tp) &&
814 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000815 >::template __enable_implicit<_Up...>(),
816 bool
817 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
821 : base_(allocator_arg_t(), __a,
822 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 Hinnant0949eed2011-06-30 21:18:19 +0000826 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827
Eric Fiselier95526d32016-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)
841 : base_(allocator_arg_t(), __a,
842 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000849 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000851 _CheckTupleLikeConstructor<
852 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
853 && !_PackExpandsToThisTuple<_Tuple>::value
854 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000855 bool
856 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000859 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000860 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000862 template <class _Tuple,
863 typename enable_if
864 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000865 _CheckTupleLikeConstructor<
866 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
867 && !_PackExpandsToThisTuple<_Tuple>::value
868 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000869 bool
870 >::type = false
871 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000872 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000873 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000874 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000875 : base_(_VSTD::forward<_Tuple>(__t)) {}
876
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000878 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000880 _CheckTupleLikeConstructor<
881 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000882 >::template __enable_implicit<_Tuple>(),
883 bool
884 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000888 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889
Eric Fiselier95526d32016-04-19 01:19:25 +0000890 template <class _Alloc, class _Tuple,
891 typename enable_if
892 <
893 _CheckTupleLikeConstructor<
894 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
895 >::template __enable_explicit<_Tuple>(),
896 bool
897 >::type = false
898 >
899 _LIBCPP_INLINE_VISIBILITY
900 explicit
901 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
902 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
903
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904 template <class _Tuple,
905 class = typename enable_if
906 <
907 __tuple_assignable<_Tuple, tuple>::value
908 >::type
909 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000912 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000914 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 return *this;
916 }
917
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000919 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
920 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921};
922
923template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000924class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925{
926public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000928 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000931 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000934 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000935 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000937 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000938 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000940 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000942 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943};
944
945template <class ..._Tp>
946inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000947typename enable_if
948<
949 __all<__is_swappable<_Tp>::value...>::value,
950 void
951>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000952swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
953 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
954 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955
956// get
957
958template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000959inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000960typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000961get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000963 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
965}
966
967template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000968inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000969const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000970get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000972 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
974}
975
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000976template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000977inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000978typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000979get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000980{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000981 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000982 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000983 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000984}
985
Eric Fiselier199bee02015-12-18 00:36:55 +0000986template <size_t _Ip, class ..._Tp>
987inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
988const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
989get(const tuple<_Tp...>&& __t) _NOEXCEPT
990{
991 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
992 return static_cast<const type&&>(
993 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
994}
995
Marshall Clowe8029e52013-07-13 02:54:05 +0000996#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000997
Eric Fiselier22c3e762016-07-02 03:18:30 +0000998namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000999
Eric Fiselier22c3e762016-07-02 03:18:30 +00001000static constexpr size_t __not_found = -1;
1001static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +00001002
Eric Fiselier22c3e762016-07-02 03:18:30 +00001003inline _LIBCPP_INLINE_VISIBILITY
1004constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1005 return !__matches ? __res :
1006 (__res == __not_found ? __curr_i : __ambiguous);
1007}
Marshall Clowe8029e52013-07-13 02:54:05 +00001008
Eric Fiselier22c3e762016-07-02 03:18:30 +00001009template <size_t _Nx>
1010inline _LIBCPP_INLINE_VISIBILITY
1011constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1012 return __i == _Nx ? __not_found :
1013 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1014}
1015
1016template <class _T1, class ..._Args>
1017struct __find_exactly_one_checked {
1018 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
1019 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1020 static_assert (value != __not_found, "type not found in type list" );
1021 static_assert(value != __ambiguous,"type occurs more than once in type list");
1022};
1023
Eric Fiselier990090f2016-07-02 03:46:08 +00001024template <class _T1>
1025struct __find_exactly_one_checked<_T1> {
1026 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1027};
1028
Eric Fiselier22c3e762016-07-02 03:18:30 +00001029} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001030
1031template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001032struct __find_exactly_one_t
1033 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1034};
Marshall Clowe8029e52013-07-13 02:54:05 +00001035
1036template <class _T1, class... _Args>
1037inline _LIBCPP_INLINE_VISIBILITY
1038constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1039{
1040 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1041}
1042
1043template <class _T1, class... _Args>
1044inline _LIBCPP_INLINE_VISIBILITY
1045constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1046{
1047 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1048}
1049
1050template <class _T1, class... _Args>
1051inline _LIBCPP_INLINE_VISIBILITY
1052constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1053{
Marshall Clow01a0e902013-07-15 20:46:11 +00001054 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001055}
1056
Eric Fiselier199bee02015-12-18 00:36:55 +00001057template <class _T1, class... _Args>
1058inline _LIBCPP_INLINE_VISIBILITY
1059constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1060{
1061 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1062}
1063
Marshall Clowe8029e52013-07-13 02:54:05 +00001064#endif
1065
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066// tie
1067
1068template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001069inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001071tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072{
1073 return tuple<_Tp&...>(__t...);
1074}
1075
1076template <class _Up>
1077struct __ignore_t
1078{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 const __ignore_t& operator=(_Tp&&) const {return *this;}
1082};
1083
1084namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1085
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001087struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088{
1089 typedef _Tp type;
1090};
1091
1092template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001093struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094{
1095 typedef _Tp& type;
1096};
1097
1098template <class _Tp>
1099struct __make_tuple_return
1100{
Marshall Clowa71f9562014-01-03 22:55:49 +00001101 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102};
1103
1104template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001105inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106tuple<typename __make_tuple_return<_Tp>::type...>
1107make_tuple(_Tp&&... __t)
1108{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001109 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110}
1111
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001112template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001113inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1114tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001115forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001116{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001117 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001118}
1119
Howard Hinnant99968442011-11-29 18:15:50 +00001120template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121struct __tuple_equal
1122{
1123 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 bool operator()(const _Tp& __x, const _Up& __y)
1126 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001127 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 }
1129};
1130
1131template <>
1132struct __tuple_equal<0>
1133{
1134 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001135 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 bool operator()(const _Tp&, const _Up&)
1137 {
1138 return true;
1139 }
1140};
1141
1142template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144bool
1145operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1146{
1147 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1148}
1149
1150template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001151inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152bool
1153operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1154{
1155 return !(__x == __y);
1156}
1157
Howard Hinnant99968442011-11-29 18:15:50 +00001158template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159struct __tuple_less
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& __x, const _Up& __y)
1164 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001165 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1166 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1167 return true;
1168 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1169 return false;
1170 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 }
1172};
1173
1174template <>
1175struct __tuple_less<0>
1176{
1177 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001178 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 bool operator()(const _Tp&, const _Up&)
1180 {
1181 return false;
1182 }
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 __tuple_less<sizeof...(_Tp)>()(__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
1201template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203bool
1204operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1205{
1206 return !(__x < __y);
1207}
1208
1209template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001210inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211bool
1212operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1213{
1214 return !(__y < __x);
1215}
1216
1217// tuple_cat
1218
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001219template <class _Tp, class _Up> struct __tuple_cat_type;
1220
1221template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001222struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001224 typedef tuple<_Ttypes..., _Utypes...> type;
1225};
1226
1227template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1228struct __tuple_cat_return_1
1229{
1230};
1231
1232template <class ..._Types, class _Tuple0>
1233struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1234{
1235 typedef typename __tuple_cat_type<tuple<_Types...>,
1236 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1237 type;
1238};
1239
1240template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1241struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1242 : public __tuple_cat_return_1<
1243 typename __tuple_cat_type<
1244 tuple<_Types...>,
1245 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1246 >::type,
1247 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1248 _Tuple1, _Tuples...>
1249{
1250};
1251
1252template <class ..._Tuples> struct __tuple_cat_return;
1253
1254template <class _Tuple0, class ..._Tuples>
1255struct __tuple_cat_return<_Tuple0, _Tuples...>
1256 : public __tuple_cat_return_1<tuple<>,
1257 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1258 _Tuples...>
1259{
1260};
1261
1262template <>
1263struct __tuple_cat_return<>
1264{
1265 typedef tuple<> type;
1266};
1267
Marshall Clowda0a0e82013-07-22 16:02:19 +00001268inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001269tuple<>
1270tuple_cat()
1271{
1272 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273}
1274
Howard Hinnant99968442011-11-29 18:15:50 +00001275template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001276struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277
Howard Hinnante48e3662010-12-12 23:04:37 +00001278template <class ..._Types, size_t ..._I0, class _Tuple0>
1279struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001281 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001282 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1283 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1284};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285
Howard Hinnante48e3662010-12-12 23:04:37 +00001286template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1287struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1288 _Tuple0, _Tuple1, _Tuples...>
1289 : public __tuple_cat_return_ref_imp<
1290 tuple<_Types..., typename __apply_cv<_Tuple0,
1291 typename tuple_element<_I0,
1292 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1293 typename __make_tuple_indices<tuple_size<typename
1294 remove_reference<_Tuple1>::type>::value>::type,
1295 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296{
Howard Hinnante48e3662010-12-12 23:04:37 +00001297};
1298
1299template <class _Tuple0, class ..._Tuples>
1300struct __tuple_cat_return_ref
1301 : public __tuple_cat_return_ref_imp<tuple<>,
1302 typename __make_tuple_indices<
1303 tuple_size<typename remove_reference<_Tuple0>::type>::value
1304 >::type, _Tuple0, _Tuples...>
1305{
1306};
1307
1308template <class _Types, class _I0, class _J0>
1309struct __tuple_cat;
1310
1311template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001312struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001313{
1314 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001316 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1317 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1318 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001319 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1320 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001321 }
1322
1323 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001324 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001325 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1326 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1327 {
1328 typedef typename remove_reference<_Tuple0>::type _T0;
1329 typedef typename remove_reference<_Tuple1>::type _T1;
1330 return __tuple_cat<
1331 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1332 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1333 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001334 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001335 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1336 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001337 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001338 _VSTD::forward<_Tuple1>(__t1),
1339 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001340 }
1341};
1342
1343template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001344inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001345typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1346tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1347{
1348 typedef typename remove_reference<_Tuple0>::type _T0;
1349 return __tuple_cat<tuple<>, __tuple_indices<>,
1350 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001351 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1352 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353}
1354
1355template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001356struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357 : true_type {};
1358
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359template <class _T1, class _T2>
1360template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1361inline _LIBCPP_INLINE_VISIBILITY
1362pair<_T1, _T2>::pair(piecewise_construct_t,
1363 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1364 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001365 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1366 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367{
1368}
1369
Howard Hinnant324bb032010-08-22 00:02:43 +00001370#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371
Eric Fiselier5839fed2016-07-18 00:35:56 +00001372#if _LIBCPP_STD_VER > 14
1373template <class _Tp>
1374constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1375
1376#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1377
1378template <class _Fn, class _Tuple, size_t ..._Id>
1379inline _LIBCPP_INLINE_VISIBILITY
1380constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1381 __tuple_indices<_Id...>)
1382_LIBCPP_NOEXCEPT_RETURN(
1383 _VSTD::__invoke_constexpr(
1384 _VSTD::forward<_Fn>(__f),
1385 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1386)
1387
1388template <class _Fn, class _Tuple>
1389inline _LIBCPP_INLINE_VISIBILITY
1390constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1391_LIBCPP_NOEXCEPT_RETURN(
1392 _VSTD::__apply_tuple_impl(
1393 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1394 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1395)
1396
1397template <class _Tp, class _Tuple, size_t... _Idx>
1398inline _LIBCPP_INLINE_VISIBILITY
1399constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1400_LIBCPP_NOEXCEPT_RETURN(
1401 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1402)
1403
1404template <class _Tp, class _Tuple>
1405inline _LIBCPP_INLINE_VISIBILITY
1406constexpr _Tp make_from_tuple(_Tuple&& __t)
1407_LIBCPP_NOEXCEPT_RETURN(
1408 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1409 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1410)
1411
1412#undef _LIBCPP_NOEXCEPT_RETURN
1413
1414#endif // _LIBCPP_STD_VER > 14
1415
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416_LIBCPP_END_NAMESPACE_STD
1417
1418#endif // _LIBCPP_TUPLE