blob: c9146fd6ef59e9179402930a4cf2e1e528e209ff [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:
Eric Fiselierf9a20c22016-11-13 20:43:50 +000087template <class T> class tuple_size;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000088template <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 Fiselierf2f36372016-12-08 23:57:08 +0000480#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
481 static constexpr bool _EnableImplicitReducedArityExtension = true;
482#else
483 static constexpr bool _EnableImplicitReducedArityExtension = false;
484#endif
485
Eric Fiselierd5019332016-04-15 18:05:59 +0000486 template <class ..._Args>
487 struct _PackExpandsToThisTuple : false_type {};
488
489 template <class _Arg>
490 struct _PackExpandsToThisTuple<_Arg>
491 : is_same<typename __uncvref<_Arg>::type, tuple> {};
492
493 template <bool _MaybeEnable, class _Dummy = void>
494 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
495
496 template <class _Dummy>
497 struct _CheckArgsConstructor<true, _Dummy>
498 {
499 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000500 static constexpr bool __enable_default() {
501 return __all<is_default_constructible<_Args>::value...>::value;
502 }
503
504 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59 +0000505 static constexpr bool __enable_explicit() {
506 return
507 __tuple_constructible<
508 tuple<_Args...>,
509 typename __make_tuple_types<tuple,
510 sizeof...(_Args) < sizeof...(_Tp) ?
511 sizeof...(_Args) :
512 sizeof...(_Tp)>::type
513 >::value &&
514 !__tuple_convertible<
515 tuple<_Args...>,
516 typename __make_tuple_types<tuple,
517 sizeof...(_Args) < sizeof...(_Tp) ?
518 sizeof...(_Args) :
519 sizeof...(_Tp)>::type
520 >::value &&
521 __all_default_constructible<
522 typename __make_tuple_types<tuple, sizeof...(_Tp),
523 sizeof...(_Args) < sizeof...(_Tp) ?
524 sizeof...(_Args) :
525 sizeof...(_Tp)>::type
526 >::value;
527 }
528
529 template <class ..._Args>
530 static constexpr bool __enable_implicit() {
531 return
532 __tuple_convertible<
533 tuple<_Args...>,
534 typename __make_tuple_types<tuple,
535 sizeof...(_Args) < sizeof...(_Tp) ?
536 sizeof...(_Args) :
537 sizeof...(_Tp)>::type
538 >::value &&
539 __all_default_constructible<
540 typename __make_tuple_types<tuple, sizeof...(_Tp),
541 sizeof...(_Args) < sizeof...(_Tp) ?
542 sizeof...(_Args) :
543 sizeof...(_Tp)>::type
544 >::value;
545 }
546 };
547
548 template <bool _MaybeEnable,
549 bool = sizeof...(_Tp) == 1,
550 class _Dummy = void>
551 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
552
553 template <class _Dummy>
554 struct _CheckTupleLikeConstructor<true, false, _Dummy>
555 {
556 template <class _Tuple>
557 static constexpr bool __enable_implicit() {
Eric Fiselier18e56b42016-12-14 22:22:38 +0000558 using _Deduced = __deduce_tuple_like<_Tuple>;
559 using _QualType = typename _Deduced::_QualType;
560 static_assert(__tuple_like<typename _Deduced::_RawType>::value, "");
561 return __tuple_convertible<_QualType, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000562 }
563
564 template <class _Tuple>
565 static constexpr bool __enable_explicit() {
Eric Fiselier18e56b42016-12-14 22:22:38 +0000566 using _Deduced = __deduce_tuple_like<_Tuple>;
567 using _QualType = typename _Deduced::_QualType;
568 static_assert(__tuple_like<typename _Deduced::_RawType>::value, "");
569 return __tuple_constructible<_QualType, tuple>::value
570 && !__tuple_convertible<_QualType, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000571 }
572 };
573
574 template <class _Dummy>
575 struct _CheckTupleLikeConstructor<true, true, _Dummy>
576 {
577 // This trait is used to disable the tuple-like constructor when
578 // the UTypes... constructor should be selected instead.
579 // See LWG issue #2549.
580 template <class _Tuple>
581 using _PreferTupleLikeConstructor = __lazy_or<
582 // Don't attempt the two checks below if the tuple we are given
583 // has the same type as this tuple.
584 is_same<typename __uncvref<_Tuple>::type, tuple>,
585 __lazy_and<
586 __lazy_not<is_constructible<_Tp..., _Tuple>>,
587 __lazy_not<is_convertible<_Tuple, _Tp...>>
588 >
589 >;
590
591 template <class _Tuple>
592 static constexpr bool __enable_implicit() {
593 return __lazy_and<
594 __tuple_convertible<_Tuple, tuple>,
595 _PreferTupleLikeConstructor<_Tuple>
596 >::value;
597 }
598
599 template <class _Tuple>
600 static constexpr bool __enable_explicit() {
601 return __lazy_and<
602 __tuple_constructible<_Tuple, tuple>,
603 _PreferTupleLikeConstructor<_Tuple>,
604 __lazy_not<__tuple_convertible<_Tuple, tuple>>
605 >::value;
606 }
607 };
608
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000609 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000610 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000611 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000612 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000613 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000614 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000615 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
616 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617public:
618
Eric Fiselierda1818a2015-02-21 02:30:41 +0000619 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000620 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02 +0000621 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000623 _LIBCPP_CONSTEXPR tuple()
624 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000625
Eric Fiselier4be71c62016-07-25 02:36:42 +0000626 tuple(tuple const&) = default;
627 tuple(tuple&&) = default;
628
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000629 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
630 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000631 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000632 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
633 >::value
634 >::type>
635 _LIBCPP_INLINE_VISIBILITY
636 tuple(_AllocArgT, _Alloc const& __a)
637 : base_(allocator_arg_t(), __a,
638 __tuple_indices<>(), __tuple_types<>(),
639 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
640 __tuple_types<_Tp...>()) {}
641
Eric Fiselier95526d32016-04-19 01:19:25 +0000642 template <bool _Dummy = true,
643 typename enable_if
644 <
645 _CheckArgsConstructor<
646 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000647 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000648 bool
649 >::type = false
650 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000652 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
654 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
655 typename __make_tuple_indices<0>::type(),
656 typename __make_tuple_types<tuple, 0>::type(),
657 __t...
658 ) {}
659
Eric Fiselier95526d32016-04-19 01:19:25 +0000660 template <bool _Dummy = true,
661 typename enable_if
662 <
663 _CheckArgsConstructor<
664 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000665 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000666 bool
667 >::type = false
668 >
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
670 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
671 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
672 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
673 typename __make_tuple_indices<0>::type(),
674 typename __make_tuple_types<tuple, 0>::type(),
675 __t...
676 ) {}
677
678 template <class _Alloc, bool _Dummy = true,
679 typename enable_if
680 <
681 _CheckArgsConstructor<
682 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000683 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000684 bool
685 >::type = false
686 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
689 : base_(allocator_arg_t(), __a,
690 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
691 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
692 typename __make_tuple_indices<0>::type(),
693 typename __make_tuple_types<tuple, 0>::type(),
694 __t...
695 ) {}
696
Eric Fiselier95526d32016-04-19 01:19:25 +0000697 template <class _Alloc, bool _Dummy = true,
698 typename enable_if
699 <
700 _CheckArgsConstructor<
701 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000702 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000703 bool
704 >::type = false
705 >
706 _LIBCPP_INLINE_VISIBILITY
707 explicit
708 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
709 : base_(allocator_arg_t(), __a,
710 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
711 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
712 typename __make_tuple_indices<0>::type(),
713 typename __make_tuple_types<tuple, 0>::type(),
714 __t...
715 ) {}
716
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 template <class ..._Up,
Eric Fiselierf2f36372016-12-08 23:57:08 +0000718 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000719 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000721 _CheckArgsConstructor<
Eric Fiselierf2f36372016-12-08 23:57:08 +0000722 sizeof...(_Up) == sizeof...(_Tp)
723 && !_PackIsTuple
724 >::template __enable_implicit<_Up...>() ||
725 _CheckArgsConstructor<
726 _EnableImplicitReducedArityExtension
727 && sizeof...(_Up) < sizeof...(_Tp)
728 && !_PackIsTuple
Eric Fiselierd5019332016-04-15 18:05:59 +0000729 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000730 bool
731 >::type = false
732 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000734 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000735 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000736 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000737 typename __make_tuple_indices<sizeof...(_Up)>::type,
738 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
739 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
740 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000741 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000742 >::value
743 ))
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000744 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
745 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
746 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
747 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
748 _VSTD::forward<_Up>(__u)...) {}
749
750 template <class ..._Up,
751 typename enable_if
752 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000753 _CheckArgsConstructor<
754 sizeof...(_Up) <= sizeof...(_Tp)
755 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000756 >::template __enable_explicit<_Up...>() ||
757 _CheckArgsConstructor<
758 !_EnableImplicitReducedArityExtension
759 && sizeof...(_Up) < sizeof...(_Tp)
760 && !_PackExpandsToThisTuple<_Up...>()
761 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000762 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000763 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000765 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 explicit
767 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000768 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21 +0000769 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000770 typename __make_tuple_indices<sizeof...(_Up)>::type,
771 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
772 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
773 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
774 _Up...
775 >::value
776 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
778 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
779 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
780 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000781 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782
783 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000784 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000785 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000786 _CheckArgsConstructor<
787 sizeof...(_Up) == sizeof...(_Tp) &&
788 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000789 >::template __enable_implicit<_Up...>(),
790 bool
791 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
795 : base_(allocator_arg_t(), __a,
796 typename __make_tuple_indices<sizeof...(_Up)>::type(),
797 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
798 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
799 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000800 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801
Eric Fiselier95526d32016-04-19 01:19:25 +0000802 template <class _Alloc, class ..._Up,
803 typename enable_if
804 <
805 _CheckArgsConstructor<
806 sizeof...(_Up) == sizeof...(_Tp) &&
807 !_PackExpandsToThisTuple<_Up...>::value
808 >::template __enable_explicit<_Up...>(),
809 bool
810 >::type = false
811 >
812 _LIBCPP_INLINE_VISIBILITY
813 explicit
814 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
815 : base_(allocator_arg_t(), __a,
816 typename __make_tuple_indices<sizeof...(_Up)>::type(),
817 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
818 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
819 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
820 _VSTD::forward<_Up>(__u)...) {}
821
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 template <class _Tuple,
Eric Fiselier18e56b42016-12-14 22:22:38 +0000823 class _Deduced = __deduce_tuple_like<_Tuple>,
824 class _TupBase = typename _Deduced::_QualType,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000825 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000827 _CheckTupleLikeConstructor<
Eric Fiselier18e56b42016-12-14 22:22:38 +0000828 _Deduced::_Size == sizeof...(_Tp)
829 && !_PackExpandsToThisTuple<_TupBase>::value
830 >::template __enable_implicit<_TupBase>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000831 bool
832 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier18e56b42016-12-14 22:22:38 +0000835 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _TupBase>::value))
836 : base_(_VSTD::forward<_TupBase>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000838 template <class _Tuple,
Eric Fiselier18e56b42016-12-14 22:22:38 +0000839 class _Deduced = __deduce_tuple_like<_Tuple>,
840 class _TupBase = typename _Deduced::_QualType,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000841 typename enable_if
842 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000843 _CheckTupleLikeConstructor<
Eric Fiselier18e56b42016-12-14 22:22:38 +0000844 _Deduced::_Size == sizeof...(_Tp)
845 && !_PackExpandsToThisTuple<_TupBase>::value
846 >::template __enable_explicit<_TupBase>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000847 bool
848 >::type = false
849 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000851 explicit
Eric Fiselier18e56b42016-12-14 22:22:38 +0000852 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _TupBase>::value))
853 : base_(_VSTD::forward<_TupBase>(__t)) {}
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000854
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 template <class _Alloc, class _Tuple,
Eric Fiselier18e56b42016-12-14 22:22:38 +0000856 class _Deduced = __deduce_tuple_like<_Tuple>,
857 class _TupBase = typename _Deduced::_QualType,
Eric Fiselier95526d32016-04-19 01:19:25 +0000858 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000860 _CheckTupleLikeConstructor<
Eric Fiselier18e56b42016-12-14 22:22:38 +0000861 _Deduced::_Size == sizeof...(_Tp)
862 >::template __enable_implicit<_TupBase>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000863 bool
864 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier18e56b42016-12-14 22:22:38 +0000868 : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869
Eric Fiselier95526d32016-04-19 01:19:25 +0000870 template <class _Alloc, class _Tuple,
Eric Fiselier18e56b42016-12-14 22:22:38 +0000871 class _Deduced = __deduce_tuple_like<_Tuple>,
872 class _TupBase = typename _Deduced::_QualType,
Eric Fiselier95526d32016-04-19 01:19:25 +0000873 typename enable_if
874 <
875 _CheckTupleLikeConstructor<
Eric Fiselier18e56b42016-12-14 22:22:38 +0000876 _Deduced::_Size == sizeof...(_Tp)
877 >::template __enable_explicit<_TupBase>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000878 bool
879 >::type = false
880 >
881 _LIBCPP_INLINE_VISIBILITY
882 explicit
883 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier18e56b42016-12-14 22:22:38 +0000884 : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {}
Eric Fiselier95526d32016-04-19 01:19:25 +0000885
Eric Fiselier4be71c62016-07-25 02:36:42 +0000886 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
887 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
888
889 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier18e56b42016-12-14 22:22:38 +0000890 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple const&, __nat>::type const& __t)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000891 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
892 {
893 base_.operator=(__t.base_);
894 return *this;
895 }
896
897 _LIBCPP_INLINE_VISIBILITY
898 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
899 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
900 {
901 base_.operator=(static_cast<base&&>(__t.base_));
902 return *this;
903 }
904
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 template <class _Tuple,
Eric Fiselier18e56b42016-12-14 22:22:38 +0000906 class _Deduced = __deduce_tuple_like<_Tuple>,
907 class _TupBase = typename _Deduced::_QualType,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 class = typename enable_if
909 <
Eric Fiselier18e56b42016-12-14 22:22:38 +0000910 __tuple_assignable<_TupBase, tuple>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 >::type
912 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 tuple&
Eric Fiselier18e56b42016-12-14 22:22:38 +0000915 operator=(_Tuple&& __t)
916 _NOEXCEPT_((is_nothrow_assignable<base&, _TupBase>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 {
Eric Fiselier18e56b42016-12-14 22:22:38 +0000918 base_.operator=(_VSTD::forward<_TupBase>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000919 return *this;
920 }
921
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000923 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
924 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925};
926
927template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000928class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929{
930public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000932 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000935 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000938 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000939 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000941 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000942 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000944 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000946 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947};
948
949template <class ..._Tp>
950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000951typename enable_if
952<
953 __all<__is_swappable<_Tp>::value...>::value,
954 void
955>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000956swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
957 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
958 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959
960// get
961
962template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000963inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000964typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000965get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000967 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
969}
970
971template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000972inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000973const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000974get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000976 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
978}
979
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000980template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000981inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000982typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000983get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000984{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000985 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000986 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21 +0000987 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000988}
989
Eric Fiselier199bee02015-12-18 00:36:55 +0000990template <size_t _Ip, class ..._Tp>
991inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
992const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
993get(const tuple<_Tp...>&& __t) _NOEXCEPT
994{
995 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
996 return static_cast<const type&&>(
997 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
998}
999
Marshall Clowe8029e52013-07-13 02:54:05 +00001000#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +00001001
Eric Fiselier22c3e762016-07-02 03:18:30 +00001002namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +00001003
Eric Fiselier22c3e762016-07-02 03:18:30 +00001004static constexpr size_t __not_found = -1;
1005static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +00001006
Eric Fiselier22c3e762016-07-02 03:18:30 +00001007inline _LIBCPP_INLINE_VISIBILITY
1008constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1009 return !__matches ? __res :
1010 (__res == __not_found ? __curr_i : __ambiguous);
1011}
Marshall Clowe8029e52013-07-13 02:54:05 +00001012
Eric Fiselier22c3e762016-07-02 03:18:30 +00001013template <size_t _Nx>
1014inline _LIBCPP_INLINE_VISIBILITY
1015constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1016 return __i == _Nx ? __not_found :
1017 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1018}
1019
1020template <class _T1, class ..._Args>
1021struct __find_exactly_one_checked {
1022 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
1023 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
1024 static_assert (value != __not_found, "type not found in type list" );
1025 static_assert(value != __ambiguous,"type occurs more than once in type list");
1026};
1027
Eric Fiselier990090f2016-07-02 03:46:08 +00001028template <class _T1>
1029struct __find_exactly_one_checked<_T1> {
1030 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1031};
1032
Eric Fiselier22c3e762016-07-02 03:18:30 +00001033} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001034
1035template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001036struct __find_exactly_one_t
1037 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1038};
Marshall Clowe8029e52013-07-13 02:54:05 +00001039
1040template <class _T1, class... _Args>
1041inline _LIBCPP_INLINE_VISIBILITY
1042constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1043{
1044 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1045}
1046
1047template <class _T1, class... _Args>
1048inline _LIBCPP_INLINE_VISIBILITY
1049constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1050{
1051 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1052}
1053
1054template <class _T1, class... _Args>
1055inline _LIBCPP_INLINE_VISIBILITY
1056constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1057{
Marshall Clow01a0e902013-07-15 20:46:11 +00001058 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001059}
1060
Eric Fiselier199bee02015-12-18 00:36:55 +00001061template <class _T1, class... _Args>
1062inline _LIBCPP_INLINE_VISIBILITY
1063constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1064{
1065 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1066}
1067
Marshall Clowe8029e52013-07-13 02:54:05 +00001068#endif
1069
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070// tie
1071
1072template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001073inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001075tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076{
1077 return tuple<_Tp&...>(__t...);
1078}
1079
1080template <class _Up>
1081struct __ignore_t
1082{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 const __ignore_t& operator=(_Tp&&) const {return *this;}
1086};
1087
1088namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1089
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001091struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092{
1093 typedef _Tp type;
1094};
1095
1096template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001097struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098{
1099 typedef _Tp& type;
1100};
1101
1102template <class _Tp>
1103struct __make_tuple_return
1104{
Marshall Clowa71f9562014-01-03 22:55:49 +00001105 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106};
1107
1108template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001109inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110tuple<typename __make_tuple_return<_Tp>::type...>
1111make_tuple(_Tp&&... __t)
1112{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001113 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114}
1115
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001116template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001117inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1118tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001119forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001120{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001121 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001122}
1123
Howard Hinnant99968442011-11-29 18:15:50 +00001124template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125struct __tuple_equal
1126{
1127 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 bool operator()(const _Tp& __x, const _Up& __y)
1130 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001131 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132 }
1133};
1134
1135template <>
1136struct __tuple_equal<0>
1137{
1138 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001139 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 bool operator()(const _Tp&, const _Up&)
1141 {
1142 return true;
1143 }
1144};
1145
1146template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148bool
1149operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1150{
1151 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1152}
1153
1154template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156bool
1157operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1158{
1159 return !(__x == __y);
1160}
1161
Howard Hinnant99968442011-11-29 18:15:50 +00001162template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163struct __tuple_less
1164{
1165 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001166 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 bool operator()(const _Tp& __x, const _Up& __y)
1168 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001169 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1170 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1171 return true;
1172 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1173 return false;
1174 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175 }
1176};
1177
1178template <>
1179struct __tuple_less<0>
1180{
1181 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001182 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 bool operator()(const _Tp&, const _Up&)
1184 {
1185 return false;
1186 }
1187};
1188
1189template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001190inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191bool
1192operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1193{
1194 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1195}
1196
1197template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001198inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199bool
1200operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1201{
1202 return __y < __x;
1203}
1204
1205template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001206inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207bool
1208operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1209{
1210 return !(__x < __y);
1211}
1212
1213template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001214inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215bool
1216operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1217{
1218 return !(__y < __x);
1219}
1220
1221// tuple_cat
1222
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001223template <class _Tp, class _Up> struct __tuple_cat_type;
1224
1225template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001226struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001228 typedef tuple<_Ttypes..., _Utypes...> type;
1229};
1230
1231template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1232struct __tuple_cat_return_1
1233{
1234};
1235
1236template <class ..._Types, class _Tuple0>
1237struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1238{
1239 typedef typename __tuple_cat_type<tuple<_Types...>,
1240 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1241 type;
1242};
1243
1244template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1245struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1246 : public __tuple_cat_return_1<
1247 typename __tuple_cat_type<
1248 tuple<_Types...>,
1249 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1250 >::type,
1251 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1252 _Tuple1, _Tuples...>
1253{
1254};
1255
1256template <class ..._Tuples> struct __tuple_cat_return;
1257
1258template <class _Tuple0, class ..._Tuples>
1259struct __tuple_cat_return<_Tuple0, _Tuples...>
1260 : public __tuple_cat_return_1<tuple<>,
1261 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1262 _Tuples...>
1263{
1264};
1265
1266template <>
1267struct __tuple_cat_return<>
1268{
1269 typedef tuple<> type;
1270};
1271
Marshall Clowda0a0e82013-07-22 16:02:19 +00001272inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001273tuple<>
1274tuple_cat()
1275{
1276 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277}
1278
Howard Hinnant99968442011-11-29 18:15:50 +00001279template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001280struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281
Howard Hinnante48e3662010-12-12 23:04:37 +00001282template <class ..._Types, size_t ..._I0, class _Tuple0>
1283struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001285 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001286 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1287 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1288};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289
Howard Hinnante48e3662010-12-12 23:04:37 +00001290template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1291struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1292 _Tuple0, _Tuple1, _Tuples...>
1293 : public __tuple_cat_return_ref_imp<
1294 tuple<_Types..., typename __apply_cv<_Tuple0,
1295 typename tuple_element<_I0,
1296 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1297 typename __make_tuple_indices<tuple_size<typename
1298 remove_reference<_Tuple1>::type>::value>::type,
1299 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300{
Howard Hinnante48e3662010-12-12 23:04:37 +00001301};
1302
1303template <class _Tuple0, class ..._Tuples>
1304struct __tuple_cat_return_ref
1305 : public __tuple_cat_return_ref_imp<tuple<>,
1306 typename __make_tuple_indices<
1307 tuple_size<typename remove_reference<_Tuple0>::type>::value
1308 >::type, _Tuple0, _Tuples...>
1309{
1310};
1311
1312template <class _Types, class _I0, class _J0>
1313struct __tuple_cat;
1314
1315template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001316struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001317{
1318 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001319 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001320 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1321 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1322 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001323 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1324 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001325 }
1326
1327 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001328 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001329 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1330 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1331 {
1332 typedef typename remove_reference<_Tuple0>::type _T0;
1333 typedef typename remove_reference<_Tuple1>::type _T1;
1334 return __tuple_cat<
1335 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1336 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1337 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001338 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001339 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1340 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001341 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001342 _VSTD::forward<_Tuple1>(__t1),
1343 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001344 }
1345};
1346
1347template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001348inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001349typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1350tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1351{
1352 typedef typename remove_reference<_Tuple0>::type _T0;
1353 return __tuple_cat<tuple<>, __tuple_indices<>,
1354 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001355 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1356 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357}
1358
1359template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001360struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 : true_type {};
1362
Eric Fiseliere1445fd2016-07-25 04:32:07 +00001363#endif // _LIBCPP_HAS_NO_VARIADICS
1364
1365#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366template <class _T1, class _T2>
1367template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1368inline _LIBCPP_INLINE_VISIBILITY
1369pair<_T1, _T2>::pair(piecewise_construct_t,
1370 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1371 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001372 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1373 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374{
1375}
Eric Fiseliere1445fd2016-07-25 04:32:07 +00001376#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377
Eric Fiselier5839fed2016-07-18 00:35:56 +00001378#if _LIBCPP_STD_VER > 14
1379template <class _Tp>
1380constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1381
1382#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1383
1384template <class _Fn, class _Tuple, size_t ..._Id>
1385inline _LIBCPP_INLINE_VISIBILITY
1386constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1387 __tuple_indices<_Id...>)
1388_LIBCPP_NOEXCEPT_RETURN(
1389 _VSTD::__invoke_constexpr(
1390 _VSTD::forward<_Fn>(__f),
1391 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1392)
1393
1394template <class _Fn, class _Tuple>
1395inline _LIBCPP_INLINE_VISIBILITY
1396constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1397_LIBCPP_NOEXCEPT_RETURN(
1398 _VSTD::__apply_tuple_impl(
1399 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1400 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1401)
1402
1403template <class _Tp, class _Tuple, size_t... _Idx>
1404inline _LIBCPP_INLINE_VISIBILITY
1405constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1406_LIBCPP_NOEXCEPT_RETURN(
1407 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1408)
1409
1410template <class _Tp, class _Tuple>
1411inline _LIBCPP_INLINE_VISIBILITY
1412constexpr _Tp make_from_tuple(_Tuple&& __t)
1413_LIBCPP_NOEXCEPT_RETURN(
1414 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1415 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1416)
1417
1418#undef _LIBCPP_NOEXCEPT_RETURN
1419
1420#endif // _LIBCPP_STD_VER > 14
1421
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422_LIBCPP_END_NAMESPACE_STD
1423
1424#endif // _LIBCPP_TUPLE