blob: 2e19f7ca8e9b964bdf94b3af5f45ed5e0da0ccdf [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
Marshall Clowc58e4722018-01-02 17:17:01 +000073inline constexpr unspecified ignore;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000074
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 Fiselier40843842017-01-02 23:54:13 +000087template <class T> class tuple_size; // undefined
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>
Marshall Clowc58e4722018-01-02 17:17:01 +000090 inline 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
Eric Fiselier191f0752017-04-19 01:23:39 +0000151#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152
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{
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000172 _Hp __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173
Eric Fiselier9c747b92016-07-20 02:57:39 +0000174 template <class _Tp>
175 static constexpr bool __can_bind_reference() {
Eric Fiselier8286acc2018-01-24 22:14:01 +0000176#if __has_keyword(__reference_binds_to_temporary)
177 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier8592d0a2018-01-24 23:10:02 +0000178#else
179 return true;
Eric Fiselier8286acc2018-01-24 22:14:01 +0000180#endif
Eric Fiselier9c747b92016-07-20 02:57:39 +0000181 }
182
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 __tuple_leaf& operator=(const __tuple_leaf&);
184public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000186 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187 {static_assert(!is_reference<_Hp>::value,
188 "Attempted to default construct a reference element in a tuple");}
189
190 template <class _Alloc>
191 _LIBCPP_INLINE_VISIBILITY
192 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000193 : __value_()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194 {static_assert(!is_reference<_Hp>::value,
195 "Attempted to default construct a reference element in a tuple");}
196
197 template <class _Alloc>
198 _LIBCPP_INLINE_VISIBILITY
199 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000200 : __value_(allocator_arg_t(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 {static_assert(!is_reference<_Hp>::value,
202 "Attempted to default construct a reference element in a tuple");}
203
204 template <class _Alloc>
205 _LIBCPP_INLINE_VISIBILITY
206 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000207 : __value_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 {static_assert(!is_reference<_Hp>::value,
209 "Attempted to default construct a reference element in a tuple");}
210
Howard Hinnante049cc52010-09-27 17:54:17 +0000211 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000212 class = typename enable_if<
213 __lazy_and<
214 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
215 , is_constructible<_Hp, _Tp>
216 >::value
217 >::type
218 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000219 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000220 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000221 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000222 {static_assert(__can_bind_reference<_Tp&&>(),
223 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224
225 template <class _Tp, class _Alloc>
226 _LIBCPP_INLINE_VISIBILITY
227 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000228 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000229 {static_assert(__can_bind_reference<_Tp&&>(),
230 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
232 template <class _Tp, class _Alloc>
233 _LIBCPP_INLINE_VISIBILITY
234 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000235 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000236 {static_assert(!is_reference<_Hp>::value,
237 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238
239 template <class _Tp, class _Alloc>
240 _LIBCPP_INLINE_VISIBILITY
241 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000242 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselier9c747b92016-07-20 02:57:39 +0000243 {static_assert(!is_reference<_Hp>::value,
244 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245
Marshall Clow398c9d82014-04-21 23:48:09 +0000246 __tuple_leaf(const __tuple_leaf& __t) = default;
247 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
249 template <class _Tp>
250 _LIBCPP_INLINE_VISIBILITY
251 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000252 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000254 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 return *this;
256 }
257
258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000259 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000261 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 return 0;
263 }
264
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267};
268
269template <size_t _Ip, class _Hp>
270class __tuple_leaf<_Ip, _Hp, true>
271 : private _Hp
272{
273
274 __tuple_leaf& operator=(const __tuple_leaf&);
275public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
277 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278
279 template <class _Alloc>
280 _LIBCPP_INLINE_VISIBILITY
281 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
282
283 template <class _Alloc>
284 _LIBCPP_INLINE_VISIBILITY
285 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
286 : _Hp(allocator_arg_t(), __a) {}
287
288 template <class _Alloc>
289 _LIBCPP_INLINE_VISIBILITY
290 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
291 : _Hp(__a) {}
292
Howard Hinnante049cc52010-09-27 17:54:17 +0000293 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000294 class = typename enable_if<
295 __lazy_and<
296 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
297 , is_constructible<_Hp, _Tp>
298 >::value
299 >::type
300 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000302 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000303 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
305 template <class _Tp, class _Alloc>
306 _LIBCPP_INLINE_VISIBILITY
307 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
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, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000313 : _Hp(allocator_arg_t(), __a, _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, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000318 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Eric Fiselier9020c082014-07-24 18:48:34 +0000320 __tuple_leaf(__tuple_leaf const &) = default;
321 __tuple_leaf(__tuple_leaf &&) = default;
322
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323 template <class _Tp>
324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000326 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000328 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329 return *this;
330 }
331
Howard Hinnanta5e01212011-05-27 19:08:18 +0000332 _LIBCPP_INLINE_VISIBILITY
333 int
334 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000336 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337 return 0;
338 }
339
Marshall Clowda0a0e82013-07-22 16:02:19 +0000340 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
341 _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 +0000342};
343
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000344template <class ..._Tp>
345_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000346void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000348template <class ..._Tp>
349struct __lazy_all : __all<_Tp::value...> {};
350
Marshall Clowbbc7c742014-10-15 10:33:02 +0000351template <class _Tp>
352struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000353
Marshall Clowbbc7c742014-10-15 10:33:02 +0000354template <class ..._Tp>
355struct __all_default_constructible<__tuple_types<_Tp...>>
356 : __all<is_default_constructible<_Tp>::value...>
357{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000358
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359// __tuple_impl
360
361template<class _Indx, class ..._Tp> struct __tuple_impl;
362
363template<size_t ..._Indx, class ..._Tp>
Eric Fiselier7d24e912017-01-16 21:15:08 +0000364struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 : public __tuple_leaf<_Indx, _Tp>...
366{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000368 _LIBCPP_CONSTEXPR __tuple_impl()
369 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000370
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 template <size_t ..._Uf, class ..._Tf,
372 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000373 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 explicit
375 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
376 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000377 _Up&&... __u)
378 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
379 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000380 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 __tuple_leaf<_Ul, _Tl>()...
382 {}
383
384 template <class _Alloc, size_t ..._Uf, class ..._Tf,
385 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387 explicit
388 __tuple_impl(allocator_arg_t, const _Alloc& __a,
389 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
390 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
391 _Up&&... __u) :
392 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000393 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
395 {}
396
397 template <class _Tuple,
398 class = typename enable_if
399 <
Howard Hinnant99324892013-04-14 00:01:13 +0000400 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401 >::type
402 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000403 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000404 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
405 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000406 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
407 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 {}
409
410 template <class _Alloc, class _Tuple,
411 class = typename enable_if
412 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000413 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 >::type
415 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
418 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000419 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000420 _VSTD::forward<typename tuple_element<_Indx,
421 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 {}
423
424 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 typename enable_if
427 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000428 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 __tuple_impl&
430 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000431 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
432 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000434 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
435 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436 return *this;
437 }
438
Howard Hinnant3de50862013-11-06 17:45:43 +0000439 __tuple_impl(const __tuple_impl&) = default;
440 __tuple_impl(__tuple_impl&&) = default;
441
442 _LIBCPP_INLINE_VISIBILITY
443 __tuple_impl&
444 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
445 {
446 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
447 return *this;
448 }
449
450 _LIBCPP_INLINE_VISIBILITY
451 __tuple_impl&
452 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
453 {
454 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
455 return *this;
456 }
Howard Hinnant28484442012-02-15 20:13:52 +0000457
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000460 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461 {
462 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
463 }
464};
465
Eric Fiselierd5019332016-04-15 18:05:59 +0000466
Eric Fiselierd5019332016-04-15 18:05:59 +0000467
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468template <class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000469class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470{
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000471 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000473 _BaseT __base_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474
Eric Fiselierf2f36372016-12-08 23:57:08 +0000475#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
476 static constexpr bool _EnableImplicitReducedArityExtension = true;
477#else
478 static constexpr bool _EnableImplicitReducedArityExtension = false;
479#endif
480
Eric Fiselierd5019332016-04-15 18:05:59 +0000481 template <class ..._Args>
482 struct _PackExpandsToThisTuple : false_type {};
483
484 template <class _Arg>
485 struct _PackExpandsToThisTuple<_Arg>
486 : is_same<typename __uncvref<_Arg>::type, tuple> {};
487
488 template <bool _MaybeEnable, class _Dummy = void>
489 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
490
491 template <class _Dummy>
492 struct _CheckArgsConstructor<true, _Dummy>
493 {
494 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000495 static constexpr bool __enable_default() {
496 return __all<is_default_constructible<_Args>::value...>::value;
497 }
498
499 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59 +0000500 static constexpr bool __enable_explicit() {
501 return
502 __tuple_constructible<
503 tuple<_Args...>,
504 typename __make_tuple_types<tuple,
505 sizeof...(_Args) < sizeof...(_Tp) ?
506 sizeof...(_Args) :
507 sizeof...(_Tp)>::type
508 >::value &&
509 !__tuple_convertible<
510 tuple<_Args...>,
511 typename __make_tuple_types<tuple,
512 sizeof...(_Args) < sizeof...(_Tp) ?
513 sizeof...(_Args) :
514 sizeof...(_Tp)>::type
515 >::value &&
516 __all_default_constructible<
517 typename __make_tuple_types<tuple, sizeof...(_Tp),
518 sizeof...(_Args) < sizeof...(_Tp) ?
519 sizeof...(_Args) :
520 sizeof...(_Tp)>::type
521 >::value;
522 }
523
524 template <class ..._Args>
525 static constexpr bool __enable_implicit() {
526 return
527 __tuple_convertible<
528 tuple<_Args...>,
529 typename __make_tuple_types<tuple,
530 sizeof...(_Args) < sizeof...(_Tp) ?
531 sizeof...(_Args) :
532 sizeof...(_Tp)>::type
533 >::value &&
534 __all_default_constructible<
535 typename __make_tuple_types<tuple, sizeof...(_Tp),
536 sizeof...(_Args) < sizeof...(_Tp) ?
537 sizeof...(_Args) :
538 sizeof...(_Tp)>::type
539 >::value;
540 }
541 };
542
543 template <bool _MaybeEnable,
544 bool = sizeof...(_Tp) == 1,
545 class _Dummy = void>
546 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
547
548 template <class _Dummy>
549 struct _CheckTupleLikeConstructor<true, false, _Dummy>
550 {
551 template <class _Tuple>
552 static constexpr bool __enable_implicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000553 return __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000554 }
555
556 template <class _Tuple>
557 static constexpr bool __enable_explicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000558 return __tuple_constructible<_Tuple, tuple>::value
559 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000560 }
561 };
562
563 template <class _Dummy>
564 struct _CheckTupleLikeConstructor<true, true, _Dummy>
565 {
566 // This trait is used to disable the tuple-like constructor when
567 // the UTypes... constructor should be selected instead.
568 // See LWG issue #2549.
569 template <class _Tuple>
570 using _PreferTupleLikeConstructor = __lazy_or<
571 // Don't attempt the two checks below if the tuple we are given
572 // has the same type as this tuple.
573 is_same<typename __uncvref<_Tuple>::type, tuple>,
574 __lazy_and<
575 __lazy_not<is_constructible<_Tp..., _Tuple>>,
576 __lazy_not<is_convertible<_Tuple, _Tp...>>
577 >
578 >;
579
580 template <class _Tuple>
581 static constexpr bool __enable_implicit() {
582 return __lazy_and<
583 __tuple_convertible<_Tuple, tuple>,
584 _PreferTupleLikeConstructor<_Tuple>
585 >::value;
586 }
587
588 template <class _Tuple>
589 static constexpr bool __enable_explicit() {
590 return __lazy_and<
591 __tuple_constructible<_Tuple, tuple>,
592 _PreferTupleLikeConstructor<_Tuple>,
593 __lazy_not<__tuple_convertible<_Tuple, tuple>>
594 >::value;
595 }
596 };
597
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000598 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000599 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000600 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000601 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000602 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000603 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000604 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
605 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606public:
607
Eric Fiselierda1818a2015-02-21 02:30:41 +0000608 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000609 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02 +0000610 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000612 _LIBCPP_CONSTEXPR tuple()
613 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000614
Eric Fiselier4be71c62016-07-25 02:36:42 +0000615 tuple(tuple const&) = default;
616 tuple(tuple&&) = default;
617
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000618 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
619 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000620 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000621 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
622 >::value
623 >::type>
624 _LIBCPP_INLINE_VISIBILITY
625 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000626 : __base_(allocator_arg_t(), __a,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000627 __tuple_indices<>(), __tuple_types<>(),
628 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
629 __tuple_types<_Tp...>()) {}
630
Eric Fiselier95526d32016-04-19 01:19:25 +0000631 template <bool _Dummy = true,
632 typename enable_if
633 <
634 _CheckArgsConstructor<
635 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000636 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000637 bool
638 >::type = false
639 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000641 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000642 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
644 typename __make_tuple_indices<0>::type(),
645 typename __make_tuple_types<tuple, 0>::type(),
646 __t...
647 ) {}
648
Eric Fiselier95526d32016-04-19 01:19:25 +0000649 template <bool _Dummy = true,
650 typename enable_if
651 <
652 _CheckArgsConstructor<
653 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000654 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000655 bool
656 >::type = false
657 >
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
659 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000660 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000661 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
662 typename __make_tuple_indices<0>::type(),
663 typename __make_tuple_types<tuple, 0>::type(),
664 __t...
665 ) {}
666
667 template <class _Alloc, bool _Dummy = true,
668 typename enable_if
669 <
670 _CheckArgsConstructor<
671 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000672 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000673 bool
674 >::type = false
675 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000678 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
680 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
681 typename __make_tuple_indices<0>::type(),
682 typename __make_tuple_types<tuple, 0>::type(),
683 __t...
684 ) {}
685
Eric Fiselier95526d32016-04-19 01:19:25 +0000686 template <class _Alloc, bool _Dummy = true,
687 typename enable_if
688 <
689 _CheckArgsConstructor<
690 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000691 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000692 bool
693 >::type = false
694 >
695 _LIBCPP_INLINE_VISIBILITY
696 explicit
697 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000698 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000699 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
700 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
701 typename __make_tuple_indices<0>::type(),
702 typename __make_tuple_types<tuple, 0>::type(),
703 __t...
704 ) {}
705
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706 template <class ..._Up,
Eric Fiselierf2f36372016-12-08 23:57:08 +0000707 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000708 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000710 _CheckArgsConstructor<
Eric Fiselierf2f36372016-12-08 23:57:08 +0000711 sizeof...(_Up) == sizeof...(_Tp)
712 && !_PackIsTuple
713 >::template __enable_implicit<_Up...>() ||
714 _CheckArgsConstructor<
715 _EnableImplicitReducedArityExtension
716 && sizeof...(_Up) < sizeof...(_Tp)
717 && !_PackIsTuple
Eric Fiselierd5019332016-04-15 18:05:59 +0000718 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000719 bool
720 >::type = false
721 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000723 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000724 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000725 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000726 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,
Marshall Clow86d311c2014-09-16 17:08:21 +0000730 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000731 >::value
732 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000733 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000734 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
735 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
736 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
737 _VSTD::forward<_Up>(__u)...) {}
738
739 template <class ..._Up,
740 typename enable_if
741 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000742 _CheckArgsConstructor<
743 sizeof...(_Up) <= sizeof...(_Tp)
744 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000745 >::template __enable_explicit<_Up...>() ||
746 _CheckArgsConstructor<
747 !_EnableImplicitReducedArityExtension
748 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselier236b7522017-02-04 22:57:01 +0000749 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000750 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000751 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000752 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000754 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 explicit
756 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000757 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000758 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000759 typename __make_tuple_indices<sizeof...(_Up)>::type,
760 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
761 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
762 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
763 _Up...
764 >::value
765 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000766 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
768 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
769 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000770 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771
772 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000773 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000775 _CheckArgsConstructor<
776 sizeof...(_Up) == sizeof...(_Tp) &&
777 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000778 >::template __enable_implicit<_Up...>(),
779 bool
780 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000784 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000785 typename __make_tuple_indices<sizeof...(_Up)>::type(),
786 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
787 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
788 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000789 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790
Eric Fiselier95526d32016-04-19 01:19:25 +0000791 template <class _Alloc, class ..._Up,
792 typename enable_if
793 <
794 _CheckArgsConstructor<
795 sizeof...(_Up) == sizeof...(_Tp) &&
796 !_PackExpandsToThisTuple<_Up...>::value
797 >::template __enable_explicit<_Up...>(),
798 bool
799 >::type = false
800 >
801 _LIBCPP_INLINE_VISIBILITY
802 explicit
803 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000804 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000805 typename __make_tuple_indices<sizeof...(_Up)>::type(),
806 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
807 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
808 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
809 _VSTD::forward<_Up>(__u)...) {}
810
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000812 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000814 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000815 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
816 && !_PackExpandsToThisTuple<_Tuple>::value
817 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000818 bool
819 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000821 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000822 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
823 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000825 template <class _Tuple,
826 typename enable_if
827 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000828 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000829 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
830 && !_PackExpandsToThisTuple<_Tuple>::value
831 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000832 bool
833 >::type = false
834 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000835 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000836 explicit
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000837 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
838 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000839
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000841 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000843 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000844 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
845 >::template __enable_implicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000846 bool
847 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000851 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852
Eric Fiselier95526d32016-04-19 01:19:25 +0000853 template <class _Alloc, class _Tuple,
854 typename enable_if
855 <
856 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000857 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
858 >::template __enable_explicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000859 bool
860 >::type = false
861 >
862 _LIBCPP_INLINE_VISIBILITY
863 explicit
864 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000865 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier95526d32016-04-19 01:19:25 +0000866
Eric Fiselier4be71c62016-07-25 02:36:42 +0000867 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
868 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
869
870 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9663ee42016-12-15 06:34:54 +0000871 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000872 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
873 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000874 __base_.operator=(__t.__base_);
Eric Fiselier4be71c62016-07-25 02:36:42 +0000875 return *this;
876 }
877
878 _LIBCPP_INLINE_VISIBILITY
879 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
880 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
881 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000882 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier4be71c62016-07-25 02:36:42 +0000883 return *this;
884 }
885
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 template <class _Tuple,
887 class = typename enable_if
888 <
Eric Fiselier9663ee42016-12-15 06:34:54 +0000889 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 >::type
891 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 tuple&
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000894 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000896 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 return *this;
898 }
899
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000901 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000902 {__base_.swap(__t.__base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903};
904
905template <>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000906class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907{
908public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000910 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000913 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000916 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000917 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000919 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000920 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000922 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000924 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925};
926
Eric Fiselier8a29c9d2017-10-04 00:04:26 +0000927#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Eric Fiselier3113ac62017-06-08 07:18:17 +0000928// NOTE: These are not yet standardized, but are required to simulate the
929// implicit deduction guide that should be generated had libc++ declared the
930// tuple-like constructors "correctly"
931template <class _Alloc, class ..._Args>
932tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
933template <class _Alloc, class ..._Args>
934tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
935#endif
936
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937template <class ..._Tp>
938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000939typename enable_if
940<
941 __all<__is_swappable<_Tp>::value...>::value,
942 void
943>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000944swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
945 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
946 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
948// get
949
950template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000951inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000952typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000953get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000955 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000956 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957}
958
959template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000960inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000961const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000962get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000964 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000965 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966}
967
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000968template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000969inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000970typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000971get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000972{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000973 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000974 return static_cast<type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000975 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000976}
977
Eric Fiselier199bee02015-12-18 00:36:55 +0000978template <size_t _Ip, class ..._Tp>
979inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
980const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
981get(const tuple<_Tp...>&& __t) _NOEXCEPT
982{
983 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
984 return static_cast<const type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000985 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier199bee02015-12-18 00:36:55 +0000986}
987
Marshall Clowe8029e52013-07-13 02:54:05 +0000988#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000989
Eric Fiselier22c3e762016-07-02 03:18:30 +0000990namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000991
Eric Fiselier22c3e762016-07-02 03:18:30 +0000992static constexpr size_t __not_found = -1;
993static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000994
Eric Fiselier22c3e762016-07-02 03:18:30 +0000995inline _LIBCPP_INLINE_VISIBILITY
996constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
997 return !__matches ? __res :
998 (__res == __not_found ? __curr_i : __ambiguous);
999}
Marshall Clowe8029e52013-07-13 02:54:05 +00001000
Eric Fiselier22c3e762016-07-02 03:18:30 +00001001template <size_t _Nx>
1002inline _LIBCPP_INLINE_VISIBILITY
1003constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1004 return __i == _Nx ? __not_found :
1005 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1006}
1007
1008template <class _T1, class ..._Args>
1009struct __find_exactly_one_checked {
Casey Carter5f7683b2017-12-12 17:22:24 +00001010 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier22c3e762016-07-02 03:18:30 +00001011 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter5f7683b2017-12-12 17:22:24 +00001012 static_assert(value != __not_found, "type not found in type list" );
1013 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier22c3e762016-07-02 03:18:30 +00001014};
1015
Eric Fiselier990090f2016-07-02 03:46:08 +00001016template <class _T1>
1017struct __find_exactly_one_checked<_T1> {
1018 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1019};
1020
Eric Fiselier22c3e762016-07-02 03:18:30 +00001021} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001022
1023template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001024struct __find_exactly_one_t
1025 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1026};
Marshall Clowe8029e52013-07-13 02:54:05 +00001027
1028template <class _T1, class... _Args>
1029inline _LIBCPP_INLINE_VISIBILITY
1030constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1031{
1032 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1033}
1034
1035template <class _T1, class... _Args>
1036inline _LIBCPP_INLINE_VISIBILITY
1037constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1038{
1039 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1040}
1041
1042template <class _T1, class... _Args>
1043inline _LIBCPP_INLINE_VISIBILITY
1044constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1045{
Marshall Clow01a0e902013-07-15 20:46:11 +00001046 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001047}
1048
Eric Fiselier199bee02015-12-18 00:36:55 +00001049template <class _T1, class... _Args>
1050inline _LIBCPP_INLINE_VISIBILITY
1051constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1052{
1053 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1054}
1055
Marshall Clowe8029e52013-07-13 02:54:05 +00001056#endif
1057
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058// tie
1059
1060template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001061inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001063tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064{
1065 return tuple<_Tp&...>(__t...);
1066}
1067
1068template <class _Up>
1069struct __ignore_t
1070{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071 template <class _Tp>
Eric Fiselier07d23d52017-02-06 01:25:31 +00001072 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1073 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074};
1075
Eric Fiselier07d23d52017-02-06 01:25:31 +00001076namespace {
Marshall Clowc58e4722018-01-02 17:17:01 +00001077 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier07d23d52017-02-06 01:25:31 +00001078}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001081struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082{
1083 typedef _Tp type;
1084};
1085
1086template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001087struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088{
1089 typedef _Tp& type;
1090};
1091
1092template <class _Tp>
1093struct __make_tuple_return
1094{
Marshall Clowa71f9562014-01-03 22:55:49 +00001095 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096};
1097
1098template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001099inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100tuple<typename __make_tuple_return<_Tp>::type...>
1101make_tuple(_Tp&&... __t)
1102{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001103 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104}
1105
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001106template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001107inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1108tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001109forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001110{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001111 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001112}
1113
Howard Hinnant99968442011-11-29 18:15:50 +00001114template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115struct __tuple_equal
1116{
1117 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 bool operator()(const _Tp& __x, const _Up& __y)
1120 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001121 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 }
1123};
1124
1125template <>
1126struct __tuple_equal<0>
1127{
1128 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 bool operator()(const _Tp&, const _Up&)
1131 {
1132 return true;
1133 }
1134};
1135
1136template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001137inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138bool
1139operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1140{
1141 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1142}
1143
1144template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001145inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146bool
1147operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1148{
1149 return !(__x == __y);
1150}
1151
Howard Hinnant99968442011-11-29 18:15:50 +00001152template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153struct __tuple_less
1154{
1155 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 bool operator()(const _Tp& __x, const _Up& __y)
1158 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001159 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1160 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1161 return true;
1162 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1163 return false;
1164 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 }
1166};
1167
1168template <>
1169struct __tuple_less<0>
1170{
1171 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001172 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173 bool operator()(const _Tp&, const _Up&)
1174 {
1175 return false;
1176 }
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 __tuple_less<sizeof...(_Tp)>()(__x, __y);
1185}
1186
1187template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001188inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189bool
1190operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1191{
1192 return __y < __x;
1193}
1194
1195template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001196inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001197bool
1198operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1199{
1200 return !(__x < __y);
1201}
1202
1203template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001204inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205bool
1206operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1207{
1208 return !(__y < __x);
1209}
1210
1211// tuple_cat
1212
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001213template <class _Tp, class _Up> struct __tuple_cat_type;
1214
1215template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001216struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001218 typedef tuple<_Ttypes..., _Utypes...> type;
1219};
1220
1221template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1222struct __tuple_cat_return_1
1223{
1224};
1225
1226template <class ..._Types, class _Tuple0>
1227struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1228{
1229 typedef typename __tuple_cat_type<tuple<_Types...>,
1230 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1231 type;
1232};
1233
1234template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1235struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1236 : public __tuple_cat_return_1<
1237 typename __tuple_cat_type<
1238 tuple<_Types...>,
1239 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1240 >::type,
1241 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1242 _Tuple1, _Tuples...>
1243{
1244};
1245
1246template <class ..._Tuples> struct __tuple_cat_return;
1247
1248template <class _Tuple0, class ..._Tuples>
1249struct __tuple_cat_return<_Tuple0, _Tuples...>
1250 : public __tuple_cat_return_1<tuple<>,
1251 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1252 _Tuples...>
1253{
1254};
1255
1256template <>
1257struct __tuple_cat_return<>
1258{
1259 typedef tuple<> type;
1260};
1261
Marshall Clowda0a0e82013-07-22 16:02:19 +00001262inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001263tuple<>
1264tuple_cat()
1265{
1266 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267}
1268
Howard Hinnant99968442011-11-29 18:15:50 +00001269template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001270struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271
Howard Hinnante48e3662010-12-12 23:04:37 +00001272template <class ..._Types, size_t ..._I0, class _Tuple0>
1273struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001275 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001276 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1277 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1278};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279
Howard Hinnante48e3662010-12-12 23:04:37 +00001280template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1281struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1282 _Tuple0, _Tuple1, _Tuples...>
1283 : public __tuple_cat_return_ref_imp<
1284 tuple<_Types..., typename __apply_cv<_Tuple0,
1285 typename tuple_element<_I0,
1286 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1287 typename __make_tuple_indices<tuple_size<typename
1288 remove_reference<_Tuple1>::type>::value>::type,
1289 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290{
Howard Hinnante48e3662010-12-12 23:04:37 +00001291};
1292
1293template <class _Tuple0, class ..._Tuples>
1294struct __tuple_cat_return_ref
1295 : public __tuple_cat_return_ref_imp<tuple<>,
1296 typename __make_tuple_indices<
1297 tuple_size<typename remove_reference<_Tuple0>::type>::value
1298 >::type, _Tuple0, _Tuples...>
1299{
1300};
1301
1302template <class _Types, class _I0, class _J0>
1303struct __tuple_cat;
1304
1305template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001306struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001307{
1308 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001310 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1311 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1312 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001313 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1314 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001315 }
1316
1317 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001318 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001319 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1320 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1321 {
1322 typedef typename remove_reference<_Tuple0>::type _T0;
1323 typedef typename remove_reference<_Tuple1>::type _T1;
1324 return __tuple_cat<
1325 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1326 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1327 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001328 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001329 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1330 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001331 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001332 _VSTD::forward<_Tuple1>(__t1),
1333 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001334 }
1335};
1336
1337template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001338inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001339typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1340tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1341{
1342 typedef typename remove_reference<_Tuple0>::type _T0;
1343 return __tuple_cat<tuple<>, __tuple_indices<>,
1344 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001345 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1346 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347}
1348
1349template <class ..._Tp, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001350struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351 : true_type {};
1352
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353template <class _T1, class _T2>
1354template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1355inline _LIBCPP_INLINE_VISIBILITY
1356pair<_T1, _T2>::pair(piecewise_construct_t,
1357 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1358 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001359 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1360 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361{
1362}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363
Eric Fiselier5839fed2016-07-18 00:35:56 +00001364#if _LIBCPP_STD_VER > 14
1365template <class _Tp>
Marshall Clowc58e4722018-01-02 17:17:01 +00001366_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier5839fed2016-07-18 00:35:56 +00001367
1368#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1369
1370template <class _Fn, class _Tuple, size_t ..._Id>
1371inline _LIBCPP_INLINE_VISIBILITY
1372constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1373 __tuple_indices<_Id...>)
1374_LIBCPP_NOEXCEPT_RETURN(
1375 _VSTD::__invoke_constexpr(
1376 _VSTD::forward<_Fn>(__f),
1377 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1378)
1379
1380template <class _Fn, class _Tuple>
1381inline _LIBCPP_INLINE_VISIBILITY
1382constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1383_LIBCPP_NOEXCEPT_RETURN(
1384 _VSTD::__apply_tuple_impl(
1385 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1386 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1387)
1388
1389template <class _Tp, class _Tuple, size_t... _Idx>
1390inline _LIBCPP_INLINE_VISIBILITY
1391constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1392_LIBCPP_NOEXCEPT_RETURN(
1393 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1394)
1395
1396template <class _Tp, class _Tuple>
1397inline _LIBCPP_INLINE_VISIBILITY
1398constexpr _Tp make_from_tuple(_Tuple&& __t)
1399_LIBCPP_NOEXCEPT_RETURN(
1400 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1401 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1402)
1403
1404#undef _LIBCPP_NOEXCEPT_RETURN
1405
1406#endif // _LIBCPP_STD_VER > 14
1407
Eric Fiselier191f0752017-04-19 01:23:39 +00001408#endif // !defined(_LIBCPP_CXX03_LANG)
1409
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410_LIBCPP_END_NAMESPACE_STD
1411
1412#endif // _LIBCPP_TUPLE