blob: 9f6661fd97c0d2211308cf1b124e6d38be846098 [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
Eric Fiselier5839fed2016-07-18 00:35:56 +000079
80// [tuple.apply], calling a function with a tuple of arguments:
81template <class F, class Tuple>
82 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
83template <class T, class Tuple>
84 constexpr T make_from_tuple(Tuple&& t); // C++17
85
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086// 20.4.1.4, tuple helper classes:
87template <class T> class tuple_size; // undefined
88template <class... T> class tuple_size<tuple<T...>>;
Eric Fiselier5839fed2016-07-18 00:35:56 +000089template <class T>
90 constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Marshall Clowa6607572015-11-19 19:45:29 +000091template <size_t I, class T> class tuple_element; // undefined
92template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
93template <size_t I, class T>
94 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095
96// 20.4.1.5, element access:
Marshall Clowa6607572015-11-19 19:45:29 +000097template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +000098 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000099 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +0000100template <size_t I, class... T>
101 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000102 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29 +0000103template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000104 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000105 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000106template <size_t I, class... T>
107 const typename tuple_element<I, tuple<T...>>::type&&
108 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109
Marshall Clowe8029e52013-07-13 02:54:05 +0000110template <class T1, class... T>
111 constexpr T1& get(tuple<T...>&) noexcept; // C++14
112template <class T1, class... T>
Marshall Clowa6607572015-11-19 19:45:29 +0000113 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000114template <class T1, class... T>
115 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000116template <class T1, class... T>
117 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000118
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000119// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19 +0000120template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
121template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
122template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
123template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
124template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
125template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126
127template <class... Types, class Alloc>
128 struct uses_allocator<tuple<Types...>, Alloc>;
129
130template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18 +0000131 void
132 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134} // std
135
136*/
137
138#include <__config>
139#include <__tuple>
140#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000142#include <__functional_base>
143#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
Howard Hinnant08e17472011-10-17 20:05:10 +0000145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000147#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
151#ifndef _LIBCPP_HAS_NO_VARIADICS
152
Marshall Clow50fe0c72014-03-03 06:18:11 +0000153
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154// __tuple_leaf
155
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000156template <size_t _Ip, class _Hp,
157 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000158 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159class __tuple_leaf;
160
161template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000164 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165{
166 swap(__x.get(), __y.get());
167}
168
169template <size_t _Ip, class _Hp, bool>
170class __tuple_leaf
171{
172 _Hp value;
173
Eric Fiselier9c747b92016-07-20 02:57:39 +0000174 template <class _Tp>
175 static constexpr bool __can_bind_reference() {
176 using _RawTp = typename remove_reference<_Tp>::type;
177 using _RawHp = typename remove_reference<_Hp>::type;
178 using _CheckLValueArg = integral_constant<bool,
179 is_lvalue_reference<_Tp>::value
180 || is_same<_RawTp, reference_wrapper<_RawHp>>::value
181 || is_same<_RawTp, reference_wrapper<typename remove_const<_RawHp>::type>>::value
182 >;
183 return !is_reference<_Hp>::value
184 || (is_lvalue_reference<_Hp>::value && _CheckLValueArg::value)
185 || (is_rvalue_reference<_Hp>::value && !is_lvalue_reference<_Tp>::value);
186 }
187
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188 __tuple_leaf& operator=(const __tuple_leaf&);
189public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000190 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
191 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192 {static_assert(!is_reference<_Hp>::value,
193 "Attempted to default construct a reference element in a tuple");}
194
195 template <class _Alloc>
196 _LIBCPP_INLINE_VISIBILITY
197 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
198 : value()
199 {static_assert(!is_reference<_Hp>::value,
200 "Attempted to default construct a reference element in a tuple");}
201
202 template <class _Alloc>
203 _LIBCPP_INLINE_VISIBILITY
204 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
205 : value(allocator_arg_t(), __a)
206 {static_assert(!is_reference<_Hp>::value,
207 "Attempted to default construct a reference element in a tuple");}
208
209 template <class _Alloc>
210 _LIBCPP_INLINE_VISIBILITY
211 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
212 : value(__a)
213 {static_assert(!is_reference<_Hp>::value,
214 "Attempted to default construct a reference element in a tuple");}
215
Howard Hinnante049cc52010-09-27 17:54:17 +0000216 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000217 class = typename enable_if<
218 __lazy_and<
219 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
220 , is_constructible<_Hp, _Tp>
221 >::value
222 >::type
223 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000225 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000226 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000227 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 "Attempted to construct a reference element in a tuple with an rvalue");}
229
230 template <class _Tp, class _Alloc>
231 _LIBCPP_INLINE_VISIBILITY
232 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000233 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000234 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235 "Attempted to construct a reference element in a tuple with an rvalue");}
236
237 template <class _Tp, class _Alloc>
238 _LIBCPP_INLINE_VISIBILITY
239 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000240 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000241 {static_assert(!is_reference<_Hp>::value,
242 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
244 template <class _Tp, class _Alloc>
245 _LIBCPP_INLINE_VISIBILITY
246 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000247 : value(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselier9c747b92016-07-20 02:57:39 +0000248 {static_assert(!is_reference<_Hp>::value,
249 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
Marshall Clow398c9d82014-04-21 23:48:09 +0000251 __tuple_leaf(const __tuple_leaf& __t) = default;
252 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253
254 template <class _Tp>
255 _LIBCPP_INLINE_VISIBILITY
256 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000257 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000259 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260 return *this;
261 }
262
263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000264 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000266 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267 return 0;
268 }
269
Marshall Clowda0a0e82013-07-22 16:02:19 +0000270 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272};
273
274template <size_t _Ip, class _Hp>
275class __tuple_leaf<_Ip, _Hp, true>
276 : private _Hp
277{
278
279 __tuple_leaf& operator=(const __tuple_leaf&);
280public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
282 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283
284 template <class _Alloc>
285 _LIBCPP_INLINE_VISIBILITY
286 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
287
288 template <class _Alloc>
289 _LIBCPP_INLINE_VISIBILITY
290 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
291 : _Hp(allocator_arg_t(), __a) {}
292
293 template <class _Alloc>
294 _LIBCPP_INLINE_VISIBILITY
295 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
296 : _Hp(__a) {}
297
Howard Hinnante049cc52010-09-27 17:54:17 +0000298 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000299 class = typename enable_if<
300 __lazy_and<
301 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
302 , is_constructible<_Hp, _Tp>
303 >::value
304 >::type
305 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000306 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000307 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000308 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310 template <class _Tp, class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000313 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314
315 template <class _Tp, class _Alloc>
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000318 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320 template <class _Tp, class _Alloc>
321 _LIBCPP_INLINE_VISIBILITY
322 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000323 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324
Eric Fiselier9020c082014-07-24 18:48:34 +0000325 __tuple_leaf(__tuple_leaf const &) = default;
326 __tuple_leaf(__tuple_leaf &&) = default;
327
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328 template <class _Tp>
329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000331 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000333 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334 return *this;
335 }
336
Howard Hinnanta5e01212011-05-27 19:08:18 +0000337 _LIBCPP_INLINE_VISIBILITY
338 int
339 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000341 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342 return 0;
343 }
344
Marshall Clowda0a0e82013-07-22 16:02:19 +0000345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
346 _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 +0000347};
348
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000349template <class ..._Tp>
350_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000351void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000353template <class ..._Tp>
354struct __lazy_all : __all<_Tp::value...> {};
355
Marshall Clowbbc7c742014-10-15 10:33:02 +0000356template <class _Tp>
357struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000358
Marshall Clowbbc7c742014-10-15 10:33:02 +0000359template <class ..._Tp>
360struct __all_default_constructible<__tuple_types<_Tp...>>
361 : __all<is_default_constructible<_Tp>::value...>
362{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000363
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364// __tuple_impl
365
366template<class _Indx, class ..._Tp> struct __tuple_impl;
367
368template<size_t ..._Indx, class ..._Tp>
369struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
370 : public __tuple_leaf<_Indx, _Tp>...
371{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000373 _LIBCPP_CONSTEXPR __tuple_impl()
374 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 template <size_t ..._Uf, class ..._Tf,
377 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379 explicit
380 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
381 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000382 _Up&&... __u)
383 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
384 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000385 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 __tuple_leaf<_Ul, _Tl>()...
387 {}
388
389 template <class _Alloc, size_t ..._Uf, class ..._Tf,
390 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 explicit
393 __tuple_impl(allocator_arg_t, const _Alloc& __a,
394 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
395 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
396 _Up&&... __u) :
397 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000398 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
400 {}
401
402 template <class _Tuple,
403 class = typename enable_if
404 <
Howard Hinnant99324892013-04-14 00:01:13 +0000405 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 >::type
407 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000409 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
410 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000411 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
412 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 {}
414
415 template <class _Alloc, class _Tuple,
416 class = typename enable_if
417 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000418 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 >::type
420 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
423 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000424 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000425 _VSTD::forward<typename tuple_element<_Indx,
426 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 {}
428
429 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431 typename enable_if
432 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000433 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 __tuple_impl&
435 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000436 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
437 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000439 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 return *this;
442 }
443
Howard Hinnant3de50862013-11-06 17:45:43 +0000444 __tuple_impl(const __tuple_impl&) = default;
445 __tuple_impl(__tuple_impl&&) = default;
446
447 _LIBCPP_INLINE_VISIBILITY
448 __tuple_impl&
449 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
450 {
451 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
452 return *this;
453 }
454
455 _LIBCPP_INLINE_VISIBILITY
456 __tuple_impl&
457 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
458 {
459 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
460 return *this;
461 }
Howard Hinnant28484442012-02-15 20:13:52 +0000462
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000465 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 {
467 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
468 }
469};
470
Eric Fiselierd5019332016-04-15 18:05:59 +0000471
Eric Fiselierd5019332016-04-15 18:05:59 +0000472
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000474class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475{
476 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
477
478 base base_;
479
Eric Fiselierd5019332016-04-15 18:05:59 +0000480 template <class ..._Args>
481 struct _PackExpandsToThisTuple : false_type {};
482
483 template <class _Arg>
484 struct _PackExpandsToThisTuple<_Arg>
485 : is_same<typename __uncvref<_Arg>::type, tuple> {};
486
487 template <bool _MaybeEnable, class _Dummy = void>
488 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
489
490 template <class _Dummy>
491 struct _CheckArgsConstructor<true, _Dummy>
492 {
493 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000494 static constexpr bool __enable_default() {
495 return __all<is_default_constructible<_Args>::value...>::value;
496 }
497
498 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59 +0000499 static constexpr bool __enable_explicit() {
500 return
501 __tuple_constructible<
502 tuple<_Args...>,
503 typename __make_tuple_types<tuple,
504 sizeof...(_Args) < sizeof...(_Tp) ?
505 sizeof...(_Args) :
506 sizeof...(_Tp)>::type
507 >::value &&
508 !__tuple_convertible<
509 tuple<_Args...>,
510 typename __make_tuple_types<tuple,
511 sizeof...(_Args) < sizeof...(_Tp) ?
512 sizeof...(_Args) :
513 sizeof...(_Tp)>::type
514 >::value &&
515 __all_default_constructible<
516 typename __make_tuple_types<tuple, sizeof...(_Tp),
517 sizeof...(_Args) < sizeof...(_Tp) ?
518 sizeof...(_Args) :
519 sizeof...(_Tp)>::type
520 >::value;
521 }
522
523 template <class ..._Args>
524 static constexpr bool __enable_implicit() {
525 return
526 __tuple_convertible<
527 tuple<_Args...>,
528 typename __make_tuple_types<tuple,
529 sizeof...(_Args) < sizeof...(_Tp) ?
530 sizeof...(_Args) :
531 sizeof...(_Tp)>::type
532 >::value &&
533 __all_default_constructible<
534 typename __make_tuple_types<tuple, sizeof...(_Tp),
535 sizeof...(_Args) < sizeof...(_Tp) ?
536 sizeof...(_Args) :
537 sizeof...(_Tp)>::type
538 >::value;
539 }
540 };
541
542 template <bool _MaybeEnable,
543 bool = sizeof...(_Tp) == 1,
544 class _Dummy = void>
545 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
546
547 template <class _Dummy>
548 struct _CheckTupleLikeConstructor<true, false, _Dummy>
549 {
550 template <class _Tuple>
551 static constexpr bool __enable_implicit() {
552 return __tuple_convertible<_Tuple, tuple>::value;
553 }
554
555 template <class _Tuple>
556 static constexpr bool __enable_explicit() {
557 return __tuple_constructible<_Tuple, tuple>::value
558 && !__tuple_convertible<_Tuple, tuple>::value;
559 }
560 };
561
562 template <class _Dummy>
563 struct _CheckTupleLikeConstructor<true, true, _Dummy>
564 {
565 // This trait is used to disable the tuple-like constructor when
566 // the UTypes... constructor should be selected instead.
567 // See LWG issue #2549.
568 template <class _Tuple>
569 using _PreferTupleLikeConstructor = __lazy_or<
570 // Don't attempt the two checks below if the tuple we are given
571 // has the same type as this tuple.
572 is_same<typename __uncvref<_Tuple>::type, tuple>,
573 __lazy_and<
574 __lazy_not<is_constructible<_Tp..., _Tuple>>,
575 __lazy_not<is_convertible<_Tuple, _Tp...>>
576 >
577 >;
578
579 template <class _Tuple>
580 static constexpr bool __enable_implicit() {
581 return __lazy_and<
582 __tuple_convertible<_Tuple, tuple>,
583 _PreferTupleLikeConstructor<_Tuple>
584 >::value;
585 }
586
587 template <class _Tuple>
588 static constexpr bool __enable_explicit() {
589 return __lazy_and<
590 __tuple_constructible<_Tuple, tuple>,
591 _PreferTupleLikeConstructor<_Tuple>,
592 __lazy_not<__tuple_convertible<_Tuple, tuple>>
593 >::value;
594 }
595 };
596
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000597 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000598 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000599 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000600 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000601 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000602 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000603 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
604 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605public:
606
Eric Fiselierda1818a2015-02-21 02:30:41 +0000607 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000608 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02 +0000609 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000611 _LIBCPP_CONSTEXPR tuple()
612 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000613
Eric Fiselier4be71c62016-07-25 02:36:42 +0000614 tuple(tuple const&) = default;
615 tuple(tuple&&) = default;
616
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000617 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
618 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000619 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000620 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
621 >::value
622 >::type>
623 _LIBCPP_INLINE_VISIBILITY
624 tuple(_AllocArgT, _Alloc const& __a)
625 : base_(allocator_arg_t(), __a,
626 __tuple_indices<>(), __tuple_types<>(),
627 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
628 __tuple_types<_Tp...>()) {}
629
Eric Fiselier95526d32016-04-19 01:19:25 +0000630 template <bool _Dummy = true,
631 typename enable_if
632 <
633 _CheckArgsConstructor<
634 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000635 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000636 bool
637 >::type = false
638 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000639 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000640 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
642 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
643 typename __make_tuple_indices<0>::type(),
644 typename __make_tuple_types<tuple, 0>::type(),
645 __t...
646 ) {}
647
Eric Fiselier95526d32016-04-19 01:19:25 +0000648 template <bool _Dummy = true,
649 typename enable_if
650 <
651 _CheckArgsConstructor<
652 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000653 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000654 bool
655 >::type = false
656 >
657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
658 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
659 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
660 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
661 typename __make_tuple_indices<0>::type(),
662 typename __make_tuple_types<tuple, 0>::type(),
663 __t...
664 ) {}
665
666 template <class _Alloc, bool _Dummy = true,
667 typename enable_if
668 <
669 _CheckArgsConstructor<
670 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000671 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000672 bool
673 >::type = false
674 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
677 : base_(allocator_arg_t(), __a,
678 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
679 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
680 typename __make_tuple_indices<0>::type(),
681 typename __make_tuple_types<tuple, 0>::type(),
682 __t...
683 ) {}
684
Eric Fiselier95526d32016-04-19 01:19:25 +0000685 template <class _Alloc, bool _Dummy = true,
686 typename enable_if
687 <
688 _CheckArgsConstructor<
689 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000690 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000691 bool
692 >::type = false
693 >
694 _LIBCPP_INLINE_VISIBILITY
695 explicit
696 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
697 : base_(allocator_arg_t(), __a,
698 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
699 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
700 typename __make_tuple_indices<0>::type(),
701 typename __make_tuple_types<tuple, 0>::type(),
702 __t...
703 ) {}
704
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000706 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000708 _CheckArgsConstructor<
709 sizeof...(_Up) <= sizeof...(_Tp)
710 && !_PackExpandsToThisTuple<_Up...>::value
711 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000712 bool
713 >::type = false
714 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000715 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000716 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000717 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000718 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000719 typename __make_tuple_indices<sizeof...(_Up)>::type,
720 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
721 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
722 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000723 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000724 >::value
725 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000726 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
727 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
728 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
729 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
730 _VSTD::forward<_Up>(__u)...) {}
731
732 template <class ..._Up,
733 typename enable_if
734 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000735 _CheckArgsConstructor<
736 sizeof...(_Up) <= sizeof...(_Tp)
737 && !_PackExpandsToThisTuple<_Up...>::value
738 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000739 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000740 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000742 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 explicit
744 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000745 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000746 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000747 typename __make_tuple_indices<sizeof...(_Up)>::type,
748 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
749 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
750 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
751 _Up...
752 >::value
753 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
755 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
756 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
757 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000758 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759
760 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000761 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000763 _CheckArgsConstructor<
764 sizeof...(_Up) == sizeof...(_Tp) &&
765 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000766 >::template __enable_implicit<_Up...>(),
767 bool
768 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
772 : base_(allocator_arg_t(), __a,
773 typename __make_tuple_indices<sizeof...(_Up)>::type(),
774 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
775 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
776 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000777 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778
Eric Fiselier95526d32016-04-19 01:19:25 +0000779 template <class _Alloc, class ..._Up,
780 typename enable_if
781 <
782 _CheckArgsConstructor<
783 sizeof...(_Up) == sizeof...(_Tp) &&
784 !_PackExpandsToThisTuple<_Up...>::value
785 >::template __enable_explicit<_Up...>(),
786 bool
787 >::type = false
788 >
789 _LIBCPP_INLINE_VISIBILITY
790 explicit
791 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
792 : base_(allocator_arg_t(), __a,
793 typename __make_tuple_indices<sizeof...(_Up)>::type(),
794 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
795 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
796 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
797 _VSTD::forward<_Up>(__u)...) {}
798
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000800 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000802 _CheckTupleLikeConstructor<
803 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
804 && !_PackExpandsToThisTuple<_Tuple>::value
805 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000806 bool
807 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000810 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000811 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000813 template <class _Tuple,
814 typename enable_if
815 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000816 _CheckTupleLikeConstructor<
817 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
818 && !_PackExpandsToThisTuple<_Tuple>::value
819 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000820 bool
821 >::type = false
822 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000823 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000824 explicit
Howard Hinnant74f26f22012-07-06 21:53:48 +0000825 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000826 : base_(_VSTD::forward<_Tuple>(__t)) {}
827
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000829 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000831 _CheckTupleLikeConstructor<
832 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000833 >::template __enable_implicit<_Tuple>(),
834 bool
835 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000839 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840
Eric Fiselier95526d32016-04-19 01:19:25 +0000841 template <class _Alloc, class _Tuple,
842 typename enable_if
843 <
844 _CheckTupleLikeConstructor<
845 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
846 >::template __enable_explicit<_Tuple>(),
847 bool
848 >::type = false
849 >
850 _LIBCPP_INLINE_VISIBILITY
851 explicit
852 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
853 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
854
Eric Fiselier4be71c62016-07-25 02:36:42 +0000855 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
856 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
857
858 _LIBCPP_INLINE_VISIBILITY
859 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
860 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
861 {
862 base_.operator=(__t.base_);
863 return *this;
864 }
865
866 _LIBCPP_INLINE_VISIBILITY
867 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
868 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
869 {
870 base_.operator=(static_cast<base&&>(__t.base_));
871 return *this;
872 }
873
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 template <class _Tuple,
875 class = typename enable_if
876 <
877 __tuple_assignable<_Tuple, tuple>::value
878 >::type
879 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000882 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000884 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885 return *this;
886 }
887
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000889 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
890 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891};
892
893template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000894class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895{
896public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000898 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000901 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000904 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000905 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000907 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000908 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000910 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000912 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913};
914
915template <class ..._Tp>
916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000917typename enable_if
918<
919 __all<__is_swappable<_Tp>::value...>::value,
920 void
921>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000922swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
923 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
924 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925
926// get
927
928template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000929inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000930typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000931get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000933 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
935}
936
937template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000938inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000939const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000940get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000942 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
944}
945
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000946template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000947inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000948typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000949get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000950{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000951 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000952 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000953 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000954}
955
Eric Fiselier199bee02015-12-18 00:36:55 +0000956template <size_t _Ip, class ..._Tp>
957inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
958const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
959get(const tuple<_Tp...>&& __t) _NOEXCEPT
960{
961 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
962 return static_cast<const type&&>(
963 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
964}
965
Marshall Clowe8029e52013-07-13 02:54:05 +0000966#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000967
Eric Fiselier22c3e762016-07-02 03:18:30 +0000968namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000969
Eric Fiselier22c3e762016-07-02 03:18:30 +0000970static constexpr size_t __not_found = -1;
971static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000972
Eric Fiselier22c3e762016-07-02 03:18:30 +0000973inline _LIBCPP_INLINE_VISIBILITY
974constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
975 return !__matches ? __res :
976 (__res == __not_found ? __curr_i : __ambiguous);
977}
Marshall Clowe8029e52013-07-13 02:54:05 +0000978
Eric Fiselier22c3e762016-07-02 03:18:30 +0000979template <size_t _Nx>
980inline _LIBCPP_INLINE_VISIBILITY
981constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
982 return __i == _Nx ? __not_found :
983 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
984}
985
986template <class _T1, class ..._Args>
987struct __find_exactly_one_checked {
988 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
989 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
990 static_assert (value != __not_found, "type not found in type list" );
991 static_assert(value != __ambiguous,"type occurs more than once in type list");
992};
993
Eric Fiselier990090f2016-07-02 03:46:08 +0000994template <class _T1>
995struct __find_exactly_one_checked<_T1> {
996 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
997};
998
Eric Fiselier22c3e762016-07-02 03:18:30 +0000999} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001000
1001template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001002struct __find_exactly_one_t
1003 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1004};
Marshall Clowe8029e52013-07-13 02:54:05 +00001005
1006template <class _T1, class... _Args>
1007inline _LIBCPP_INLINE_VISIBILITY
1008constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1009{
1010 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1011}
1012
1013template <class _T1, class... _Args>
1014inline _LIBCPP_INLINE_VISIBILITY
1015constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1016{
1017 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1018}
1019
1020template <class _T1, class... _Args>
1021inline _LIBCPP_INLINE_VISIBILITY
1022constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1023{
Marshall Clow01a0e902013-07-15 20:46:11 +00001024 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001025}
1026
Eric Fiselier199bee02015-12-18 00:36:55 +00001027template <class _T1, class... _Args>
1028inline _LIBCPP_INLINE_VISIBILITY
1029constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1030{
1031 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1032}
1033
Marshall Clowe8029e52013-07-13 02:54:05 +00001034#endif
1035
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036// tie
1037
1038template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001039inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001041tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042{
1043 return tuple<_Tp&...>(__t...);
1044}
1045
1046template <class _Up>
1047struct __ignore_t
1048{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051 const __ignore_t& operator=(_Tp&&) const {return *this;}
1052};
1053
1054namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1055
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001057struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058{
1059 typedef _Tp type;
1060};
1061
1062template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001063struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064{
1065 typedef _Tp& type;
1066};
1067
1068template <class _Tp>
1069struct __make_tuple_return
1070{
Marshall Clowa71f9562014-01-03 22:55:49 +00001071 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072};
1073
1074template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001075inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076tuple<typename __make_tuple_return<_Tp>::type...>
1077make_tuple(_Tp&&... __t)
1078{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001079 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080}
1081
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001082template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001083inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1084tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001085forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001086{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001087 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001088}
1089
Howard Hinnant99968442011-11-29 18:15:50 +00001090template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091struct __tuple_equal
1092{
1093 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 bool operator()(const _Tp& __x, const _Up& __y)
1096 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001097 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 }
1099};
1100
1101template <>
1102struct __tuple_equal<0>
1103{
1104 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 bool operator()(const _Tp&, const _Up&)
1107 {
1108 return true;
1109 }
1110};
1111
1112template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001113inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114bool
1115operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1116{
1117 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1118}
1119
1120template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001121inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122bool
1123operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1124{
1125 return !(__x == __y);
1126}
1127
Howard Hinnant99968442011-11-29 18:15:50 +00001128template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129struct __tuple_less
1130{
1131 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 bool operator()(const _Tp& __x, const _Up& __y)
1134 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001135 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1136 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1137 return true;
1138 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1139 return false;
1140 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 }
1142};
1143
1144template <>
1145struct __tuple_less<0>
1146{
1147 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 bool operator()(const _Tp&, const _Up&)
1150 {
1151 return false;
1152 }
1153};
1154
1155template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001156inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157bool
1158operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1159{
1160 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1161}
1162
1163template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165bool
1166operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1167{
1168 return __y < __x;
1169}
1170
1171template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001172inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173bool
1174operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1175{
1176 return !(__x < __y);
1177}
1178
1179template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001180inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181bool
1182operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1183{
1184 return !(__y < __x);
1185}
1186
1187// tuple_cat
1188
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001189template <class _Tp, class _Up> struct __tuple_cat_type;
1190
1191template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001192struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001194 typedef tuple<_Ttypes..., _Utypes...> type;
1195};
1196
1197template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1198struct __tuple_cat_return_1
1199{
1200};
1201
1202template <class ..._Types, class _Tuple0>
1203struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1204{
1205 typedef typename __tuple_cat_type<tuple<_Types...>,
1206 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1207 type;
1208};
1209
1210template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1211struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1212 : public __tuple_cat_return_1<
1213 typename __tuple_cat_type<
1214 tuple<_Types...>,
1215 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1216 >::type,
1217 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1218 _Tuple1, _Tuples...>
1219{
1220};
1221
1222template <class ..._Tuples> struct __tuple_cat_return;
1223
1224template <class _Tuple0, class ..._Tuples>
1225struct __tuple_cat_return<_Tuple0, _Tuples...>
1226 : public __tuple_cat_return_1<tuple<>,
1227 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1228 _Tuples...>
1229{
1230};
1231
1232template <>
1233struct __tuple_cat_return<>
1234{
1235 typedef tuple<> type;
1236};
1237
Marshall Clowda0a0e82013-07-22 16:02:19 +00001238inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001239tuple<>
1240tuple_cat()
1241{
1242 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243}
1244
Howard Hinnant99968442011-11-29 18:15:50 +00001245template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001246struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247
Howard Hinnante48e3662010-12-12 23:04:37 +00001248template <class ..._Types, size_t ..._I0, class _Tuple0>
1249struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001251 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001252 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1253 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1254};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255
Howard Hinnante48e3662010-12-12 23:04:37 +00001256template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1257struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1258 _Tuple0, _Tuple1, _Tuples...>
1259 : public __tuple_cat_return_ref_imp<
1260 tuple<_Types..., typename __apply_cv<_Tuple0,
1261 typename tuple_element<_I0,
1262 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1263 typename __make_tuple_indices<tuple_size<typename
1264 remove_reference<_Tuple1>::type>::value>::type,
1265 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266{
Howard Hinnante48e3662010-12-12 23:04:37 +00001267};
1268
1269template <class _Tuple0, class ..._Tuples>
1270struct __tuple_cat_return_ref
1271 : public __tuple_cat_return_ref_imp<tuple<>,
1272 typename __make_tuple_indices<
1273 tuple_size<typename remove_reference<_Tuple0>::type>::value
1274 >::type, _Tuple0, _Tuples...>
1275{
1276};
1277
1278template <class _Types, class _I0, class _J0>
1279struct __tuple_cat;
1280
1281template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001282struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001283{
1284 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001286 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1287 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1288 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001289 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1290 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001291 }
1292
1293 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001295 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1296 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1297 {
1298 typedef typename remove_reference<_Tuple0>::type _T0;
1299 typedef typename remove_reference<_Tuple1>::type _T1;
1300 return __tuple_cat<
1301 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1302 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1303 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001304 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001305 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1306 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001307 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001308 _VSTD::forward<_Tuple1>(__t1),
1309 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001310 }
1311};
1312
1313template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001314inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001315typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1316tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1317{
1318 typedef typename remove_reference<_Tuple0>::type _T0;
1319 return __tuple_cat<tuple<>, __tuple_indices<>,
1320 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001321 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1322 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323}
1324
1325template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001326struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 : true_type {};
1328
Eric Fiseliere1445fd2016-07-25 04:32:07 +00001329#endif // _LIBCPP_HAS_NO_VARIADICS
1330
1331#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332template <class _T1, class _T2>
1333template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1334inline _LIBCPP_INLINE_VISIBILITY
1335pair<_T1, _T2>::pair(piecewise_construct_t,
1336 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1337 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001338 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1339 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340{
1341}
Eric Fiseliere1445fd2016-07-25 04:32:07 +00001342#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
Eric Fiselier5839fed2016-07-18 00:35:56 +00001344#if _LIBCPP_STD_VER > 14
1345template <class _Tp>
1346constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1347
1348#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1349
1350template <class _Fn, class _Tuple, size_t ..._Id>
1351inline _LIBCPP_INLINE_VISIBILITY
1352constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1353 __tuple_indices<_Id...>)
1354_LIBCPP_NOEXCEPT_RETURN(
1355 _VSTD::__invoke_constexpr(
1356 _VSTD::forward<_Fn>(__f),
1357 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1358)
1359
1360template <class _Fn, class _Tuple>
1361inline _LIBCPP_INLINE_VISIBILITY
1362constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1363_LIBCPP_NOEXCEPT_RETURN(
1364 _VSTD::__apply_tuple_impl(
1365 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1366 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1367)
1368
1369template <class _Tp, class _Tuple, size_t... _Idx>
1370inline _LIBCPP_INLINE_VISIBILITY
1371constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1372_LIBCPP_NOEXCEPT_RETURN(
1373 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1374)
1375
1376template <class _Tp, class _Tuple>
1377inline _LIBCPP_INLINE_VISIBILITY
1378constexpr _Tp make_from_tuple(_Tuple&& __t)
1379_LIBCPP_NOEXCEPT_RETURN(
1380 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1381 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1382)
1383
1384#undef _LIBCPP_NOEXCEPT_RETURN
1385
1386#endif // _LIBCPP_STD_VER > 14
1387
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388_LIBCPP_END_NAMESPACE_STD
1389
1390#endif // _LIBCPP_TUPLE