blob: 1463170fe1c70a1c87503383e8ca6a96c95aebf0 [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
Howard Hinnanta5e01212011-05-27 19:08:18 +0000379template <bool ...> struct __all;
380
381template <>
382struct __all<>
383{
384 static const bool value = true;
385};
386
Howard Hinnant99968442011-11-29 18:15:50 +0000387template <bool _B0, bool ... _Bp>
388struct __all<_B0, _Bp...>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000389{
Howard Hinnant99968442011-11-29 18:15:50 +0000390 static const bool value = _B0 && __all<_Bp...>::value;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000391};
392
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393// __tuple_impl
394
395template<class _Indx, class ..._Tp> struct __tuple_impl;
396
397template<size_t ..._Indx, class ..._Tp>
398struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
399 : public __tuple_leaf<_Indx, _Tp>...
400{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000402 _LIBCPP_CONSTEXPR __tuple_impl()
403 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000404
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405 template <size_t ..._Uf, class ..._Tf,
406 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 explicit
409 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
410 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000411 _Up&&... __u)
412 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
413 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000414 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 __tuple_leaf<_Ul, _Tl>()...
416 {}
417
418 template <class _Alloc, size_t ..._Uf, class ..._Tf,
419 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 explicit
422 __tuple_impl(allocator_arg_t, const _Alloc& __a,
423 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
424 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
425 _Up&&... __u) :
426 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000427 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
429 {}
430
431 template <class _Tuple,
432 class = typename enable_if
433 <
Howard Hinnant99324892013-04-14 00:01:13 +0000434 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 >::type
436 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000438 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
439 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000440 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
441 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 {}
443
444 template <class _Alloc, class _Tuple,
445 class = typename enable_if
446 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000447 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 >::type
449 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
452 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000453 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000454 _VSTD::forward<typename tuple_element<_Indx,
455 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 {}
457
458 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 typename enable_if
461 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000462 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 __tuple_impl&
464 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000465 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
466 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000468 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
469 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 return *this;
471 }
472
Howard Hinnant3de50862013-11-06 17:45:43 +0000473 __tuple_impl(const __tuple_impl&) = default;
474 __tuple_impl(__tuple_impl&&) = default;
475
476 _LIBCPP_INLINE_VISIBILITY
477 __tuple_impl&
478 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
479 {
480 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
481 return *this;
482 }
483
484 _LIBCPP_INLINE_VISIBILITY
485 __tuple_impl&
486 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
487 {
488 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
489 return *this;
490 }
Howard Hinnant28484442012-02-15 20:13:52 +0000491
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000494 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495 {
496 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
497 }
498};
499
500template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000501class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502{
503 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
504
505 base base_;
506
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000507 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000508 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000509 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000510 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000511 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000512 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513public:
514
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
Howard Hinnant74f26f22012-07-06 21:53:48 +0000520 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
528 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 <
542 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
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000550 >::value,
551 bool
552 >::type = false
553 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000554 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000555 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000556 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000557 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000558 typename __make_tuple_indices<sizeof...(_Up)>::type,
559 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
560 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
561 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000562 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000563 >::value
564 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000565 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
566 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
567 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
568 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
569 _VSTD::forward<_Up>(__u)...) {}
570
571 template <class ..._Up,
572 typename enable_if
573 <
574 sizeof...(_Up) <= sizeof...(_Tp) &&
575 __tuple_constructible
576 <
577 tuple<_Up...>,
578 typename __make_tuple_types<tuple,
579 sizeof...(_Up) < sizeof...(_Tp) ?
580 sizeof...(_Up) :
581 sizeof...(_Tp)>::type
582 >::value &&
583 !__tuple_convertible
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 bool
592 >::type =false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000594 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 explicit
596 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000597 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000598 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000599 typename __make_tuple_indices<sizeof...(_Up)>::type,
600 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
601 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
602 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
603 _Up...
604 >::value
605 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
607 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
608 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
609 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000610 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611
612 template <class _Alloc, class ..._Up,
613 class = typename enable_if
614 <
615 sizeof...(_Up) <= sizeof...(_Tp) &&
616 __tuple_convertible
617 <
618 tuple<_Up...>,
619 typename __make_tuple_types<tuple,
620 sizeof...(_Up) < sizeof...(_Tp) ?
621 sizeof...(_Up) :
622 sizeof...(_Tp)>::type
623 >::value
624 >::type
625 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
628 : base_(allocator_arg_t(), __a,
629 typename __make_tuple_indices<sizeof...(_Up)>::type(),
630 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
631 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
632 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000633 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634
635 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000636 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 <
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000638 __tuple_convertible<_Tuple, tuple>::value,
639 bool
640 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000642 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000643 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000644 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000646 template <class _Tuple,
647 typename enable_if
648 <
649 __tuple_constructible<_Tuple, tuple>::value &&
650 !__tuple_convertible<_Tuple, tuple>::value,
651 bool
652 >::type = false
653 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000655 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000656 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000657 : base_(_VSTD::forward<_Tuple>(__t)) {}
658
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 template <class _Alloc, class _Tuple,
660 class = typename enable_if
661 <
662 __tuple_convertible<_Tuple, tuple>::value
663 >::type
664 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000667 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668
669 template <class _Tuple,
670 class = typename enable_if
671 <
672 __tuple_assignable<_Tuple, tuple>::value
673 >::type
674 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000677 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000679 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 return *this;
681 }
682
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000684 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
685 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686};
687
688template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000689class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690{
691public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000693 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000696 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000699 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000700 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000702 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000703 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000705 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000707 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708};
709
710template <class ..._Tp>
711inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000712typename enable_if
713<
714 __all<__is_swappable<_Tp>::value...>::value,
715 void
716>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000717swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
718 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
719 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720
721// get
722
723template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000724inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000725typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000726get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000728 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
730}
731
732template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000733inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000734const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000735get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000737 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
739}
740
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000741template <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 Hinnantcd2254b2010-11-17 19:52:17 +0000745{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000746 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000747 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000748 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000749}
750
Marshall Clowe8029e52013-07-13 02:54:05 +0000751#if _LIBCPP_STD_VER > 11
752// get by type
753template <typename _T1, size_t _Idx, typename... _Args>
754struct __find_exactly_one_t_helper;
755
756// -- find exactly one
757template <typename _T1, size_t _Idx, typename... _Args>
758struct __find_exactly_one_t_checker {
759 static constexpr size_t value = _Idx;
760// Check the rest of the list to make sure there's only one
761 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
762 };
763
764
765template <typename _T1, size_t _Idx>
766struct __find_exactly_one_t_helper <_T1, _Idx> {
767 static constexpr size_t value = -1;
768 };
769
770template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
771struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
772 static constexpr size_t value =
773 std::conditional<
774 std::is_same<_T1, _Head>::value,
Marshall Clow19e78622013-10-01 13:28:20 +0000775 __find_exactly_one_t_checker<_T1, _Idx, _Args...>,
Marshall Clowe8029e52013-07-13 02:54:05 +0000776 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
777 >::type::value;
778 };
779
780template <typename _T1, typename... _Args>
781struct __find_exactly_one_t {
782 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
783 static_assert ( value != -1, "type not found in type list" );
784 };
785
786template <class _T1, class... _Args>
787inline _LIBCPP_INLINE_VISIBILITY
788constexpr _T1& get(tuple<_Args...>& __tup) noexcept
789{
790 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
791}
792
793template <class _T1, class... _Args>
794inline _LIBCPP_INLINE_VISIBILITY
795constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
796{
797 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
798}
799
800template <class _T1, class... _Args>
801inline _LIBCPP_INLINE_VISIBILITY
802constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
803{
Marshall Clow01a0e902013-07-15 20:46:11 +0000804 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +0000805}
806
807#endif
808
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809// tie
810
811template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +0000812inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000814tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815{
816 return tuple<_Tp&...>(__t...);
817}
818
819template <class _Up>
820struct __ignore_t
821{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824 const __ignore_t& operator=(_Tp&&) const {return *this;}
825};
826
827namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
828
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000829template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830
831template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000832struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833{
834 typedef _Tp type;
835};
836
837template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000838struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839{
840 typedef _Tp& type;
841};
842
843template <class _Tp>
844struct __make_tuple_return
845{
Marshall Clowa71f9562014-01-03 22:55:49 +0000846 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847};
848
849template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000850inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851tuple<typename __make_tuple_return<_Tp>::type...>
852make_tuple(_Tp&&... __t)
853{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000854 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855}
856
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000857template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000858inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
859tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000860forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000861{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000862 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000863}
864
Howard Hinnant99968442011-11-29 18:15:50 +0000865template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866struct __tuple_equal
867{
868 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000869 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 bool operator()(const _Tp& __x, const _Up& __y)
871 {
Marshall Clowba6dbf42014-06-24 00:46:19 +0000872 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 }
874};
875
876template <>
877struct __tuple_equal<0>
878{
879 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000880 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881 bool operator()(const _Tp&, const _Up&)
882 {
883 return true;
884 }
885};
886
887template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000888inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889bool
890operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
891{
892 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
893}
894
895template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000896inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897bool
898operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
899{
900 return !(__x == __y);
901}
902
Howard Hinnant99968442011-11-29 18:15:50 +0000903template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904struct __tuple_less
905{
906 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000907 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 bool operator()(const _Tp& __x, const _Up& __y)
909 {
Howard Hinnant99968442011-11-29 18:15:50 +0000910 return __tuple_less<_Ip-1>()(__x, __y) ||
Marshall Clowba6dbf42014-06-24 00:46:19 +0000911 (!__tuple_less<_Ip-1>()(__y, __x) && _VSTD::get<_Ip-1>(__x) < _VSTD::get<_Ip-1>(__y));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 }
913};
914
915template <>
916struct __tuple_less<0>
917{
918 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000919 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920 bool operator()(const _Tp&, const _Up&)
921 {
922 return false;
923 }
924};
925
926template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000927inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928bool
929operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
930{
931 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
932}
933
934template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000935inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936bool
937operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
938{
939 return __y < __x;
940}
941
942template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000943inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944bool
945operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
946{
947 return !(__x < __y);
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 !(__y < __x);
956}
957
958// tuple_cat
959
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000960template <class _Tp, class _Up> struct __tuple_cat_type;
961
962template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +0000963struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964{
Howard Hinnant0e1493e2010-12-11 20:47:50 +0000965 typedef tuple<_Ttypes..., _Utypes...> type;
966};
967
968template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
969struct __tuple_cat_return_1
970{
971};
972
973template <class ..._Types, class _Tuple0>
974struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
975{
976 typedef typename __tuple_cat_type<tuple<_Types...>,
977 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
978 type;
979};
980
981template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
982struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
983 : public __tuple_cat_return_1<
984 typename __tuple_cat_type<
985 tuple<_Types...>,
986 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
987 >::type,
988 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
989 _Tuple1, _Tuples...>
990{
991};
992
993template <class ..._Tuples> struct __tuple_cat_return;
994
995template <class _Tuple0, class ..._Tuples>
996struct __tuple_cat_return<_Tuple0, _Tuples...>
997 : public __tuple_cat_return_1<tuple<>,
998 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
999 _Tuples...>
1000{
1001};
1002
1003template <>
1004struct __tuple_cat_return<>
1005{
1006 typedef tuple<> type;
1007};
1008
Marshall Clowda0a0e82013-07-22 16:02:19 +00001009inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001010tuple<>
1011tuple_cat()
1012{
1013 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014}
1015
Howard Hinnant99968442011-11-29 18:15:50 +00001016template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001017struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018
Howard Hinnante48e3662010-12-12 23:04:37 +00001019template <class ..._Types, size_t ..._I0, class _Tuple0>
1020struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001022 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001023 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1024 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1025};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026
Howard Hinnante48e3662010-12-12 23:04:37 +00001027template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1028struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1029 _Tuple0, _Tuple1, _Tuples...>
1030 : public __tuple_cat_return_ref_imp<
1031 tuple<_Types..., typename __apply_cv<_Tuple0,
1032 typename tuple_element<_I0,
1033 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1034 typename __make_tuple_indices<tuple_size<typename
1035 remove_reference<_Tuple1>::type>::value>::type,
1036 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037{
Howard Hinnante48e3662010-12-12 23:04:37 +00001038};
1039
1040template <class _Tuple0, class ..._Tuples>
1041struct __tuple_cat_return_ref
1042 : public __tuple_cat_return_ref_imp<tuple<>,
1043 typename __make_tuple_indices<
1044 tuple_size<typename remove_reference<_Tuple0>::type>::value
1045 >::type, _Tuple0, _Tuples...>
1046{
1047};
1048
1049template <class _Types, class _I0, class _J0>
1050struct __tuple_cat;
1051
1052template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001053struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001054{
1055 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001056 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001057 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1058 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1059 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001060 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1061 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001062 }
1063
1064 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001065 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001066 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1067 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1068 {
1069 typedef typename remove_reference<_Tuple0>::type _T0;
1070 typedef typename remove_reference<_Tuple1>::type _T1;
1071 return __tuple_cat<
1072 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1073 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1074 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001075 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001076 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1077 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001078 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001079 _VSTD::forward<_Tuple1>(__t1),
1080 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001081 }
1082};
1083
1084template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001085inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001086typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1087tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1088{
1089 typedef typename remove_reference<_Tuple0>::type _T0;
1090 return __tuple_cat<tuple<>, __tuple_indices<>,
1091 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001092 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1093 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094}
1095
1096template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001097struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 : true_type {};
1099
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100template <class _T1, class _T2>
1101template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1102inline _LIBCPP_INLINE_VISIBILITY
1103pair<_T1, _T2>::pair(piecewise_construct_t,
1104 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1105 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001106 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1107 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108{
1109}
1110
Howard Hinnant324bb032010-08-22 00:02:43 +00001111#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112
1113_LIBCPP_END_NAMESPACE_STD
1114
1115#endif // _LIBCPP_TUPLE