blob: 6a65aba455b3d4c02a54684aa634b476de90e283 [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
Howard Hinnant0e1493e2010-12-11 20:47:50 +000079
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080// 20.4.1.4, tuple helper classes:
81template <class T> class tuple_size; // undefined
82template <class... T> class tuple_size<tuple<T...>>;
Marshall Clowa6607572015-11-19 19:45:29 +000083template <size_t I, class T> class tuple_element; // undefined
84template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
85template <size_t I, class T>
86 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087
88// 20.4.1.5, element access:
Marshall Clowa6607572015-11-19 19:45:29 +000089template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +000090 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000091 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +000092template <size_t I, class... T>
93 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000094 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +000095template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +000096 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000097 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier199bee02015-12-18 00:36:55 +000098template <size_t I, class... T>
99 const typename tuple_element<I, tuple<T...>>::type&&
100 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101
Marshall Clowe8029e52013-07-13 02:54:05 +0000102template <class T1, class... T>
103 constexpr T1& get(tuple<T...>&) noexcept; // C++14
104template <class T1, class... T>
Marshall Clowa6607572015-11-19 19:45:29 +0000105 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000106template <class T1, class... T>
107 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000108template <class T1, class... T>
109 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000110
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19 +0000112template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
113template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
114template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
115template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
116template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
117template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118
119template <class... Types, class Alloc>
120 struct uses_allocator<tuple<Types...>, Alloc>;
121
122template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000123 void
124 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000125
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126} // std
127
128*/
129
130#include <__config>
131#include <__tuple>
132#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000134#include <__functional_base>
135#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136
Howard Hinnant08e17472011-10-17 20:05:10 +0000137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000139#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140
141_LIBCPP_BEGIN_NAMESPACE_STD
142
143#ifndef _LIBCPP_HAS_NO_VARIADICS
144
145// tuple_size
146
147template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000148class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149 : public integral_constant<size_t, sizeof...(_Tp)>
150{
151};
152
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153// tuple_element
154
155template <size_t _Ip, class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000156class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157{
158public:
Howard Hinnantf83417b2011-01-24 16:07:25 +0000159 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160};
161
Marshall Clow50fe0c72014-03-03 06:18:11 +0000162#if _LIBCPP_STD_VER > 11
163template <size_t _Ip, class ..._Tp>
164using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
165#endif
166
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167// __tuple_leaf
168
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000169template <size_t _Ip, class _Hp,
170 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000171 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172class __tuple_leaf;
173
174template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000175inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000177 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178{
179 swap(__x.get(), __y.get());
180}
181
182template <size_t _Ip, class _Hp, bool>
183class __tuple_leaf
184{
185 _Hp value;
186
187 __tuple_leaf& operator=(const __tuple_leaf&);
188public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000189 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
190 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191 {static_assert(!is_reference<_Hp>::value,
192 "Attempted to default construct a reference element in a tuple");}
193
194 template <class _Alloc>
195 _LIBCPP_INLINE_VISIBILITY
196 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
197 : value()
198 {static_assert(!is_reference<_Hp>::value,
199 "Attempted to default construct a reference element in a tuple");}
200
201 template <class _Alloc>
202 _LIBCPP_INLINE_VISIBILITY
203 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
204 : value(allocator_arg_t(), __a)
205 {static_assert(!is_reference<_Hp>::value,
206 "Attempted to default construct a reference element in a tuple");}
207
208 template <class _Alloc>
209 _LIBCPP_INLINE_VISIBILITY
210 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
211 : value(__a)
212 {static_assert(!is_reference<_Hp>::value,
213 "Attempted to default construct a reference element in a tuple");}
214
Howard Hinnante049cc52010-09-27 17:54:17 +0000215 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000216 class = typename enable_if<
217 __lazy_and<
218 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
219 , is_constructible<_Hp, _Tp>
220 >::value
221 >::type
222 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000224 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000225 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000226 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000227 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 (is_lvalue_reference<_Tp>::value ||
229 is_same<typename remove_reference<_Tp>::type,
230 reference_wrapper<
231 typename remove_reference<_Hp>::type
232 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000233 >::value)) ||
Howard Hinnante049cc52010-09-27 17:54:17 +0000234 (is_rvalue_reference<_Hp>::value &&
235 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236 "Attempted to construct a reference element in a tuple with an rvalue");}
237
238 template <class _Tp, class _Alloc>
239 _LIBCPP_INLINE_VISIBILITY
240 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000241 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000242 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000243 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244 (is_lvalue_reference<_Tp>::value ||
245 is_same<typename remove_reference<_Tp>::type,
246 reference_wrapper<
247 typename remove_reference<_Hp>::type
248 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000249 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250 "Attempted to construct a reference element in a tuple with an rvalue");}
251
252 template <class _Tp, class _Alloc>
253 _LIBCPP_INLINE_VISIBILITY
254 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000255 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000257 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 (is_lvalue_reference<_Tp>::value ||
259 is_same<typename remove_reference<_Tp>::type,
260 reference_wrapper<
261 typename remove_reference<_Hp>::type
262 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000263 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264 "Attempted to construct a reference element in a tuple with an rvalue");}
265
266 template <class _Tp, class _Alloc>
267 _LIBCPP_INLINE_VISIBILITY
268 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000269 : value(_VSTD::forward<_Tp>(__t), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000271 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 (is_lvalue_reference<_Tp>::value ||
273 is_same<typename remove_reference<_Tp>::type,
274 reference_wrapper<
275 typename remove_reference<_Hp>::type
276 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000277 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278 "Attempted to construct a reference element in a tuple with an rvalue");}
279
Marshall Clow398c9d82014-04-21 23:48:09 +0000280 __tuple_leaf(const __tuple_leaf& __t) = default;
281 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282
283 template <class _Tp>
284 _LIBCPP_INLINE_VISIBILITY
285 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000286 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000288 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289 return *this;
290 }
291
292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000293 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000295 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296 return 0;
297 }
298
Marshall Clowda0a0e82013-07-22 16:02:19 +0000299 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301};
302
303template <size_t _Ip, class _Hp>
304class __tuple_leaf<_Ip, _Hp, true>
305 : private _Hp
306{
307
308 __tuple_leaf& operator=(const __tuple_leaf&);
309public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000310 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
311 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313 template <class _Alloc>
314 _LIBCPP_INLINE_VISIBILITY
315 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
316
317 template <class _Alloc>
318 _LIBCPP_INLINE_VISIBILITY
319 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
320 : _Hp(allocator_arg_t(), __a) {}
321
322 template <class _Alloc>
323 _LIBCPP_INLINE_VISIBILITY
324 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
325 : _Hp(__a) {}
326
Howard Hinnante049cc52010-09-27 17:54:17 +0000327 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000328 class = typename enable_if<
329 __lazy_and<
330 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
331 , is_constructible<_Hp, _Tp>
332 >::value
333 >::type
334 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000336 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000337 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338
339 template <class _Tp, class _Alloc>
340 _LIBCPP_INLINE_VISIBILITY
341 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000342 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343
344 template <class _Tp, class _Alloc>
345 _LIBCPP_INLINE_VISIBILITY
346 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000347 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
349 template <class _Tp, class _Alloc>
350 _LIBCPP_INLINE_VISIBILITY
351 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000352 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
Eric Fiselier9020c082014-07-24 18:48:34 +0000354 __tuple_leaf(__tuple_leaf const &) = default;
355 __tuple_leaf(__tuple_leaf &&) = default;
356
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357 template <class _Tp>
358 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000360 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000362 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 return *this;
364 }
365
Howard Hinnanta5e01212011-05-27 19:08:18 +0000366 _LIBCPP_INLINE_VISIBILITY
367 int
368 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000370 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 return 0;
372 }
373
Marshall Clowda0a0e82013-07-22 16:02:19 +0000374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
375 _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 +0000376};
377
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000378template <class ..._Tp>
379_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000380void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000382template <bool ..._Pred>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000383struct __all
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000384 : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000385{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000386
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000387template <class ..._Tp>
388struct __lazy_all : __all<_Tp::value...> {};
389
Marshall Clowbbc7c742014-10-15 10:33:02 +0000390template <class _Tp>
391struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000392
Marshall Clowbbc7c742014-10-15 10:33:02 +0000393template <class ..._Tp>
394struct __all_default_constructible<__tuple_types<_Tp...>>
395 : __all<is_default_constructible<_Tp>::value...>
396{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000397
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398// __tuple_impl
399
400template<class _Indx, class ..._Tp> struct __tuple_impl;
401
402template<size_t ..._Indx, class ..._Tp>
403struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
404 : public __tuple_leaf<_Indx, _Tp>...
405{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000407 _LIBCPP_CONSTEXPR __tuple_impl()
408 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000409
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 template <size_t ..._Uf, class ..._Tf,
411 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000412 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 explicit
414 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
415 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000416 _Up&&... __u)
417 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
418 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000419 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 __tuple_leaf<_Ul, _Tl>()...
421 {}
422
423 template <class _Alloc, size_t ..._Uf, class ..._Tf,
424 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 explicit
427 __tuple_impl(allocator_arg_t, const _Alloc& __a,
428 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
429 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
430 _Up&&... __u) :
431 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000432 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
434 {}
435
436 template <class _Tuple,
437 class = typename enable_if
438 <
Howard Hinnant99324892013-04-14 00:01:13 +0000439 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 >::type
441 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000442 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000443 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
444 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000445 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
446 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 {}
448
449 template <class _Alloc, class _Tuple,
450 class = typename enable_if
451 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000452 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 >::type
454 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
457 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000458 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000459 _VSTD::forward<typename tuple_element<_Indx,
460 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461 {}
462
463 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465 typename enable_if
466 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000467 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 __tuple_impl&
469 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000470 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
471 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000473 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
474 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 return *this;
476 }
477
Howard Hinnant3de50862013-11-06 17:45:43 +0000478 __tuple_impl(const __tuple_impl&) = default;
479 __tuple_impl(__tuple_impl&&) = default;
480
481 _LIBCPP_INLINE_VISIBILITY
482 __tuple_impl&
483 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
484 {
485 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
486 return *this;
487 }
488
489 _LIBCPP_INLINE_VISIBILITY
490 __tuple_impl&
491 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
492 {
493 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
494 return *this;
495 }
Howard Hinnant28484442012-02-15 20:13:52 +0000496
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000499 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 {
501 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
502 }
503};
504
Eric Fiselierd5019332016-04-15 18:05:59 +0000505template <bool _IsTuple, class _SizeTrait, size_t _Expected>
506struct __tuple_like_with_size_imp : false_type {};
507
508template <class _SizeTrait, size_t _Expected>
509struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
510 : integral_constant<bool, _SizeTrait::value == _Expected> {};
511
512template <class _Tuple, size_t _ExpectedSize,
513 class _RawTuple = typename __uncvref<_Tuple>::type>
514using __tuple_like_with_size = __tuple_like_with_size_imp<
515 __tuple_like<_RawTuple>::value,
516 tuple_size<_RawTuple>, _ExpectedSize
517 >;
518
519
520struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
521 template <class ...>
522 static constexpr bool __enable_explicit() { return false; }
523 template <class ...>
524 static constexpr bool __enable_implicit() { return false; }
525};
526
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000528class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529{
530 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
531
532 base base_;
533
Eric Fiselierd5019332016-04-15 18:05:59 +0000534 template <class ..._Args>
535 struct _PackExpandsToThisTuple : false_type {};
536
537 template <class _Arg>
538 struct _PackExpandsToThisTuple<_Arg>
539 : is_same<typename __uncvref<_Arg>::type, tuple> {};
540
541 template <bool _MaybeEnable, class _Dummy = void>
542 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
543
544 template <class _Dummy>
545 struct _CheckArgsConstructor<true, _Dummy>
546 {
547 template <class ..._Args>
548 static constexpr bool __enable_explicit() {
549 return
550 __tuple_constructible<
551 tuple<_Args...>,
552 typename __make_tuple_types<tuple,
553 sizeof...(_Args) < sizeof...(_Tp) ?
554 sizeof...(_Args) :
555 sizeof...(_Tp)>::type
556 >::value &&
557 !__tuple_convertible<
558 tuple<_Args...>,
559 typename __make_tuple_types<tuple,
560 sizeof...(_Args) < sizeof...(_Tp) ?
561 sizeof...(_Args) :
562 sizeof...(_Tp)>::type
563 >::value &&
564 __all_default_constructible<
565 typename __make_tuple_types<tuple, sizeof...(_Tp),
566 sizeof...(_Args) < sizeof...(_Tp) ?
567 sizeof...(_Args) :
568 sizeof...(_Tp)>::type
569 >::value;
570 }
571
572 template <class ..._Args>
573 static constexpr bool __enable_implicit() {
574 return
575 __tuple_convertible<
576 tuple<_Args...>,
577 typename __make_tuple_types<tuple,
578 sizeof...(_Args) < sizeof...(_Tp) ?
579 sizeof...(_Args) :
580 sizeof...(_Tp)>::type
581 >::value &&
582 __all_default_constructible<
583 typename __make_tuple_types<tuple, sizeof...(_Tp),
584 sizeof...(_Args) < sizeof...(_Tp) ?
585 sizeof...(_Args) :
586 sizeof...(_Tp)>::type
587 >::value;
588 }
589 };
590
591 template <bool _MaybeEnable,
592 bool = sizeof...(_Tp) == 1,
593 class _Dummy = void>
594 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
595
596 template <class _Dummy>
597 struct _CheckTupleLikeConstructor<true, false, _Dummy>
598 {
599 template <class _Tuple>
600 static constexpr bool __enable_implicit() {
601 return __tuple_convertible<_Tuple, tuple>::value;
602 }
603
604 template <class _Tuple>
605 static constexpr bool __enable_explicit() {
606 return __tuple_constructible<_Tuple, tuple>::value
607 && !__tuple_convertible<_Tuple, tuple>::value;
608 }
609 };
610
611 template <class _Dummy>
612 struct _CheckTupleLikeConstructor<true, true, _Dummy>
613 {
614 // This trait is used to disable the tuple-like constructor when
615 // the UTypes... constructor should be selected instead.
616 // See LWG issue #2549.
617 template <class _Tuple>
618 using _PreferTupleLikeConstructor = __lazy_or<
619 // Don't attempt the two checks below if the tuple we are given
620 // has the same type as this tuple.
621 is_same<typename __uncvref<_Tuple>::type, tuple>,
622 __lazy_and<
623 __lazy_not<is_constructible<_Tp..., _Tuple>>,
624 __lazy_not<is_convertible<_Tuple, _Tp...>>
625 >
626 >;
627
628 template <class _Tuple>
629 static constexpr bool __enable_implicit() {
630 return __lazy_and<
631 __tuple_convertible<_Tuple, tuple>,
632 _PreferTupleLikeConstructor<_Tuple>
633 >::value;
634 }
635
636 template <class _Tuple>
637 static constexpr bool __enable_explicit() {
638 return __lazy_and<
639 __tuple_constructible<_Tuple, tuple>,
640 _PreferTupleLikeConstructor<_Tuple>,
641 __lazy_not<__tuple_convertible<_Tuple, tuple>>
642 >::value;
643 }
644 };
645
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000646 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000647 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000648 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000649 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000650 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000651 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000652 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
653 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654public:
655
Eric Fiselierda1818a2015-02-21 02:30:41 +0000656 template <bool _Dummy = true, class = typename enable_if<
657 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
Marshall Clowbbc7c742014-10-15 10:33:02 +0000658 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000660 _LIBCPP_CONSTEXPR tuple()
661 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000662
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000663 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
664 __lazy_and<
665 is_base_of<allocator_arg_t, _AllocArgT>,
666 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
667 >::value
668 >::type>
669 _LIBCPP_INLINE_VISIBILITY
670 tuple(_AllocArgT, _Alloc const& __a)
671 : base_(allocator_arg_t(), __a,
672 __tuple_indices<>(), __tuple_types<>(),
673 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
674 __tuple_types<_Tp...>()) {}
675
Marshall Clowda0a0e82013-07-22 16:02:19 +0000676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000677 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
679 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
680 typename __make_tuple_indices<0>::type(),
681 typename __make_tuple_types<tuple, 0>::type(),
682 __t...
683 ) {}
684
685 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
688 : base_(allocator_arg_t(), __a,
689 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
690 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
691 typename __make_tuple_indices<0>::type(),
692 typename __make_tuple_types<tuple, 0>::type(),
693 __t...
694 ) {}
695
696 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000697 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000699 _CheckArgsConstructor<
700 sizeof...(_Up) <= sizeof...(_Tp)
701 && !_PackExpandsToThisTuple<_Up...>::value
702 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000703 bool
704 >::type = false
705 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000707 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000708 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000709 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000710 typename __make_tuple_indices<sizeof...(_Up)>::type,
711 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
712 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
713 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000714 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000715 >::value
716 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000717 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
718 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
719 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
720 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
721 _VSTD::forward<_Up>(__u)...) {}
722
723 template <class ..._Up,
724 typename enable_if
725 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000726 _CheckArgsConstructor<
727 sizeof...(_Up) <= sizeof...(_Tp)
728 && !_PackExpandsToThisTuple<_Up...>::value
729 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000730 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000731 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 explicit
735 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000736 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000737 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000738 typename __make_tuple_indices<sizeof...(_Up)>::type,
739 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
740 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
741 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
742 _Up...
743 >::value
744 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
746 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
747 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
748 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000749 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750
751 template <class _Alloc, class ..._Up,
752 class = typename enable_if
753 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000754 _CheckArgsConstructor<
755 sizeof...(_Up) == sizeof...(_Tp) &&
756 !_PackExpandsToThisTuple<_Up...>::value
757 >::template __enable_implicit<_Up...>()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758 >::type
759 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
762 : base_(allocator_arg_t(), __a,
763 typename __make_tuple_indices<sizeof...(_Up)>::type(),
764 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
765 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
766 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000767 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768
769 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000770 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000772 _CheckTupleLikeConstructor<
773 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
774 && !_PackExpandsToThisTuple<_Tuple>::value
775 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000776 bool
777 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000779 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000780 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000781 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000783 template <class _Tuple,
784 typename enable_if
785 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000786 _CheckTupleLikeConstructor<
787 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
788 && !_PackExpandsToThisTuple<_Tuple>::value
789 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000790 bool
791 >::type = false
792 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000793 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000794 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000795 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000796 : base_(_VSTD::forward<_Tuple>(__t)) {}
797
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 template <class _Alloc, class _Tuple,
799 class = typename enable_if
800 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000801 _CheckTupleLikeConstructor<
802 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
803 >::template __enable_implicit<_Tuple>()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 >::type
805 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000808 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809
810 template <class _Tuple,
811 class = typename enable_if
812 <
813 __tuple_assignable<_Tuple, tuple>::value
814 >::type
815 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000818 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000820 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 return *this;
822 }
823
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000825 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
826 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827};
828
829template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000830class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831{
832public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000834 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000837 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000840 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000841 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000843 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000844 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000846 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000848 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849};
850
851template <class ..._Tp>
852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000853typename enable_if
854<
855 __all<__is_swappable<_Tp>::value...>::value,
856 void
857>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000858swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
859 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
860 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861
862// get
863
864template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000865inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000866typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000867get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000869 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
871}
872
873template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000874inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000875const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000876get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000878 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
880}
881
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000882template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000883inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000884typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000885get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000886{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000887 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000888 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000889 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000890}
891
Eric Fiselier199bee02015-12-18 00:36:55 +0000892template <size_t _Ip, class ..._Tp>
893inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
894const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
895get(const tuple<_Tp...>&& __t) _NOEXCEPT
896{
897 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
898 return static_cast<const type&&>(
899 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
900}
901
Marshall Clowe8029e52013-07-13 02:54:05 +0000902#if _LIBCPP_STD_VER > 11
903// get by type
904template <typename _T1, size_t _Idx, typename... _Args>
905struct __find_exactly_one_t_helper;
906
907// -- find exactly one
908template <typename _T1, size_t _Idx, typename... _Args>
909struct __find_exactly_one_t_checker {
910 static constexpr size_t value = _Idx;
911// Check the rest of the list to make sure there's only one
912 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
913 };
914
915
916template <typename _T1, size_t _Idx>
917struct __find_exactly_one_t_helper <_T1, _Idx> {
918 static constexpr size_t value = -1;
919 };
920
921template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
922struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
923 static constexpr size_t value =
924 std::conditional<
925 std::is_same<_T1, _Head>::value,
Marshall Clow19e78622013-10-01 13:28:20 +0000926 __find_exactly_one_t_checker<_T1, _Idx, _Args...>,
Marshall Clowe8029e52013-07-13 02:54:05 +0000927 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
928 >::type::value;
929 };
930
931template <typename _T1, typename... _Args>
932struct __find_exactly_one_t {
933 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
934 static_assert ( value != -1, "type not found in type list" );
935 };
936
937template <class _T1, class... _Args>
938inline _LIBCPP_INLINE_VISIBILITY
939constexpr _T1& get(tuple<_Args...>& __tup) noexcept
940{
941 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
942}
943
944template <class _T1, class... _Args>
945inline _LIBCPP_INLINE_VISIBILITY
946constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
947{
948 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
949}
950
951template <class _T1, class... _Args>
952inline _LIBCPP_INLINE_VISIBILITY
953constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
954{
Marshall Clow01a0e902013-07-15 20:46:11 +0000955 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +0000956}
957
Eric Fiselier199bee02015-12-18 00:36:55 +0000958template <class _T1, class... _Args>
959inline _LIBCPP_INLINE_VISIBILITY
960constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
961{
962 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
963}
964
Marshall Clowe8029e52013-07-13 02:54:05 +0000965#endif
966
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967// tie
968
969template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +0000970inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000972tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973{
974 return tuple<_Tp&...>(__t...);
975}
976
977template <class _Up>
978struct __ignore_t
979{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 const __ignore_t& operator=(_Tp&&) const {return *this;}
983};
984
985namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
986
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000988struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989{
990 typedef _Tp type;
991};
992
993template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000994struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995{
996 typedef _Tp& type;
997};
998
999template <class _Tp>
1000struct __make_tuple_return
1001{
Marshall Clowa71f9562014-01-03 22:55:49 +00001002 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003};
1004
1005template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001006inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007tuple<typename __make_tuple_return<_Tp>::type...>
1008make_tuple(_Tp&&... __t)
1009{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001010 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011}
1012
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001013template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001014inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1015tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001016forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001017{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001018 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001019}
1020
Howard Hinnant99968442011-11-29 18:15:50 +00001021template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022struct __tuple_equal
1023{
1024 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001025 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026 bool operator()(const _Tp& __x, const _Up& __y)
1027 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001028 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 }
1030};
1031
1032template <>
1033struct __tuple_equal<0>
1034{
1035 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001036 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037 bool operator()(const _Tp&, const _Up&)
1038 {
1039 return true;
1040 }
1041};
1042
1043template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001044inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045bool
1046operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1047{
1048 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1049}
1050
1051template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001052inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053bool
1054operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1055{
1056 return !(__x == __y);
1057}
1058
Howard Hinnant99968442011-11-29 18:15:50 +00001059template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060struct __tuple_less
1061{
1062 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001063 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 bool operator()(const _Tp& __x, const _Up& __y)
1065 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001066 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1067 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1068 return true;
1069 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1070 return false;
1071 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 }
1073};
1074
1075template <>
1076struct __tuple_less<0>
1077{
1078 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 bool operator()(const _Tp&, const _Up&)
1081 {
1082 return false;
1083 }
1084};
1085
1086template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001087inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088bool
1089operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1090{
1091 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1092}
1093
1094template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001095inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096bool
1097operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1098{
1099 return __y < __x;
1100}
1101
1102template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001103inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104bool
1105operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1106{
1107 return !(__x < __y);
1108}
1109
1110template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001111inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112bool
1113operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1114{
1115 return !(__y < __x);
1116}
1117
1118// tuple_cat
1119
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001120template <class _Tp, class _Up> struct __tuple_cat_type;
1121
1122template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001123struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001124{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001125 typedef tuple<_Ttypes..., _Utypes...> type;
1126};
1127
1128template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1129struct __tuple_cat_return_1
1130{
1131};
1132
1133template <class ..._Types, class _Tuple0>
1134struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1135{
1136 typedef typename __tuple_cat_type<tuple<_Types...>,
1137 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1138 type;
1139};
1140
1141template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1142struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1143 : public __tuple_cat_return_1<
1144 typename __tuple_cat_type<
1145 tuple<_Types...>,
1146 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1147 >::type,
1148 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1149 _Tuple1, _Tuples...>
1150{
1151};
1152
1153template <class ..._Tuples> struct __tuple_cat_return;
1154
1155template <class _Tuple0, class ..._Tuples>
1156struct __tuple_cat_return<_Tuple0, _Tuples...>
1157 : public __tuple_cat_return_1<tuple<>,
1158 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1159 _Tuples...>
1160{
1161};
1162
1163template <>
1164struct __tuple_cat_return<>
1165{
1166 typedef tuple<> type;
1167};
1168
Marshall Clowda0a0e82013-07-22 16:02:19 +00001169inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001170tuple<>
1171tuple_cat()
1172{
1173 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174}
1175
Howard Hinnant99968442011-11-29 18:15:50 +00001176template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001177struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178
Howard Hinnante48e3662010-12-12 23:04:37 +00001179template <class ..._Types, size_t ..._I0, class _Tuple0>
1180struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001182 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001183 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1184 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1185};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186
Howard Hinnante48e3662010-12-12 23:04:37 +00001187template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1188struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1189 _Tuple0, _Tuple1, _Tuples...>
1190 : public __tuple_cat_return_ref_imp<
1191 tuple<_Types..., typename __apply_cv<_Tuple0,
1192 typename tuple_element<_I0,
1193 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1194 typename __make_tuple_indices<tuple_size<typename
1195 remove_reference<_Tuple1>::type>::value>::type,
1196 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001197{
Howard Hinnante48e3662010-12-12 23:04:37 +00001198};
1199
1200template <class _Tuple0, class ..._Tuples>
1201struct __tuple_cat_return_ref
1202 : public __tuple_cat_return_ref_imp<tuple<>,
1203 typename __make_tuple_indices<
1204 tuple_size<typename remove_reference<_Tuple0>::type>::value
1205 >::type, _Tuple0, _Tuples...>
1206{
1207};
1208
1209template <class _Types, class _I0, class _J0>
1210struct __tuple_cat;
1211
1212template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001213struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001214{
1215 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001216 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001217 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1218 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1219 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001220 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1221 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001222 }
1223
1224 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001225 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001226 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1227 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1228 {
1229 typedef typename remove_reference<_Tuple0>::type _T0;
1230 typedef typename remove_reference<_Tuple1>::type _T1;
1231 return __tuple_cat<
1232 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1233 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1234 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001235 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001236 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1237 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001238 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001239 _VSTD::forward<_Tuple1>(__t1),
1240 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001241 }
1242};
1243
1244template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001245inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001246typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1247tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1248{
1249 typedef typename remove_reference<_Tuple0>::type _T0;
1250 return __tuple_cat<tuple<>, __tuple_indices<>,
1251 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001252 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1253 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001254}
1255
1256template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001257struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 : true_type {};
1259
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260template <class _T1, class _T2>
1261template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1262inline _LIBCPP_INLINE_VISIBILITY
1263pair<_T1, _T2>::pair(piecewise_construct_t,
1264 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1265 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001266 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1267 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268{
1269}
1270
Howard Hinnant324bb032010-08-22 00:02:43 +00001271#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272
1273_LIBCPP_END_NAMESPACE_STD
1274
1275#endif // _LIBCPP_TUPLE