blob: 3a22aa5ff5ace4fb5f19713da31912338b2052bf [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...>>;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070083template <intsize_t I, class T> class tuple_element; // undefined
84template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
85template <size_t _Ip, class ..._Tp>
86 using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087
88// 20.4.1.5, element access:
Dan Albert1d4a1ed2016-05-25 22:36:09 -070089template <intsize_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
Dan Albert1d4a1ed2016-05-25 22:36:09 -070092template <intsize_t I, class... T>
93 typename const tuple_element<I, tuple<T...>>::type &
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000094 get(const tuple<T...>&) noexcept; // constexpr in C++14
Dan Albert1d4a1ed2016-05-25 22:36:09 -070095template <intsize_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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
Marshall Clowe8029e52013-07-13 02:54:05 +000099template <class T1, class... T>
100 constexpr T1& get(tuple<T...>&) noexcept; // C++14
101template <class T1, class... T>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700102 constexpr T1 const& get(const tuple<T...>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000103template <class T1, class... T>
104 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
105
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000106// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19 +0000107template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
108template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
109template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
110template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
111template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
112template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000113
114template <class... Types, class Alloc>
115 struct uses_allocator<tuple<Types...>, Alloc>;
116
117template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000118 void
119 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000121} // std
122
123*/
124
125#include <__config>
126#include <__tuple>
127#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000129#include <__functional_base>
130#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131
Howard Hinnant08e17472011-10-17 20:05:10 +0000132#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000134#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000135
136_LIBCPP_BEGIN_NAMESPACE_STD
137
138#ifndef _LIBCPP_HAS_NO_VARIADICS
139
140// tuple_size
141
142template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000143class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144 : public integral_constant<size_t, sizeof...(_Tp)>
145{
146};
147
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148// tuple_element
149
150template <size_t _Ip, class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000151class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152{
153public:
Howard Hinnantf83417b2011-01-24 16:07:25 +0000154 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155};
156
Marshall Clow50fe0c72014-03-03 06:18:11 +0000157#if _LIBCPP_STD_VER > 11
158template <size_t _Ip, class ..._Tp>
159using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
160#endif
161
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162// __tuple_leaf
163
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000164template <size_t _Ip, class _Hp,
165 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000166 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167class __tuple_leaf;
168
169template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000171void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000172 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173{
174 swap(__x.get(), __y.get());
175}
176
177template <size_t _Ip, class _Hp, bool>
178class __tuple_leaf
179{
180 _Hp value;
181
182 __tuple_leaf& operator=(const __tuple_leaf&);
183public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000184 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
185 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 {static_assert(!is_reference<_Hp>::value,
187 "Attempted to default construct a reference element in a tuple");}
188
189 template <class _Alloc>
190 _LIBCPP_INLINE_VISIBILITY
191 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
192 : value()
193 {static_assert(!is_reference<_Hp>::value,
194 "Attempted to default construct a reference element in a tuple");}
195
196 template <class _Alloc>
197 _LIBCPP_INLINE_VISIBILITY
198 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
199 : value(allocator_arg_t(), __a)
200 {static_assert(!is_reference<_Hp>::value,
201 "Attempted to default construct a reference element in a tuple");}
202
203 template <class _Alloc>
204 _LIBCPP_INLINE_VISIBILITY
205 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
206 : value(__a)
207 {static_assert(!is_reference<_Hp>::value,
208 "Attempted to default construct a reference element in a tuple");}
209
Howard Hinnante049cc52010-09-27 17:54:17 +0000210 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000211 class = typename enable_if<
212 __lazy_and<
213 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
214 , is_constructible<_Hp, _Tp>
215 >::value
216 >::type
217 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000219 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000220 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000221 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000222 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 (is_lvalue_reference<_Tp>::value ||
224 is_same<typename remove_reference<_Tp>::type,
225 reference_wrapper<
226 typename remove_reference<_Hp>::type
227 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000228 >::value)) ||
Howard Hinnante049cc52010-09-27 17:54:17 +0000229 (is_rvalue_reference<_Hp>::value &&
230 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231 "Attempted to construct a reference element in a tuple with an rvalue");}
232
233 template <class _Tp, class _Alloc>
234 _LIBCPP_INLINE_VISIBILITY
235 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000236 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000238 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 (is_lvalue_reference<_Tp>::value ||
240 is_same<typename remove_reference<_Tp>::type,
241 reference_wrapper<
242 typename remove_reference<_Hp>::type
243 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000244 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245 "Attempted to construct a reference element in a tuple with an rvalue");}
246
247 template <class _Tp, class _Alloc>
248 _LIBCPP_INLINE_VISIBILITY
249 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000250 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000252 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253 (is_lvalue_reference<_Tp>::value ||
254 is_same<typename remove_reference<_Tp>::type,
255 reference_wrapper<
256 typename remove_reference<_Hp>::type
257 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000258 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259 "Attempted to construct a reference element in a tuple with an rvalue");}
260
261 template <class _Tp, class _Alloc>
262 _LIBCPP_INLINE_VISIBILITY
263 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000264 : value(_VSTD::forward<_Tp>(__t), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000266 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267 (is_lvalue_reference<_Tp>::value ||
268 is_same<typename remove_reference<_Tp>::type,
269 reference_wrapper<
270 typename remove_reference<_Hp>::type
271 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000272 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273 "Attempted to construct a reference element in a tuple with an rvalue");}
274
Marshall Clow398c9d82014-04-21 23:48:09 +0000275 __tuple_leaf(const __tuple_leaf& __t) = default;
276 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277
278 template <class _Tp>
279 _LIBCPP_INLINE_VISIBILITY
280 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000281 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000283 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284 return *this;
285 }
286
287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000288 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000290 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 return 0;
292 }
293
Marshall Clowda0a0e82013-07-22 16:02:19 +0000294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296};
297
298template <size_t _Ip, class _Hp>
299class __tuple_leaf<_Ip, _Hp, true>
300 : private _Hp
301{
302
303 __tuple_leaf& operator=(const __tuple_leaf&);
304public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000305 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
306 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307
308 template <class _Alloc>
309 _LIBCPP_INLINE_VISIBILITY
310 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
311
312 template <class _Alloc>
313 _LIBCPP_INLINE_VISIBILITY
314 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
315 : _Hp(allocator_arg_t(), __a) {}
316
317 template <class _Alloc>
318 _LIBCPP_INLINE_VISIBILITY
319 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
320 : _Hp(__a) {}
321
Howard Hinnante049cc52010-09-27 17:54:17 +0000322 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000323 class = typename enable_if<
324 __lazy_and<
325 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
326 , is_constructible<_Hp, _Tp>
327 >::value
328 >::type
329 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000330 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000331 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000332 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333
334 template <class _Tp, class _Alloc>
335 _LIBCPP_INLINE_VISIBILITY
336 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
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, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000342 : _Hp(allocator_arg_t(), __a, _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, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000347 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
Eric Fiselier9020c082014-07-24 18:48:34 +0000349 __tuple_leaf(__tuple_leaf const &) = default;
350 __tuple_leaf(__tuple_leaf &&) = default;
351
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352 template <class _Tp>
353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000355 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000357 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358 return *this;
359 }
360
Howard Hinnanta5e01212011-05-27 19:08:18 +0000361 _LIBCPP_INLINE_VISIBILITY
362 int
363 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000365 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366 return 0;
367 }
368
Marshall Clowda0a0e82013-07-22 16:02:19 +0000369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
370 _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 +0000371};
372
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000373template <class ..._Tp>
374_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000375void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000377template <bool ..._Pred>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000378struct __all
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000379 : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000380{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000381
Marshall Clowbbc7c742014-10-15 10:33:02 +0000382template <class _Tp>
383struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000384
Marshall Clowbbc7c742014-10-15 10:33:02 +0000385template <class ..._Tp>
386struct __all_default_constructible<__tuple_types<_Tp...>>
387 : __all<is_default_constructible<_Tp>::value...>
388{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000389
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390// __tuple_impl
391
392template<class _Indx, class ..._Tp> struct __tuple_impl;
393
394template<size_t ..._Indx, class ..._Tp>
395struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
396 : public __tuple_leaf<_Indx, _Tp>...
397{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000399 _LIBCPP_CONSTEXPR __tuple_impl()
400 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000401
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template <size_t ..._Uf, class ..._Tf,
403 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405 explicit
406 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
407 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000408 _Up&&... __u)
409 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
410 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000411 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 __tuple_leaf<_Ul, _Tl>()...
413 {}
414
415 template <class _Alloc, size_t ..._Uf, class ..._Tf,
416 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 explicit
419 __tuple_impl(allocator_arg_t, const _Alloc& __a,
420 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
421 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
422 _Up&&... __u) :
423 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000424 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
426 {}
427
428 template <class _Tuple,
429 class = typename enable_if
430 <
Howard Hinnant99324892013-04-14 00:01:13 +0000431 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 >::type
433 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000434 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000435 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
436 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000437 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
438 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 {}
440
441 template <class _Alloc, class _Tuple,
442 class = typename enable_if
443 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700444 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 >::type
446 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
449 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000450 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000451 _VSTD::forward<typename tuple_element<_Indx,
452 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 {}
454
455 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 typename enable_if
458 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000459 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 __tuple_impl&
461 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000462 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
463 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000465 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
466 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 return *this;
468 }
469
Howard Hinnant3de50862013-11-06 17:45:43 +0000470 __tuple_impl(const __tuple_impl&) = default;
471 __tuple_impl(__tuple_impl&&) = default;
472
473 _LIBCPP_INLINE_VISIBILITY
474 __tuple_impl&
475 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
476 {
477 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
478 return *this;
479 }
480
481 _LIBCPP_INLINE_VISIBILITY
482 __tuple_impl&
483 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
484 {
485 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
486 return *this;
487 }
Howard Hinnant28484442012-02-15 20:13:52 +0000488
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000491 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492 {
493 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
494 }
495};
496
497template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000498class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499{
500 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
501
502 base base_;
503
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000504 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000505 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000506 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000507 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000508 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000509 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510public:
511
Eric Fiselierda1818a2015-02-21 02:30:41 +0000512 template <bool _Dummy = true, class = typename enable_if<
513 __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
Marshall Clowbbc7c742014-10-15 10:33:02 +0000514 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000516 _LIBCPP_CONSTEXPR tuple()
517 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000518
Marshall Clowda0a0e82013-07-22 16:02:19 +0000519 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700520 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
522 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
523 typename __make_tuple_indices<0>::type(),
524 typename __make_tuple_types<tuple, 0>::type(),
525 __t...
526 ) {}
527
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700528 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
531 : base_(allocator_arg_t(), __a,
532 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
533 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
534 typename __make_tuple_indices<0>::type(),
535 typename __make_tuple_types<tuple, 0>::type(),
536 __t...
537 ) {}
538
539 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000540 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700542 sizeof...(_Up) <= sizeof...(_Tp) &&
543 __tuple_convertible
544 <
545 tuple<_Up...>,
546 typename __make_tuple_types<tuple,
547 sizeof...(_Up) < sizeof...(_Tp) ?
548 sizeof...(_Up) :
549 sizeof...(_Tp)>::type
550 >::value &&
551 __all_default_constructible<
552 typename __make_tuple_types<tuple, sizeof...(_Tp),
553 sizeof...(_Up) < sizeof...(_Tp) ?
554 sizeof...(_Up) :
555 sizeof...(_Tp)>::type
556 >::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000557 bool
558 >::type = false
559 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000560 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000561 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000562 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000563 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000564 typename __make_tuple_indices<sizeof...(_Up)>::type,
565 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
566 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
567 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000568 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000569 >::value
570 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000571 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
572 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
573 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
574 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
575 _VSTD::forward<_Up>(__u)...) {}
576
577 template <class ..._Up,
578 typename enable_if
579 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700580 sizeof...(_Up) <= sizeof...(_Tp) &&
581 __tuple_constructible
582 <
583 tuple<_Up...>,
584 typename __make_tuple_types<tuple,
585 sizeof...(_Up) < sizeof...(_Tp) ?
586 sizeof...(_Up) :
587 sizeof...(_Tp)>::type
588 >::value &&
589 !__tuple_convertible
590 <
591 tuple<_Up...>,
592 typename __make_tuple_types<tuple,
593 sizeof...(_Up) < sizeof...(_Tp) ?
594 sizeof...(_Up) :
595 sizeof...(_Tp)>::type
596 >::value &&
597 __all_default_constructible<
598 typename __make_tuple_types<tuple, sizeof...(_Tp),
599 sizeof...(_Up) < sizeof...(_Tp) ?
600 sizeof...(_Up) :
601 sizeof...(_Tp)>::type
602 >::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000603 bool
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700604 >::type =false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000606 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 explicit
608 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000609 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000610 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000611 typename __make_tuple_indices<sizeof...(_Up)>::type,
612 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
613 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
614 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
615 _Up...
616 >::value
617 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
619 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
620 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
621 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000622 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623
624 template <class _Alloc, class ..._Up,
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700625 class = typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700627 sizeof...(_Up) <= sizeof...(_Tp) &&
628 __tuple_convertible
629 <
630 tuple<_Up...>,
631 typename __make_tuple_types<tuple,
632 sizeof...(_Up) < sizeof...(_Tp) ?
633 sizeof...(_Up) :
634 sizeof...(_Tp)>::type
635 >::value &&
636 __all_default_constructible<
637 typename __make_tuple_types<tuple, sizeof...(_Tp),
638 sizeof...(_Up) < sizeof...(_Tp) ?
639 sizeof...(_Up) :
640 sizeof...(_Tp)>::type
641 >::value
642 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
646 : base_(allocator_arg_t(), __a,
647 typename __make_tuple_indices<sizeof...(_Up)>::type(),
648 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
649 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
650 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000651 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652
653 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000654 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700656 __tuple_convertible<_Tuple, tuple>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000657 bool
658 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000661 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000662 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000664 template <class _Tuple,
665 typename enable_if
666 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700667 __tuple_constructible<_Tuple, tuple>::value &&
668 !__tuple_convertible<_Tuple, tuple>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000669 bool
670 >::type = false
671 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000673 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000674 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000675 : base_(_VSTD::forward<_Tuple>(__t)) {}
676
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 template <class _Alloc, class _Tuple,
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700678 class = typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 <
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700680 __tuple_convertible<_Tuple, tuple>::value
681 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000685 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686
687 template <class _Tuple,
688 class = typename enable_if
689 <
690 __tuple_assignable<_Tuple, tuple>::value
691 >::type
692 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000695 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000697 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 return *this;
699 }
700
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000702 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
703 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704};
705
706template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000707class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708{
709public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000711 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000714 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000717 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000718 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000720 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000721 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000723 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000725 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726};
727
728template <class ..._Tp>
729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000730typename enable_if
731<
732 __all<__is_swappable<_Tp>::value...>::value,
733 void
734>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000735swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
736 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
737 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738
739// get
740
741template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000742inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000743typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000744get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000746 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
748}
749
750template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000751inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000752const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000753get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000755 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
757}
758
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000759template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000760inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000761typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000762get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000763{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000764 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000765 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000766 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000767}
768
Marshall Clowe8029e52013-07-13 02:54:05 +0000769#if _LIBCPP_STD_VER > 11
770// get by type
771template <typename _T1, size_t _Idx, typename... _Args>
772struct __find_exactly_one_t_helper;
773
774// -- find exactly one
775template <typename _T1, size_t _Idx, typename... _Args>
776struct __find_exactly_one_t_checker {
777 static constexpr size_t value = _Idx;
778// Check the rest of the list to make sure there's only one
779 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
780 };
781
782
783template <typename _T1, size_t _Idx>
784struct __find_exactly_one_t_helper <_T1, _Idx> {
785 static constexpr size_t value = -1;
786 };
787
788template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
789struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
790 static constexpr size_t value =
791 std::conditional<
792 std::is_same<_T1, _Head>::value,
Marshall Clow19e78622013-10-01 13:28:20 +0000793 __find_exactly_one_t_checker<_T1, _Idx, _Args...>,
Marshall Clowe8029e52013-07-13 02:54:05 +0000794 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
795 >::type::value;
796 };
797
798template <typename _T1, typename... _Args>
799struct __find_exactly_one_t {
800 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
801 static_assert ( value != -1, "type not found in type list" );
802 };
803
804template <class _T1, class... _Args>
805inline _LIBCPP_INLINE_VISIBILITY
806constexpr _T1& get(tuple<_Args...>& __tup) noexcept
807{
808 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
809}
810
811template <class _T1, class... _Args>
812inline _LIBCPP_INLINE_VISIBILITY
813constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
814{
815 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
816}
817
818template <class _T1, class... _Args>
819inline _LIBCPP_INLINE_VISIBILITY
820constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
821{
Marshall Clow01a0e902013-07-15 20:46:11 +0000822 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +0000823}
824
825#endif
826
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827// tie
828
829template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +0000830inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000832tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833{
834 return tuple<_Tp&...>(__t...);
835}
836
837template <class _Up>
838struct __ignore_t
839{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 const __ignore_t& operator=(_Tp&&) const {return *this;}
843};
844
845namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
846
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000848struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849{
850 typedef _Tp type;
851};
852
853template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000854struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855{
856 typedef _Tp& type;
857};
858
859template <class _Tp>
860struct __make_tuple_return
861{
Marshall Clowa71f9562014-01-03 22:55:49 +0000862 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863};
864
865template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000866inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867tuple<typename __make_tuple_return<_Tp>::type...>
868make_tuple(_Tp&&... __t)
869{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000870 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871}
872
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000873template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000874inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
875tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000876forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000877{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000878 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000879}
880
Howard Hinnant99968442011-11-29 18:15:50 +0000881template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000882struct __tuple_equal
883{
884 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000885 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 bool operator()(const _Tp& __x, const _Up& __y)
887 {
Marshall Clowba6dbf42014-06-24 00:46:19 +0000888 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 }
890};
891
892template <>
893struct __tuple_equal<0>
894{
895 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000896 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 bool operator()(const _Tp&, const _Up&)
898 {
899 return true;
900 }
901};
902
903template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000904inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905bool
906operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
907{
908 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
909}
910
911template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000912inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913bool
914operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
915{
916 return !(__x == __y);
917}
918
Howard Hinnant99968442011-11-29 18:15:50 +0000919template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920struct __tuple_less
921{
922 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000923 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924 bool operator()(const _Tp& __x, const _Up& __y)
925 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +0000926 const size_t __idx = tuple_size<_Tp>::value - _Ip;
927 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
928 return true;
929 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
930 return false;
931 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 }
933};
934
935template <>
936struct __tuple_less<0>
937{
938 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000939 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940 bool operator()(const _Tp&, const _Up&)
941 {
942 return false;
943 }
944};
945
946template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000947inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948bool
949operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
950{
951 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
952}
953
954template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000955inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956bool
957operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
958{
959 return __y < __x;
960}
961
962template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000963inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964bool
965operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
966{
967 return !(__x < __y);
968}
969
970template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000971inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972bool
973operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
974{
975 return !(__y < __x);
976}
977
978// tuple_cat
979
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000980template <class _Tp, class _Up> struct __tuple_cat_type;
981
982template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +0000983struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984{
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000985 typedef tuple<_Ttypes..., _Utypes...> type;
986};
987
988template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
989struct __tuple_cat_return_1
990{
991};
992
993template <class ..._Types, class _Tuple0>
994struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
995{
996 typedef typename __tuple_cat_type<tuple<_Types...>,
997 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
998 type;
999};
1000
1001template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1002struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1003 : public __tuple_cat_return_1<
1004 typename __tuple_cat_type<
1005 tuple<_Types...>,
1006 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1007 >::type,
1008 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1009 _Tuple1, _Tuples...>
1010{
1011};
1012
1013template <class ..._Tuples> struct __tuple_cat_return;
1014
1015template <class _Tuple0, class ..._Tuples>
1016struct __tuple_cat_return<_Tuple0, _Tuples...>
1017 : public __tuple_cat_return_1<tuple<>,
1018 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1019 _Tuples...>
1020{
1021};
1022
1023template <>
1024struct __tuple_cat_return<>
1025{
1026 typedef tuple<> type;
1027};
1028
Marshall Clowda0a0e82013-07-22 16:02:19 +00001029inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001030tuple<>
1031tuple_cat()
1032{
1033 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034}
1035
Howard Hinnant99968442011-11-29 18:15:50 +00001036template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001037struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038
Howard Hinnante48e3662010-12-12 23:04:37 +00001039template <class ..._Types, size_t ..._I0, class _Tuple0>
1040struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001042 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001043 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1044 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1045};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046
Howard Hinnante48e3662010-12-12 23:04:37 +00001047template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1048struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1049 _Tuple0, _Tuple1, _Tuples...>
1050 : public __tuple_cat_return_ref_imp<
1051 tuple<_Types..., typename __apply_cv<_Tuple0,
1052 typename tuple_element<_I0,
1053 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1054 typename __make_tuple_indices<tuple_size<typename
1055 remove_reference<_Tuple1>::type>::value>::type,
1056 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057{
Howard Hinnante48e3662010-12-12 23:04:37 +00001058};
1059
1060template <class _Tuple0, class ..._Tuples>
1061struct __tuple_cat_return_ref
1062 : public __tuple_cat_return_ref_imp<tuple<>,
1063 typename __make_tuple_indices<
1064 tuple_size<typename remove_reference<_Tuple0>::type>::value
1065 >::type, _Tuple0, _Tuples...>
1066{
1067};
1068
1069template <class _Types, class _I0, class _J0>
1070struct __tuple_cat;
1071
1072template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001073struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001074{
1075 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001077 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1078 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1079 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001080 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1081 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001082 }
1083
1084 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001086 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1087 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1088 {
1089 typedef typename remove_reference<_Tuple0>::type _T0;
1090 typedef typename remove_reference<_Tuple1>::type _T1;
1091 return __tuple_cat<
1092 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1093 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1094 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001095 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001096 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1097 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001098 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001099 _VSTD::forward<_Tuple1>(__t1),
1100 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001101 }
1102};
1103
1104template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001105inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001106typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1107tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1108{
1109 typedef typename remove_reference<_Tuple0>::type _T0;
1110 return __tuple_cat<tuple<>, __tuple_indices<>,
1111 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001112 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1113 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114}
1115
1116template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001117struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 : true_type {};
1119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120template <class _T1, class _T2>
1121template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1122inline _LIBCPP_INLINE_VISIBILITY
1123pair<_T1, _T2>::pair(piecewise_construct_t,
1124 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1125 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001126 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1127 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128{
1129}
1130
Howard Hinnant324bb032010-08-22 00:02:43 +00001131#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132
1133_LIBCPP_END_NAMESPACE_STD
1134
1135#endif // _LIBCPP_TUPLE