blob: fb5428ec1c3ccec4b2fd704c35f0b4f1cd769b59 [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>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000144#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145
Howard Hinnant08e17472011-10-17 20:05:10 +0000146#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000147#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000148#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149
150_LIBCPP_BEGIN_NAMESPACE_STD
151
Eric Fiselier191f0752017-04-19 01:23:39 +0000152#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
Marshall Clow50fe0c72014-03-03 06:18:11 +0000154
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155// __tuple_leaf
156
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000157template <size_t _Ip, class _Hp,
158 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000159 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160class __tuple_leaf;
161
162template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000163inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000165 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166{
167 swap(__x.get(), __y.get());
168}
169
170template <size_t _Ip, class _Hp, bool>
171class __tuple_leaf
172{
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000173 _Hp __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000174
Eric Fiselier9c747b92016-07-20 02:57:39 +0000175 template <class _Tp>
176 static constexpr bool __can_bind_reference() {
Eric Fiselier8286acc2018-01-24 22:14:01 +0000177#if __has_keyword(__reference_binds_to_temporary)
178 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier8592d0a2018-01-24 23:10:02 +0000179#else
180 return true;
Eric Fiselier8286acc2018-01-24 22:14:01 +0000181#endif
Eric Fiselier9c747b92016-07-20 02:57:39 +0000182 }
183
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184 __tuple_leaf& operator=(const __tuple_leaf&);
185public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000186 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000187 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188 {static_assert(!is_reference<_Hp>::value,
189 "Attempted to default construct a reference element in a tuple");}
190
191 template <class _Alloc>
192 _LIBCPP_INLINE_VISIBILITY
193 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000194 : __value_()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195 {static_assert(!is_reference<_Hp>::value,
196 "Attempted to default construct a reference element in a tuple");}
197
198 template <class _Alloc>
199 _LIBCPP_INLINE_VISIBILITY
200 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000201 : __value_(allocator_arg_t(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202 {static_assert(!is_reference<_Hp>::value,
203 "Attempted to default construct a reference element in a tuple");}
204
205 template <class _Alloc>
206 _LIBCPP_INLINE_VISIBILITY
207 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000208 : __value_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209 {static_assert(!is_reference<_Hp>::value,
210 "Attempted to default construct a reference element in a tuple");}
211
Howard Hinnante049cc52010-09-27 17:54:17 +0000212 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000213 class = typename enable_if<
214 __lazy_and<
Marshall Clow52f9ca22018-02-06 20:56:55 +0000215 __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>>
Eric Fiselier9020c082014-07-24 18:48:34 +0000216 , is_constructible<_Hp, _Tp>
217 >::value
218 >::type
219 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000220 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000221 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000222 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000223 {static_assert(__can_bind_reference<_Tp&&>(),
224 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225
226 template <class _Tp, class _Alloc>
227 _LIBCPP_INLINE_VISIBILITY
228 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000229 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier8286acc2018-01-24 22:14:01 +0000230 {static_assert(__can_bind_reference<_Tp&&>(),
231 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232
233 template <class _Tp, class _Alloc>
234 _LIBCPP_INLINE_VISIBILITY
235 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000236 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39 +0000237 {static_assert(!is_reference<_Hp>::value,
238 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239
240 template <class _Tp, class _Alloc>
241 _LIBCPP_INLINE_VISIBILITY
242 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000243 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselier9c747b92016-07-20 02:57:39 +0000244 {static_assert(!is_reference<_Hp>::value,
245 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
Marshall Clow398c9d82014-04-21 23:48:09 +0000247 __tuple_leaf(const __tuple_leaf& __t) = default;
248 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
250 template <class _Tp>
251 _LIBCPP_INLINE_VISIBILITY
252 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000253 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000255 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 return *this;
257 }
258
259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000260 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000262 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 return 0;
264 }
265
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268};
269
270template <size_t _Ip, class _Hp>
271class __tuple_leaf<_Ip, _Hp, true>
272 : private _Hp
273{
274
275 __tuple_leaf& operator=(const __tuple_leaf&);
276public:
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
278 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280 template <class _Alloc>
281 _LIBCPP_INLINE_VISIBILITY
282 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
283
284 template <class _Alloc>
285 _LIBCPP_INLINE_VISIBILITY
286 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
287 : _Hp(allocator_arg_t(), __a) {}
288
289 template <class _Alloc>
290 _LIBCPP_INLINE_VISIBILITY
291 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
292 : _Hp(__a) {}
293
Howard Hinnante049cc52010-09-27 17:54:17 +0000294 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34 +0000295 class = typename enable_if<
296 __lazy_and<
Marshall Clow52f9ca22018-02-06 20:56:55 +0000297 __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>>
Eric Fiselier9020c082014-07-24 18:48:34 +0000298 , is_constructible<_Hp, _Tp>
299 >::value
300 >::type
301 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000302 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000303 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000304 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
306 template <class _Tp, class _Alloc>
307 _LIBCPP_INLINE_VISIBILITY
308 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000309 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310
311 template <class _Tp, class _Alloc>
312 _LIBCPP_INLINE_VISIBILITY
313 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000314 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315
316 template <class _Tp, class _Alloc>
317 _LIBCPP_INLINE_VISIBILITY
318 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000319 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
Eric Fiselier9020c082014-07-24 18:48:34 +0000321 __tuple_leaf(__tuple_leaf const &) = default;
322 __tuple_leaf(__tuple_leaf &&) = default;
323
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324 template <class _Tp>
325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48 +0000327 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000329 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330 return *this;
331 }
332
Howard Hinnanta5e01212011-05-27 19:08:18 +0000333 _LIBCPP_INLINE_VISIBILITY
334 int
335 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000337 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338 return 0;
339 }
340
Marshall Clowda0a0e82013-07-22 16:02:19 +0000341 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
342 _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 +0000343};
344
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000345template <class ..._Tp>
346_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000347void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000349template <class ..._Tp>
350struct __lazy_all : __all<_Tp::value...> {};
351
Marshall Clowbbc7c742014-10-15 10:33:02 +0000352template <class _Tp>
353struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18 +0000354
Marshall Clowbbc7c742014-10-15 10:33:02 +0000355template <class ..._Tp>
356struct __all_default_constructible<__tuple_types<_Tp...>>
357 : __all<is_default_constructible<_Tp>::value...>
358{ };
Howard Hinnanta5e01212011-05-27 19:08:18 +0000359
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360// __tuple_impl
361
362template<class _Indx, class ..._Tp> struct __tuple_impl;
363
364template<size_t ..._Indx, class ..._Tp>
Eric Fiselier7d24e912017-01-16 21:15:08 +0000365struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366 : public __tuple_leaf<_Indx, _Tp>...
367{
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000369 _LIBCPP_CONSTEXPR __tuple_impl()
370 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000371
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 template <size_t ..._Uf, class ..._Tf,
373 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +0000374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375 explicit
376 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
377 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000378 _Up&&... __u)
379 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
380 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19 +0000381 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 __tuple_leaf<_Ul, _Tl>()...
383 {}
384
385 template <class _Alloc, size_t ..._Uf, class ..._Tf,
386 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 explicit
389 __tuple_impl(allocator_arg_t, const _Alloc& __a,
390 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
391 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
392 _Up&&... __u) :
393 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000394 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
396 {}
397
398 template <class _Tuple,
399 class = typename enable_if
400 <
Howard Hinnant99324892013-04-14 00:01:13 +0000401 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 >::type
403 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48 +0000405 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
406 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000407 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
408 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409 {}
410
411 template <class _Alloc, class _Tuple,
412 class = typename enable_if
413 <
Eric Fiselier95526d32016-04-19 01:19:25 +0000414 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 >::type
416 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
419 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43 +0000420 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000421 _VSTD::forward<typename tuple_element<_Indx,
422 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 {}
424
425 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 typename enable_if
428 <
Howard Hinnantf83417b2011-01-24 16:07:25 +0000429 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 __tuple_impl&
431 >::type
Howard Hinnant74f26f22012-07-06 21:53:48 +0000432 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
433 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000435 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
436 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 return *this;
438 }
439
Howard Hinnant3de50862013-11-06 17:45:43 +0000440 __tuple_impl(const __tuple_impl&) = default;
441 __tuple_impl(__tuple_impl&&) = default;
442
443 _LIBCPP_INLINE_VISIBILITY
444 __tuple_impl&
445 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
446 {
447 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
448 return *this;
449 }
450
451 _LIBCPP_INLINE_VISIBILITY
452 __tuple_impl&
453 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
454 {
455 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
456 return *this;
457 }
Howard Hinnant28484442012-02-15 20:13:52 +0000458
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000461 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 {
463 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
464 }
465};
466
Eric Fiselierd5019332016-04-15 18:05:59 +0000467
Eric Fiselierd5019332016-04-15 18:05:59 +0000468
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469template <class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000470class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471{
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000472 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000474 _BaseT __base_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475
Eric Fiselierf2f36372016-12-08 23:57:08 +0000476#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
477 static constexpr bool _EnableImplicitReducedArityExtension = true;
478#else
479 static constexpr bool _EnableImplicitReducedArityExtension = false;
480#endif
481
Eric Fiselierd5019332016-04-15 18:05:59 +0000482 template <class ..._Args>
483 struct _PackExpandsToThisTuple : false_type {};
484
485 template <class _Arg>
486 struct _PackExpandsToThisTuple<_Arg>
487 : is_same<typename __uncvref<_Arg>::type, tuple> {};
488
489 template <bool _MaybeEnable, class _Dummy = void>
490 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
491
492 template <class _Dummy>
493 struct _CheckArgsConstructor<true, _Dummy>
494 {
495 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000496 static constexpr bool __enable_default() {
497 return __all<is_default_constructible<_Args>::value...>::value;
498 }
499
500 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59 +0000501 static constexpr bool __enable_explicit() {
502 return
503 __tuple_constructible<
504 tuple<_Args...>,
505 typename __make_tuple_types<tuple,
506 sizeof...(_Args) < sizeof...(_Tp) ?
507 sizeof...(_Args) :
508 sizeof...(_Tp)>::type
509 >::value &&
510 !__tuple_convertible<
511 tuple<_Args...>,
512 typename __make_tuple_types<tuple,
513 sizeof...(_Args) < sizeof...(_Tp) ?
514 sizeof...(_Args) :
515 sizeof...(_Tp)>::type
516 >::value &&
517 __all_default_constructible<
518 typename __make_tuple_types<tuple, sizeof...(_Tp),
519 sizeof...(_Args) < sizeof...(_Tp) ?
520 sizeof...(_Args) :
521 sizeof...(_Tp)>::type
522 >::value;
523 }
524
525 template <class ..._Args>
526 static constexpr bool __enable_implicit() {
527 return
528 __tuple_convertible<
529 tuple<_Args...>,
530 typename __make_tuple_types<tuple,
531 sizeof...(_Args) < sizeof...(_Tp) ?
532 sizeof...(_Args) :
533 sizeof...(_Tp)>::type
534 >::value &&
535 __all_default_constructible<
536 typename __make_tuple_types<tuple, sizeof...(_Tp),
537 sizeof...(_Args) < sizeof...(_Tp) ?
538 sizeof...(_Args) :
539 sizeof...(_Tp)>::type
540 >::value;
541 }
542 };
543
544 template <bool _MaybeEnable,
545 bool = sizeof...(_Tp) == 1,
546 class _Dummy = void>
547 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
548
549 template <class _Dummy>
550 struct _CheckTupleLikeConstructor<true, false, _Dummy>
551 {
552 template <class _Tuple>
553 static constexpr bool __enable_implicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000554 return __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000555 }
556
557 template <class _Tuple>
558 static constexpr bool __enable_explicit() {
Eric Fiselier9663ee42016-12-15 06:34:54 +0000559 return __tuple_constructible<_Tuple, tuple>::value
560 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselierd5019332016-04-15 18:05:59 +0000561 }
562 };
563
564 template <class _Dummy>
565 struct _CheckTupleLikeConstructor<true, true, _Dummy>
566 {
567 // This trait is used to disable the tuple-like constructor when
568 // the UTypes... constructor should be selected instead.
569 // See LWG issue #2549.
570 template <class _Tuple>
571 using _PreferTupleLikeConstructor = __lazy_or<
572 // Don't attempt the two checks below if the tuple we are given
573 // has the same type as this tuple.
574 is_same<typename __uncvref<_Tuple>::type, tuple>,
575 __lazy_and<
576 __lazy_not<is_constructible<_Tp..., _Tuple>>,
577 __lazy_not<is_convertible<_Tuple, _Tp...>>
578 >
579 >;
580
581 template <class _Tuple>
582 static constexpr bool __enable_implicit() {
583 return __lazy_and<
584 __tuple_convertible<_Tuple, tuple>,
585 _PreferTupleLikeConstructor<_Tuple>
586 >::value;
587 }
588
589 template <class _Tuple>
590 static constexpr bool __enable_explicit() {
591 return __lazy_and<
592 __tuple_constructible<_Tuple, tuple>,
593 _PreferTupleLikeConstructor<_Tuple>,
594 __lazy_not<__tuple_convertible<_Tuple, tuple>>
595 >::value;
596 }
597 };
598
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000599 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000600 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000601 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000602 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000603 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04 +0000604 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000605 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
606 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607public:
608
Eric Fiselierda1818a2015-02-21 02:30:41 +0000609 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000610 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02 +0000611 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000613 _LIBCPP_CONSTEXPR tuple()
614 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45 +0000615
Eric Fiselier4be71c62016-07-25 02:36:42 +0000616 tuple(tuple const&) = default;
617 tuple(tuple&&) = default;
618
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000619 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
620 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13 +0000621 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000622 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
623 >::value
624 >::type>
625 _LIBCPP_INLINE_VISIBILITY
626 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000627 : __base_(allocator_arg_t(), __a,
Eric Fiselier55ad3ac2016-04-15 03:29:40 +0000628 __tuple_indices<>(), __tuple_types<>(),
629 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
630 __tuple_types<_Tp...>()) {}
631
Eric Fiselier95526d32016-04-19 01:19:25 +0000632 template <bool _Dummy = true,
633 typename enable_if
634 <
635 _CheckArgsConstructor<
636 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000637 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000638 bool
639 >::type = false
640 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25 +0000642 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000643 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
645 typename __make_tuple_indices<0>::type(),
646 typename __make_tuple_types<tuple, 0>::type(),
647 __t...
648 ) {}
649
Eric Fiselier95526d32016-04-19 01:19:25 +0000650 template <bool _Dummy = true,
651 typename enable_if
652 <
653 _CheckArgsConstructor<
654 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000655 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000656 bool
657 >::type = false
658 >
659 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
660 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000661 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000662 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
663 typename __make_tuple_indices<0>::type(),
664 typename __make_tuple_types<tuple, 0>::type(),
665 __t...
666 ) {}
667
668 template <class _Alloc, bool _Dummy = true,
669 typename enable_if
670 <
671 _CheckArgsConstructor<
672 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000673 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000674 bool
675 >::type = false
676 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000679 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
681 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
682 typename __make_tuple_indices<0>::type(),
683 typename __make_tuple_types<tuple, 0>::type(),
684 __t...
685 ) {}
686
Eric Fiselier95526d32016-04-19 01:19:25 +0000687 template <class _Alloc, bool _Dummy = true,
688 typename enable_if
689 <
690 _CheckArgsConstructor<
691 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31 +0000692 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000693 bool
694 >::type = false
695 >
696 _LIBCPP_INLINE_VISIBILITY
697 explicit
698 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000699 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000700 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
701 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
702 typename __make_tuple_indices<0>::type(),
703 typename __make_tuple_types<tuple, 0>::type(),
704 __t...
705 ) {}
706
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 template <class ..._Up,
Eric Fiselierf2f36372016-12-08 23:57:08 +0000708 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000709 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000711 _CheckArgsConstructor<
Eric Fiselierf2f36372016-12-08 23:57:08 +0000712 sizeof...(_Up) == sizeof...(_Tp)
713 && !_PackIsTuple
714 >::template __enable_implicit<_Up...>() ||
715 _CheckArgsConstructor<
716 _EnableImplicitReducedArityExtension
717 && sizeof...(_Up) < sizeof...(_Tp)
718 && !_PackIsTuple
Eric Fiselierd5019332016-04-15 18:05:59 +0000719 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000720 bool
721 >::type = false
722 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000723 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000724 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000725 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000726 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000727 typename __make_tuple_indices<sizeof...(_Up)>::type,
728 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
729 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
730 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21 +0000731 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48 +0000732 >::value
733 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000734 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000735 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
736 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
737 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
738 _VSTD::forward<_Up>(__u)...) {}
739
740 template <class ..._Up,
741 typename enable_if
742 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000743 _CheckArgsConstructor<
744 sizeof...(_Up) <= sizeof...(_Tp)
745 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000746 >::template __enable_explicit<_Up...>() ||
747 _CheckArgsConstructor<
748 !_EnableImplicitReducedArityExtension
749 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselier236b7522017-02-04 22:57:01 +0000750 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselierf2f36372016-12-08 23:57:08 +0000751 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000752 bool
Eric Fiselierd5019332016-04-15 18:05:59 +0000753 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000755 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 explicit
757 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48 +0000758 _NOEXCEPT_((
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000759 is_nothrow_constructible<_BaseT,
Howard Hinnant74f26f22012-07-06 21:53:48 +0000760 typename __make_tuple_indices<sizeof...(_Up)>::type,
761 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
762 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
763 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
764 _Up...
765 >::value
766 ))
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000767 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
769 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
770 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000771 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772
773 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25 +0000774 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000776 _CheckArgsConstructor<
777 sizeof...(_Up) == sizeof...(_Tp) &&
778 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25 +0000779 >::template __enable_implicit<_Up...>(),
780 bool
781 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000785 : __base_(allocator_arg_t(), __a,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 typename __make_tuple_indices<sizeof...(_Up)>::type(),
787 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
788 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
789 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000790 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791
Eric Fiselier95526d32016-04-19 01:19:25 +0000792 template <class _Alloc, class ..._Up,
793 typename enable_if
794 <
795 _CheckArgsConstructor<
796 sizeof...(_Up) == sizeof...(_Tp) &&
797 !_PackExpandsToThisTuple<_Up...>::value
798 >::template __enable_explicit<_Up...>(),
799 bool
800 >::type = false
801 >
802 _LIBCPP_INLINE_VISIBILITY
803 explicit
804 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000805 : __base_(allocator_arg_t(), __a,
Eric Fiselier95526d32016-04-19 01:19:25 +0000806 typename __make_tuple_indices<sizeof...(_Up)>::type(),
807 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
808 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
809 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
810 _VSTD::forward<_Up>(__u)...) {}
811
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000813 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000815 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000816 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
817 && !_PackExpandsToThisTuple<_Tuple>::value
818 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000819 bool
820 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000822 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000823 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
824 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000826 template <class _Tuple,
827 typename enable_if
828 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000829 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000830 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
831 && !_PackExpandsToThisTuple<_Tuple>::value
832 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000833 bool
834 >::type = false
835 >
Marshall Clowda0a0e82013-07-22 16:02:19 +0000836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000837 explicit
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000838 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
839 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000840
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25 +0000842 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843 <
Eric Fiselierd5019332016-04-15 18:05:59 +0000844 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000845 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
846 >::template __enable_implicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000847 bool
848 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000852 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853
Eric Fiselier95526d32016-04-19 01:19:25 +0000854 template <class _Alloc, class _Tuple,
855 typename enable_if
856 <
857 _CheckTupleLikeConstructor<
Eric Fiselier9663ee42016-12-15 06:34:54 +0000858 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
859 >::template __enable_explicit<_Tuple>(),
Eric Fiselier95526d32016-04-19 01:19:25 +0000860 bool
861 >::type = false
862 >
863 _LIBCPP_INLINE_VISIBILITY
864 explicit
865 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000866 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier95526d32016-04-19 01:19:25 +0000867
Eric Fiselier4be71c62016-07-25 02:36:42 +0000868 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
869 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
870
871 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9663ee42016-12-15 06:34:54 +0000872 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000873 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
874 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000875 __base_.operator=(__t.__base_);
Eric Fiselier4be71c62016-07-25 02:36:42 +0000876 return *this;
877 }
878
879 _LIBCPP_INLINE_VISIBILITY
880 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
881 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
882 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000883 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier4be71c62016-07-25 02:36:42 +0000884 return *this;
885 }
886
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 template <class _Tuple,
888 class = typename enable_if
889 <
Eric Fiselier9663ee42016-12-15 06:34:54 +0000890 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 >::type
892 >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 tuple&
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000895 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 {
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000897 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898 return *this;
899 }
900
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000902 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000903 {__base_.swap(__t.__base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904};
905
906template <>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000907class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908{
909public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27 +0000911 _LIBCPP_CONSTEXPR tuple() _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&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000917 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000918 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000920 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50 +0000921 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48 +0000923 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18 +0000925 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926};
927
Eric Fiselier8a29c9d2017-10-04 00:04:26 +0000928#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Eric Fiselier3113ac62017-06-08 07:18:17 +0000929// NOTE: These are not yet standardized, but are required to simulate the
930// implicit deduction guide that should be generated had libc++ declared the
931// tuple-like constructors "correctly"
932template <class _Alloc, class ..._Args>
933tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
934template <class _Alloc, class ..._Args>
935tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
936#endif
937
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938template <class ..._Tp>
939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000940typename enable_if
941<
942 __all<__is_swappable<_Tp>::value...>::value,
943 void
944>::type
Howard Hinnanta5e01212011-05-27 19:08:18 +0000945swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
946 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
947 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948
949// get
950
951template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000952inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000953typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000954get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000956 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000957 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958}
959
960template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000961inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000962const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000963get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000965 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000966 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967}
968
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000969template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000970inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000971typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04 +0000972get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000973{
Howard Hinnantf83417b2011-01-24 16:07:25 +0000974 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30 +0000975 return static_cast<type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000976 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000977}
978
Eric Fiselier199bee02015-12-18 00:36:55 +0000979template <size_t _Ip, class ..._Tp>
980inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
981const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
982get(const tuple<_Tp...>&& __t) _NOEXCEPT
983{
984 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
985 return static_cast<const type&&>(
Eric Fiselierbf86c8f2017-06-01 02:14:21 +0000986 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier199bee02015-12-18 00:36:55 +0000987}
988
Marshall Clowe8029e52013-07-13 02:54:05 +0000989#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000990
Eric Fiselier22c3e762016-07-02 03:18:30 +0000991namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05 +0000992
Eric Fiselier22c3e762016-07-02 03:18:30 +0000993static constexpr size_t __not_found = -1;
994static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05 +0000995
Eric Fiselier22c3e762016-07-02 03:18:30 +0000996inline _LIBCPP_INLINE_VISIBILITY
997constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
998 return !__matches ? __res :
999 (__res == __not_found ? __curr_i : __ambiguous);
1000}
Marshall Clowe8029e52013-07-13 02:54:05 +00001001
Eric Fiselier22c3e762016-07-02 03:18:30 +00001002template <size_t _Nx>
1003inline _LIBCPP_INLINE_VISIBILITY
1004constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1005 return __i == _Nx ? __not_found :
1006 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1007}
1008
1009template <class _T1, class ..._Args>
1010struct __find_exactly_one_checked {
Casey Carter5f7683b2017-12-12 17:22:24 +00001011 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier22c3e762016-07-02 03:18:30 +00001012 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter5f7683b2017-12-12 17:22:24 +00001013 static_assert(value != __not_found, "type not found in type list" );
1014 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier22c3e762016-07-02 03:18:30 +00001015};
1016
Eric Fiselier990090f2016-07-02 03:46:08 +00001017template <class _T1>
1018struct __find_exactly_one_checked<_T1> {
1019 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1020};
1021
Eric Fiselier22c3e762016-07-02 03:18:30 +00001022} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:05 +00001023
1024template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:30 +00001025struct __find_exactly_one_t
1026 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1027};
Marshall Clowe8029e52013-07-13 02:54:05 +00001028
1029template <class _T1, class... _Args>
1030inline _LIBCPP_INLINE_VISIBILITY
1031constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1032{
1033 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1034}
1035
1036template <class _T1, class... _Args>
1037inline _LIBCPP_INLINE_VISIBILITY
1038constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1039{
1040 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1041}
1042
1043template <class _T1, class... _Args>
1044inline _LIBCPP_INLINE_VISIBILITY
1045constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1046{
Marshall Clow01a0e902013-07-15 20:46:11 +00001047 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:05 +00001048}
1049
Eric Fiselier199bee02015-12-18 00:36:55 +00001050template <class _T1, class... _Args>
1051inline _LIBCPP_INLINE_VISIBILITY
1052constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1053{
1054 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1055}
1056
Marshall Clowe8029e52013-07-13 02:54:05 +00001057#endif
1058
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059// tie
1060
1061template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:46 +00001062inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001064tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065{
1066 return tuple<_Tp&...>(__t...);
1067}
1068
1069template <class _Up>
1070struct __ignore_t
1071{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 template <class _Tp>
Eric Fiselier07d23d52017-02-06 01:25:31 +00001073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1074 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075};
1076
Eric Fiselier07d23d52017-02-06 01:25:31 +00001077namespace {
Marshall Clowc58e4722018-01-02 17:17:01 +00001078 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier07d23d52017-02-06 01:25:31 +00001079}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001082struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
1084 typedef _Tp type;
1085};
1086
1087template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +00001088struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089{
1090 typedef _Tp& type;
1091};
1092
1093template <class _Tp>
1094struct __make_tuple_return
1095{
Marshall Clowa71f9562014-01-03 22:55:49 +00001096 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097};
1098
1099template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001100inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101tuple<typename __make_tuple_return<_Tp>::type...>
1102make_tuple(_Tp&&... __t)
1103{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001104 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105}
1106
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001107template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001108inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1109tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:48 +00001110forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001111{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001112 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:38 +00001113}
1114
Howard Hinnant99968442011-11-29 18:15:50 +00001115template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116struct __tuple_equal
1117{
1118 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 bool operator()(const _Tp& __x, const _Up& __y)
1121 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001122 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 }
1124};
1125
1126template <>
1127struct __tuple_equal<0>
1128{
1129 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001130 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 bool operator()(const _Tp&, const _Up&)
1132 {
1133 return true;
1134 }
1135};
1136
1137template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001138inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139bool
1140operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1141{
1142 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1143}
1144
1145template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001146inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147bool
1148operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1149{
1150 return !(__x == __y);
1151}
1152
Howard Hinnant99968442011-11-29 18:15:50 +00001153template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154struct __tuple_less
1155{
1156 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158 bool operator()(const _Tp& __x, const _Up& __y)
1159 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:17 +00001160 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1161 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1162 return true;
1163 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1164 return false;
1165 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 }
1167};
1168
1169template <>
1170struct __tuple_less<0>
1171{
1172 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 bool operator()(const _Tp&, const _Up&)
1175 {
1176 return false;
1177 }
1178};
1179
1180template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001181inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182bool
1183operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1184{
1185 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1186}
1187
1188template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001189inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190bool
1191operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1192{
1193 return __y < __x;
1194}
1195
1196template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001197inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198bool
1199operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1200{
1201 return !(__x < __y);
1202}
1203
1204template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001205inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206bool
1207operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1208{
1209 return !(__y < __x);
1210}
1211
1212// tuple_cat
1213
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001214template <class _Tp, class _Up> struct __tuple_cat_type;
1215
1216template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001217struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001219 typedef tuple<_Ttypes..., _Utypes...> type;
1220};
1221
1222template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1223struct __tuple_cat_return_1
1224{
1225};
1226
1227template <class ..._Types, class _Tuple0>
1228struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1229{
1230 typedef typename __tuple_cat_type<tuple<_Types...>,
1231 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1232 type;
1233};
1234
1235template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1236struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1237 : public __tuple_cat_return_1<
1238 typename __tuple_cat_type<
1239 tuple<_Types...>,
1240 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1241 >::type,
1242 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1243 _Tuple1, _Tuples...>
1244{
1245};
1246
1247template <class ..._Tuples> struct __tuple_cat_return;
1248
1249template <class _Tuple0, class ..._Tuples>
1250struct __tuple_cat_return<_Tuple0, _Tuples...>
1251 : public __tuple_cat_return_1<tuple<>,
1252 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1253 _Tuples...>
1254{
1255};
1256
1257template <>
1258struct __tuple_cat_return<>
1259{
1260 typedef tuple<> type;
1261};
1262
Marshall Clowda0a0e82013-07-22 16:02:19 +00001263inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001264tuple<>
1265tuple_cat()
1266{
1267 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268}
1269
Howard Hinnant99968442011-11-29 18:15:50 +00001270template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:37 +00001271struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272
Howard Hinnante48e3662010-12-12 23:04:37 +00001273template <class ..._Types, size_t ..._I0, class _Tuple0>
1274struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275{
Howard Hinnant0e1493e2010-12-11 20:47:50 +00001276 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:37 +00001277 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1278 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1279};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280
Howard Hinnante48e3662010-12-12 23:04:37 +00001281template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1282struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1283 _Tuple0, _Tuple1, _Tuples...>
1284 : public __tuple_cat_return_ref_imp<
1285 tuple<_Types..., typename __apply_cv<_Tuple0,
1286 typename tuple_element<_I0,
1287 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1288 typename __make_tuple_indices<tuple_size<typename
1289 remove_reference<_Tuple1>::type>::value>::type,
1290 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291{
Howard Hinnante48e3662010-12-12 23:04:37 +00001292};
1293
1294template <class _Tuple0, class ..._Tuples>
1295struct __tuple_cat_return_ref
1296 : public __tuple_cat_return_ref_imp<tuple<>,
1297 typename __make_tuple_indices<
1298 tuple_size<typename remove_reference<_Tuple0>::type>::value
1299 >::type, _Tuple0, _Tuples...>
1300{
1301};
1302
1303template <class _Types, class _I0, class _J0>
1304struct __tuple_cat;
1305
1306template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:25 +00001307struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:37 +00001308{
1309 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001310 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001311 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1312 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1313 {
Marshall Clowba6dbf42014-06-24 00:46:19 +00001314 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1315 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001316 }
1317
1318 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001319 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001320 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1321 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1322 {
1323 typedef typename remove_reference<_Tuple0>::type _T0;
1324 typedef typename remove_reference<_Tuple1>::type _T1;
1325 return __tuple_cat<
1326 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1327 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1328 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:37 +00001329 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:19 +00001330 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1331 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:37 +00001332 ),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001333 _VSTD::forward<_Tuple1>(__t1),
1334 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:37 +00001335 }
1336};
1337
1338template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:19 +00001339inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:37 +00001340typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1341tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1342{
1343 typedef typename remove_reference<_Tuple0>::type _T0;
1344 return __tuple_cat<tuple<>, __tuple_indices<>,
1345 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:19 +00001346 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1347 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348}
1349
1350template <class ..._Tp, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001351struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352 : true_type {};
1353
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354template <class _T1, class _T2>
1355template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1356inline _LIBCPP_INLINE_VISIBILITY
1357pair<_T1, _T2>::pair(piecewise_construct_t,
1358 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1359 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00001360 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1361 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362{
1363}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364
Eric Fiselier5839fed2016-07-18 00:35:56 +00001365#if _LIBCPP_STD_VER > 14
1366template <class _Tp>
Marshall Clowc58e4722018-01-02 17:17:01 +00001367_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier5839fed2016-07-18 00:35:56 +00001368
1369#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1370
1371template <class _Fn, class _Tuple, size_t ..._Id>
1372inline _LIBCPP_INLINE_VISIBILITY
1373constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1374 __tuple_indices<_Id...>)
1375_LIBCPP_NOEXCEPT_RETURN(
1376 _VSTD::__invoke_constexpr(
1377 _VSTD::forward<_Fn>(__f),
1378 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1379)
1380
1381template <class _Fn, class _Tuple>
1382inline _LIBCPP_INLINE_VISIBILITY
1383constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1384_LIBCPP_NOEXCEPT_RETURN(
1385 _VSTD::__apply_tuple_impl(
1386 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clow52f9ca22018-02-06 20:56:55 +00001387 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier5839fed2016-07-18 00:35:56 +00001388)
1389
1390template <class _Tp, class _Tuple, size_t... _Idx>
1391inline _LIBCPP_INLINE_VISIBILITY
1392constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1393_LIBCPP_NOEXCEPT_RETURN(
1394 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1395)
1396
1397template <class _Tp, class _Tuple>
1398inline _LIBCPP_INLINE_VISIBILITY
1399constexpr _Tp make_from_tuple(_Tuple&& __t)
1400_LIBCPP_NOEXCEPT_RETURN(
1401 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clow52f9ca22018-02-06 20:56:55 +00001402 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier5839fed2016-07-18 00:35:56 +00001403)
1404
1405#undef _LIBCPP_NOEXCEPT_RETURN
1406
1407#endif // _LIBCPP_STD_VER > 14
1408
Eric Fiselier191f0752017-04-19 01:23:39 +00001409#endif // !defined(_LIBCPP_CXX03_LANG)
1410
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411_LIBCPP_END_NAMESPACE_STD
1412
1413#endif // _LIBCPP_TUPLE