blob: 93518d8bd6481d26285e12fa8e47e436954088ad [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...>>;
83template <intsize_t I, class T> class tuple_element; // undefined
84template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
Marshall Clow50fe0c72014-03-03 06:18:11 +000085template <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:
Howard Hinnanta5e01212011-05-27 19:08:18 +000089template <intsize_t I, class... T>
90 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000091 get(tuple<T...>&) noexcept; // constexpr in C++14
Howard Hinnanta5e01212011-05-27 19:08:18 +000092template <intsize_t I, class... T>
Marshall Clow50fe0c72014-03-03 06:18:11 +000093 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
Howard Hinnanta5e01212011-05-27 19:08:18 +000095template <intsize_t I, class... T>
96 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>
102 constexpr T1 const& get(const tuple<T...>&) noexcept; // C++14
103template <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
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000164template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value
165#if __has_feature(is_final)
166 && !__is_final(_Hp)
167#endif
168 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169class __tuple_leaf;
170
171template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000172inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000174 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175{
176 swap(__x.get(), __y.get());
177}
178
179template <size_t _Ip, class _Hp, bool>
180class __tuple_leaf
181{
182 _Hp value;
183
184 __tuple_leaf& operator=(const __tuple_leaf&);
185public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000186 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
187 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188 {static_assert(!is_reference<_Hp>::value,
189 "Attempted to default construct a reference element in a tuple");}
190
191 template <class _Alloc>
192 _LIBCPP_INLINE_VISIBILITY
193 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
194 : value()
195 {static_assert(!is_reference<_Hp>::value,
196 "Attempted to default construct a reference element in a tuple");}
197
198 template <class _Alloc>
199 _LIBCPP_INLINE_VISIBILITY
200 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
201 : value(allocator_arg_t(), __a)
202 {static_assert(!is_reference<_Hp>::value,
203 "Attempted to default construct a reference element in a tuple");}
204
205 template <class _Alloc>
206 _LIBCPP_INLINE_VISIBILITY
207 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
208 : value(__a)
209 {static_assert(!is_reference<_Hp>::value,
210 "Attempted to default construct a reference element in a tuple");}
211
Howard Hinnante049cc52010-09-27 17:54:17 +0000212 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000213 class = typename enable_if<
214 __lazy_and<
215 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
216 , is_constructible<_Hp, _Tp>
217 >::value
218 >::type
219 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000220 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000221 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000222 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000223 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000224 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225 (is_lvalue_reference<_Tp>::value ||
226 is_same<typename remove_reference<_Tp>::type,
227 reference_wrapper<
228 typename remove_reference<_Hp>::type
229 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000230 >::value)) ||
Howard Hinnante049cc52010-09-27 17:54:17 +0000231 (is_rvalue_reference<_Hp>::value &&
232 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233 "Attempted to construct a reference element in a tuple with an rvalue");}
234
235 template <class _Tp, class _Alloc>
236 _LIBCPP_INLINE_VISIBILITY
237 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000238 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000240 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241 (is_lvalue_reference<_Tp>::value ||
242 is_same<typename remove_reference<_Tp>::type,
243 reference_wrapper<
244 typename remove_reference<_Hp>::type
245 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000246 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247 "Attempted to construct a reference element in a tuple with an rvalue");}
248
249 template <class _Tp, class _Alloc>
250 _LIBCPP_INLINE_VISIBILITY
251 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000252 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000254 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 (is_lvalue_reference<_Tp>::value ||
256 is_same<typename remove_reference<_Tp>::type,
257 reference_wrapper<
258 typename remove_reference<_Hp>::type
259 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000260 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261 "Attempted to construct a reference element in a tuple with an rvalue");}
262
263 template <class _Tp, class _Alloc>
264 _LIBCPP_INLINE_VISIBILITY
265 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000266 : value(_VSTD::forward<_Tp>(__t), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000268 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269 (is_lvalue_reference<_Tp>::value ||
270 is_same<typename remove_reference<_Tp>::type,
271 reference_wrapper<
272 typename remove_reference<_Hp>::type
273 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000274 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275 "Attempted to construct a reference element in a tuple with an rvalue");}
276
Marshall Clow398c9d82014-04-21 23:48:09 +0000277 __tuple_leaf(const __tuple_leaf& __t) = default;
278 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280 template <class _Tp>
281 _LIBCPP_INLINE_VISIBILITY
282 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000283 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000285 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 return *this;
287 }
288
289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000290 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000292 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 return 0;
294 }
295
Marshall Clowda0a0e82013-07-22 16:02:19 +0000296 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298};
299
300template <size_t _Ip, class _Hp>
301class __tuple_leaf<_Ip, _Hp, true>
302 : private _Hp
303{
304
305 __tuple_leaf& operator=(const __tuple_leaf&);
306public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
308 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310 template <class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
313
314 template <class _Alloc>
315 _LIBCPP_INLINE_VISIBILITY
316 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
317 : _Hp(allocator_arg_t(), __a) {}
318
319 template <class _Alloc>
320 _LIBCPP_INLINE_VISIBILITY
321 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
322 : _Hp(__a) {}
323
Howard Hinnante049cc52010-09-27 17:54:17 +0000324 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000325 class = typename enable_if<
326 __lazy_and<
327 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
328 , is_constructible<_Hp, _Tp>
329 >::value
330 >::type
331 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000332 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000333 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000334 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336 template <class _Tp, class _Alloc>
337 _LIBCPP_INLINE_VISIBILITY
338 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000339 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
341 template <class _Tp, class _Alloc>
342 _LIBCPP_INLINE_VISIBILITY
343 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000344 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346 template <class _Tp, class _Alloc>
347 _LIBCPP_INLINE_VISIBILITY
348 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000349 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350
Eric Fiselier9020c082014-07-24 18:48:34 +0000351 __tuple_leaf(__tuple_leaf const &) = default;
352 __tuple_leaf(__tuple_leaf &&) = default;
353
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 template <class _Tp>
355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000357 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000359 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360 return *this;
361 }
362
Howard Hinnanta5e01212011-05-27 19:08:18 +0000363 _LIBCPP_INLINE_VISIBILITY
364 int
365 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000367 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368 return 0;
369 }
370
Marshall Clowda0a0e82013-07-22 16:02:19 +0000371 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
372 _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 +0000373};
374
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000375template <class ..._Tp>
376_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000377void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000379template <bool ..._Pred>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000380struct __all
Eric Fiselier6cb69ff2014-11-25 21:57:41 +0000381 : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
Marshall Clowbbc7c742014-10-15 10:33:02 +0000382{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000383
Marshall Clowbbc7c742014-10-15 10:33:02 +0000384template <class _Tp>
385struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000386
Marshall Clowbbc7c742014-10-15 10:33:02 +0000387template <class ..._Tp>
388struct __all_default_constructible<__tuple_types<_Tp...>>
389 : __all<is_default_constructible<_Tp>::value...>
390{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000391
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392// __tuple_impl
393
394template<class _Indx, class ..._Tp> struct __tuple_impl;
395
396template<size_t ..._Indx, class ..._Tp>
397struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
398 : public __tuple_leaf<_Indx, _Tp>...
399{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000401 _LIBCPP_CONSTEXPR __tuple_impl()
402 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000403
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404 template <size_t ..._Uf, class ..._Tf,
405 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407 explicit
408 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
409 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000410 _Up&&... __u)
411 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
412 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000413 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 __tuple_leaf<_Ul, _Tl>()...
415 {}
416
417 template <class _Alloc, size_t ..._Uf, class ..._Tf,
418 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 explicit
421 __tuple_impl(allocator_arg_t, const _Alloc& __a,
422 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
423 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
424 _Up&&... __u) :
425 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000426 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
428 {}
429
430 template <class _Tuple,
431 class = typename enable_if
432 <
Howard Hinnant99324892013-04-14 00:01:13 +0000433 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 >::type
435 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000436 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000437 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
438 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000439 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 {}
442
443 template <class _Alloc, class _Tuple,
444 class = typename enable_if
445 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000446 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 >::type
448 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
451 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000452 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000453 _VSTD::forward<typename tuple_element<_Indx,
454 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 {}
456
457 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 typename enable_if
460 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000461 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 __tuple_impl&
463 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000464 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
465 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000467 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
468 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469 return *this;
470 }
471
Howard Hinnant3de50862013-11-06 17:45:43 +0000472 __tuple_impl(const __tuple_impl&) = default;
473 __tuple_impl(__tuple_impl&&) = default;
474
475 _LIBCPP_INLINE_VISIBILITY
476 __tuple_impl&
477 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
478 {
479 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
480 return *this;
481 }
482
483 _LIBCPP_INLINE_VISIBILITY
484 __tuple_impl&
485 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
486 {
487 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
488 return *this;
489 }
Howard Hinnant28484442012-02-15 20:13:52 +0000490
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000493 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 {
495 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
496 }
497};
498
499template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000500class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501{
502 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
503
504 base base_;
505
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 typename tuple_element<_Jp, tuple<_Up...> >::type& get(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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000510 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000511 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512public:
513
Marshall Clowbbc7c742014-10-15 10:33:02 +0000514 template <bool _Dummy = true, class _Up = typename enable_if<
515 __all<(_Dummy && is_default_constructible<_Tp>::value)...>::value
516 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000518 _LIBCPP_CONSTEXPR tuple()
519 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000520
Marshall Clowda0a0e82013-07-22 16:02:19 +0000521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000522 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
524 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
525 typename __make_tuple_indices<0>::type(),
526 typename __make_tuple_types<tuple, 0>::type(),
527 __t...
528 ) {}
529
530 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
533 : base_(allocator_arg_t(), __a,
534 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
535 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
536 typename __make_tuple_indices<0>::type(),
537 typename __make_tuple_types<tuple, 0>::type(),
538 __t...
539 ) {}
540
541 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000542 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 <
544 sizeof...(_Up) <= sizeof...(_Tp) &&
545 __tuple_convertible
546 <
547 tuple<_Up...>,
548 typename __make_tuple_types<tuple,
549 sizeof...(_Up) < sizeof...(_Tp) ?
550 sizeof...(_Up) :
551 sizeof...(_Tp)>::type
Marshall Clowbbc7c742014-10-15 10:33:02 +0000552 >::value &&
553 __all_default_constructible<
554 typename __make_tuple_types<tuple, sizeof...(_Tp),
555 sizeof...(_Up) < sizeof...(_Tp) ?
556 sizeof...(_Up) :
557 sizeof...(_Tp)>::type
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000558 >::value,
559 bool
560 >::type = false
561 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000562 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000563 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000564 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000565 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000566 typename __make_tuple_indices<sizeof...(_Up)>::type,
567 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
568 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
569 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000570 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000571 >::value
572 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000573 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
574 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
575 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
576 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
577 _VSTD::forward<_Up>(__u)...) {}
578
579 template <class ..._Up,
580 typename enable_if
581 <
582 sizeof...(_Up) <= sizeof...(_Tp) &&
583 __tuple_constructible
584 <
585 tuple<_Up...>,
586 typename __make_tuple_types<tuple,
587 sizeof...(_Up) < sizeof...(_Tp) ?
588 sizeof...(_Up) :
589 sizeof...(_Tp)>::type
590 >::value &&
591 !__tuple_convertible
592 <
593 tuple<_Up...>,
594 typename __make_tuple_types<tuple,
595 sizeof...(_Up) < sizeof...(_Tp) ?
596 sizeof...(_Up) :
597 sizeof...(_Tp)>::type
Marshall Clowbbc7c742014-10-15 10:33:02 +0000598 >::value &&
599 __all_default_constructible<
600 typename __make_tuple_types<tuple, sizeof...(_Tp),
601 sizeof...(_Up) < sizeof...(_Tp) ?
602 sizeof...(_Up) :
603 sizeof...(_Tp)>::type
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000604 >::value,
605 bool
606 >::type =false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000608 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 explicit
610 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000611 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000612 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000613 typename __make_tuple_indices<sizeof...(_Up)>::type,
614 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
615 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
616 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
617 _Up...
618 >::value
619 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
621 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
622 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
623 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000624 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625
626 template <class _Alloc, class ..._Up,
627 class = typename enable_if
628 <
629 sizeof...(_Up) <= sizeof...(_Tp) &&
630 __tuple_convertible
631 <
632 tuple<_Up...>,
633 typename __make_tuple_types<tuple,
634 sizeof...(_Up) < sizeof...(_Tp) ?
635 sizeof...(_Up) :
636 sizeof...(_Tp)>::type
Marshall Clowbbc7c742014-10-15 10:33:02 +0000637 >::value &&
638 __all_default_constructible<
639 typename __make_tuple_types<tuple, sizeof...(_Tp),
640 sizeof...(_Up) < sizeof...(_Tp) ?
641 sizeof...(_Up) :
642 sizeof...(_Tp)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 >::value
644 >::type
645 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
648 : base_(allocator_arg_t(), __a,
649 typename __make_tuple_indices<sizeof...(_Up)>::type(),
650 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
651 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
652 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000653 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654
655 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000656 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 <
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000658 __tuple_convertible<_Tuple, tuple>::value,
659 bool
660 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000663 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000664 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000666 template <class _Tuple,
667 typename enable_if
668 <
669 __tuple_constructible<_Tuple, tuple>::value &&
670 !__tuple_convertible<_Tuple, tuple>::value,
671 bool
672 >::type = false
673 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000675 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000676 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000677 : base_(_VSTD::forward<_Tuple>(__t)) {}
678
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 template <class _Alloc, class _Tuple,
680 class = typename enable_if
681 <
682 __tuple_convertible<_Tuple, tuple>::value
683 >::type
684 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000687 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688
689 template <class _Tuple,
690 class = typename enable_if
691 <
692 __tuple_assignable<_Tuple, tuple>::value
693 >::type
694 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000697 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000699 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 return *this;
701 }
702
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000704 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
705 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706};
707
708template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000709class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710{
711public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000713 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000716 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000719 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000720 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000722 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000723 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000725 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000727 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728};
729
730template <class ..._Tp>
731inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000732typename enable_if
733<
734 __all<__is_swappable<_Tp>::value...>::value,
735 void
736>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000737swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
738 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
739 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740
741// get
742
743template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000744inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000745typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000746get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000748 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
750}
751
752template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000753inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000754const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000755get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000757 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
759}
760
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000761template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000762inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000763typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000764get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000765{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000766 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000767 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000768 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000769}
770
Marshall Clowe8029e52013-07-13 02:54:05 +0000771#if _LIBCPP_STD_VER > 11
772// get by type
773template <typename _T1, size_t _Idx, typename... _Args>
774struct __find_exactly_one_t_helper;
775
776// -- find exactly one
777template <typename _T1, size_t _Idx, typename... _Args>
778struct __find_exactly_one_t_checker {
779 static constexpr size_t value = _Idx;
780// Check the rest of the list to make sure there's only one
781 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
782 };
783
784
785template <typename _T1, size_t _Idx>
786struct __find_exactly_one_t_helper <_T1, _Idx> {
787 static constexpr size_t value = -1;
788 };
789
790template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
791struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
792 static constexpr size_t value =
793 std::conditional<
794 std::is_same<_T1, _Head>::value,
Marshall Clow19e78622013-10-01 13:28:20 +0000795 __find_exactly_one_t_checker<_T1, _Idx, _Args...>,
Marshall Clowe8029e52013-07-13 02:54:05 +0000796 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
797 >::type::value;
798 };
799
800template <typename _T1, typename... _Args>
801struct __find_exactly_one_t {
802 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
803 static_assert ( value != -1, "type not found in type list" );
804 };
805
806template <class _T1, class... _Args>
807inline _LIBCPP_INLINE_VISIBILITY
808constexpr _T1& get(tuple<_Args...>& __tup) noexcept
809{
810 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
811}
812
813template <class _T1, class... _Args>
814inline _LIBCPP_INLINE_VISIBILITY
815constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
816{
817 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
818}
819
820template <class _T1, class... _Args>
821inline _LIBCPP_INLINE_VISIBILITY
822constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
823{
Marshall Clow01a0e902013-07-15 20:46:11 +0000824 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +0000825}
826
827#endif
828
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829// tie
830
831template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +0000832inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000834tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835{
836 return tuple<_Tp&...>(__t...);
837}
838
839template <class _Up>
840struct __ignore_t
841{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844 const __ignore_t& operator=(_Tp&&) const {return *this;}
845};
846
847namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
848
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000849template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850
851template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000852struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853{
854 typedef _Tp type;
855};
856
857template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000858struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859{
860 typedef _Tp& type;
861};
862
863template <class _Tp>
864struct __make_tuple_return
865{
Marshall Clowa71f9562014-01-03 22:55:49 +0000866 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867};
868
869template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000870inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871tuple<typename __make_tuple_return<_Tp>::type...>
872make_tuple(_Tp&&... __t)
873{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000874 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875}
876
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000877template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000878inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
879tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000880forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000881{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000882 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000883}
884
Howard Hinnant99968442011-11-29 18:15:50 +0000885template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886struct __tuple_equal
887{
888 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000889 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 bool operator()(const _Tp& __x, const _Up& __y)
891 {
Marshall Clowba6dbf42014-06-24 00:46:19 +0000892 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 }
894};
895
896template <>
897struct __tuple_equal<0>
898{
899 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000900 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 bool operator()(const _Tp&, const _Up&)
902 {
903 return true;
904 }
905};
906
907template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000908inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909bool
910operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
911{
912 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
913}
914
915template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000916inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917bool
918operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
919{
920 return !(__x == __y);
921}
922
Howard Hinnant99968442011-11-29 18:15:50 +0000923template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924struct __tuple_less
925{
926 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000927 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 bool operator()(const _Tp& __x, const _Up& __y)
929 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +0000930 const size_t __idx = tuple_size<_Tp>::value - _Ip;
931 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
932 return true;
933 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
934 return false;
935 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 }
937};
938
939template <>
940struct __tuple_less<0>
941{
942 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000943 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944 bool operator()(const _Tp&, const _Up&)
945 {
946 return false;
947 }
948};
949
950template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000951inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952bool
953operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
954{
955 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
956}
957
958template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000959inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960bool
961operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
962{
963 return __y < __x;
964}
965
966template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000967inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968bool
969operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
970{
971 return !(__x < __y);
972}
973
974template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000975inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976bool
977operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
978{
979 return !(__y < __x);
980}
981
982// tuple_cat
983
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000984template <class _Tp, class _Up> struct __tuple_cat_type;
985
986template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +0000987struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988{
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000989 typedef tuple<_Ttypes..., _Utypes...> type;
990};
991
992template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
993struct __tuple_cat_return_1
994{
995};
996
997template <class ..._Types, class _Tuple0>
998struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
999{
1000 typedef typename __tuple_cat_type<tuple<_Types...>,
1001 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1002 type;
1003};
1004
1005template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1006struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1007 : public __tuple_cat_return_1<
1008 typename __tuple_cat_type<
1009 tuple<_Types...>,
1010 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1011 >::type,
1012 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1013 _Tuple1, _Tuples...>
1014{
1015};
1016
1017template <class ..._Tuples> struct __tuple_cat_return;
1018
1019template <class _Tuple0, class ..._Tuples>
1020struct __tuple_cat_return<_Tuple0, _Tuples...>
1021 : public __tuple_cat_return_1<tuple<>,
1022 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1023 _Tuples...>
1024{
1025};
1026
1027template <>
1028struct __tuple_cat_return<>
1029{
1030 typedef tuple<> type;
1031};
1032
Marshall Clowda0a0e82013-07-22 16:02:19 +00001033inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001034tuple<>
1035tuple_cat()
1036{
1037 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038}
1039
Howard Hinnant99968442011-11-29 18:15:50 +00001040template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001041struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042
Howard Hinnante48e3662010-12-12 23:04:37 +00001043template <class ..._Types, size_t ..._I0, class _Tuple0>
1044struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001046 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001047 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1048 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1049};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050
Howard Hinnante48e3662010-12-12 23:04:37 +00001051template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1052struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1053 _Tuple0, _Tuple1, _Tuples...>
1054 : public __tuple_cat_return_ref_imp<
1055 tuple<_Types..., typename __apply_cv<_Tuple0,
1056 typename tuple_element<_I0,
1057 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1058 typename __make_tuple_indices<tuple_size<typename
1059 remove_reference<_Tuple1>::type>::value>::type,
1060 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061{
Howard Hinnante48e3662010-12-12 23:04:37 +00001062};
1063
1064template <class _Tuple0, class ..._Tuples>
1065struct __tuple_cat_return_ref
1066 : public __tuple_cat_return_ref_imp<tuple<>,
1067 typename __make_tuple_indices<
1068 tuple_size<typename remove_reference<_Tuple0>::type>::value
1069 >::type, _Tuple0, _Tuples...>
1070{
1071};
1072
1073template <class _Types, class _I0, class _J0>
1074struct __tuple_cat;
1075
1076template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001077struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001078{
1079 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001080 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001081 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1082 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1083 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001084 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1085 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001086 }
1087
1088 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001089 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001090 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1091 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1092 {
1093 typedef typename remove_reference<_Tuple0>::type _T0;
1094 typedef typename remove_reference<_Tuple1>::type _T1;
1095 return __tuple_cat<
1096 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1097 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1098 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001099 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001100 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1101 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001102 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001103 _VSTD::forward<_Tuple1>(__t1),
1104 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001105 }
1106};
1107
1108template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001109inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001110typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1111tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1112{
1113 typedef typename remove_reference<_Tuple0>::type _T0;
1114 return __tuple_cat<tuple<>, __tuple_indices<>,
1115 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001116 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1117 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118}
1119
1120template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001121struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 : true_type {};
1123
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001124template <class _T1, class _T2>
1125template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1126inline _LIBCPP_INLINE_VISIBILITY
1127pair<_T1, _T2>::pair(piecewise_construct_t,
1128 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1129 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001130 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1131 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132{
1133}
1134
Howard Hinnant324bb032010-08-22 00:02:43 +00001135#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136
1137_LIBCPP_END_NAMESPACE_STD
1138
1139#endif // _LIBCPP_TUPLE