blob: 1829932e14a86a6dda1689272c4753815eec080a [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
Howard Hinnanta5e01212011-05-27 19:08:18 +000076template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept;
77template <class... T> tuple<T&...> tie(T&...) noexcept;
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...>>;
85
86// 20.4.1.5, element access:
Howard Hinnanta5e01212011-05-27 19:08:18 +000087template <intsize_t I, class... T>
88 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000089 get(tuple<T...>&) noexcept; // constexpr in C++14
Howard Hinnanta5e01212011-05-27 19:08:18 +000090template <intsize_t I, class... T>
91 typename tuple_element<I, tuple<T...>>::type const&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000092 get(const tuple<T...>&) noexcept; // constexpr in C++14
Howard Hinnanta5e01212011-05-27 19:08:18 +000093template <intsize_t I, class... T>
94 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000095 get(tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096
Marshall Clowe8029e52013-07-13 02:54:05 +000097template <class T1, class... T>
98 constexpr T1& get(tuple<T...>&) noexcept; // C++14
99template <class T1, class... T>
100 constexpr T1 const& get(const tuple<T...>&) noexcept; // C++14
101template <class T1, class... T>
102 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
103
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000104// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19 +0000105template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
106template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
107template<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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111
112template <class... Types, class Alloc>
113 struct uses_allocator<tuple<Types...>, Alloc>;
114
115template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000116 void
117 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000119} // std
120
121*/
122
123#include <__config>
124#include <__tuple>
125#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000127#include <__functional_base>
128#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129
Howard Hinnant08e17472011-10-17 20:05:10 +0000130#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000132#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133
134_LIBCPP_BEGIN_NAMESPACE_STD
135
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000136// allocator_arg_t
137
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000138struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000139
Howard Hinnant46e94932012-07-07 20:56:04 +0000140#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000141extern const allocator_arg_t allocator_arg;
Howard Hinnant46e94932012-07-07 20:56:04 +0000142#else
143constexpr allocator_arg_t allocator_arg = allocator_arg_t();
144#endif
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000145
146// uses_allocator
147
148template <class _Tp>
149struct __has_allocator_type
150{
151private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000152 struct __two {char __lx; char __lxx;};
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000153 template <class _Up> static __two __test(...);
154 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
155public:
156 static const bool value = sizeof(__test<_Tp>(0)) == 1;
157};
158
159template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
160struct __uses_allocator
161 : public integral_constant<bool,
162 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
163{
164};
165
166template <class _Tp, class _Alloc>
167struct __uses_allocator<_Tp, _Alloc, false>
168 : public false_type
169{
170};
171
172template <class _Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000173struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000174 : public __uses_allocator<_Tp, _Alloc>
175{
176};
177
178#ifndef _LIBCPP_HAS_NO_VARIADICS
179
180// uses-allocator construction
181
182template <class _Tp, class _Alloc, class ..._Args>
183struct __uses_alloc_ctor_imp
184{
185 static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
186 static const bool __ic =
187 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
188 static const int value = __ua ? 2 - __ic : 0;
189};
190
191template <class _Tp, class _Alloc, class ..._Args>
192struct __uses_alloc_ctor
193 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
194 {};
195
196#endif // _LIBCPP_HAS_NO_VARIADICS
197
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198#ifndef _LIBCPP_HAS_NO_VARIADICS
199
200// tuple_size
201
202template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000203class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 : public integral_constant<size_t, sizeof...(_Tp)>
205{
206};
207
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208// tuple_element
209
210template <size_t _Ip, class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000211class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212{
213public:
Howard Hinnantf83417b2011-01-24 16:07:25 +0000214 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215};
216
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217// __tuple_leaf
218
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000219template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value
220#if __has_feature(is_final)
221 && !__is_final(_Hp)
222#endif
223 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224class __tuple_leaf;
225
226template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000229 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230{
231 swap(__x.get(), __y.get());
232}
233
234template <size_t _Ip, class _Hp, bool>
235class __tuple_leaf
236{
237 _Hp value;
238
239 __tuple_leaf& operator=(const __tuple_leaf&);
240public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000241 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
242 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243 {static_assert(!is_reference<_Hp>::value,
244 "Attempted to default construct a reference element in a tuple");}
245
246 template <class _Alloc>
247 _LIBCPP_INLINE_VISIBILITY
248 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
249 : value()
250 {static_assert(!is_reference<_Hp>::value,
251 "Attempted to default construct a reference element in a tuple");}
252
253 template <class _Alloc>
254 _LIBCPP_INLINE_VISIBILITY
255 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
256 : value(allocator_arg_t(), __a)
257 {static_assert(!is_reference<_Hp>::value,
258 "Attempted to default construct a reference element in a tuple");}
259
260 template <class _Alloc>
261 _LIBCPP_INLINE_VISIBILITY
262 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
263 : value(__a)
264 {static_assert(!is_reference<_Hp>::value,
265 "Attempted to default construct a reference element in a tuple");}
266
Howard Hinnante049cc52010-09-27 17:54:17 +0000267 template <class _Tp,
268 class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000270 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000271 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnante049cc52010-09-27 17:54:17 +0000272 {static_assert(!is_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000273 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274 (is_lvalue_reference<_Tp>::value ||
275 is_same<typename remove_reference<_Tp>::type,
276 reference_wrapper<
277 typename remove_reference<_Hp>::type
278 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000279 >::value)) ||
Howard Hinnante049cc52010-09-27 17:54:17 +0000280 (is_rvalue_reference<_Hp>::value &&
281 !is_lvalue_reference<_Tp>::value),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282 "Attempted to construct a reference element in a tuple with an rvalue");}
283
284 template <class _Tp, class _Alloc>
285 _LIBCPP_INLINE_VISIBILITY
286 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000287 : value(_VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000289 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290 (is_lvalue_reference<_Tp>::value ||
291 is_same<typename remove_reference<_Tp>::type,
292 reference_wrapper<
293 typename remove_reference<_Hp>::type
294 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000295 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296 "Attempted to construct a reference element in a tuple with an rvalue");}
297
298 template <class _Tp, class _Alloc>
299 _LIBCPP_INLINE_VISIBILITY
300 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000301 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000303 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304 (is_lvalue_reference<_Tp>::value ||
305 is_same<typename remove_reference<_Tp>::type,
306 reference_wrapper<
307 typename remove_reference<_Hp>::type
308 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000309 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310 "Attempted to construct a reference element in a tuple with an rvalue");}
311
312 template <class _Tp, class _Alloc>
313 _LIBCPP_INLINE_VISIBILITY
314 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000315 : value(_VSTD::forward<_Tp>(__t), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316 {static_assert(!is_lvalue_reference<_Hp>::value ||
Howard Hinnantec3773c2011-12-01 20:21:04 +0000317 (is_lvalue_reference<_Hp>::value &&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000318 (is_lvalue_reference<_Tp>::value ||
319 is_same<typename remove_reference<_Tp>::type,
320 reference_wrapper<
321 typename remove_reference<_Hp>::type
322 >
Howard Hinnantec3773c2011-12-01 20:21:04 +0000323 >::value)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324 "Attempted to construct a reference element in a tuple with an rvalue");}
325
Marshall Clowda0a0e82013-07-22 16:02:19 +0000326 _LIBCPP_INLINE_VISIBILITY
327 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000328 __tuple_leaf(const __tuple_leaf& __t) _NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value)
Howard Hinnante049cc52010-09-27 17:54:17 +0000329 : value(__t.get())
330 {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
331
Marshall Clowda0a0e82013-07-22 16:02:19 +0000332 _LIBCPP_INLINE_VISIBILITY
333 _LIBCPP_CONSTEXPR_AFTER_CXX11
334 __tuple_leaf(__tuple_leaf&& __t) _NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value)
335 : value(_VSTD::move(__t.get()))
336 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337
338 template <class _Tp>
339 _LIBCPP_INLINE_VISIBILITY
340 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000341 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000343 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344 return *this;
345 }
346
347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000348 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000350 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351 return 0;
352 }
353
Marshall Clowda0a0e82013-07-22 16:02:19 +0000354 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
355 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356};
357
358template <size_t _Ip, class _Hp>
359class __tuple_leaf<_Ip, _Hp, true>
360 : private _Hp
361{
362
363 __tuple_leaf& operator=(const __tuple_leaf&);
364public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000365 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
366 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
368 template <class _Alloc>
369 _LIBCPP_INLINE_VISIBILITY
370 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
371
372 template <class _Alloc>
373 _LIBCPP_INLINE_VISIBILITY
374 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
375 : _Hp(allocator_arg_t(), __a) {}
376
377 template <class _Alloc>
378 _LIBCPP_INLINE_VISIBILITY
379 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
380 : _Hp(__a) {}
381
Howard Hinnante049cc52010-09-27 17:54:17 +0000382 template <class _Tp,
383 class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000385 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000386 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388 template <class _Tp, class _Alloc>
389 _LIBCPP_INLINE_VISIBILITY
390 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000391 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392
393 template <class _Tp, class _Alloc>
394 _LIBCPP_INLINE_VISIBILITY
395 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000396 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
398 template <class _Tp, class _Alloc>
399 _LIBCPP_INLINE_VISIBILITY
400 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000401 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402
403 template <class _Tp>
404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000406 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000408 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409 return *this;
410 }
411
Howard Hinnanta5e01212011-05-27 19:08:18 +0000412 _LIBCPP_INLINE_VISIBILITY
413 int
414 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000416 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417 return 0;
418 }
419
Marshall Clowda0a0e82013-07-22 16:02:19 +0000420 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
421 _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 +0000422};
423
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424template <class ..._Tp>
425_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000426void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427
Howard Hinnanta5e01212011-05-27 19:08:18 +0000428template <bool ...> struct __all;
429
430template <>
431struct __all<>
432{
433 static const bool value = true;
434};
435
Howard Hinnant99968442011-11-29 18:15:50 +0000436template <bool _B0, bool ... _Bp>
437struct __all<_B0, _Bp...>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000438{
Howard Hinnant99968442011-11-29 18:15:50 +0000439 static const bool value = _B0 && __all<_Bp...>::value;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000440};
441
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442// __tuple_impl
443
444template<class _Indx, class ..._Tp> struct __tuple_impl;
445
446template<size_t ..._Indx, class ..._Tp>
447struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
448 : public __tuple_leaf<_Indx, _Tp>...
449{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000451 _LIBCPP_CONSTEXPR __tuple_impl()
452 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000453
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454 template <size_t ..._Uf, class ..._Tf,
455 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000456 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 explicit
458 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
459 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000460 _Up&&... __u)
461 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
462 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000463 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 __tuple_leaf<_Ul, _Tl>()...
465 {}
466
467 template <class _Alloc, size_t ..._Uf, class ..._Tf,
468 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 explicit
471 __tuple_impl(allocator_arg_t, const _Alloc& __a,
472 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
473 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
474 _Up&&... __u) :
475 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000476 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
478 {}
479
480 template <class _Tuple,
481 class = typename enable_if
482 <
Howard Hinnant99324892013-04-14 00:01:13 +0000483 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484 >::type
485 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000486 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000487 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
488 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000489 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
490 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 {}
492
493 template <class _Alloc, class _Tuple,
494 class = typename enable_if
495 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000496 __tuple_convertible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497 >::type
498 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
501 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000502 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000503 _VSTD::forward<typename tuple_element<_Indx,
504 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 {}
506
507 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 typename enable_if
510 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000511 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 __tuple_impl&
513 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000514 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
515 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000517 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
518 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519 return *this;
520 }
521
Howard Hinnant28484442012-02-15 20:13:52 +0000522 _LIBCPP_INLINE_VISIBILITY
523 __tuple_impl&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000524 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
Howard Hinnant28484442012-02-15 20:13:52 +0000525 {
526 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
527 return *this;
528 }
529
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000532 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 {
534 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
535 }
536};
537
538template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000539class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540{
541 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
542
543 base base_;
544
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000545 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000546 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000547 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000548 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000549 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000550 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551public:
552
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000554 _LIBCPP_CONSTEXPR tuple()
555 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000556
Marshall Clowda0a0e82013-07-22 16:02:19 +0000557 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000558 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
560 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
561 typename __make_tuple_indices<0>::type(),
562 typename __make_tuple_types<tuple, 0>::type(),
563 __t...
564 ) {}
565
566 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
569 : base_(allocator_arg_t(), __a,
570 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
571 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
572 typename __make_tuple_indices<0>::type(),
573 typename __make_tuple_types<tuple, 0>::type(),
574 __t...
575 ) {}
576
577 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000578 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 <
580 sizeof...(_Up) <= sizeof...(_Tp) &&
581 __tuple_convertible
582 <
583 tuple<_Up...>,
584 typename __make_tuple_types<tuple,
585 sizeof...(_Up) < sizeof...(_Tp) ?
586 sizeof...(_Up) :
587 sizeof...(_Tp)>::type
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000588 >::value,
589 bool
590 >::type = false
591 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000592 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000593 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000594 _NOEXCEPT_((
595 is_nothrow_constructible<
596 typename __make_tuple_indices<sizeof...(_Up)>::type,
597 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
598 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
599 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
600 _Up...
601 >::value
602 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000603 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
604 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
605 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
606 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
607 _VSTD::forward<_Up>(__u)...) {}
608
609 template <class ..._Up,
610 typename enable_if
611 <
612 sizeof...(_Up) <= sizeof...(_Tp) &&
613 __tuple_constructible
614 <
615 tuple<_Up...>,
616 typename __make_tuple_types<tuple,
617 sizeof...(_Up) < sizeof...(_Tp) ?
618 sizeof...(_Up) :
619 sizeof...(_Tp)>::type
620 >::value &&
621 !__tuple_convertible
622 <
623 tuple<_Up...>,
624 typename __make_tuple_types<tuple,
625 sizeof...(_Up) < sizeof...(_Tp) ?
626 sizeof...(_Up) :
627 sizeof...(_Tp)>::type
628 >::value,
629 bool
630 >::type =false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000632 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 explicit
634 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000635 _NOEXCEPT_((
636 is_nothrow_constructible<
637 typename __make_tuple_indices<sizeof...(_Up)>::type,
638 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
639 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
640 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
641 _Up...
642 >::value
643 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
645 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
646 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
647 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000648 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649
650 template <class _Alloc, class ..._Up,
651 class = typename enable_if
652 <
653 sizeof...(_Up) <= sizeof...(_Tp) &&
654 __tuple_convertible
655 <
656 tuple<_Up...>,
657 typename __make_tuple_types<tuple,
658 sizeof...(_Up) < sizeof...(_Tp) ?
659 sizeof...(_Up) :
660 sizeof...(_Tp)>::type
661 >::value
662 >::type
663 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
666 : base_(allocator_arg_t(), __a,
667 typename __make_tuple_indices<sizeof...(_Up)>::type(),
668 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
669 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
670 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000671 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672
673 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000674 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 <
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000676 __tuple_convertible<_Tuple, tuple>::value,
677 bool
678 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000681 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000682 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000684 template <class _Tuple,
685 typename enable_if
686 <
687 __tuple_constructible<_Tuple, tuple>::value &&
688 !__tuple_convertible<_Tuple, tuple>::value,
689 bool
690 >::type = false
691 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000693 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000694 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000695 : base_(_VSTD::forward<_Tuple>(__t)) {}
696
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 template <class _Alloc, class _Tuple,
698 class = typename enable_if
699 <
700 __tuple_convertible<_Tuple, tuple>::value
701 >::type
702 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000705 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706
707 template <class _Tuple,
708 class = typename enable_if
709 <
710 __tuple_assignable<_Tuple, tuple>::value
711 >::type
712 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000715 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000717 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 return *this;
719 }
720
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000722 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
723 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724};
725
726template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000727class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728{
729public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000731 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000734 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000737 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000738 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000740 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000741 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000743 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000745 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746};
747
748template <class ..._Tp>
749inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000750typename enable_if
751<
752 __all<__is_swappable<_Tp>::value...>::value,
753 void
754>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000755swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
756 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
757 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758
759// get
760
761template <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 Hinnantbc8d3f92010-05-11 19:42:16 +0000765{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000766 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
768}
769
770template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000771inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000772const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000773get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000775 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
777}
778
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000779template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000780inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000781typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000782get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000783{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000784 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000785 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000786 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000787}
788
Marshall Clowe8029e52013-07-13 02:54:05 +0000789#if _LIBCPP_STD_VER > 11
790// get by type
791template <typename _T1, size_t _Idx, typename... _Args>
792struct __find_exactly_one_t_helper;
793
794// -- find exactly one
795template <typename _T1, size_t _Idx, typename... _Args>
796struct __find_exactly_one_t_checker {
797 static constexpr size_t value = _Idx;
798// Check the rest of the list to make sure there's only one
799 static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" );
800 };
801
802
803template <typename _T1, size_t _Idx>
804struct __find_exactly_one_t_helper <_T1, _Idx> {
805 static constexpr size_t value = -1;
806 };
807
808template <typename _T1, size_t _Idx, typename _Head, typename... _Args>
809struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> {
810 static constexpr size_t value =
811 std::conditional<
812 std::is_same<_T1, _Head>::value,
813 __find_exactly_one_t_checker<_T1, _Idx,   _Args...>,
814 __find_exactly_one_t_helper <_T1, _Idx+1, _Args...>
815 >::type::value;
816 };
817
818template <typename _T1, typename... _Args>
819struct __find_exactly_one_t {
820 static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value;
821 static_assert ( value != -1, "type not found in type list" );
822 };
823
824template <class _T1, class... _Args>
825inline _LIBCPP_INLINE_VISIBILITY
826constexpr _T1& get(tuple<_Args...>& __tup) noexcept
827{
828 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
829}
830
831template <class _T1, class... _Args>
832inline _LIBCPP_INLINE_VISIBILITY
833constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
834{
835 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
836}
837
838template <class _T1, class... _Args>
839inline _LIBCPP_INLINE_VISIBILITY
840constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
841{
Marshall Clow01a0e902013-07-15 20:46:11 +0000842 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +0000843}
844
845#endif
846
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847// tie
848
849template <class ..._Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000852tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853{
854 return tuple<_Tp&...>(__t...);
855}
856
857template <class _Up>
858struct __ignore_t
859{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 const __ignore_t& operator=(_Tp&&) const {return *this;}
863};
864
865namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
866
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000867template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868
869template <class _Tp>
870struct ___make_tuple_return
871{
872 typedef _Tp type;
873};
874
875template <class _Tp>
Howard Hinnantf83417b2011-01-24 16:07:25 +0000876struct ___make_tuple_return<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877{
878 typedef _Tp& type;
879};
880
881template <class _Tp>
882struct __make_tuple_return
883{
884 typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
885};
886
887template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000888inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889tuple<typename __make_tuple_return<_Tp>::type...>
890make_tuple(_Tp&&... __t)
891{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000892 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893}
894
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000895template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000896inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
897tuple<_Tp&&...>
898__forward_as_tuple(_Tp&&... __t) _NOEXCEPT
899{
900 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
901}
902
903template <class... _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000904inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000905tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +0000906forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000907{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000908 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +0000909}
910
Howard Hinnant99968442011-11-29 18:15:50 +0000911template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912struct __tuple_equal
913{
914 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000915 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916 bool operator()(const _Tp& __x, const _Up& __y)
917 {
Howard Hinnant99968442011-11-29 18:15:50 +0000918 return __tuple_equal<_Ip - 1>()(__x, __y) && get<_Ip-1>(__x) == get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000919 }
920};
921
922template <>
923struct __tuple_equal<0>
924{
925 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000926 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 bool operator()(const _Tp&, const _Up&)
928 {
929 return true;
930 }
931};
932
933template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000934inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935bool
936operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
937{
938 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
939}
940
941template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000942inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943bool
944operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
945{
946 return !(__x == __y);
947}
948
Howard Hinnant99968442011-11-29 18:15:50 +0000949template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950struct __tuple_less
951{
952 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000953 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 bool operator()(const _Tp& __x, const _Up& __y)
955 {
Howard Hinnant99968442011-11-29 18:15:50 +0000956 return __tuple_less<_Ip-1>()(__x, __y) ||
957 (!__tuple_less<_Ip-1>()(__y, __x) && get<_Ip-1>(__x) < get<_Ip-1>(__y));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 }
959};
960
961template <>
962struct __tuple_less<0>
963{
964 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000965 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966 bool operator()(const _Tp&, const _Up&)
967 {
968 return false;
969 }
970};
971
972template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000973inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974bool
975operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
976{
977 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
978}
979
980template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000981inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982bool
983operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
984{
985 return __y < __x;
986}
987
988template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000989inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990bool
991operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
992{
993 return !(__x < __y);
994}
995
996template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000997inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998bool
999operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1000{
1001 return !(__y < __x);
1002}
1003
1004// tuple_cat
1005
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001006template <class _Tp, class _Up> struct __tuple_cat_type;
1007
1008template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001009struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001011 typedef tuple<_Ttypes..., _Utypes...> type;
1012};
1013
1014template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1015struct __tuple_cat_return_1
1016{
1017};
1018
1019template <class ..._Types, class _Tuple0>
1020struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1021{
1022 typedef typename __tuple_cat_type<tuple<_Types...>,
1023 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1024 type;
1025};
1026
1027template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1028struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1029 : public __tuple_cat_return_1<
1030 typename __tuple_cat_type<
1031 tuple<_Types...>,
1032 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1033 >::type,
1034 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1035 _Tuple1, _Tuples...>
1036{
1037};
1038
1039template <class ..._Tuples> struct __tuple_cat_return;
1040
1041template <class _Tuple0, class ..._Tuples>
1042struct __tuple_cat_return<_Tuple0, _Tuples...>
1043 : public __tuple_cat_return_1<tuple<>,
1044 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1045 _Tuples...>
1046{
1047};
1048
1049template <>
1050struct __tuple_cat_return<>
1051{
1052 typedef tuple<> type;
1053};
1054
Marshall Clowda0a0e82013-07-22 16:02:19 +00001055inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001056tuple<>
1057tuple_cat()
1058{
1059 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060}
1061
Howard Hinnant99968442011-11-29 18:15:50 +00001062template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001063struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064
Howard Hinnante48e3662010-12-12 23:04:37 +00001065template <class ..._Types, size_t ..._I0, class _Tuple0>
1066struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001068 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001069 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1070 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1071};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072
Howard Hinnante48e3662010-12-12 23:04:37 +00001073template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1074struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1075 _Tuple0, _Tuple1, _Tuples...>
1076 : public __tuple_cat_return_ref_imp<
1077 tuple<_Types..., typename __apply_cv<_Tuple0,
1078 typename tuple_element<_I0,
1079 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1080 typename __make_tuple_indices<tuple_size<typename
1081 remove_reference<_Tuple1>::type>::value>::type,
1082 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
Howard Hinnante48e3662010-12-12 23:04:37 +00001084};
1085
1086template <class _Tuple0, class ..._Tuples>
1087struct __tuple_cat_return_ref
1088 : public __tuple_cat_return_ref_imp<tuple<>,
1089 typename __make_tuple_indices<
1090 tuple_size<typename remove_reference<_Tuple0>::type>::value
1091 >::type, _Tuple0, _Tuples...>
1092{
1093};
1094
1095template <class _Types, class _I0, class _J0>
1096struct __tuple_cat;
1097
1098template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001099struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001100{
1101 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001103 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1104 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1105 {
Marshall Clowda0a0e82013-07-22 16:02:19 +00001106 return __forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))...,
Howard Hinnant0949eed2011-06-30 21:18:19 +00001107 get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001108 }
1109
1110 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001112 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1113 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1114 {
1115 typedef typename remove_reference<_Tuple0>::type _T0;
1116 typedef typename remove_reference<_Tuple1>::type _T1;
1117 return __tuple_cat<
1118 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1119 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1120 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowda0a0e82013-07-22 16:02:19 +00001121 (__forward_as_tuple(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001122 _VSTD::forward<_Types>(get<_I0>(__t))...,
1123 get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001124 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001125 _VSTD::forward<_Tuple1>(__t1),
1126 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001127 }
1128};
1129
1130template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001131inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001132typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1133tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1134{
1135 typedef typename remove_reference<_Tuple0>::type _T0;
1136 return __tuple_cat<tuple<>, __tuple_indices<>,
1137 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001138 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1139 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140}
1141
1142template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001143struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 : true_type {};
1145
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146template <class _T1, class _T2>
1147template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1148inline _LIBCPP_INLINE_VISIBILITY
1149pair<_T1, _T2>::pair(piecewise_construct_t,
1150 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1151 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001152 : first(_VSTD::forward<_Args1>(get<_I1>( __first_args))...),
1153 second(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154{
1155}
1156
Howard Hinnant324bb032010-08-22 00:02:43 +00001157#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158
1159_LIBCPP_END_NAMESPACE_STD
1160
1161#endif // _LIBCPP_TUPLE