blob: c4cd3bc54957203b3d534b95820c4cffbe9bf400 [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:
Louis Dionnea7a2beb2019-09-26 14:51:10 +000022 explicit(see-below) constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) 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>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) 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>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) 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>
Louis Dionne1afad1d2019-07-22 20:45:23 +000041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 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>
Louis Dionne1afad1d2019-07-22 20:45:23 +000049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
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
Louis Dionne616da2a2019-08-12 18:30:31 +000072template <class ...T>
73tuple(T...) -> tuple<T...>; // since C++17
74template <class T1, class T2>
75tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
76template <class Alloc, class ...T>
77tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
78template <class Alloc, class T1, class T2>
79tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
80template <class Alloc, class ...T>
81tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
82
Marshall Clowf1bf62f2018-01-02 17:17:01 +000083inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000084
Marshall Clow2229cee2013-07-22 16:02:19 +000085template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000086template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000087template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000088template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000089
90// [tuple.apply], calling a function with a tuple of arguments:
91template <class F, class Tuple>
92 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
93template <class T, class Tuple>
94 constexpr T make_from_tuple(Tuple&& t); // C++17
95
Howard Hinnantc51e1022010-05-11 19:42:16 +000096// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +000097template <class T> struct tuple_size; // undefined
98template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +000099template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000100 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000101template <size_t I, class T> struct tuple_element; // undefined
102template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000103template <size_t I, class T>
104 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000107template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000108 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000109 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000110template <size_t I, class... T>
111 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000112 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000113template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000114 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000115 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000116template <size_t I, class... T>
117 const typename tuple_element<I, tuple<T...>>::type&&
118 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119
Marshall Clow15b02e02013-07-13 02:54:05 +0000120template <class T1, class... T>
121 constexpr T1& get(tuple<T...>&) noexcept; // C++14
122template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000123 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000124template <class T1, class... T>
125 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000126template <class T1, class... T>
127 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000128
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000130template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
131template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
132template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
133template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
134template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
135template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
137template <class... Types, class Alloc>
138 struct uses_allocator<tuple<Types...>, Alloc>;
139
140template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000141 void
142 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144} // std
145
146*/
147
148#include <__config>
149#include <__tuple>
150#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000152#include <__functional_base>
153#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000154#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000156#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000158#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159
160_LIBCPP_BEGIN_NAMESPACE_STD
161
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000162#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Marshall Clowf50d66f2014-03-03 06:18:11 +0000164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165// __tuple_leaf
166
Eric Fiselierf7394302015-06-13 07:08:02 +0000167template <size_t _Ip, class _Hp,
168 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000169 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170class __tuple_leaf;
171
172template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000175 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176{
177 swap(__x.get(), __y.get());
178}
179
180template <size_t _Ip, class _Hp, bool>
181class __tuple_leaf
182{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000183 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184
Eric Fiselierca8bba12016-07-20 02:57:39 +0000185 template <class _Tp>
186 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000187#if __has_keyword(__reference_binds_to_temporary)
188 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000189#else
190 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000191#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000192 }
193
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194 __tuple_leaf& operator=(const __tuple_leaf&);
195public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000197 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 {static_assert(!is_reference<_Hp>::value,
199 "Attempted to default construct a reference element in a tuple");}
200
201 template <class _Alloc>
202 _LIBCPP_INLINE_VISIBILITY
203 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000204 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205 {static_assert(!is_reference<_Hp>::value,
206 "Attempted to default construct a reference element in a tuple");}
207
208 template <class _Alloc>
209 _LIBCPP_INLINE_VISIBILITY
210 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000211 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 {static_assert(!is_reference<_Hp>::value,
213 "Attempted to default construct a reference element in a tuple");}
214
215 template <class _Alloc>
216 _LIBCPP_INLINE_VISIBILITY
217 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000218 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 {static_assert(!is_reference<_Hp>::value,
220 "Attempted to default construct a reference element in a tuple");}
221
Howard Hinnant693fc212010-09-27 17:54:17 +0000222 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000223 class = _EnableIf<
224 _And<
225 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
226 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000227 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000228 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000229 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000231 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000232 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000233 {static_assert(__can_bind_reference<_Tp&&>(),
234 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235
236 template <class _Tp, class _Alloc>
237 _LIBCPP_INLINE_VISIBILITY
238 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000239 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000240 {static_assert(__can_bind_reference<_Tp&&>(),
241 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242
243 template <class _Tp, class _Alloc>
244 _LIBCPP_INLINE_VISIBILITY
245 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000246 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000247 {static_assert(!is_reference<_Hp>::value,
248 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249
250 template <class _Tp, class _Alloc>
251 _LIBCPP_INLINE_VISIBILITY
252 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000253 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000254 {static_assert(!is_reference<_Hp>::value,
255 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256
Marshall Clow47fcee52014-04-21 23:48:09 +0000257 __tuple_leaf(const __tuple_leaf& __t) = default;
258 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259
260 template <class _Tp>
261 _LIBCPP_INLINE_VISIBILITY
262 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000263 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000265 __value_ = _VSTD::forward<_Tp>(__t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 return *this;
267 }
268
269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000270 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000272 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 return 0;
274 }
275
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278};
279
280template <size_t _Ip, class _Hp>
281class __tuple_leaf<_Ip, _Hp, true>
282 : private _Hp
283{
284
285 __tuple_leaf& operator=(const __tuple_leaf&);
286public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
288 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290 template <class _Alloc>
291 _LIBCPP_INLINE_VISIBILITY
292 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
293
294 template <class _Alloc>
295 _LIBCPP_INLINE_VISIBILITY
296 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
297 : _Hp(allocator_arg_t(), __a) {}
298
299 template <class _Alloc>
300 _LIBCPP_INLINE_VISIBILITY
301 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
302 : _Hp(__a) {}
303
Howard Hinnant693fc212010-09-27 17:54:17 +0000304 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000305 class = _EnableIf<
306 _And<
307 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
308 is_constructible<_Hp, _Tp>
309 >::value
310 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000311 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000313 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000314 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315
316 template <class _Tp, class _Alloc>
317 _LIBCPP_INLINE_VISIBILITY
318 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000319 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
321 template <class _Tp, class _Alloc>
322 _LIBCPP_INLINE_VISIBILITY
323 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000324 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325
326 template <class _Tp, class _Alloc>
327 _LIBCPP_INLINE_VISIBILITY
328 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000329 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000331 __tuple_leaf(__tuple_leaf const &) = default;
332 __tuple_leaf(__tuple_leaf &&) = default;
333
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 template <class _Tp>
335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 __tuple_leaf&
Howard Hinnant62751642012-07-06 21:53:48 +0000337 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000339 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 return *this;
341 }
342
Howard Hinnant89ef1212011-05-27 19:08:18 +0000343 _LIBCPP_INLINE_VISIBILITY
344 int
345 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000347 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 return 0;
349 }
350
Marshall Clow2229cee2013-07-22 16:02:19 +0000351 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
352 _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 +0000353};
354
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000355template <class ..._Tp>
356_LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000357void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358
Marshall Clowc470eae2014-10-15 10:33:02 +0000359template <class _Tp>
360struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000361
Marshall Clowc470eae2014-10-15 10:33:02 +0000362template <class ..._Tp>
363struct __all_default_constructible<__tuple_types<_Tp...>>
364 : __all<is_default_constructible<_Tp>::value...>
365{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000366
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367// __tuple_impl
368
369template<class _Indx, class ..._Tp> struct __tuple_impl;
370
371template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000372struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 : public __tuple_leaf<_Indx, _Tp>...
374{
Howard Hinnant38469632012-07-06 20:39:45 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000376 _LIBCPP_CONSTEXPR __tuple_impl()
377 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000378
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379 template <size_t ..._Uf, class ..._Tf,
380 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000381 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 explicit
383 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
384 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000385 _Up&&... __u)
386 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
387 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000388 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389 __tuple_leaf<_Ul, _Tl>()...
390 {}
391
392 template <class _Alloc, size_t ..._Uf, class ..._Tf,
393 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 explicit
396 __tuple_impl(allocator_arg_t, const _Alloc& __a,
397 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
398 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
399 _Up&&... __u) :
400 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000401 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
403 {}
404
405 template <class _Tuple,
406 class = typename enable_if
407 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000408 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 >::type
410 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000412 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
413 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000414 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
415 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 {}
417
418 template <class _Alloc, class _Tuple,
419 class = typename enable_if
420 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000421 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 >::type
423 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
426 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000427 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000428 _VSTD::forward<typename tuple_element<_Indx,
429 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 {}
431
432 template <class _Tuple>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 typename enable_if
435 <
Howard Hinnant3a47c3d2011-01-24 16:07:25 +0000436 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 __tuple_impl&
438 >::type
Howard Hinnant62751642012-07-06 21:53:48 +0000439 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000442 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
443 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 return *this;
445 }
446
Howard Hinnant0d032d12013-11-06 17:45:43 +0000447 __tuple_impl(const __tuple_impl&) = default;
448 __tuple_impl(__tuple_impl&&) = default;
449
450 _LIBCPP_INLINE_VISIBILITY
451 __tuple_impl&
452 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
453 {
454 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
455 return *this;
456 }
457
458 _LIBCPP_INLINE_VISIBILITY
459 __tuple_impl&
460 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
461 {
462 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
463 return *this;
464 }
Howard Hinnantbcb62c62012-02-15 20:13:52 +0000465
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000468 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 {
470 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
471 }
472};
473
Eric Fiselier264d04a2016-04-15 18:05:59 +0000474
Eric Fiselier264d04a2016-04-15 18:05:59 +0000475
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000477class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000479 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000481 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482
Eric Fiselier41b686e2016-12-08 23:57:08 +0000483#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
484 static constexpr bool _EnableImplicitReducedArityExtension = true;
485#else
486 static constexpr bool _EnableImplicitReducedArityExtension = false;
487#endif
488
Eric Fiselier264d04a2016-04-15 18:05:59 +0000489 template <class ..._Args>
490 struct _PackExpandsToThisTuple : false_type {};
491
492 template <class _Arg>
493 struct _PackExpandsToThisTuple<_Arg>
494 : is_same<typename __uncvref<_Arg>::type, tuple> {};
495
496 template <bool _MaybeEnable, class _Dummy = void>
497 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
498
499 template <class _Dummy>
500 struct _CheckArgsConstructor<true, _Dummy>
501 {
502 template <class ..._Args>
Louis Dionne668a50c2019-09-27 15:06:52 +0000503 struct __enable_implicit_default
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000504 // In C++03, there's no way to implement the resolution of LWG2510.
505#ifdef _LIBCPP_CXX03_LANG
Louis Dionne668a50c2019-09-27 15:06:52 +0000506 : true_type
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000507#else
Louis Dionne668a50c2019-09-27 15:06:52 +0000508 : __all<__is_implicitly_default_constructible<_Args>::value...>
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000509#endif
Louis Dionne668a50c2019-09-27 15:06:52 +0000510 { };
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000511
512 template <class ..._Args>
Louis Dionne668a50c2019-09-27 15:06:52 +0000513 struct __enable_explicit_default
514 : integral_constant<bool,
515 __all<is_default_constructible<_Args>::value...>::value &&
516 !__enable_implicit_default<_Args...>::value
517 >
518 { };
Eric Fiseliere61db632016-07-25 04:32:07 +0000519
520 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000521 static constexpr bool __enable_explicit() {
522 return
523 __tuple_constructible<
524 tuple<_Args...>,
525 typename __make_tuple_types<tuple,
526 sizeof...(_Args) < sizeof...(_Tp) ?
527 sizeof...(_Args) :
528 sizeof...(_Tp)>::type
529 >::value &&
530 !__tuple_convertible<
531 tuple<_Args...>,
532 typename __make_tuple_types<tuple,
533 sizeof...(_Args) < sizeof...(_Tp) ?
534 sizeof...(_Args) :
535 sizeof...(_Tp)>::type
536 >::value &&
537 __all_default_constructible<
538 typename __make_tuple_types<tuple, sizeof...(_Tp),
539 sizeof...(_Args) < sizeof...(_Tp) ?
540 sizeof...(_Args) :
541 sizeof...(_Tp)>::type
542 >::value;
543 }
544
545 template <class ..._Args>
546 static constexpr bool __enable_implicit() {
547 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000548 __tuple_constructible<
549 tuple<_Args...>,
550 typename __make_tuple_types<tuple,
551 sizeof...(_Args) < sizeof...(_Tp) ?
552 sizeof...(_Args) :
553 sizeof...(_Tp)>::type
554 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000555 __tuple_convertible<
556 tuple<_Args...>,
557 typename __make_tuple_types<tuple,
558 sizeof...(_Args) < sizeof...(_Tp) ?
559 sizeof...(_Args) :
560 sizeof...(_Tp)>::type
561 >::value &&
562 __all_default_constructible<
563 typename __make_tuple_types<tuple, sizeof...(_Tp),
564 sizeof...(_Args) < sizeof...(_Tp) ?
565 sizeof...(_Args) :
566 sizeof...(_Tp)>::type
567 >::value;
568 }
569 };
570
571 template <bool _MaybeEnable,
572 bool = sizeof...(_Tp) == 1,
573 class _Dummy = void>
574 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
575
576 template <class _Dummy>
577 struct _CheckTupleLikeConstructor<true, false, _Dummy>
578 {
579 template <class _Tuple>
580 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000581 return __tuple_constructible<_Tuple, tuple>::value
582 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000583 }
584
585 template <class _Tuple>
586 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000587 return __tuple_constructible<_Tuple, tuple>::value
588 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000589 }
590 };
591
592 template <class _Dummy>
593 struct _CheckTupleLikeConstructor<true, true, _Dummy>
594 {
595 // This trait is used to disable the tuple-like constructor when
596 // the UTypes... constructor should be selected instead.
597 // See LWG issue #2549.
598 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000599 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000600 // Don't attempt the two checks below if the tuple we are given
601 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000602 _IsSame<__uncvref_t<_Tuple>, tuple>,
603 _Lazy<_And,
604 _Not<is_constructible<_Tp..., _Tuple>>,
605 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000606 >
607 >;
608
609 template <class _Tuple>
610 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000611 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000612 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000613 __tuple_convertible<_Tuple, tuple>,
614 _PreferTupleLikeConstructor<_Tuple>
615 >::value;
616 }
617
618 template <class _Tuple>
619 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000620 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000621 __tuple_constructible<_Tuple, tuple>,
622 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000623 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000624 >::value;
625 }
626 };
627
Eric Fiselierec5a2102019-07-12 23:01:48 +0000628 template <class _Tuple, bool _DisableIfLValue>
629 using _EnableImplicitTupleLikeConstructor = _EnableIf<
630 _CheckTupleLikeConstructor<
631 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
632 && !_PackExpandsToThisTuple<_Tuple>::value
633 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
634 >::template __enable_implicit<_Tuple>(),
635 bool
636 >;
637
638 template <class _Tuple, bool _DisableIfLValue>
639 using _EnableExplicitTupleLikeConstructor = _EnableIf<
640 _CheckTupleLikeConstructor<
641 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
642 && !_PackExpandsToThisTuple<_Tuple>::value
643 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
644 >::template __enable_explicit<_Tuple>(),
645 bool
646 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000647 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000648 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000649 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000650 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000651 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000652 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000653 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
654 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655public:
656
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000657 template <bool _Dummy = true, _EnableIf<
Louis Dionne668a50c2019-09-27 15:06:52 +0000658 _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>::value
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000659 , void*> = nullptr>
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
661 tuple()
662 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
663
664 template <bool _Dummy = true, _EnableIf<
Louis Dionne668a50c2019-09-27 15:06:52 +0000665 _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>::value
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000666 , void*> = nullptr>
667 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
668 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000669 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000670
Eric Fiselier737a16d2016-07-25 02:36:42 +0000671 tuple(tuple const&) = default;
672 tuple(tuple&&) = default;
673
Louis Dionne668a50c2019-09-27 15:06:52 +0000674 template <class _AllocArgT, class _Alloc, bool _Dummy = true, _EnableIf<
Eric Fiselier3906a132019-06-23 20:28:29 +0000675 _And<
676 _IsSame<allocator_arg_t, _AllocArgT>,
Louis Dionne668a50c2019-09-27 15:06:52 +0000677 typename _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>
Eric Fiselierc170df52016-04-15 03:29:40 +0000678 >::value
Louis Dionne668a50c2019-09-27 15:06:52 +0000679 , void*> = nullptr
Eric Fiselier3906a132019-06-23 20:28:29 +0000680 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000681 _LIBCPP_INLINE_VISIBILITY
682 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000683 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000684 __tuple_indices<>(), __tuple_types<>(),
685 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
686 __tuple_types<_Tp...>()) {}
687
Louis Dionne668a50c2019-09-27 15:06:52 +0000688 template <class _AllocArgT, class _Alloc, bool _Dummy = true, _EnableIf<
689 _And<
690 _IsSame<allocator_arg_t, _AllocArgT>,
691 typename _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>
692 >::value
693 , void*> = nullptr
694 >
695 explicit _LIBCPP_INLINE_VISIBILITY
696 tuple(_AllocArgT, _Alloc const& __a)
697 : __base_(allocator_arg_t(), __a,
698 __tuple_indices<>(), __tuple_types<>(),
699 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
700 __tuple_types<_Tp...>()) {}
701
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000702 template <bool _Dummy = true,
703 typename enable_if
704 <
705 _CheckArgsConstructor<
706 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000707 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000708 bool
709 >::type = false
710 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000711 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000712 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000713 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
715 typename __make_tuple_indices<0>::type(),
716 typename __make_tuple_types<tuple, 0>::type(),
717 __t...
718 ) {}
719
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000720 template <bool _Dummy = true,
721 typename enable_if
722 <
723 _CheckArgsConstructor<
724 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000725 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000726 bool
727 >::type = false
728 >
729 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
730 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000731 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000732 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
733 typename __make_tuple_indices<0>::type(),
734 typename __make_tuple_types<tuple, 0>::type(),
735 __t...
736 ) {}
737
738 template <class _Alloc, bool _Dummy = true,
739 typename enable_if
740 <
741 _CheckArgsConstructor<
742 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000743 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000744 bool
745 >::type = false
746 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000749 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
751 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
752 typename __make_tuple_indices<0>::type(),
753 typename __make_tuple_types<tuple, 0>::type(),
754 __t...
755 ) {}
756
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000757 template <class _Alloc, bool _Dummy = true,
758 typename enable_if
759 <
760 _CheckArgsConstructor<
761 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000762 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000763 bool
764 >::type = false
765 >
766 _LIBCPP_INLINE_VISIBILITY
767 explicit
768 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000769 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000770 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
771 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
772 typename __make_tuple_indices<0>::type(),
773 typename __make_tuple_types<tuple, 0>::type(),
774 __t...
775 ) {}
776
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000778 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000779 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000781 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000782 sizeof...(_Up) == sizeof...(_Tp)
783 && !_PackIsTuple
784 >::template __enable_implicit<_Up...>() ||
785 _CheckArgsConstructor<
786 _EnableImplicitReducedArityExtension
787 && sizeof...(_Up) < sizeof...(_Tp)
788 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000789 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000790 bool
791 >::type = false
792 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000793 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000794 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000795 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000796 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000797 typename __make_tuple_indices<sizeof...(_Up)>::type,
798 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
799 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
800 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000801 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000802 >::value
803 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000804 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000805 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
806 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
807 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
808 _VSTD::forward<_Up>(__u)...) {}
809
810 template <class ..._Up,
811 typename enable_if
812 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000813 _CheckArgsConstructor<
814 sizeof...(_Up) <= sizeof...(_Tp)
815 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000816 >::template __enable_explicit<_Up...>() ||
817 _CheckArgsConstructor<
818 !_EnableImplicitReducedArityExtension
819 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000820 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000821 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000822 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000823 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000825 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 explicit
827 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000828 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000829 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000830 typename __make_tuple_indices<sizeof...(_Up)>::type,
831 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
832 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
833 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
834 _Up...
835 >::value
836 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000837 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
839 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
840 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000841 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842
843 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000844 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000846 _CheckArgsConstructor<
847 sizeof...(_Up) == sizeof...(_Tp) &&
848 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000849 >::template __enable_implicit<_Up...>(),
850 bool
851 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000855 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 typename __make_tuple_indices<sizeof...(_Up)>::type(),
857 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
858 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
859 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000860 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000862 template <class _Alloc, class ..._Up,
863 typename enable_if
864 <
865 _CheckArgsConstructor<
866 sizeof...(_Up) == sizeof...(_Tp) &&
867 !_PackExpandsToThisTuple<_Up...>::value
868 >::template __enable_explicit<_Up...>(),
869 bool
870 >::type = false
871 >
872 _LIBCPP_INLINE_VISIBILITY
873 explicit
874 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000875 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000876 typename __make_tuple_indices<sizeof...(_Up)>::type(),
877 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
878 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
879 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
880 _VSTD::forward<_Up>(__u)...) {}
881
Eric Fiselierec5a2102019-07-12 23:01:48 +0000882 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000883 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000884 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
885 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886
Eric Fiselierec5a2102019-07-12 23:01:48 +0000887 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
888 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
889 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
890 : __base_(__t) {}
891 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000892 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000893 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000894 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
895 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000896
Eric Fiselierec5a2102019-07-12 23:01:48 +0000897 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
898 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
899 explicit
900 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
901 : __base_(__t) {}
902
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000904 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000906 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000907 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
908 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000909 bool
910 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000914 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000916 template <class _Alloc, class _Tuple,
917 typename enable_if
918 <
919 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000920 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
921 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000922 bool
923 >::type = false
924 >
925 _LIBCPP_INLINE_VISIBILITY
926 explicit
927 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000928 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000929
Eric Fiselier737a16d2016-07-25 02:36:42 +0000930 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
931 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
932
933 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000934 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000935 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
936 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000937 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000938 return *this;
939 }
940
941 _LIBCPP_INLINE_VISIBILITY
942 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
943 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
944 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000945 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000946 return *this;
947 }
948
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 template <class _Tuple,
950 class = typename enable_if
951 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000952 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953 >::type
954 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000957 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000959 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 return *this;
961 }
962
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000964 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000965 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966};
967
968template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000969class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970{
971public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000972 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000973 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000976 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000979 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000980 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000982 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000983 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000985 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000987 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988};
989
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000990#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +0000991template <class ..._Tp>
992tuple(_Tp...) -> tuple<_Tp...>;
993template <class _Tp1, class _Tp2>
994tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
995template <class _Alloc, class ..._Tp>
996tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
997template <class _Alloc, class _Tp1, class _Tp2>
998tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
999template <class _Alloc, class ..._Tp>
1000tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001001#endif
1002
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003template <class ..._Tp>
1004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +00001005typename enable_if
1006<
1007 __all<__is_swappable<_Tp>::value...>::value,
1008 void
1009>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001010swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1011 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1012 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
1014// get
1015
1016template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001017inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001018typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001019get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001021 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001022 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023}
1024
1025template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001026inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001027const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001028get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001030 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001031 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032}
1033
Howard Hinnant22e97242010-11-17 19:52:17 +00001034template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001035inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001036typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001037get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001038{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001039 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001040 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001041 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001042}
1043
Eric Fiselier6dea8092015-12-18 00:36:55 +00001044template <size_t _Ip, class ..._Tp>
1045inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1046const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1047get(const tuple<_Tp...>&& __t) _NOEXCEPT
1048{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001049 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001050 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001051 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001052}
1053
Marshall Clow15b02e02013-07-13 02:54:05 +00001054#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001055
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001056namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001057
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001058static constexpr size_t __not_found = -1;
1059static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001060
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001061inline _LIBCPP_INLINE_VISIBILITY
1062constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1063 return !__matches ? __res :
1064 (__res == __not_found ? __curr_i : __ambiguous);
1065}
Marshall Clow15b02e02013-07-13 02:54:05 +00001066
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001067template <size_t _Nx>
1068inline _LIBCPP_INLINE_VISIBILITY
1069constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1070 return __i == _Nx ? __not_found :
1071 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1072}
1073
1074template <class _T1, class ..._Args>
1075struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001076 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001077 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001078 static_assert(value != __not_found, "type not found in type list" );
1079 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001080};
1081
Eric Fiselier8087d302016-07-02 03:46:08 +00001082template <class _T1>
1083struct __find_exactly_one_checked<_T1> {
1084 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1085};
1086
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001087} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001088
1089template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001090struct __find_exactly_one_t
1091 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1092};
Marshall Clow15b02e02013-07-13 02:54:05 +00001093
1094template <class _T1, class... _Args>
1095inline _LIBCPP_INLINE_VISIBILITY
1096constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1097{
1098 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1099}
1100
1101template <class _T1, class... _Args>
1102inline _LIBCPP_INLINE_VISIBILITY
1103constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1104{
1105 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1106}
1107
1108template <class _T1, class... _Args>
1109inline _LIBCPP_INLINE_VISIBILITY
1110constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1111{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001112 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001113}
1114
Eric Fiselier6dea8092015-12-18 00:36:55 +00001115template <class _T1, class... _Args>
1116inline _LIBCPP_INLINE_VISIBILITY
1117constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1118{
1119 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1120}
1121
Marshall Clow15b02e02013-07-13 02:54:05 +00001122#endif
1123
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124// tie
1125
1126template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001127inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001129tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130{
1131 return tuple<_Tp&...>(__t...);
1132}
1133
1134template <class _Up>
1135struct __ignore_t
1136{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001138 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1139 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140};
1141
Eric Fiselier24e70262017-02-06 01:25:31 +00001142namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001143 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001144}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001148tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149make_tuple(_Tp&&... __t)
1150{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001151 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152}
1153
Howard Hinnant3d203a32010-08-19 18:59:38 +00001154template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1156tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001157forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001158{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001159 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001160}
1161
Howard Hinnantc834c512011-11-29 18:15:50 +00001162template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163struct __tuple_equal
1164{
1165 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001166 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 bool operator()(const _Tp& __x, const _Up& __y)
1168 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001169 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170 }
1171};
1172
1173template <>
1174struct __tuple_equal<0>
1175{
1176 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 bool operator()(const _Tp&, const _Up&)
1179 {
1180 return true;
1181 }
1182};
1183
1184template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001185inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186bool
1187operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1188{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001189 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1191}
1192
1193template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195bool
1196operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1197{
1198 return !(__x == __y);
1199}
1200
Howard Hinnantc834c512011-11-29 18:15:50 +00001201template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202struct __tuple_less
1203{
1204 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001205 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206 bool operator()(const _Tp& __x, const _Up& __y)
1207 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001208 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1209 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1210 return true;
1211 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1212 return false;
1213 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214 }
1215};
1216
1217template <>
1218struct __tuple_less<0>
1219{
1220 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001221 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222 bool operator()(const _Tp&, const _Up&)
1223 {
1224 return false;
1225 }
1226};
1227
1228template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001229inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230bool
1231operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1232{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001233 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1235}
1236
1237template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001238inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239bool
1240operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1241{
1242 return __y < __x;
1243}
1244
1245template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001246inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247bool
1248operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1249{
1250 return !(__x < __y);
1251}
1252
1253template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001254inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255bool
1256operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1257{
1258 return !(__y < __x);
1259}
1260
1261// tuple_cat
1262
Howard Hinnant6256ee72010-12-11 20:47:50 +00001263template <class _Tp, class _Up> struct __tuple_cat_type;
1264
1265template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001266struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001268 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001269};
1270
1271template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1272struct __tuple_cat_return_1
1273{
1274};
1275
1276template <class ..._Types, class _Tuple0>
1277struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1278{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001279 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001280 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001281 type;
1282};
1283
1284template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1285struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1286 : public __tuple_cat_return_1<
1287 typename __tuple_cat_type<
1288 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001289 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001290 >::type,
1291 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1292 _Tuple1, _Tuples...>
1293{
1294};
1295
1296template <class ..._Tuples> struct __tuple_cat_return;
1297
1298template <class _Tuple0, class ..._Tuples>
1299struct __tuple_cat_return<_Tuple0, _Tuples...>
1300 : public __tuple_cat_return_1<tuple<>,
1301 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1302 _Tuples...>
1303{
1304};
1305
1306template <>
1307struct __tuple_cat_return<>
1308{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001309 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001310};
1311
Marshall Clow2229cee2013-07-22 16:02:19 +00001312inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001313tuple<>
1314tuple_cat()
1315{
1316 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001317}
1318
Howard Hinnantc834c512011-11-29 18:15:50 +00001319template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001320struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321
Howard Hinnant21376f62010-12-12 23:04:37 +00001322template <class ..._Types, size_t ..._I0, class _Tuple0>
1323struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001325 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001326 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1327 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1328};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329
Howard Hinnant21376f62010-12-12 23:04:37 +00001330template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1331struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1332 _Tuple0, _Tuple1, _Tuples...>
1333 : public __tuple_cat_return_ref_imp<
1334 tuple<_Types..., typename __apply_cv<_Tuple0,
1335 typename tuple_element<_I0,
1336 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1337 typename __make_tuple_indices<tuple_size<typename
1338 remove_reference<_Tuple1>::type>::value>::type,
1339 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340{
Howard Hinnant21376f62010-12-12 23:04:37 +00001341};
1342
1343template <class _Tuple0, class ..._Tuples>
1344struct __tuple_cat_return_ref
1345 : public __tuple_cat_return_ref_imp<tuple<>,
1346 typename __make_tuple_indices<
1347 tuple_size<typename remove_reference<_Tuple0>::type>::value
1348 >::type, _Tuple0, _Tuples...>
1349{
1350};
1351
1352template <class _Types, class _I0, class _J0>
1353struct __tuple_cat;
1354
1355template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001356struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001357{
1358 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001360 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1361 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1362 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001363 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1364 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001365 }
1366
1367 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001369 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1370 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1371 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001372 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1373 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001374 return __tuple_cat<
1375 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1376 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1377 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowded420b2013-10-05 18:46:37 +00001378 (forward_as_tuple(
Marshall Clow60e4aa72014-06-24 00:46:19 +00001379 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1380 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnant21376f62010-12-12 23:04:37 +00001381 ),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001382 _VSTD::forward<_Tuple1>(__t1),
1383 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001384 }
1385};
1386
1387template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001388inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001389typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1390tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1391{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001392 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001393 return __tuple_cat<tuple<>, __tuple_indices<>,
1394 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001395 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1396 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397}
1398
1399template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001400struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401 : true_type {};
1402
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403template <class _T1, class _T2>
1404template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1405inline _LIBCPP_INLINE_VISIBILITY
1406pair<_T1, _T2>::pair(piecewise_construct_t,
1407 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1408 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001409 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1410 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411{
1412}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413
Eric Fiselier8e892c52016-07-18 00:35:56 +00001414#if _LIBCPP_STD_VER > 14
1415template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001416_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001417
1418#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1419
1420template <class _Fn, class _Tuple, size_t ..._Id>
1421inline _LIBCPP_INLINE_VISIBILITY
1422constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1423 __tuple_indices<_Id...>)
1424_LIBCPP_NOEXCEPT_RETURN(
1425 _VSTD::__invoke_constexpr(
1426 _VSTD::forward<_Fn>(__f),
1427 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1428)
1429
1430template <class _Fn, class _Tuple>
1431inline _LIBCPP_INLINE_VISIBILITY
1432constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1433_LIBCPP_NOEXCEPT_RETURN(
1434 _VSTD::__apply_tuple_impl(
1435 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001436 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001437)
1438
1439template <class _Tp, class _Tuple, size_t... _Idx>
1440inline _LIBCPP_INLINE_VISIBILITY
1441constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1442_LIBCPP_NOEXCEPT_RETURN(
1443 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1444)
1445
1446template <class _Tp, class _Tuple>
1447inline _LIBCPP_INLINE_VISIBILITY
1448constexpr _Tp make_from_tuple(_Tuple&& __t)
1449_LIBCPP_NOEXCEPT_RETURN(
1450 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001451 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001452)
1453
1454#undef _LIBCPP_NOEXCEPT_RETURN
1455
1456#endif // _LIBCPP_STD_VER > 14
1457
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001458#endif // !defined(_LIBCPP_CXX03_LANG)
1459
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460_LIBCPP_END_NAMESPACE_STD
1461
1462#endif // _LIBCPP_TUPLE