blob: 031d25a9854fced8eee48fbe0aba1777ea002c04 [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
Eric Fiselierec5a2102019-07-12 23:01:48 +0000604 template <class _Tuple, bool _DisableIfLValue>
605 using _EnableImplicitTupleLikeConstructor = _EnableIf<
606 _CheckTupleLikeConstructor<
607 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
608 && !_PackExpandsToThisTuple<_Tuple>::value
609 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
610 >::template __enable_implicit<_Tuple>(),
611 bool
612 >;
613
614 template <class _Tuple, bool _DisableIfLValue>
615 using _EnableExplicitTupleLikeConstructor = _EnableIf<
616 _CheckTupleLikeConstructor<
617 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
618 && !_PackExpandsToThisTuple<_Tuple>::value
619 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
620 >::template __enable_explicit<_Tuple>(),
621 bool
622 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000623 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000624 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000625 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000626 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000627 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000628 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000629 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
630 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631public:
632
Eric Fiseliercba58302015-02-21 02:30:41 +0000633 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere61db632016-07-25 04:32:07 +0000634 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowc470eae2014-10-15 10:33:02 +0000635 >::type>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000637 _LIBCPP_CONSTEXPR tuple()
638 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000639
Eric Fiselier737a16d2016-07-25 02:36:42 +0000640 tuple(tuple const&) = default;
641 tuple(tuple&&) = default;
642
Eric Fiselier3906a132019-06-23 20:28:29 +0000643 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf<
644 _And<
645 _IsSame<allocator_arg_t, _AllocArgT>,
646 __dependent_type<is_default_constructible<_Tp>, _Dummy>...
Eric Fiselierc170df52016-04-15 03:29:40 +0000647 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000648 >
649 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000650 _LIBCPP_INLINE_VISIBILITY
651 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000652 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000653 __tuple_indices<>(), __tuple_types<>(),
654 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
655 __tuple_types<_Tp...>()) {}
656
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000657 template <bool _Dummy = true,
658 typename enable_if
659 <
660 _CheckArgsConstructor<
661 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000662 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000663 bool
664 >::type = false
665 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000667 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000668 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
670 typename __make_tuple_indices<0>::type(),
671 typename __make_tuple_types<tuple, 0>::type(),
672 __t...
673 ) {}
674
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000675 template <bool _Dummy = true,
676 typename enable_if
677 <
678 _CheckArgsConstructor<
679 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000680 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000681 bool
682 >::type = false
683 >
684 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
685 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000686 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000687 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
693 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_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000699 bool
700 >::type = false
701 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000704 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
706 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
707 typename __make_tuple_indices<0>::type(),
708 typename __make_tuple_types<tuple, 0>::type(),
709 __t...
710 ) {}
711
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000712 template <class _Alloc, bool _Dummy = true,
713 typename enable_if
714 <
715 _CheckArgsConstructor<
716 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000717 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000718 bool
719 >::type = false
720 >
721 _LIBCPP_INLINE_VISIBILITY
722 explicit
723 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000724 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000725 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
726 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
727 typename __make_tuple_indices<0>::type(),
728 typename __make_tuple_types<tuple, 0>::type(),
729 __t...
730 ) {}
731
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000733 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000734 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000736 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000737 sizeof...(_Up) == sizeof...(_Tp)
738 && !_PackIsTuple
739 >::template __enable_implicit<_Up...>() ||
740 _CheckArgsConstructor<
741 _EnableImplicitReducedArityExtension
742 && sizeof...(_Up) < sizeof...(_Tp)
743 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000744 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000745 bool
746 >::type = false
747 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000748 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000749 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000750 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000751 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000752 typename __make_tuple_indices<sizeof...(_Up)>::type,
753 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
754 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
755 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000756 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000757 >::value
758 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000759 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000760 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
761 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
762 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
763 _VSTD::forward<_Up>(__u)...) {}
764
765 template <class ..._Up,
766 typename enable_if
767 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000768 _CheckArgsConstructor<
769 sizeof...(_Up) <= sizeof...(_Tp)
770 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000771 >::template __enable_explicit<_Up...>() ||
772 _CheckArgsConstructor<
773 !_EnableImplicitReducedArityExtension
774 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000775 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000776 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000777 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000778 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000780 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 explicit
782 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000783 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000784 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000785 typename __make_tuple_indices<sizeof...(_Up)>::type,
786 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
787 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
788 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
789 _Up...
790 >::value
791 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000792 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793 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
798 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000799 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000801 _CheckArgsConstructor<
802 sizeof...(_Up) == sizeof...(_Tp) &&
803 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000804 >::template __enable_implicit<_Up...>(),
805 bool
806 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000810 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811 typename __make_tuple_indices<sizeof...(_Up)>::type(),
812 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
813 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
814 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000815 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000817 template <class _Alloc, class ..._Up,
818 typename enable_if
819 <
820 _CheckArgsConstructor<
821 sizeof...(_Up) == sizeof...(_Tp) &&
822 !_PackExpandsToThisTuple<_Up...>::value
823 >::template __enable_explicit<_Up...>(),
824 bool
825 >::type = false
826 >
827 _LIBCPP_INLINE_VISIBILITY
828 explicit
829 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000830 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000831 typename __make_tuple_indices<sizeof...(_Up)>::type(),
832 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
833 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
834 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
835 _VSTD::forward<_Up>(__u)...) {}
836
Eric Fiselierec5a2102019-07-12 23:01:48 +0000837 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000838 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000839 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
840 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841
Eric Fiselierec5a2102019-07-12 23:01:48 +0000842 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
843 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
844 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
845 : __base_(__t) {}
846 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000847 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000848 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000849 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
850 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000851
Eric Fiselierec5a2102019-07-12 23:01:48 +0000852 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
853 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
854 explicit
855 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
856 : __base_(__t) {}
857
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000859 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000861 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000862 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
863 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000864 bool
865 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000869 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000871 template <class _Alloc, class _Tuple,
872 typename enable_if
873 <
874 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000875 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
876 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000877 bool
878 >::type = false
879 >
880 _LIBCPP_INLINE_VISIBILITY
881 explicit
882 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000883 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000884
Eric Fiselier737a16d2016-07-25 02:36:42 +0000885 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
886 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
887
888 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000889 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000890 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
891 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000892 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000893 return *this;
894 }
895
896 _LIBCPP_INLINE_VISIBILITY
897 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
898 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
899 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000900 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000901 return *this;
902 }
903
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 template <class _Tuple,
905 class = typename enable_if
906 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000907 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 >::type
909 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000912 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000914 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 return *this;
916 }
917
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000919 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000920 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921};
922
923template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000924class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925{
926public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000927 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000928 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000931 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000934 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000935 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000937 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000938 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000940 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000942 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943};
944
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000945#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Eric Fiselier9a5075c2017-06-08 07:18:17 +0000946// NOTE: These are not yet standardized, but are required to simulate the
947// implicit deduction guide that should be generated had libc++ declared the
948// tuple-like constructors "correctly"
949template <class _Alloc, class ..._Args>
950tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>;
951template <class _Alloc, class ..._Args>
952tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>;
953#endif
954
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955template <class ..._Tp>
956inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000957typename enable_if
958<
959 __all<__is_swappable<_Tp>::value...>::value,
960 void
961>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +0000962swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
963 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
964 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965
966// get
967
968template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000969inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000970typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000971get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000973 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000974 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975}
976
977template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000978inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000979const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +0000980get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000982 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000983 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984}
985
Howard Hinnant22e97242010-11-17 19:52:17 +0000986template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +0000987inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000988typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +0000989get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000990{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000991 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +0000992 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000993 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +0000994}
995
Eric Fiselier6dea8092015-12-18 00:36:55 +0000996template <size_t _Ip, class ..._Tp>
997inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
998const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
999get(const tuple<_Tp...>&& __t) _NOEXCEPT
1000{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001001 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001002 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001003 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001004}
1005
Marshall Clow15b02e02013-07-13 02:54:05 +00001006#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001007
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001008namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001009
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001010static constexpr size_t __not_found = -1;
1011static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001012
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001013inline _LIBCPP_INLINE_VISIBILITY
1014constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1015 return !__matches ? __res :
1016 (__res == __not_found ? __curr_i : __ambiguous);
1017}
Marshall Clow15b02e02013-07-13 02:54:05 +00001018
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001019template <size_t _Nx>
1020inline _LIBCPP_INLINE_VISIBILITY
1021constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1022 return __i == _Nx ? __not_found :
1023 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1024}
1025
1026template <class _T1, class ..._Args>
1027struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001028 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001029 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001030 static_assert(value != __not_found, "type not found in type list" );
1031 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001032};
1033
Eric Fiselier8087d302016-07-02 03:46:08 +00001034template <class _T1>
1035struct __find_exactly_one_checked<_T1> {
1036 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1037};
1038
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001039} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001040
1041template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001042struct __find_exactly_one_t
1043 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1044};
Marshall Clow15b02e02013-07-13 02:54:05 +00001045
1046template <class _T1, class... _Args>
1047inline _LIBCPP_INLINE_VISIBILITY
1048constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1049{
1050 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1051}
1052
1053template <class _T1, class... _Args>
1054inline _LIBCPP_INLINE_VISIBILITY
1055constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1056{
1057 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1058}
1059
1060template <class _T1, class... _Args>
1061inline _LIBCPP_INLINE_VISIBILITY
1062constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1063{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001064 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001065}
1066
Eric Fiselier6dea8092015-12-18 00:36:55 +00001067template <class _T1, class... _Args>
1068inline _LIBCPP_INLINE_VISIBILITY
1069constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1070{
1071 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1072}
1073
Marshall Clow15b02e02013-07-13 02:54:05 +00001074#endif
1075
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076// tie
1077
1078template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001079inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001081tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082{
1083 return tuple<_Tp&...>(__t...);
1084}
1085
1086template <class _Up>
1087struct __ignore_t
1088{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1091 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092};
1093
Eric Fiselier24e70262017-02-06 01:25:31 +00001094namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001095 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001096}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001099inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001100tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101make_tuple(_Tp&&... __t)
1102{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001103 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104}
1105
Howard Hinnant3d203a32010-08-19 18:59:38 +00001106template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001107inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1108tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001109forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001110{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001111 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001112}
1113
Howard Hinnantc834c512011-11-29 18:15:50 +00001114template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115struct __tuple_equal
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& __x, const _Up& __y)
1120 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001121 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122 }
1123};
1124
1125template <>
1126struct __tuple_equal<0>
1127{
1128 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 bool operator()(const _Tp&, const _Up&)
1131 {
1132 return true;
1133 }
1134};
1135
1136template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001137inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138bool
1139operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1140{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001141 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1143}
1144
1145template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001146inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147bool
1148operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1149{
1150 return !(__x == __y);
1151}
1152
Howard Hinnantc834c512011-11-29 18:15:50 +00001153template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154struct __tuple_less
1155{
1156 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 bool operator()(const _Tp& __x, const _Up& __y)
1159 {
Duncan P. N. Exon Smith6d3ec092015-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 Hinnantc51e1022010-05-11 19:42:16 +00001166 }
1167};
1168
1169template <>
1170struct __tuple_less<0>
1171{
1172 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-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 Clow2229cee2013-07-22 16:02:19 +00001181inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182bool
1183operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1184{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001185 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1187}
1188
1189template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001190inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191bool
1192operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1193{
1194 return __y < __x;
1195}
1196
1197template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001198inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199bool
1200operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1201{
1202 return !(__x < __y);
1203}
1204
1205template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001206inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207bool
1208operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1209{
1210 return !(__y < __x);
1211}
1212
1213// tuple_cat
1214
Howard Hinnant6256ee72010-12-11 20:47:50 +00001215template <class _Tp, class _Up> struct __tuple_cat_type;
1216
1217template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001218struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001220 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001221};
1222
1223template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1224struct __tuple_cat_return_1
1225{
1226};
1227
1228template <class ..._Types, class _Tuple0>
1229struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1230{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001231 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001232 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001233 type;
1234};
1235
1236template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1237struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1238 : public __tuple_cat_return_1<
1239 typename __tuple_cat_type<
1240 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001241 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001242 >::type,
1243 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1244 _Tuple1, _Tuples...>
1245{
1246};
1247
1248template <class ..._Tuples> struct __tuple_cat_return;
1249
1250template <class _Tuple0, class ..._Tuples>
1251struct __tuple_cat_return<_Tuple0, _Tuples...>
1252 : public __tuple_cat_return_1<tuple<>,
1253 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1254 _Tuples...>
1255{
1256};
1257
1258template <>
1259struct __tuple_cat_return<>
1260{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001261 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001262};
1263
Marshall Clow2229cee2013-07-22 16:02:19 +00001264inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001265tuple<>
1266tuple_cat()
1267{
1268 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269}
1270
Howard Hinnantc834c512011-11-29 18:15:50 +00001271template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001272struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273
Howard Hinnant21376f62010-12-12 23:04:37 +00001274template <class ..._Types, size_t ..._I0, class _Tuple0>
1275struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001276{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001277 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001278 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1279 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1280};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281
Howard Hinnant21376f62010-12-12 23:04:37 +00001282template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1283struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1284 _Tuple0, _Tuple1, _Tuples...>
1285 : public __tuple_cat_return_ref_imp<
1286 tuple<_Types..., typename __apply_cv<_Tuple0,
1287 typename tuple_element<_I0,
1288 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1289 typename __make_tuple_indices<tuple_size<typename
1290 remove_reference<_Tuple1>::type>::value>::type,
1291 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292{
Howard Hinnant21376f62010-12-12 23:04:37 +00001293};
1294
1295template <class _Tuple0, class ..._Tuples>
1296struct __tuple_cat_return_ref
1297 : public __tuple_cat_return_ref_imp<tuple<>,
1298 typename __make_tuple_indices<
1299 tuple_size<typename remove_reference<_Tuple0>::type>::value
1300 >::type, _Tuple0, _Tuples...>
1301{
1302};
1303
1304template <class _Types, class _I0, class _J0>
1305struct __tuple_cat;
1306
1307template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001308struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001309{
1310 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001312 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1313 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1314 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001315 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1316 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001317 }
1318
1319 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001320 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001321 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1322 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1323 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001324 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1325 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001326 return __tuple_cat<
1327 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1328 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1329 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowded420b2013-10-05 18:46:37 +00001330 (forward_as_tuple(
Marshall Clow60e4aa72014-06-24 00:46:19 +00001331 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1332 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnant21376f62010-12-12 23:04:37 +00001333 ),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001334 _VSTD::forward<_Tuple1>(__t1),
1335 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001336 }
1337};
1338
1339template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001340inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001341typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1342tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1343{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001344 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001345 return __tuple_cat<tuple<>, __tuple_indices<>,
1346 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001347 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1348 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349}
1350
1351template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001352struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001353 : true_type {};
1354
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355template <class _T1, class _T2>
1356template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1357inline _LIBCPP_INLINE_VISIBILITY
1358pair<_T1, _T2>::pair(piecewise_construct_t,
1359 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1360 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001361 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1362 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363{
1364}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365
Eric Fiselier8e892c52016-07-18 00:35:56 +00001366#if _LIBCPP_STD_VER > 14
1367template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001368_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001369
1370#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1371
1372template <class _Fn, class _Tuple, size_t ..._Id>
1373inline _LIBCPP_INLINE_VISIBILITY
1374constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1375 __tuple_indices<_Id...>)
1376_LIBCPP_NOEXCEPT_RETURN(
1377 _VSTD::__invoke_constexpr(
1378 _VSTD::forward<_Fn>(__f),
1379 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1380)
1381
1382template <class _Fn, class _Tuple>
1383inline _LIBCPP_INLINE_VISIBILITY
1384constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1385_LIBCPP_NOEXCEPT_RETURN(
1386 _VSTD::__apply_tuple_impl(
1387 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001388 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001389)
1390
1391template <class _Tp, class _Tuple, size_t... _Idx>
1392inline _LIBCPP_INLINE_VISIBILITY
1393constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1394_LIBCPP_NOEXCEPT_RETURN(
1395 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1396)
1397
1398template <class _Tp, class _Tuple>
1399inline _LIBCPP_INLINE_VISIBILITY
1400constexpr _Tp make_from_tuple(_Tuple&& __t)
1401_LIBCPP_NOEXCEPT_RETURN(
1402 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001403 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001404)
1405
1406#undef _LIBCPP_NOEXCEPT_RETURN
1407
1408#endif // _LIBCPP_STD_VER > 14
1409
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001410#endif // !defined(_LIBCPP_CXX03_LANG)
1411
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412_LIBCPP_END_NAMESPACE_STD
1413
1414#endif // _LIBCPP_TUPLE