blob: de30e86c72b48348f163c4b860f3cbadaf597a31 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
22 constexpr tuple();
Marshall Clow2229cee2013-07-22 16:02:19 +000023 explicit tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Marshall Clow2229cee2013-07-22 16:02:19 +000025 explicit tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Marshall Clow2229cee2013-07-22 16:02:19 +000029 tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Marshall Clow2229cee2013-07-22 16:02:19 +000031 tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Marshall Clow2229cee2013-07-22 16:02:19 +000033 tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Marshall Clow2229cee2013-07-22 16:02:19 +000035 tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
41 tuple(allocator_arg_t, const Alloc& a, const T&...);
42 template <class Alloc, class... U>
43 tuple(allocator_arg_t, const Alloc& a, U&&...);
44 template <class Alloc>
45 tuple(allocator_arg_t, const Alloc& a, const tuple&);
46 template <class Alloc>
47 tuple(allocator_arg_t, const Alloc& a, tuple&&);
48 template <class Alloc, class... U>
49 tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
50 template <class Alloc, class... U>
51 tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
52 template <class Alloc, class U1, class U2>
53 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
54 template <class Alloc, class U1, class U2>
55 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
56
57 tuple& operator=(const tuple&);
Howard Hinnant89ef1212011-05-27 19:08:18 +000058 tuple&
59 operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 template <class... U>
61 tuple& operator=(const tuple<U...>&);
62 template <class... U>
63 tuple& operator=(tuple<U...>&&);
64 template <class U1, class U2>
65 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
66 template <class U1, class U2>
Louis Dionnea6316ed2018-11-12 01:28:07 +000067 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
Howard Hinnantc51e1022010-05-11 19:42:16 +000068
Howard Hinnant89ef1212011-05-27 19:08:18 +000069 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
Howard Hinnantc51e1022010-05-11 19:42:16 +000070};
71
Marshall Clowf1bf62f2018-01-02 17:17:01 +000072inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000073
Marshall Clow2229cee2013-07-22 16:02:19 +000074template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000075template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000076template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000077template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000078
79// [tuple.apply], calling a function with a tuple of arguments:
80template <class F, class Tuple>
81 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
82template <class T, class Tuple>
83 constexpr T make_from_tuple(Tuple&& t); // C++17
84
Howard Hinnantc51e1022010-05-11 19:42:16 +000085// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +000086template <class T> struct tuple_size; // undefined
87template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +000088template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +000089 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +000090template <size_t I, class T> struct tuple_element; // undefined
91template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +000092template <size_t I, class T>
93 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +000096template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +000097 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +000098 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +000099template <size_t I, class... T>
100 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000101 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000102template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000103 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000104 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000105template <size_t I, class... T>
106 const typename tuple_element<I, tuple<T...>>::type&&
107 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108
Marshall Clow15b02e02013-07-13 02:54:05 +0000109template <class T1, class... T>
110 constexpr T1& get(tuple<T...>&) noexcept; // C++14
111template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000112 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000113template <class T1, class... T>
114 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000115template <class T1, class... T>
116 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000117
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000119template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
120template<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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125
126template <class... Types, class Alloc>
127 struct uses_allocator<tuple<Types...>, Alloc>;
128
129template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000130 void
131 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133} // std
134
135*/
136
137#include <__config>
138#include <__tuple>
139#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000141#include <__functional_base>
142#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000143#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000147#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000151#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152
Marshall Clowf50d66f2014-03-03 06:18:11 +0000153
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154// __tuple_leaf
155
Eric Fiselierf7394302015-06-13 07:08:02 +0000156template <size_t _Ip, class _Hp,
157 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000158 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159class __tuple_leaf;
160
161template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000164 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-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 Fiselier3e0d4372017-06-01 02:14:21 +0000172 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173
Eric Fiselierca8bba12016-07-20 02:57:39 +0000174 template <class _Tp>
175 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000176#if __has_keyword(__reference_binds_to_temporary)
177 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000178#else
179 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000180#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000181 }
182
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183 __tuple_leaf& operator=(const __tuple_leaf&);
184public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000186 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187 {static_assert(!is_reference<_Hp>::value,
188 "Attempted to default construct a reference element in a tuple");}
189
190 template <class _Alloc>
191 _LIBCPP_INLINE_VISIBILITY
192 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000193 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194 {static_assert(!is_reference<_Hp>::value,
195 "Attempted to default construct a reference element in a tuple");}
196
197 template <class _Alloc>
198 _LIBCPP_INLINE_VISIBILITY
199 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000200 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201 {static_assert(!is_reference<_Hp>::value,
202 "Attempted to default construct a reference element in a tuple");}
203
204 template <class _Alloc>
205 _LIBCPP_INLINE_VISIBILITY
206 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000207 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 {static_assert(!is_reference<_Hp>::value,
209 "Attempted to default construct a reference element in a tuple");}
210
Howard Hinnant693fc212010-09-27 17:54:17 +0000211 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000212 class = _EnableIf<
213 _And<
214 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
215 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000216 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000217 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000218 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000219 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000220 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000221 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000222 {static_assert(__can_bind_reference<_Tp&&>(),
223 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224
225 template <class _Tp, class _Alloc>
226 _LIBCPP_INLINE_VISIBILITY
227 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000228 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000229 {static_assert(__can_bind_reference<_Tp&&>(),
230 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231
232 template <class _Tp, class _Alloc>
233 _LIBCPP_INLINE_VISIBILITY
234 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000235 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000236 {static_assert(!is_reference<_Hp>::value,
237 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238
239 template <class _Tp, class _Alloc>
240 _LIBCPP_INLINE_VISIBILITY
241 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000242 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000243 {static_assert(!is_reference<_Hp>::value,
244 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
Marshall Clow47fcee52014-04-21 23:48:09 +0000246 __tuple_leaf(const __tuple_leaf& __t) = default;
247 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248
249 template <class _Tp>
250 _LIBCPP_INLINE_VISIBILITY
251 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000252 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000254 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 return *this;
256 }
257
258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000259 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000261 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 return 0;
263 }
264
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267};
268
269template <size_t _Ip, class _Hp>
270class __tuple_leaf<_Ip, _Hp, true>
271 : private _Hp
272{
273
274 __tuple_leaf& operator=(const __tuple_leaf&);
275public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
277 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278
279 template <class _Alloc>
280 _LIBCPP_INLINE_VISIBILITY
281 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
282
283 template <class _Alloc>
284 _LIBCPP_INLINE_VISIBILITY
285 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
286 : _Hp(allocator_arg_t(), __a) {}
287
288 template <class _Alloc>
289 _LIBCPP_INLINE_VISIBILITY
290 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
291 : _Hp(__a) {}
292
Howard Hinnant693fc212010-09-27 17:54:17 +0000293 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000294 class = _EnableIf<
295 _And<
296 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
297 is_constructible<_Hp, _Tp>
298 >::value
299 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000300 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000302 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000303 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304
305 template <class _Tp, class _Alloc>
306 _LIBCPP_INLINE_VISIBILITY
307 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000308 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309
310 template <class _Tp, class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000313 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314
315 template <class _Tp, class _Alloc>
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000318 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000320 __tuple_leaf(__tuple_leaf const &) = default;
321 __tuple_leaf(__tuple_leaf &&) = default;
322
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 template <class _Tp>
324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000326 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000328 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 return *this;
330 }
331
Howard Hinnant89ef1212011-05-27 19:08:18 +0000332 _LIBCPP_INLINE_VISIBILITY
333 int
334 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000336 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337 return 0;
338 }
339
Marshall Clow2229cee2013-07-22 16:02:19 +0000340 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
341 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342};
343
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000344template <class ..._Tp>
345_LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000346void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347
Marshall Clowc470eae2014-10-15 10:33:02 +0000348template <class _Tp>
349struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000350
Marshall Clowc470eae2014-10-15 10:33:02 +0000351template <class ..._Tp>
352struct __all_default_constructible<__tuple_types<_Tp...>>
353 : __all<is_default_constructible<_Tp>::value...>
354{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000355
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356// __tuple_impl
357
358template<class _Indx, class ..._Tp> struct __tuple_impl;
359
360template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000361struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 : public __tuple_leaf<_Indx, _Tp>...
363{
Howard Hinnant38469632012-07-06 20:39:45 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000365 _LIBCPP_CONSTEXPR __tuple_impl()
366 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000367
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 template <size_t ..._Uf, class ..._Tf,
369 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371 explicit
372 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
373 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000374 _Up&&... __u)
375 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
376 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000377 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 __tuple_leaf<_Ul, _Tl>()...
379 {}
380
381 template <class _Alloc, size_t ..._Uf, class ..._Tf,
382 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 explicit
385 __tuple_impl(allocator_arg_t, const _Alloc& __a,
386 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
387 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
388 _Up&&... __u) :
389 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000390 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
392 {}
393
394 template <class _Tuple,
395 class = typename enable_if
396 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000397 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 >::type
399 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000401 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
402 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000403 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
404 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 {}
406
407 template <class _Alloc, class _Tuple,
408 class = typename enable_if
409 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000410 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 >::type
412 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
415 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000416 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000417 _VSTD::forward<typename tuple_element<_Indx,
418 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 {}
420
421 template <class _Tuple>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 typename enable_if
424 <
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000425 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 __tuple_impl&
427 >::type
Howard Hinnant62751642012-07-06 21:53:48 +0000428 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
429 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000431 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
432 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433 return *this;
434 }
435
Howard Hinnant0d032d12013-11-06 17:45:43 +0000436 __tuple_impl(const __tuple_impl&) = default;
437 __tuple_impl(__tuple_impl&&) = default;
438
439 _LIBCPP_INLINE_VISIBILITY
440 __tuple_impl&
441 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
442 {
443 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
444 return *this;
445 }
446
447 _LIBCPP_INLINE_VISIBILITY
448 __tuple_impl&
449 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
450 {
451 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
452 return *this;
453 }
Howard Hinnantbcb62c62012-02-15 20:13:52 +0000454
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000457 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 {
459 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
460 }
461};
462
Eric Fiselier264d04a2016-04-15 18:05:59 +0000463
Eric Fiselier264d04a2016-04-15 18:05:59 +0000464
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000466class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000468 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000470 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471
Eric Fiselier41b686e2016-12-08 23:57:08 +0000472#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
473 static constexpr bool _EnableImplicitReducedArityExtension = true;
474#else
475 static constexpr bool _EnableImplicitReducedArityExtension = false;
476#endif
477
Eric Fiselier264d04a2016-04-15 18:05:59 +0000478 template <class ..._Args>
479 struct _PackExpandsToThisTuple : false_type {};
480
481 template <class _Arg>
482 struct _PackExpandsToThisTuple<_Arg>
483 : is_same<typename __uncvref<_Arg>::type, tuple> {};
484
485 template <bool _MaybeEnable, class _Dummy = void>
486 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
487
488 template <class _Dummy>
489 struct _CheckArgsConstructor<true, _Dummy>
490 {
491 template <class ..._Args>
Eric Fiseliere61db632016-07-25 04:32:07 +0000492 static constexpr bool __enable_default() {
493 return __all<is_default_constructible<_Args>::value...>::value;
494 }
495
496 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000497 static constexpr bool __enable_explicit() {
498 return
499 __tuple_constructible<
500 tuple<_Args...>,
501 typename __make_tuple_types<tuple,
502 sizeof...(_Args) < sizeof...(_Tp) ?
503 sizeof...(_Args) :
504 sizeof...(_Tp)>::type
505 >::value &&
506 !__tuple_convertible<
507 tuple<_Args...>,
508 typename __make_tuple_types<tuple,
509 sizeof...(_Args) < sizeof...(_Tp) ?
510 sizeof...(_Args) :
511 sizeof...(_Tp)>::type
512 >::value &&
513 __all_default_constructible<
514 typename __make_tuple_types<tuple, sizeof...(_Tp),
515 sizeof...(_Args) < sizeof...(_Tp) ?
516 sizeof...(_Args) :
517 sizeof...(_Tp)>::type
518 >::value;
519 }
520
521 template <class ..._Args>
522 static constexpr bool __enable_implicit() {
523 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000524 __tuple_constructible<
525 tuple<_Args...>,
526 typename __make_tuple_types<tuple,
527 sizeof...(_Args) < sizeof...(_Tp) ?
528 sizeof...(_Args) :
529 sizeof...(_Tp)>::type
530 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000531 __tuple_convertible<
532 tuple<_Args...>,
533 typename __make_tuple_types<tuple,
534 sizeof...(_Args) < sizeof...(_Tp) ?
535 sizeof...(_Args) :
536 sizeof...(_Tp)>::type
537 >::value &&
538 __all_default_constructible<
539 typename __make_tuple_types<tuple, sizeof...(_Tp),
540 sizeof...(_Args) < sizeof...(_Tp) ?
541 sizeof...(_Args) :
542 sizeof...(_Tp)>::type
543 >::value;
544 }
545 };
546
547 template <bool _MaybeEnable,
548 bool = sizeof...(_Tp) == 1,
549 class _Dummy = void>
550 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
551
552 template <class _Dummy>
553 struct _CheckTupleLikeConstructor<true, false, _Dummy>
554 {
555 template <class _Tuple>
556 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000557 return __tuple_constructible<_Tuple, tuple>::value
558 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000559 }
560
561 template <class _Tuple>
562 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000563 return __tuple_constructible<_Tuple, tuple>::value
564 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000565 }
566 };
567
568 template <class _Dummy>
569 struct _CheckTupleLikeConstructor<true, true, _Dummy>
570 {
571 // This trait is used to disable the tuple-like constructor when
572 // the UTypes... constructor should be selected instead.
573 // See LWG issue #2549.
574 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000575 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000576 // Don't attempt the two checks below if the tuple we are given
577 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000578 _IsSame<__uncvref_t<_Tuple>, tuple>,
579 _Lazy<_And,
580 _Not<is_constructible<_Tp..., _Tuple>>,
581 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000582 >
583 >;
584
585 template <class _Tuple>
586 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000587 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000588 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000589 __tuple_convertible<_Tuple, tuple>,
590 _PreferTupleLikeConstructor<_Tuple>
591 >::value;
592 }
593
594 template <class _Tuple>
595 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000596 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000597 __tuple_constructible<_Tuple, tuple>,
598 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000599 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000600 >::value;
601 }
602 };
603
Marshall Clow0abb1042013-07-17 18:25:36 +0000604 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000605 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000606 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000607 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000608 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000609 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000610 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
611 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612public:
613
Eric Fiseliercba58302015-02-21 02:30:41 +0000614 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere61db632016-07-25 04:32:07 +0000615 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowc470eae2014-10-15 10:33:02 +0000616 >::type>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000618 _LIBCPP_CONSTEXPR tuple()
619 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000620
Eric Fiselier737a16d2016-07-25 02:36:42 +0000621 tuple(tuple const&) = default;
622 tuple(tuple&&) = default;
623
Eric Fiselier3906a132019-06-23 20:28:29 +0000624 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf<
625 _And<
626 _IsSame<allocator_arg_t, _AllocArgT>,
627 __dependent_type<is_default_constructible<_Tp>, _Dummy>...
Eric Fiselierc170df52016-04-15 03:29:40 +0000628 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000629 >
630 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000631 _LIBCPP_INLINE_VISIBILITY
632 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000633 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000634 __tuple_indices<>(), __tuple_types<>(),
635 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
636 __tuple_types<_Tp...>()) {}
637
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000638 template <bool _Dummy = true,
639 typename enable_if
640 <
641 _CheckArgsConstructor<
642 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000643 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000644 bool
645 >::type = false
646 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000648 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000649 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
651 typename __make_tuple_indices<0>::type(),
652 typename __make_tuple_types<tuple, 0>::type(),
653 __t...
654 ) {}
655
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000656 template <bool _Dummy = true,
657 typename enable_if
658 <
659 _CheckArgsConstructor<
660 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000661 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000662 bool
663 >::type = false
664 >
665 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
666 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000667 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000668 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
669 typename __make_tuple_indices<0>::type(),
670 typename __make_tuple_types<tuple, 0>::type(),
671 __t...
672 ) {}
673
674 template <class _Alloc, bool _Dummy = true,
675 typename enable_if
676 <
677 _CheckArgsConstructor<
678 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000679 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000680 bool
681 >::type = false
682 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000685 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
687 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
688 typename __make_tuple_indices<0>::type(),
689 typename __make_tuple_types<tuple, 0>::type(),
690 __t...
691 ) {}
692
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000693 template <class _Alloc, bool _Dummy = true,
694 typename enable_if
695 <
696 _CheckArgsConstructor<
697 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000698 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000699 bool
700 >::type = false
701 >
702 _LIBCPP_INLINE_VISIBILITY
703 explicit
704 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000705 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000706 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
707 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
708 typename __make_tuple_indices<0>::type(),
709 typename __make_tuple_types<tuple, 0>::type(),
710 __t...
711 ) {}
712
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000714 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000715 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000717 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000718 sizeof...(_Up) == sizeof...(_Tp)
719 && !_PackIsTuple
720 >::template __enable_implicit<_Up...>() ||
721 _CheckArgsConstructor<
722 _EnableImplicitReducedArityExtension
723 && sizeof...(_Up) < sizeof...(_Tp)
724 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000725 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000726 bool
727 >::type = false
728 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000729 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000730 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000731 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000732 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000733 typename __make_tuple_indices<sizeof...(_Up)>::type,
734 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
735 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
736 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000737 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000738 >::value
739 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000740 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000741 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
742 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
743 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
744 _VSTD::forward<_Up>(__u)...) {}
745
746 template <class ..._Up,
747 typename enable_if
748 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000749 _CheckArgsConstructor<
750 sizeof...(_Up) <= sizeof...(_Tp)
751 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000752 >::template __enable_explicit<_Up...>() ||
753 _CheckArgsConstructor<
754 !_EnableImplicitReducedArityExtension
755 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000756 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000757 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000758 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000759 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000761 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 explicit
763 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000764 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000765 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000766 typename __make_tuple_indices<sizeof...(_Up)>::type,
767 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
768 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
769 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
770 _Up...
771 >::value
772 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000773 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
775 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
776 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000777 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778
779 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000780 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000782 _CheckArgsConstructor<
783 sizeof...(_Up) == sizeof...(_Tp) &&
784 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000785 >::template __enable_implicit<_Up...>(),
786 bool
787 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000791 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792 typename __make_tuple_indices<sizeof...(_Up)>::type(),
793 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
794 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
795 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000796 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000798 template <class _Alloc, class ..._Up,
799 typename enable_if
800 <
801 _CheckArgsConstructor<
802 sizeof...(_Up) == sizeof...(_Tp) &&
803 !_PackExpandsToThisTuple<_Up...>::value
804 >::template __enable_explicit<_Up...>(),
805 bool
806 >::type = false
807 >
808 _LIBCPP_INLINE_VISIBILITY
809 explicit
810 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000811 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000812 typename __make_tuple_indices<sizeof...(_Up)>::type(),
813 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
814 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
815 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
816 _VSTD::forward<_Up>(__u)...) {}
817
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 template <class _Tuple,
Howard Hinnant65704d02012-04-01 23:10:42 +0000819 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000821 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000822 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
823 && !_PackExpandsToThisTuple<_Tuple>::value
824 >::template __enable_implicit<_Tuple>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000825 bool
826 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000828 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000829 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
830 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831
Howard Hinnant65704d02012-04-01 23:10:42 +0000832 template <class _Tuple,
833 typename enable_if
834 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000835 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000836 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
837 && !_PackExpandsToThisTuple<_Tuple>::value
838 >::template __enable_explicit<_Tuple>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000839 bool
840 >::type = false
841 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000842 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000843 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000844 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
845 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000846
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000848 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000850 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000851 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
852 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000853 bool
854 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000858 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000860 template <class _Alloc, class _Tuple,
861 typename enable_if
862 <
863 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000864 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
865 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000866 bool
867 >::type = false
868 >
869 _LIBCPP_INLINE_VISIBILITY
870 explicit
871 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000872 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000873
Eric Fiselier737a16d2016-07-25 02:36:42 +0000874 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
875 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
876
877 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000878 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000879 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
880 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000881 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000882 return *this;
883 }
884
885 _LIBCPP_INLINE_VISIBILITY
886 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
887 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
888 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000889 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000890 return *this;
891 }
892
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 template <class _Tuple,
894 class = typename enable_if
895 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000896 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 >::type
898 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000901 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000903 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 return *this;
905 }
906
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000908 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000909 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910};
911
912template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000913class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914{
915public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000916 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000917 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000920 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000923 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000924 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000926 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000927 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000929 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000931 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932};
933
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000934#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Eric Fiselier9a5075c2017-06-08 07:18:17 +0000935// NOTE: These are not yet standardized, but are required to simulate the
936// implicit deduction guide that should be generated had libc++ declared the
937// tuple-like constructors "correctly"
938template <class _Alloc, class ..._Args>
939tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
940template <class _Alloc, class ..._Args>
941tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
942#endif
943
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944template <class ..._Tp>
945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000946typename enable_if
947<
948 __all<__is_swappable<_Tp>::value...>::value,
949 void
950>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +0000951swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
952 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
953 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954
955// get
956
957template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000958inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000959typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000960get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000962 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000963 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964}
965
966template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000967inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000968const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000969get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000971 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000972 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973}
974
Howard Hinnant22e97242010-11-17 19:52:17 +0000975template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000976inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000977typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +0000978get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000979{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000980 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +0000981 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000982 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +0000983}
984
Eric Fiselier6dea8092015-12-18 00:36:55 +0000985template <size_t _Ip, class ..._Tp>
986inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
987const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
988get(const tuple<_Tp...>&& __t) _NOEXCEPT
989{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000990 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000991 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000992 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +0000993}
994
Marshall Clow15b02e02013-07-13 02:54:05 +0000995#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +0000996
Eric Fiselier2d0e2042016-07-02 03:18:30 +0000997namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +0000998
Eric Fiselier2d0e2042016-07-02 03:18:30 +0000999static constexpr size_t __not_found = -1;
1000static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001001
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001002inline _LIBCPP_INLINE_VISIBILITY
1003constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1004 return !__matches ? __res :
1005 (__res == __not_found ? __curr_i : __ambiguous);
1006}
Marshall Clow15b02e02013-07-13 02:54:05 +00001007
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001008template <size_t _Nx>
1009inline _LIBCPP_INLINE_VISIBILITY
1010constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1011 return __i == _Nx ? __not_found :
1012 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1013}
1014
1015template <class _T1, class ..._Args>
1016struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001017 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001018 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001019 static_assert(value != __not_found, "type not found in type list" );
1020 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001021};
1022
Eric Fiselier8087d302016-07-02 03:46:08 +00001023template <class _T1>
1024struct __find_exactly_one_checked<_T1> {
1025 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1026};
1027
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001028} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001029
1030template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001031struct __find_exactly_one_t
1032 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1033};
Marshall Clow15b02e02013-07-13 02:54:05 +00001034
1035template <class _T1, class... _Args>
1036inline _LIBCPP_INLINE_VISIBILITY
1037constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1038{
1039 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1040}
1041
1042template <class _T1, class... _Args>
1043inline _LIBCPP_INLINE_VISIBILITY
1044constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1045{
1046 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1047}
1048
1049template <class _T1, class... _Args>
1050inline _LIBCPP_INLINE_VISIBILITY
1051constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1052{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001053 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001054}
1055
Eric Fiselier6dea8092015-12-18 00:36:55 +00001056template <class _T1, class... _Args>
1057inline _LIBCPP_INLINE_VISIBILITY
1058constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1059{
1060 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1061}
1062
Marshall Clow15b02e02013-07-13 02:54:05 +00001063#endif
1064
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065// tie
1066
1067template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001068inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001070tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071{
1072 return tuple<_Tp&...>(__t...);
1073}
1074
1075template <class _Up>
1076struct __ignore_t
1077{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1080 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081};
1082
Eric Fiselier24e70262017-02-06 01:25:31 +00001083namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001084 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001085}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001088inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001089tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090make_tuple(_Tp&&... __t)
1091{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001092 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093}
1094
Howard Hinnant3d203a32010-08-19 18:59:38 +00001095template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001096inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1097tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001098forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001099{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001100 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001101}
1102
Howard Hinnantc834c512011-11-29 18:15:50 +00001103template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104struct __tuple_equal
1105{
1106 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 bool operator()(const _Tp& __x, const _Up& __y)
1109 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001110 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 }
1112};
1113
1114template <>
1115struct __tuple_equal<0>
1116{
1117 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 bool operator()(const _Tp&, const _Up&)
1120 {
1121 return true;
1122 }
1123};
1124
1125template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001126inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127bool
1128operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1129{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001130 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1132}
1133
1134template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001135inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136bool
1137operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1138{
1139 return !(__x == __y);
1140}
1141
Howard Hinnantc834c512011-11-29 18:15:50 +00001142template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143struct __tuple_less
1144{
1145 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001146 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 bool operator()(const _Tp& __x, const _Up& __y)
1148 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001149 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1150 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1151 return true;
1152 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1153 return false;
1154 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155 }
1156};
1157
1158template <>
1159struct __tuple_less<0>
1160{
1161 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163 bool operator()(const _Tp&, const _Up&)
1164 {
1165 return false;
1166 }
1167};
1168
1169template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171bool
1172operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1173{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001174 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1176}
1177
1178template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001179inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180bool
1181operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1182{
1183 return __y < __x;
1184}
1185
1186template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001187inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188bool
1189operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1190{
1191 return !(__x < __y);
1192}
1193
1194template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001195inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196bool
1197operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1198{
1199 return !(__y < __x);
1200}
1201
1202// tuple_cat
1203
Howard Hinnant6256ee72010-12-11 20:47:50 +00001204template <class _Tp, class _Up> struct __tuple_cat_type;
1205
1206template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001207struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001209 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001210};
1211
1212template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1213struct __tuple_cat_return_1
1214{
1215};
1216
1217template <class ..._Types, class _Tuple0>
1218struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1219{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001220 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001221 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001222 type;
1223};
1224
1225template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1226struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1227 : public __tuple_cat_return_1<
1228 typename __tuple_cat_type<
1229 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001230 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001231 >::type,
1232 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1233 _Tuple1, _Tuples...>
1234{
1235};
1236
1237template <class ..._Tuples> struct __tuple_cat_return;
1238
1239template <class _Tuple0, class ..._Tuples>
1240struct __tuple_cat_return<_Tuple0, _Tuples...>
1241 : public __tuple_cat_return_1<tuple<>,
1242 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1243 _Tuples...>
1244{
1245};
1246
1247template <>
1248struct __tuple_cat_return<>
1249{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001250 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001251};
1252
Marshall Clow2229cee2013-07-22 16:02:19 +00001253inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001254tuple<>
1255tuple_cat()
1256{
1257 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258}
1259
Howard Hinnantc834c512011-11-29 18:15:50 +00001260template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001261struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262
Howard Hinnant21376f62010-12-12 23:04:37 +00001263template <class ..._Types, size_t ..._I0, class _Tuple0>
1264struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001266 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001267 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1268 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1269};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270
Howard Hinnant21376f62010-12-12 23:04:37 +00001271template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1272struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1273 _Tuple0, _Tuple1, _Tuples...>
1274 : public __tuple_cat_return_ref_imp<
1275 tuple<_Types..., typename __apply_cv<_Tuple0,
1276 typename tuple_element<_I0,
1277 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1278 typename __make_tuple_indices<tuple_size<typename
1279 remove_reference<_Tuple1>::type>::value>::type,
1280 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281{
Howard Hinnant21376f62010-12-12 23:04:37 +00001282};
1283
1284template <class _Tuple0, class ..._Tuples>
1285struct __tuple_cat_return_ref
1286 : public __tuple_cat_return_ref_imp<tuple<>,
1287 typename __make_tuple_indices<
1288 tuple_size<typename remove_reference<_Tuple0>::type>::value
1289 >::type, _Tuple0, _Tuples...>
1290{
1291};
1292
1293template <class _Types, class _I0, class _J0>
1294struct __tuple_cat;
1295
1296template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001297struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001298{
1299 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001301 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1302 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1303 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001304 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1305 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001306 }
1307
1308 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001310 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1311 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1312 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001313 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1314 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001315 return __tuple_cat<
1316 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1317 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1318 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowded420b2013-10-05 18:46:37 +00001319 (forward_as_tuple(
Marshall Clow60e4aa72014-06-24 00:46:19 +00001320 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1321 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnant21376f62010-12-12 23:04:37 +00001322 ),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001323 _VSTD::forward<_Tuple1>(__t1),
1324 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001325 }
1326};
1327
1328template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001329inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001330typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1331tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1332{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001333 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001334 return __tuple_cat<tuple<>, __tuple_indices<>,
1335 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001336 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1337 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338}
1339
1340template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001341struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342 : true_type {};
1343
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344template <class _T1, class _T2>
1345template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1346inline _LIBCPP_INLINE_VISIBILITY
1347pair<_T1, _T2>::pair(piecewise_construct_t,
1348 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1349 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001350 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1351 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352{
1353}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354
Eric Fiselier8e892c52016-07-18 00:35:56 +00001355#if _LIBCPP_STD_VER > 14
1356template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001357_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001358
1359#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1360
1361template <class _Fn, class _Tuple, size_t ..._Id>
1362inline _LIBCPP_INLINE_VISIBILITY
1363constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1364 __tuple_indices<_Id...>)
1365_LIBCPP_NOEXCEPT_RETURN(
1366 _VSTD::__invoke_constexpr(
1367 _VSTD::forward<_Fn>(__f),
1368 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1369)
1370
1371template <class _Fn, class _Tuple>
1372inline _LIBCPP_INLINE_VISIBILITY
1373constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1374_LIBCPP_NOEXCEPT_RETURN(
1375 _VSTD::__apply_tuple_impl(
1376 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001377 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001378)
1379
1380template <class _Tp, class _Tuple, size_t... _Idx>
1381inline _LIBCPP_INLINE_VISIBILITY
1382constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1383_LIBCPP_NOEXCEPT_RETURN(
1384 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1385)
1386
1387template <class _Tp, class _Tuple>
1388inline _LIBCPP_INLINE_VISIBILITY
1389constexpr _Tp make_from_tuple(_Tuple&& __t)
1390_LIBCPP_NOEXCEPT_RETURN(
1391 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001392 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001393)
1394
1395#undef _LIBCPP_NOEXCEPT_RETURN
1396
1397#endif // _LIBCPP_STD_VER > 14
1398
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001399#endif // !defined(_LIBCPP_CXX03_LANG)
1400
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401_LIBCPP_END_NAMESPACE_STD
1402
1403#endif // _LIBCPP_TUPLE