blob: 1accb9c67a732fc492687bd0567b6f6339dc7a7f [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);
178#endif
Eric Fiselier9c747b92016-07-20 02:57:39 +0000179 }
180
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181 __tuple_leaf& operator=(const __tuple_leaf&);
182public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000183 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000184 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185 {static_assert(!is_reference<_Hp>::value,
186 "Attempted to default construct a reference element in a tuple");}
187
188 template <class _Alloc>
189 _LIBCPP_INLINE_VISIBILITY
190 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000191 : __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, 1>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000198 : __value_(allocator_arg_t(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 {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, 2>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000205 : __value_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206 {static_assert(!is_reference<_Hp>::value,
207 "Attempted to default construct a reference element in a tuple");}
208
Howard Hinnante049cc52010-09-27 17:54:17 +0000209 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000210 class = typename enable_if<
211 __lazy_and<
212 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
213 , is_constructible<_Hp, _Tp>
214 >::value
215 >::type
216 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000217 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000218 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000219 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000220 {static_assert(__can_bind_reference<_Tp&&>(),
221 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222
223 template <class _Tp, class _Alloc>
224 _LIBCPP_INLINE_VISIBILITY
225 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000226 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000227 {static_assert(__can_bind_reference<_Tp&&>(),
228 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000229
230 template <class _Tp, class _Alloc>
231 _LIBCPP_INLINE_VISIBILITY
232 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000233 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000234 {static_assert(!is_reference<_Hp>::value,
235 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236
237 template <class _Tp, class _Alloc>
238 _LIBCPP_INLINE_VISIBILITY
239 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000240 : __value_(_VSTD::forward<_Tp>(__t), __a)
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
Marshall Clow398c9d82014-04-21 23:48:09 +0000244 __tuple_leaf(const __tuple_leaf& __t) = default;
245 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
247 template <class _Tp>
248 _LIBCPP_INLINE_VISIBILITY
249 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000250 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000252 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253 return *this;
254 }
255
256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000257 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000259 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260 return 0;
261 }
262
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000263 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
264 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265};
266
267template <size_t _Ip, class _Hp>
268class __tuple_leaf<_Ip, _Hp, true>
269 : private _Hp
270{
271
272 __tuple_leaf& operator=(const __tuple_leaf&);
273public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000274 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
275 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277 template <class _Alloc>
278 _LIBCPP_INLINE_VISIBILITY
279 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
280
281 template <class _Alloc>
282 _LIBCPP_INLINE_VISIBILITY
283 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
284 : _Hp(allocator_arg_t(), __a) {}
285
286 template <class _Alloc>
287 _LIBCPP_INLINE_VISIBILITY
288 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
289 : _Hp(__a) {}
290
Howard Hinnante049cc52010-09-27 17:54:17 +0000291 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000292 class = typename enable_if<
293 __lazy_and<
294 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
295 , is_constructible<_Hp, _Tp>
296 >::value
297 >::type
298 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000299 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000300 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000301 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
303 template <class _Tp, class _Alloc>
304 _LIBCPP_INLINE_VISIBILITY
305 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000306 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307
308 template <class _Tp, class _Alloc>
309 _LIBCPP_INLINE_VISIBILITY
310 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000311 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313 template <class _Tp, class _Alloc>
314 _LIBCPP_INLINE_VISIBILITY
315 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000316 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317
Eric Fiselier9020c082014-07-24 18:48:34 +0000318 __tuple_leaf(__tuple_leaf const &) = default;
319 __tuple_leaf(__tuple_leaf &&) = default;
320
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000321 template <class _Tp>
322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000324 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000326 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 return *this;
328 }
329
Howard Hinnanta5e01212011-05-27 19:08:18 +0000330 _LIBCPP_INLINE_VISIBILITY
331 int
332 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000334 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335 return 0;
336 }
337
Marshall Clowda0a0e82013-07-22 16:02:19 +0000338 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
339 _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 +0000340};
341
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000342template <class ..._Tp>
343_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000344void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000346template <class ..._Tp>
347struct __lazy_all : __all<_Tp::value...> {};
348
Marshall Clowbbc7c742014-10-15 10:33:02 +0000349template <class _Tp>
350struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000351
Marshall Clowbbc7c742014-10-15 10:33:02 +0000352template <class ..._Tp>
353struct __all_default_constructible<__tuple_types<_Tp...>>
354 : __all<is_default_constructible<_Tp>::value...>
355{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000356
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357// __tuple_impl
358
359template<class _Indx, class ..._Tp> struct __tuple_impl;
360
361template<size_t ..._Indx, class ..._Tp>
Eric Fiselier7d24e912017-01-16 21:15:08 +0000362struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 : public __tuple_leaf<_Indx, _Tp>...
364{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000366 _LIBCPP_CONSTEXPR __tuple_impl()
367 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000368
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 template <size_t ..._Uf, class ..._Tf,
370 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000371 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 explicit
373 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
374 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000375 _Up&&... __u)
376 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
377 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000378 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379 __tuple_leaf<_Ul, _Tl>()...
380 {}
381
382 template <class _Alloc, size_t ..._Uf, class ..._Tf,
383 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 explicit
386 __tuple_impl(allocator_arg_t, const _Alloc& __a,
387 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
388 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
389 _Up&&... __u) :
390 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000391 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
393 {}
394
395 template <class _Tuple,
396 class = typename enable_if
397 <
Howard Hinnant99324892013-04-14 00:01:13 +0000398 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399 >::type
400 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000401 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000402 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
403 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000404 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
405 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 {}
407
408 template <class _Alloc, class _Tuple,
409 class = typename enable_if
410 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000411 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 >::type
413 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
416 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000417 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000418 _VSTD::forward<typename tuple_element<_Indx,
419 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 {}
421
422 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424 typename enable_if
425 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000426 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 __tuple_impl&
428 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000429 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
430 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000432 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
433 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 return *this;
435 }
436
Howard Hinnant3de50862013-11-06 17:45:43 +0000437 __tuple_impl(const __tuple_impl&) = default;
438 __tuple_impl(__tuple_impl&&) = default;
439
440 _LIBCPP_INLINE_VISIBILITY
441 __tuple_impl&
442 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
443 {
444 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
445 return *this;
446 }
447
448 _LIBCPP_INLINE_VISIBILITY
449 __tuple_impl&
450 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
451 {
452 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
453 return *this;
454 }
Howard Hinnant28484442012-02-15 20:13:52 +0000455
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000458 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 {
460 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
461 }
462};
463
Eric Fiselierd5019332016-04-15 18:05:59 +0000464
Eric Fiselierd5019332016-04-15 18:05:59 +0000465
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466template <class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000467class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468{
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000469 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000471 _BaseT __base_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472
Eric Fiselierf2f36372016-12-08 23:57:08 +0000473#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
474 static constexpr bool _EnableImplicitReducedArityExtension = true;
475#else
476 static constexpr bool _EnableImplicitReducedArityExtension = false;
477#endif
478
Eric Fiselierd5019332016-04-15 18:05:59 +0000479 template <class ..._Args>
480 struct _PackExpandsToThisTuple : false_type {};
481
482 template <class _Arg>
483 struct _PackExpandsToThisTuple<_Arg>
484 : is_same<typename __uncvref<_Arg>::type, tuple> {};
485
486 template <bool _MaybeEnable, class _Dummy = void>
487 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
488
489 template <class _Dummy>
490 struct _CheckArgsConstructor<true, _Dummy>
491 {
492 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000493 static constexpr bool __enable_default() {
494 return __all<is_default_constructible<_Args>::value...>::value;
495 }
496
497 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59 +0000498 static constexpr bool __enable_explicit() {
499 return
500 __tuple_constructible<
501 tuple<_Args...>,
502 typename __make_tuple_types<tuple,
503 sizeof...(_Args) < sizeof...(_Tp) ?
504 sizeof...(_Args) :
505 sizeof...(_Tp)>::type
506 >::value &&
507 !__tuple_convertible<
508 tuple<_Args...>,
509 typename __make_tuple_types<tuple,
510 sizeof...(_Args) < sizeof...(_Tp) ?
511 sizeof...(_Args) :
512 sizeof...(_Tp)>::type
513 >::value &&
514 __all_default_constructible<
515 typename __make_tuple_types<tuple, sizeof...(_Tp),
516 sizeof...(_Args) < sizeof...(_Tp) ?
517 sizeof...(_Args) :
518 sizeof...(_Tp)>::type
519 >::value;
520 }
521
522 template <class ..._Args>
523 static constexpr bool __enable_implicit() {
524 return
525 __tuple_convertible<
526 tuple<_Args...>,
527 typename __make_tuple_types<tuple,
528 sizeof...(_Args) < sizeof...(_Tp) ?
529 sizeof...(_Args) :
530 sizeof...(_Tp)>::type
531 >::value &&
532 __all_default_constructible<
533 typename __make_tuple_types<tuple, sizeof...(_Tp),
534 sizeof...(_Args) < sizeof...(_Tp) ?
535 sizeof...(_Args) :
536 sizeof...(_Tp)>::type
537 >::value;
538 }
539 };
540
541 template <bool _MaybeEnable,
542 bool = sizeof...(_Tp) == 1,
543 class _Dummy = void>
544 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
545
546 template <class _Dummy>
547 struct _CheckTupleLikeConstructor<true, false, _Dummy>
548 {
549 template <class _Tuple>
550 static constexpr bool __enable_implicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000551 return __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000552 }
553
554 template <class _Tuple>
555 static constexpr bool __enable_explicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000556 return __tuple_constructible<_Tuple, tuple>::value
557 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000558 }
559 };
560
561 template <class _Dummy>
562 struct _CheckTupleLikeConstructor<true, true, _Dummy>
563 {
564 // This trait is used to disable the tuple-like constructor when
565 // the UTypes... constructor should be selected instead.
566 // See LWG issue #2549.
567 template <class _Tuple>
568 using _PreferTupleLikeConstructor = __lazy_or<
569 // Don't attempt the two checks below if the tuple we are given
570 // has the same type as this tuple.
571 is_same<typename __uncvref<_Tuple>::type, tuple>,
572 __lazy_and<
573 __lazy_not<is_constructible<_Tp..., _Tuple>>,
574 __lazy_not<is_convertible<_Tuple, _Tp...>>
575 >
576 >;
577
578 template <class _Tuple>
579 static constexpr bool __enable_implicit() {
580 return __lazy_and<
581 __tuple_convertible<_Tuple, tuple>,
582 _PreferTupleLikeConstructor<_Tuple>
583 >::value;
584 }
585
586 template <class _Tuple>
587 static constexpr bool __enable_explicit() {
588 return __lazy_and<
589 __tuple_constructible<_Tuple, tuple>,
590 _PreferTupleLikeConstructor<_Tuple>,
591 __lazy_not<__tuple_convertible<_Tuple, tuple>>
592 >::value;
593 }
594 };
595
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000596 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000597 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const 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 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000602 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
603 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604public:
605
Eric Fiselierda1818a2015-02-21 02:30:41 +0000606 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000607 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02 +0000608 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000610 _LIBCPP_CONSTEXPR tuple()
611 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000612
Eric Fiselier4be71c62016-07-25 02:36:42 +0000613 tuple(tuple const&) = default;
614 tuple(tuple&&) = default;
615
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000616 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
617 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000618 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000619 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
620 >::value
621 >::type>
622 _LIBCPP_INLINE_VISIBILITY
623 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000624 : __base_(allocator_arg_t(), __a,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000625 __tuple_indices<>(), __tuple_types<>(),
626 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
627 __tuple_types<_Tp...>()) {}
628
Eric Fiselier95526d32016-04-19 01:19:25 +0000629 template <bool _Dummy = true,
630 typename enable_if
631 <
632 _CheckArgsConstructor<
633 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000634 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000635 bool
636 >::type = false
637 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000639 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000640 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
642 typename __make_tuple_indices<0>::type(),
643 typename __make_tuple_types<tuple, 0>::type(),
644 __t...
645 ) {}
646
Eric Fiselier95526d32016-04-19 01:19:25 +0000647 template <bool _Dummy = true,
648 typename enable_if
649 <
650 _CheckArgsConstructor<
651 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000652 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000653 bool
654 >::type = false
655 >
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
657 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000658 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000659 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
660 typename __make_tuple_indices<0>::type(),
661 typename __make_tuple_types<tuple, 0>::type(),
662 __t...
663 ) {}
664
665 template <class _Alloc, bool _Dummy = true,
666 typename enable_if
667 <
668 _CheckArgsConstructor<
669 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000670 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000671 bool
672 >::type = false
673 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000676 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
678 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
679 typename __make_tuple_indices<0>::type(),
680 typename __make_tuple_types<tuple, 0>::type(),
681 __t...
682 ) {}
683
Eric Fiselier95526d32016-04-19 01:19:25 +0000684 template <class _Alloc, bool _Dummy = true,
685 typename enable_if
686 <
687 _CheckArgsConstructor<
688 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000689 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000690 bool
691 >::type = false
692 >
693 _LIBCPP_INLINE_VISIBILITY
694 explicit
695 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000696 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000697 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
698 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
699 typename __make_tuple_indices<0>::type(),
700 typename __make_tuple_types<tuple, 0>::type(),
701 __t...
702 ) {}
703
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 template <class ..._Up,
Eric Fiselierf2f36372016-12-08 23:57:08 +0000705 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000706 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000708 _CheckArgsConstructor<
Eric Fiselierf2f36372016-12-08 23:57:08 +0000709 sizeof...(_Up) == sizeof...(_Tp)
710 && !_PackIsTuple
711 >::template __enable_implicit<_Up...>() ||
712 _CheckArgsConstructor<
713 _EnableImplicitReducedArityExtension
714 && sizeof...(_Up) < sizeof...(_Tp)
715 && !_PackIsTuple
Eric Fiselierd5019332016-04-15 18:05:59 +0000716 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000717 bool
718 >::type = false
719 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000720 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000721 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000722 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000723 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000724 typename __make_tuple_indices<sizeof...(_Up)>::type,
725 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
726 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
727 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000728 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000729 >::value
730 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000731 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000732 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
733 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
734 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
735 _VSTD::forward<_Up>(__u)...) {}
736
737 template <class ..._Up,
738 typename enable_if
739 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000740 _CheckArgsConstructor<
741 sizeof...(_Up) <= sizeof...(_Tp)
742 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000743 >::template __enable_explicit<_Up...>() ||
744 _CheckArgsConstructor<
745 !_EnableImplicitReducedArityExtension
746 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselier236b7522017-02-04 22:57:01 +0000747 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000748 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000749 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000750 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000752 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753 explicit
754 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000755 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000756 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000757 typename __make_tuple_indices<sizeof...(_Up)>::type,
758 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
759 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
760 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
761 _Up...
762 >::value
763 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000764 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
766 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
767 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000768 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769
770 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000771 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000773 _CheckArgsConstructor<
774 sizeof...(_Up) == sizeof...(_Tp) &&
775 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000776 >::template __enable_implicit<_Up...>(),
777 bool
778 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000782 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 typename __make_tuple_indices<sizeof...(_Up)>::type(),
784 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
785 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
786 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000787 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788
Eric Fiselier95526d32016-04-19 01:19:25 +0000789 template <class _Alloc, class ..._Up,
790 typename enable_if
791 <
792 _CheckArgsConstructor<
793 sizeof...(_Up) == sizeof...(_Tp) &&
794 !_PackExpandsToThisTuple<_Up...>::value
795 >::template __enable_explicit<_Up...>(),
796 bool
797 >::type = false
798 >
799 _LIBCPP_INLINE_VISIBILITY
800 explicit
801 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000802 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000803 typename __make_tuple_indices<sizeof...(_Up)>::type(),
804 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
805 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
806 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
807 _VSTD::forward<_Up>(__u)...) {}
808
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000810 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000812 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000813 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
814 && !_PackExpandsToThisTuple<_Tuple>::value
815 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000816 bool
817 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000819 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000820 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
821 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000823 template <class _Tuple,
824 typename enable_if
825 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000826 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000827 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
828 && !_PackExpandsToThisTuple<_Tuple>::value
829 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000830 bool
831 >::type = false
832 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000834 explicit
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000835 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
836 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000837
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000839 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000841 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000842 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
843 >::template __enable_implicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000844 bool
845 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000849 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850
Eric Fiselier95526d32016-04-19 01:19:25 +0000851 template <class _Alloc, class _Tuple,
852 typename enable_if
853 <
854 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000855 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
856 >::template __enable_explicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000857 bool
858 >::type = false
859 >
860 _LIBCPP_INLINE_VISIBILITY
861 explicit
862 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000863 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier95526d32016-04-19 01:19:25 +0000864
Eric Fiselier4be71c62016-07-25 02:36:42 +0000865 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
866 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
867
868 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9663ee42016-12-15 06:34:54 +0000869 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000870 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
871 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000872 __base_.operator=(__t.__base_);
Eric Fiselier4be71c62016-07-25 02:36:42 +0000873 return *this;
874 }
875
876 _LIBCPP_INLINE_VISIBILITY
877 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
878 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
879 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000880 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier4be71c62016-07-25 02:36:42 +0000881 return *this;
882 }
883
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 template <class _Tuple,
885 class = typename enable_if
886 <
Eric Fiselier9663ee42016-12-15 06:34:54 +0000887 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 >::type
889 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 tuple&
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000892 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000894 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 return *this;
896 }
897
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000899 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000900 {__base_.swap(__t.__base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901};
902
903template <>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000904class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905{
906public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000908 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000911 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000914 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000915 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000917 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000918 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000920 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000922 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923};
924
Eric Fiselier8a29c9d2017-10-04 00:04:26 +0000925#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Eric Fiselier3113ac62017-06-08 07:18:17 +0000926// NOTE: These are not yet standardized, but are required to simulate the
927// implicit deduction guide that should be generated had libc++ declared the
928// tuple-like constructors "correctly"
929template <class _Alloc, class ..._Args>
930tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
931template <class _Alloc, class ..._Args>
932tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
933#endif
934
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935template <class ..._Tp>
936inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000937typename enable_if
938<
939 __all<__is_swappable<_Tp>::value...>::value,
940 void
941>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000942swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
943 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
944 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945
946// get
947
948template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000949inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000950typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000951get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000953 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000954 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955}
956
957template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000958inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000959const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000960get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000962 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000963 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964}
965
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000966template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000967inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000968typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000969get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000970{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000971 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000972 return static_cast<type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000973 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000974}
975
Eric Fiselier199bee02015-12-18 00:36:55 +0000976template <size_t _Ip, class ..._Tp>
977inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
978const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
979get(const tuple<_Tp...>&& __t) _NOEXCEPT
980{
981 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
982 return static_cast<const type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000983 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier199bee02015-12-18 00:36:55 +0000984}
985
Marshall Clowe8029e52013-07-13 02:54:05 +0000986#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000987
Eric Fiselier22c3e762016-07-02 03:18:30 +0000988namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000989
Eric Fiselier22c3e762016-07-02 03:18:30 +0000990static constexpr size_t __not_found = -1;
991static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000992
Eric Fiselier22c3e762016-07-02 03:18:30 +0000993inline _LIBCPP_INLINE_VISIBILITY
994constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
995 return !__matches ? __res :
996 (__res == __not_found ? __curr_i : __ambiguous);
997}
Marshall Clowe8029e52013-07-13 02:54:05 +0000998
Eric Fiselier22c3e762016-07-02 03:18:30 +0000999template <size_t _Nx>
1000inline _LIBCPP_INLINE_VISIBILITY
1001constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1002 return __i == _Nx ? __not_found :
1003 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1004}
1005
1006template <class _T1, class ..._Args>
1007struct __find_exactly_one_checked {
Casey Carter5f7683b2017-12-12 17:22:24 +00001008 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier22c3e762016-07-02 03:18:30 +00001009 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter5f7683b2017-12-12 17:22:24 +00001010 static_assert(value != __not_found, "type not found in type list" );
1011 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier22c3e762016-07-02 03:18:30 +00001012};
1013
Eric Fiselier990090f2016-07-02 03:46:08 +00001014template <class _T1>
1015struct __find_exactly_one_checked<_T1> {
1016 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1017};
1018
Eric Fiselier22c3e762016-07-02 03:18:30 +00001019} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001020
1021template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001022struct __find_exactly_one_t
1023 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1024};
Marshall Clowe8029e52013-07-13 02:54:05 +00001025
1026template <class _T1, class... _Args>
1027inline _LIBCPP_INLINE_VISIBILITY
1028constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1029{
1030 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1031}
1032
1033template <class _T1, class... _Args>
1034inline _LIBCPP_INLINE_VISIBILITY
1035constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1036{
1037 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1038}
1039
1040template <class _T1, class... _Args>
1041inline _LIBCPP_INLINE_VISIBILITY
1042constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1043{
Marshall Clow01a0e902013-07-15 20:46:11 +00001044 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001045}
1046
Eric Fiselier199bee02015-12-18 00:36:55 +00001047template <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>(_VSTD::move(__tup));
1052}
1053
Marshall Clowe8029e52013-07-13 02:54:05 +00001054#endif
1055
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056// tie
1057
1058template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001059inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001061tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062{
1063 return tuple<_Tp&...>(__t...);
1064}
1065
1066template <class _Up>
1067struct __ignore_t
1068{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 template <class _Tp>
Eric Fiselier07d23d52017-02-06 01:25:31 +00001070 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1071 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072};
1073
Eric Fiselier07d23d52017-02-06 01:25:31 +00001074namespace {
Marshall Clowc58e4722018-01-02 17:17:01 +00001075 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier07d23d52017-02-06 01:25:31 +00001076}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001079struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080{
1081 typedef _Tp type;
1082};
1083
1084template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001085struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086{
1087 typedef _Tp& type;
1088};
1089
1090template <class _Tp>
1091struct __make_tuple_return
1092{
Marshall Clowa71f9562014-01-03 22:55:49 +00001093 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094};
1095
1096template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001097inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098tuple<typename __make_tuple_return<_Tp>::type...>
1099make_tuple(_Tp&&... __t)
1100{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001101 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102}
1103
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001104template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001105inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1106tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001107forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001108{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001109 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001110}
1111
Howard Hinnant99968442011-11-29 18:15:50 +00001112template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001113struct __tuple_equal
1114{
1115 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 bool operator()(const _Tp& __x, const _Up& __y)
1118 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001119 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 }
1121};
1122
1123template <>
1124struct __tuple_equal<0>
1125{
1126 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001127 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 bool operator()(const _Tp&, const _Up&)
1129 {
1130 return true;
1131 }
1132};
1133
1134template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001135inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136bool
1137operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1138{
1139 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1140}
1141
1142template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144bool
1145operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1146{
1147 return !(__x == __y);
1148}
1149
Howard Hinnant99968442011-11-29 18:15:50 +00001150template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151struct __tuple_less
1152{
1153 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001154 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 bool operator()(const _Tp& __x, const _Up& __y)
1156 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001157 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1158 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1159 return true;
1160 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1161 return false;
1162 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 }
1164};
1165
1166template <>
1167struct __tuple_less<0>
1168{
1169 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001170 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 bool operator()(const _Tp&, const _Up&)
1172 {
1173 return false;
1174 }
1175};
1176
1177template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179bool
1180operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1181{
1182 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1183}
1184
1185template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001186inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187bool
1188operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1189{
1190 return __y < __x;
1191}
1192
1193template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195bool
1196operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1197{
1198 return !(__x < __y);
1199}
1200
1201template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203bool
1204operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1205{
1206 return !(__y < __x);
1207}
1208
1209// tuple_cat
1210
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001211template <class _Tp, class _Up> struct __tuple_cat_type;
1212
1213template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001214struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001216 typedef tuple<_Ttypes..., _Utypes...> type;
1217};
1218
1219template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1220struct __tuple_cat_return_1
1221{
1222};
1223
1224template <class ..._Types, class _Tuple0>
1225struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1226{
1227 typedef typename __tuple_cat_type<tuple<_Types...>,
1228 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1229 type;
1230};
1231
1232template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1233struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1234 : public __tuple_cat_return_1<
1235 typename __tuple_cat_type<
1236 tuple<_Types...>,
1237 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1238 >::type,
1239 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1240 _Tuple1, _Tuples...>
1241{
1242};
1243
1244template <class ..._Tuples> struct __tuple_cat_return;
1245
1246template <class _Tuple0, class ..._Tuples>
1247struct __tuple_cat_return<_Tuple0, _Tuples...>
1248 : public __tuple_cat_return_1<tuple<>,
1249 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1250 _Tuples...>
1251{
1252};
1253
1254template <>
1255struct __tuple_cat_return<>
1256{
1257 typedef tuple<> type;
1258};
1259
Marshall Clowda0a0e82013-07-22 16:02:19 +00001260inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001261tuple<>
1262tuple_cat()
1263{
1264 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265}
1266
Howard Hinnant99968442011-11-29 18:15:50 +00001267template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001268struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269
Howard Hinnante48e3662010-12-12 23:04:37 +00001270template <class ..._Types, size_t ..._I0, class _Tuple0>
1271struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001273 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001274 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1275 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1276};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277
Howard Hinnante48e3662010-12-12 23:04:37 +00001278template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1279struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1280 _Tuple0, _Tuple1, _Tuples...>
1281 : public __tuple_cat_return_ref_imp<
1282 tuple<_Types..., typename __apply_cv<_Tuple0,
1283 typename tuple_element<_I0,
1284 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1285 typename __make_tuple_indices<tuple_size<typename
1286 remove_reference<_Tuple1>::type>::value>::type,
1287 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288{
Howard Hinnante48e3662010-12-12 23:04:37 +00001289};
1290
1291template <class _Tuple0, class ..._Tuples>
1292struct __tuple_cat_return_ref
1293 : public __tuple_cat_return_ref_imp<tuple<>,
1294 typename __make_tuple_indices<
1295 tuple_size<typename remove_reference<_Tuple0>::type>::value
1296 >::type, _Tuple0, _Tuples...>
1297{
1298};
1299
1300template <class _Types, class _I0, class _J0>
1301struct __tuple_cat;
1302
1303template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001304struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001305{
1306 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001308 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1309 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1310 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001311 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1312 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001313 }
1314
1315 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001316 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001317 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1318 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1319 {
1320 typedef typename remove_reference<_Tuple0>::type _T0;
1321 typedef typename remove_reference<_Tuple1>::type _T1;
1322 return __tuple_cat<
1323 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1324 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1325 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001326 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001327 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1328 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001329 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001330 _VSTD::forward<_Tuple1>(__t1),
1331 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001332 }
1333};
1334
1335template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001336inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001337typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1338tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1339{
1340 typedef typename remove_reference<_Tuple0>::type _T0;
1341 return __tuple_cat<tuple<>, __tuple_indices<>,
1342 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001343 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1344 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345}
1346
1347template <class ..._Tp, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001348struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349 : true_type {};
1350
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351template <class _T1, class _T2>
1352template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1353inline _LIBCPP_INLINE_VISIBILITY
1354pair<_T1, _T2>::pair(piecewise_construct_t,
1355 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1356 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001357 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1358 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359{
1360}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361
Eric Fiselier5839fed2016-07-18 00:35:56 +00001362#if _LIBCPP_STD_VER > 14
1363template <class _Tp>
Marshall Clowc58e4722018-01-02 17:17:01 +00001364_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier5839fed2016-07-18 00:35:56 +00001365
1366#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1367
1368template <class _Fn, class _Tuple, size_t ..._Id>
1369inline _LIBCPP_INLINE_VISIBILITY
1370constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1371 __tuple_indices<_Id...>)
1372_LIBCPP_NOEXCEPT_RETURN(
1373 _VSTD::__invoke_constexpr(
1374 _VSTD::forward<_Fn>(__f),
1375 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1376)
1377
1378template <class _Fn, class _Tuple>
1379inline _LIBCPP_INLINE_VISIBILITY
1380constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1381_LIBCPP_NOEXCEPT_RETURN(
1382 _VSTD::__apply_tuple_impl(
1383 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1384 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1385)
1386
1387template <class _Tp, class _Tuple, size_t... _Idx>
1388inline _LIBCPP_INLINE_VISIBILITY
1389constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1390_LIBCPP_NOEXCEPT_RETURN(
1391 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1392)
1393
1394template <class _Tp, class _Tuple>
1395inline _LIBCPP_INLINE_VISIBILITY
1396constexpr _Tp make_from_tuple(_Tuple&& __t)
1397_LIBCPP_NOEXCEPT_RETURN(
1398 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1399 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1400)
1401
1402#undef _LIBCPP_NOEXCEPT_RETURN
1403
1404#endif // _LIBCPP_STD_VER > 14
1405
Eric Fiselier191f0752017-04-19 01:23:39 +00001406#endif // !defined(_LIBCPP_CXX03_LANG)
1407
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408_LIBCPP_END_NAMESPACE_STD
1409
1410#endif // _LIBCPP_TUPLE