blob: 32f43805ff77bdaf962f933684a7e854fec6a5c2 [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 Fiselier55ad3ac2016-04-15 03:29:40 +0000382template <class ..._Tp>
383struct __lazy_all : __all<_Tp::value...> {};
384
Marshall Clowbbc7c742014-10-15 10:33:02 +0000385template <class _Tp>
386struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000387
Marshall Clowbbc7c742014-10-15 10:33:02 +0000388template <class ..._Tp>
389struct __all_default_constructible<__tuple_types<_Tp...>>
390 : __all<is_default_constructible<_Tp>::value...>
391{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000392
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393// __tuple_impl
394
395template<class _Indx, class ..._Tp> struct __tuple_impl;
396
397template<size_t ..._Indx, class ..._Tp>
398struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
399 : public __tuple_leaf<_Indx, _Tp>...
400{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000402 _LIBCPP_CONSTEXPR __tuple_impl()
403 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000404
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405 template <size_t ..._Uf, class ..._Tf,
406 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 explicit
409 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
410 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000411 _Up&&... __u)
412 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
413 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000414 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 __tuple_leaf<_Ul, _Tl>()...
416 {}
417
418 template <class _Alloc, size_t ..._Uf, class ..._Tf,
419 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 explicit
422 __tuple_impl(allocator_arg_t, const _Alloc& __a,
423 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
424 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
425 _Up&&... __u) :
426 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000427 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
429 {}
430
431 template <class _Tuple,
432 class = typename enable_if
433 <
Howard Hinnant99324892013-04-14 00:01:13 +0000434 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 >::type
436 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000438 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
439 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000440 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
441 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 {}
443
444 template <class _Alloc, class _Tuple,
445 class = typename enable_if
446 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000447 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 >::type
449 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
452 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000453 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000454 _VSTD::forward<typename tuple_element<_Indx,
455 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 {}
457
458 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 typename enable_if
461 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000462 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 __tuple_impl&
464 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000465 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
466 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000468 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
469 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 return *this;
471 }
472
Howard Hinnant3de50862013-11-06 17:45:43 +0000473 __tuple_impl(const __tuple_impl&) = default;
474 __tuple_impl(__tuple_impl&&) = default;
475
476 _LIBCPP_INLINE_VISIBILITY
477 __tuple_impl&
478 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
479 {
480 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
481 return *this;
482 }
483
484 _LIBCPP_INLINE_VISIBILITY
485 __tuple_impl&
486 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
487 {
488 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
489 return *this;
490 }
Howard Hinnant28484442012-02-15 20:13:52 +0000491
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000494 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495 {
496 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
497 }
498};
499
Eric Fiselierd5019332016-04-15 18:05:59 +0000500template <bool _IsTuple, class _SizeTrait, size_t _Expected>
501struct __tuple_like_with_size_imp : false_type {};
502
503template <class _SizeTrait, size_t _Expected>
504struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
505 : integral_constant<bool, _SizeTrait::value == _Expected> {};
506
507template <class _Tuple, size_t _ExpectedSize,
508 class _RawTuple = typename __uncvref<_Tuple>::type>
509using __tuple_like_with_size = __tuple_like_with_size_imp<
510 __tuple_like<_RawTuple>::value,
511 tuple_size<_RawTuple>, _ExpectedSize
512 >;
513
514
515struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
516 template <class ...>
517 static constexpr bool __enable_explicit() { return false; }
518 template <class ...>
519 static constexpr bool __enable_implicit() { return false; }
520};
521
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000523class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524{
525 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
526
527 base base_;
528
Eric Fiselierd5019332016-04-15 18:05:59 +0000529 template <class ..._Args>
530 struct _PackExpandsToThisTuple : false_type {};
531
532 template <class _Arg>
533 struct _PackExpandsToThisTuple<_Arg>
534 : is_same<typename __uncvref<_Arg>::type, tuple> {};
535
536 template <bool _MaybeEnable, class _Dummy = void>
537 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
538
539 template <class _Dummy>
540 struct _CheckArgsConstructor<true, _Dummy>
541 {
542 template <class ..._Args>
543 static constexpr bool __enable_explicit() {
544 return
545 __tuple_constructible<
546 tuple<_Args...>,
547 typename __make_tuple_types<tuple,
548 sizeof...(_Args) < sizeof...(_Tp) ?
549 sizeof...(_Args) :
550 sizeof...(_Tp)>::type
551 >::value &&
552 !__tuple_convertible<
553 tuple<_Args...>,
554 typename __make_tuple_types<tuple,
555 sizeof...(_Args) < sizeof...(_Tp) ?
556 sizeof...(_Args) :
557 sizeof...(_Tp)>::type
558 >::value &&
559 __all_default_constructible<
560 typename __make_tuple_types<tuple, sizeof...(_Tp),
561 sizeof...(_Args) < sizeof...(_Tp) ?
562 sizeof...(_Args) :
563 sizeof...(_Tp)>::type
564 >::value;
565 }
566
567 template <class ..._Args>
568 static constexpr bool __enable_implicit() {
569 return
570 __tuple_convertible<
571 tuple<_Args...>,
572 typename __make_tuple_types<tuple,
573 sizeof...(_Args) < sizeof...(_Tp) ?
574 sizeof...(_Args) :
575 sizeof...(_Tp)>::type
576 >::value &&
577 __all_default_constructible<
578 typename __make_tuple_types<tuple, sizeof...(_Tp),
579 sizeof...(_Args) < sizeof...(_Tp) ?
580 sizeof...(_Args) :
581 sizeof...(_Tp)>::type
582 >::value;
583 }
584 };
585
586 template <bool _MaybeEnable,
587 bool = sizeof...(_Tp) == 1,
588 class _Dummy = void>
589 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
590
591 template <class _Dummy>
592 struct _CheckTupleLikeConstructor<true, false, _Dummy>
593 {
594 template <class _Tuple>
595 static constexpr bool __enable_implicit() {
596 return __tuple_convertible<_Tuple, tuple>::value;
597 }
598
599 template <class _Tuple>
600 static constexpr bool __enable_explicit() {
601 return __tuple_constructible<_Tuple, tuple>::value
602 && !__tuple_convertible<_Tuple, tuple>::value;
603 }
604 };
605
606 template <class _Dummy>
607 struct _CheckTupleLikeConstructor<true, true, _Dummy>
608 {
609 // This trait is used to disable the tuple-like constructor when
610 // the UTypes... constructor should be selected instead.
611 // See LWG issue #2549.
612 template <class _Tuple>
613 using _PreferTupleLikeConstructor = __lazy_or<
614 // Don't attempt the two checks below if the tuple we are given
615 // has the same type as this tuple.
616 is_same<typename __uncvref<_Tuple>::type, tuple>,
617 __lazy_and<
618 __lazy_not<is_constructible<_Tp..., _Tuple>>,
619 __lazy_not<is_convertible<_Tuple, _Tp...>>
620 >
621 >;
622
623 template <class _Tuple>
624 static constexpr bool __enable_implicit() {
625 return __lazy_and<
626 __tuple_convertible<_Tuple, tuple>,
627 _PreferTupleLikeConstructor<_Tuple>
628 >::value;
629 }
630
631 template <class _Tuple>
632 static constexpr bool __enable_explicit() {
633 return __lazy_and<
634 __tuple_constructible<_Tuple, tuple>,
635 _PreferTupleLikeConstructor<_Tuple>,
636 __lazy_not<__tuple_convertible<_Tuple, tuple>>
637 >::value;
638 }
639 };
640
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000641 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000642 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000643 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000644 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000645 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000646 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000647 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
648 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649public:
650
Eric Fiselierda1818a2015-02-21 02:30:41 +0000651 template <bool _Dummy = true, class = typename enable_if<
652 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
Marshall Clowbbc7c742014-10-15 10:33:02 +0000653 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000655 _LIBCPP_CONSTEXPR tuple()
656 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000657
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000658 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
659 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000660 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000661 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
662 >::value
663 >::type>
664 _LIBCPP_INLINE_VISIBILITY
665 tuple(_AllocArgT, _Alloc const& __a)
666 : base_(allocator_arg_t(), __a,
667 __tuple_indices<>(), __tuple_types<>(),
668 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
669 __tuple_types<_Tp...>()) {}
670
Eric Fiselier95526d32016-04-19 01:19:25 +0000671 template <bool _Dummy = true,
672 typename enable_if
673 <
674 _CheckArgsConstructor<
675 _Dummy
676 >::template __enable_implicit<_Tp...>(),
677 bool
678 >::type = false
679 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000681 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
683 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
684 typename __make_tuple_indices<0>::type(),
685 typename __make_tuple_types<tuple, 0>::type(),
686 __t...
687 ) {}
688
Eric Fiselier95526d32016-04-19 01:19:25 +0000689 template <bool _Dummy = true,
690 typename enable_if
691 <
692 _CheckArgsConstructor<
693 _Dummy
694 >::template __enable_explicit<_Tp...>(),
695 bool
696 >::type = false
697 >
698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
699 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
700 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
701 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
702 typename __make_tuple_indices<0>::type(),
703 typename __make_tuple_types<tuple, 0>::type(),
704 __t...
705 ) {}
706
707 template <class _Alloc, bool _Dummy = true,
708 typename enable_if
709 <
710 _CheckArgsConstructor<
711 _Dummy
712 >::template __enable_implicit<_Tp...>(),
713 bool
714 >::type = false
715 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
718 : base_(allocator_arg_t(), __a,
719 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
720 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
721 typename __make_tuple_indices<0>::type(),
722 typename __make_tuple_types<tuple, 0>::type(),
723 __t...
724 ) {}
725
Eric Fiselier95526d32016-04-19 01:19:25 +0000726 template <class _Alloc, bool _Dummy = true,
727 typename enable_if
728 <
729 _CheckArgsConstructor<
730 _Dummy
731 >::template __enable_explicit<_Tp...>(),
732 bool
733 >::type = false
734 >
735 _LIBCPP_INLINE_VISIBILITY
736 explicit
737 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
738 : base_(allocator_arg_t(), __a,
739 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
740 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
741 typename __make_tuple_indices<0>::type(),
742 typename __make_tuple_types<tuple, 0>::type(),
743 __t...
744 ) {}
745
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000747 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000749 _CheckArgsConstructor<
750 sizeof...(_Up) <= sizeof...(_Tp)
751 && !_PackExpandsToThisTuple<_Up...>::value
752 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000753 bool
754 >::type = false
755 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000756 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000757 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000758 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000759 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000760 typename __make_tuple_indices<sizeof...(_Up)>::type,
761 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
762 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
763 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000764 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000765 >::value
766 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000767 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
768 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
769 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
770 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
771 _VSTD::forward<_Up>(__u)...) {}
772
773 template <class ..._Up,
774 typename enable_if
775 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000776 _CheckArgsConstructor<
777 sizeof...(_Up) <= sizeof...(_Tp)
778 && !_PackExpandsToThisTuple<_Up...>::value
779 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000780 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000781 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000783 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 explicit
785 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000786 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000787 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000788 typename __make_tuple_indices<sizeof...(_Up)>::type,
789 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
790 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
791 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
792 _Up...
793 >::value
794 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
796 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
797 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
798 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000799 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800
801 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000802 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000804 _CheckArgsConstructor<
805 sizeof...(_Up) == sizeof...(_Tp) &&
806 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000807 >::template __enable_implicit<_Up...>(),
808 bool
809 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
813 : base_(allocator_arg_t(), __a,
814 typename __make_tuple_indices<sizeof...(_Up)>::type(),
815 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
816 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
817 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000818 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819
Eric Fiselier95526d32016-04-19 01:19:25 +0000820 template <class _Alloc, class ..._Up,
821 typename enable_if
822 <
823 _CheckArgsConstructor<
824 sizeof...(_Up) == sizeof...(_Tp) &&
825 !_PackExpandsToThisTuple<_Up...>::value
826 >::template __enable_explicit<_Up...>(),
827 bool
828 >::type = false
829 >
830 _LIBCPP_INLINE_VISIBILITY
831 explicit
832 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
833 : base_(allocator_arg_t(), __a,
834 typename __make_tuple_indices<sizeof...(_Up)>::type(),
835 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
836 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
837 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
838 _VSTD::forward<_Up>(__u)...) {}
839
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000841 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000843 _CheckTupleLikeConstructor<
844 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
845 && !_PackExpandsToThisTuple<_Tuple>::value
846 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000847 bool
848 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000851 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000852 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000854 template <class _Tuple,
855 typename enable_if
856 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000857 _CheckTupleLikeConstructor<
858 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
859 && !_PackExpandsToThisTuple<_Tuple>::value
860 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000861 bool
862 >::type = false
863 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000865 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000866 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000867 : base_(_VSTD::forward<_Tuple>(__t)) {}
868
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000870 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000872 _CheckTupleLikeConstructor<
873 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000874 >::template __enable_implicit<_Tuple>(),
875 bool
876 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000880 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881
Eric Fiselier95526d32016-04-19 01:19:25 +0000882 template <class _Alloc, class _Tuple,
883 typename enable_if
884 <
885 _CheckTupleLikeConstructor<
886 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
887 >::template __enable_explicit<_Tuple>(),
888 bool
889 >::type = false
890 >
891 _LIBCPP_INLINE_VISIBILITY
892 explicit
893 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
894 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
895
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 template <class _Tuple,
897 class = typename enable_if
898 <
899 __tuple_assignable<_Tuple, tuple>::value
900 >::type
901 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000904 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000906 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907 return *this;
908 }
909
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000911 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
912 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913};
914
915template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000916class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917{
918public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000920 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000923 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000926 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000927 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000929 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000930 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000932 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000934 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935};
936
937template <class ..._Tp>
938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000939typename enable_if
940<
941 __all<__is_swappable<_Tp>::value...>::value,
942 void
943>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000944swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
945 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
946 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
948// get
949
950template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000951inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000952typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000953get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000955 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
957}
958
959template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000960inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000961const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000962get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000964 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
966}
967
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000968template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000969inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000970typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000971get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000972{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000973 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000974 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000975 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000976}
977
Eric Fiselier199bee02015-12-18 00:36:55 +0000978template <size_t _Ip, class ..._Tp>
979inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
980const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
981get(const tuple<_Tp...>&& __t) _NOEXCEPT
982{
983 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
984 return static_cast<const type&&>(
985 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
986}
987
Marshall Clowe8029e52013-07-13 02:54:05 +0000988#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000989
Eric Fiselier22c3e762016-07-02 03:18:30 +0000990namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000991
Eric Fiselier22c3e762016-07-02 03:18:30 +0000992static constexpr size_t __not_found = -1;
993static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000994
Eric Fiselier22c3e762016-07-02 03:18:30 +0000995inline _LIBCPP_INLINE_VISIBILITY
996constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
997 return !__matches ? __res :
998 (__res == __not_found ? __curr_i : __ambiguous);
999}
Marshall Clowe8029e52013-07-13 02:54:05 +00001000
Eric Fiselier22c3e762016-07-02 03:18:30 +00001001template <size_t _Nx>
1002inline _LIBCPP_INLINE_VISIBILITY
1003constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1004 return __i == _Nx ? __not_found :
1005 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1006}
1007
1008template <class _T1, class ..._Args>
1009struct __find_exactly_one_checked {
1010 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
1011 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1012 static_assert (value != __not_found, "type not found in type list" );
1013 static_assert(value != __ambiguous,"type occurs more than once in type list");
1014};
1015
1016} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001017
1018template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001019struct __find_exactly_one_t
1020 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1021};
Marshall Clowe8029e52013-07-13 02:54:05 +00001022
1023template <class _T1, class... _Args>
1024inline _LIBCPP_INLINE_VISIBILITY
1025constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1026{
1027 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1028}
1029
1030template <class _T1, class... _Args>
1031inline _LIBCPP_INLINE_VISIBILITY
1032constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1033{
1034 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1035}
1036
1037template <class _T1, class... _Args>
1038inline _LIBCPP_INLINE_VISIBILITY
1039constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1040{
Marshall Clow01a0e902013-07-15 20:46:11 +00001041 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001042}
1043
Eric Fiselier199bee02015-12-18 00:36:55 +00001044template <class _T1, class... _Args>
1045inline _LIBCPP_INLINE_VISIBILITY
1046constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1047{
1048 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1049}
1050
Marshall Clowe8029e52013-07-13 02:54:05 +00001051#endif
1052
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053// tie
1054
1055template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001056inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001058tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059{
1060 return tuple<_Tp&...>(__t...);
1061}
1062
1063template <class _Up>
1064struct __ignore_t
1065{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068 const __ignore_t& operator=(_Tp&&) const {return *this;}
1069};
1070
1071namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1072
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001074struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075{
1076 typedef _Tp type;
1077};
1078
1079template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001080struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081{
1082 typedef _Tp& type;
1083};
1084
1085template <class _Tp>
1086struct __make_tuple_return
1087{
Marshall Clowa71f9562014-01-03 22:55:49 +00001088 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089};
1090
1091template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001092inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093tuple<typename __make_tuple_return<_Tp>::type...>
1094make_tuple(_Tp&&... __t)
1095{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001096 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097}
1098
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001099template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001100inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1101tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001102forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001103{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001104 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001105}
1106
Howard Hinnant99968442011-11-29 18:15:50 +00001107template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108struct __tuple_equal
1109{
1110 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 bool operator()(const _Tp& __x, const _Up& __y)
1113 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001114 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115 }
1116};
1117
1118template <>
1119struct __tuple_equal<0>
1120{
1121 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 bool operator()(const _Tp&, const _Up&)
1124 {
1125 return true;
1126 }
1127};
1128
1129template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001130inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131bool
1132operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1133{
1134 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1135}
1136
1137template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001138inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139bool
1140operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1141{
1142 return !(__x == __y);
1143}
1144
Howard Hinnant99968442011-11-29 18:15:50 +00001145template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146struct __tuple_less
1147{
1148 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001149 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 bool operator()(const _Tp& __x, const _Up& __y)
1151 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001152 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1153 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1154 return true;
1155 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1156 return false;
1157 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158 }
1159};
1160
1161template <>
1162struct __tuple_less<0>
1163{
1164 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 bool operator()(const _Tp&, const _Up&)
1167 {
1168 return false;
1169 }
1170};
1171
1172template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174bool
1175operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1176{
1177 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1178}
1179
1180template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001181inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182bool
1183operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1184{
1185 return __y < __x;
1186}
1187
1188template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001189inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190bool
1191operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1192{
1193 return !(__x < __y);
1194}
1195
1196template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001197inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198bool
1199operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1200{
1201 return !(__y < __x);
1202}
1203
1204// tuple_cat
1205
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001206template <class _Tp, class _Up> struct __tuple_cat_type;
1207
1208template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001209struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001211 typedef tuple<_Ttypes..., _Utypes...> type;
1212};
1213
1214template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1215struct __tuple_cat_return_1
1216{
1217};
1218
1219template <class ..._Types, class _Tuple0>
1220struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1221{
1222 typedef typename __tuple_cat_type<tuple<_Types...>,
1223 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1224 type;
1225};
1226
1227template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1228struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1229 : public __tuple_cat_return_1<
1230 typename __tuple_cat_type<
1231 tuple<_Types...>,
1232 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1233 >::type,
1234 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1235 _Tuple1, _Tuples...>
1236{
1237};
1238
1239template <class ..._Tuples> struct __tuple_cat_return;
1240
1241template <class _Tuple0, class ..._Tuples>
1242struct __tuple_cat_return<_Tuple0, _Tuples...>
1243 : public __tuple_cat_return_1<tuple<>,
1244 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1245 _Tuples...>
1246{
1247};
1248
1249template <>
1250struct __tuple_cat_return<>
1251{
1252 typedef tuple<> type;
1253};
1254
Marshall Clowda0a0e82013-07-22 16:02:19 +00001255inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001256tuple<>
1257tuple_cat()
1258{
1259 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260}
1261
Howard Hinnant99968442011-11-29 18:15:50 +00001262template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001263struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264
Howard Hinnante48e3662010-12-12 23:04:37 +00001265template <class ..._Types, size_t ..._I0, class _Tuple0>
1266struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001268 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001269 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1270 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1271};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272
Howard Hinnante48e3662010-12-12 23:04:37 +00001273template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1274struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1275 _Tuple0, _Tuple1, _Tuples...>
1276 : public __tuple_cat_return_ref_imp<
1277 tuple<_Types..., typename __apply_cv<_Tuple0,
1278 typename tuple_element<_I0,
1279 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1280 typename __make_tuple_indices<tuple_size<typename
1281 remove_reference<_Tuple1>::type>::value>::type,
1282 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283{
Howard Hinnante48e3662010-12-12 23:04:37 +00001284};
1285
1286template <class _Tuple0, class ..._Tuples>
1287struct __tuple_cat_return_ref
1288 : public __tuple_cat_return_ref_imp<tuple<>,
1289 typename __make_tuple_indices<
1290 tuple_size<typename remove_reference<_Tuple0>::type>::value
1291 >::type, _Tuple0, _Tuples...>
1292{
1293};
1294
1295template <class _Types, class _I0, class _J0>
1296struct __tuple_cat;
1297
1298template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001299struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001300{
1301 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001302 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001303 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1304 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1305 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001306 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1307 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001308 }
1309
1310 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001312 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1313 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1314 {
1315 typedef typename remove_reference<_Tuple0>::type _T0;
1316 typedef typename remove_reference<_Tuple1>::type _T1;
1317 return __tuple_cat<
1318 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1319 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1320 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001321 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001322 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1323 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001324 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001325 _VSTD::forward<_Tuple1>(__t1),
1326 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001327 }
1328};
1329
1330template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001331inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001332typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1333tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1334{
1335 typedef typename remove_reference<_Tuple0>::type _T0;
1336 return __tuple_cat<tuple<>, __tuple_indices<>,
1337 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001338 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1339 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340}
1341
1342template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001343struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001344 : true_type {};
1345
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346template <class _T1, class _T2>
1347template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1348inline _LIBCPP_INLINE_VISIBILITY
1349pair<_T1, _T2>::pair(piecewise_construct_t,
1350 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1351 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001352 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1353 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354{
1355}
1356
Howard Hinnant324bb032010-08-22 00:02:43 +00001357#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358
1359_LIBCPP_END_NAMESPACE_STD
1360
1361#endif // _LIBCPP_TUPLE