blob: c3c7db5ff11845da259259fa12715adc1fd69494 [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 {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000502 template <int&...>
503 static constexpr bool __enable_implicit_default() {
504 return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
505 }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000506
Eric Fiselier18d72a02019-09-30 20:55:30 +0000507 template <int&...>
508 static constexpr bool __enable_explicit_default() {
509 return
510 __all<is_default_constructible<_Tp>::value...>::value &&
511 !__enable_implicit_default< >();
512 }
513
Eric Fiseliere61db632016-07-25 04:32:07 +0000514
515 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000516 static constexpr bool __enable_explicit() {
517 return
518 __tuple_constructible<
519 tuple<_Args...>,
520 typename __make_tuple_types<tuple,
521 sizeof...(_Args) < sizeof...(_Tp) ?
522 sizeof...(_Args) :
523 sizeof...(_Tp)>::type
524 >::value &&
525 !__tuple_convertible<
526 tuple<_Args...>,
527 typename __make_tuple_types<tuple,
528 sizeof...(_Args) < sizeof...(_Tp) ?
529 sizeof...(_Args) :
530 sizeof...(_Tp)>::type
531 >::value &&
532 __all_default_constructible<
533 typename __make_tuple_types<tuple, sizeof...(_Tp),
534 sizeof...(_Args) < sizeof...(_Tp) ?
535 sizeof...(_Args) :
536 sizeof...(_Tp)>::type
537 >::value;
538 }
539
540 template <class ..._Args>
541 static constexpr bool __enable_implicit() {
542 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000543 __tuple_constructible<
544 tuple<_Args...>,
545 typename __make_tuple_types<tuple,
546 sizeof...(_Args) < sizeof...(_Tp) ?
547 sizeof...(_Args) :
548 sizeof...(_Tp)>::type
549 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000550 __tuple_convertible<
551 tuple<_Args...>,
552 typename __make_tuple_types<tuple,
553 sizeof...(_Args) < sizeof...(_Tp) ?
554 sizeof...(_Args) :
555 sizeof...(_Tp)>::type
556 >::value &&
557 __all_default_constructible<
558 typename __make_tuple_types<tuple, sizeof...(_Tp),
559 sizeof...(_Args) < sizeof...(_Tp) ?
560 sizeof...(_Args) :
561 sizeof...(_Tp)>::type
562 >::value;
563 }
564 };
565
566 template <bool _MaybeEnable,
567 bool = sizeof...(_Tp) == 1,
568 class _Dummy = void>
569 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
570
571 template <class _Dummy>
572 struct _CheckTupleLikeConstructor<true, false, _Dummy>
573 {
574 template <class _Tuple>
575 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000576 return __tuple_constructible<_Tuple, tuple>::value
577 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000578 }
579
580 template <class _Tuple>
581 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000582 return __tuple_constructible<_Tuple, tuple>::value
583 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000584 }
585 };
586
587 template <class _Dummy>
588 struct _CheckTupleLikeConstructor<true, true, _Dummy>
589 {
590 // This trait is used to disable the tuple-like constructor when
591 // the UTypes... constructor should be selected instead.
592 // See LWG issue #2549.
593 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000594 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000595 // Don't attempt the two checks below if the tuple we are given
596 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000597 _IsSame<__uncvref_t<_Tuple>, tuple>,
598 _Lazy<_And,
599 _Not<is_constructible<_Tp..., _Tuple>>,
600 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000601 >
602 >;
603
604 template <class _Tuple>
605 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000606 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000607 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000608 __tuple_convertible<_Tuple, tuple>,
609 _PreferTupleLikeConstructor<_Tuple>
610 >::value;
611 }
612
613 template <class _Tuple>
614 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000615 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000616 __tuple_constructible<_Tuple, tuple>,
617 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000618 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000619 >::value;
620 }
621 };
622
Eric Fiselierec5a2102019-07-12 23:01:48 +0000623 template <class _Tuple, bool _DisableIfLValue>
624 using _EnableImplicitTupleLikeConstructor = _EnableIf<
625 _CheckTupleLikeConstructor<
626 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
627 && !_PackExpandsToThisTuple<_Tuple>::value
628 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
629 >::template __enable_implicit<_Tuple>(),
630 bool
631 >;
632
633 template <class _Tuple, bool _DisableIfLValue>
634 using _EnableExplicitTupleLikeConstructor = _EnableIf<
635 _CheckTupleLikeConstructor<
636 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
637 && !_PackExpandsToThisTuple<_Tuple>::value
638 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
639 >::template __enable_explicit<_Tuple>(),
640 bool
641 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000642 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000643 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000644 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000645 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000646 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000647 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000648 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
649 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650public:
651
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000652 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000653 _CheckArgsConstructor<_Dummy>::__enable_implicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000654 , void*> = nullptr>
655 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
656 tuple()
657 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
658
659 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000660 _CheckArgsConstructor<_Dummy>::__enable_explicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000661 , void*> = nullptr>
662 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
663 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000664 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000665
Eric Fiselier737a16d2016-07-25 02:36:42 +0000666 tuple(tuple const&) = default;
667 tuple(tuple&&) = default;
668
Eric Fiselier18d72a02019-09-30 20:55:30 +0000669 template <class _AllocArgT, class _Alloc, _EnableIf<
670 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000671 , void*> = nullptr
Eric Fiselier3906a132019-06-23 20:28:29 +0000672 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000673 _LIBCPP_INLINE_VISIBILITY
674 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000675 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000676 __tuple_indices<>(), __tuple_types<>(),
677 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
678 __tuple_types<_Tp...>()) {}
679
Eric Fiselier18d72a02019-09-30 20:55:30 +0000680 template <class _AllocArgT, class _Alloc, _EnableIf<
681 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000682 , void*> = nullptr
683 >
684 explicit _LIBCPP_INLINE_VISIBILITY
685 tuple(_AllocArgT, _Alloc const& __a)
686 : __base_(allocator_arg_t(), __a,
687 __tuple_indices<>(), __tuple_types<>(),
688 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
689 __tuple_types<_Tp...>()) {}
690
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000691 template <bool _Dummy = true,
692 typename enable_if
693 <
694 _CheckArgsConstructor<
695 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000696 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000697 bool
698 >::type = false
699 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000701 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000702 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
704 typename __make_tuple_indices<0>::type(),
705 typename __make_tuple_types<tuple, 0>::type(),
706 __t...
707 ) {}
708
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000709 template <bool _Dummy = true,
710 typename enable_if
711 <
712 _CheckArgsConstructor<
713 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000714 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000715 bool
716 >::type = false
717 >
718 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
719 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000720 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000721 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
722 typename __make_tuple_indices<0>::type(),
723 typename __make_tuple_types<tuple, 0>::type(),
724 __t...
725 ) {}
726
727 template <class _Alloc, bool _Dummy = true,
728 typename enable_if
729 <
730 _CheckArgsConstructor<
731 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000732 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000733 bool
734 >::type = false
735 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000738 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
740 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
741 typename __make_tuple_indices<0>::type(),
742 typename __make_tuple_types<tuple, 0>::type(),
743 __t...
744 ) {}
745
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000746 template <class _Alloc, bool _Dummy = true,
747 typename enable_if
748 <
749 _CheckArgsConstructor<
750 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000751 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000752 bool
753 >::type = false
754 >
755 _LIBCPP_INLINE_VISIBILITY
756 explicit
757 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000758 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000759 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
760 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
761 typename __make_tuple_indices<0>::type(),
762 typename __make_tuple_types<tuple, 0>::type(),
763 __t...
764 ) {}
765
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000767 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000768 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000770 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000771 sizeof...(_Up) == sizeof...(_Tp)
772 && !_PackIsTuple
773 >::template __enable_implicit<_Up...>() ||
774 _CheckArgsConstructor<
775 _EnableImplicitReducedArityExtension
776 && sizeof...(_Up) < sizeof...(_Tp)
777 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000778 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000779 bool
780 >::type = false
781 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000783 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000784 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000785 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000786 typename __make_tuple_indices<sizeof...(_Up)>::type,
787 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
788 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
789 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000790 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000791 >::value
792 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000793 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000794 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
795 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
796 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
797 _VSTD::forward<_Up>(__u)...) {}
798
799 template <class ..._Up,
800 typename enable_if
801 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000802 _CheckArgsConstructor<
803 sizeof...(_Up) <= sizeof...(_Tp)
804 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000805 >::template __enable_explicit<_Up...>() ||
806 _CheckArgsConstructor<
807 !_EnableImplicitReducedArityExtension
808 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000809 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000810 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000811 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000812 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815 explicit
816 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000817 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000818 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000819 typename __make_tuple_indices<sizeof...(_Up)>::type,
820 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
821 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
822 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
823 _Up...
824 >::value
825 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000826 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
828 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
829 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000830 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831
832 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000833 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000835 _CheckArgsConstructor<
836 sizeof...(_Up) == sizeof...(_Tp) &&
837 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000838 >::template __enable_implicit<_Up...>(),
839 bool
840 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000844 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845 typename __make_tuple_indices<sizeof...(_Up)>::type(),
846 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
847 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
848 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000849 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000851 template <class _Alloc, class ..._Up,
852 typename enable_if
853 <
854 _CheckArgsConstructor<
855 sizeof...(_Up) == sizeof...(_Tp) &&
856 !_PackExpandsToThisTuple<_Up...>::value
857 >::template __enable_explicit<_Up...>(),
858 bool
859 >::type = false
860 >
861 _LIBCPP_INLINE_VISIBILITY
862 explicit
863 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000864 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000865 typename __make_tuple_indices<sizeof...(_Up)>::type(),
866 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
867 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
868 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
869 _VSTD::forward<_Up>(__u)...) {}
870
Eric Fiselierec5a2102019-07-12 23:01:48 +0000871 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000872 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000873 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
874 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
Eric Fiselierec5a2102019-07-12 23:01:48 +0000876 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
877 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
878 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
879 : __base_(__t) {}
880 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000881 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000882 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000883 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
884 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000885
Eric Fiselierec5a2102019-07-12 23:01:48 +0000886 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
887 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
888 explicit
889 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
890 : __base_(__t) {}
891
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000893 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000895 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000896 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
897 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000898 bool
899 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000903 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000905 template <class _Alloc, class _Tuple,
906 typename enable_if
907 <
908 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000909 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
910 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000911 bool
912 >::type = false
913 >
914 _LIBCPP_INLINE_VISIBILITY
915 explicit
916 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000917 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000918
Eric Fiselier737a16d2016-07-25 02:36:42 +0000919 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
920 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
921
922 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000923 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000924 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
925 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000926 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000927 return *this;
928 }
929
930 _LIBCPP_INLINE_VISIBILITY
931 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
932 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
933 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000934 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000935 return *this;
936 }
937
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938 template <class _Tuple,
939 class = typename enable_if
940 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000941 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 >::type
943 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000946 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000948 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 return *this;
950 }
951
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000953 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000954 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955};
956
957template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000958class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959{
960public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000961 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000962 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000965 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000968 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000969 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000971 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000972 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000974 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000976 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977};
978
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000979#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +0000980template <class ..._Tp>
981tuple(_Tp...) -> tuple<_Tp...>;
982template <class _Tp1, class _Tp2>
983tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
984template <class _Alloc, class ..._Tp>
985tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
986template <class _Alloc, class _Tp1, class _Tp2>
987tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
988template <class _Alloc, class ..._Tp>
989tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +0000990#endif
991
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992template <class ..._Tp>
993inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000994typename enable_if
995<
996 __all<__is_swappable<_Tp>::value...>::value,
997 void
998>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +0000999swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1000 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1001 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002
1003// get
1004
1005template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001006inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001007typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001008get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001010 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001011 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012}
1013
1014template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001015inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001016const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001017get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001019 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001020 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021}
1022
Howard Hinnant22e97242010-11-17 19:52:17 +00001023template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001024inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001025typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001026get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001027{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001028 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001029 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001030 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001031}
1032
Eric Fiselier6dea8092015-12-18 00:36:55 +00001033template <size_t _Ip, class ..._Tp>
1034inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1035const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1036get(const tuple<_Tp...>&& __t) _NOEXCEPT
1037{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001038 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001039 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001040 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001041}
1042
Marshall Clow15b02e02013-07-13 02:54:05 +00001043#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001044
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001045namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001046
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001047static constexpr size_t __not_found = -1;
1048static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001049
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001050inline _LIBCPP_INLINE_VISIBILITY
1051constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1052 return !__matches ? __res :
1053 (__res == __not_found ? __curr_i : __ambiguous);
1054}
Marshall Clow15b02e02013-07-13 02:54:05 +00001055
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001056template <size_t _Nx>
1057inline _LIBCPP_INLINE_VISIBILITY
1058constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1059 return __i == _Nx ? __not_found :
1060 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1061}
1062
1063template <class _T1, class ..._Args>
1064struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001065 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001066 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001067 static_assert(value != __not_found, "type not found in type list" );
1068 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001069};
1070
Eric Fiselier8087d302016-07-02 03:46:08 +00001071template <class _T1>
1072struct __find_exactly_one_checked<_T1> {
1073 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1074};
1075
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001076} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001077
1078template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001079struct __find_exactly_one_t
1080 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1081};
Marshall Clow15b02e02013-07-13 02:54:05 +00001082
1083template <class _T1, class... _Args>
1084inline _LIBCPP_INLINE_VISIBILITY
1085constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1086{
1087 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1088}
1089
1090template <class _T1, class... _Args>
1091inline _LIBCPP_INLINE_VISIBILITY
1092constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1093{
1094 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1095}
1096
1097template <class _T1, class... _Args>
1098inline _LIBCPP_INLINE_VISIBILITY
1099constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1100{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001101 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001102}
1103
Eric Fiselier6dea8092015-12-18 00:36:55 +00001104template <class _T1, class... _Args>
1105inline _LIBCPP_INLINE_VISIBILITY
1106constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1107{
1108 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1109}
1110
Marshall Clow15b02e02013-07-13 02:54:05 +00001111#endif
1112
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113// tie
1114
1115template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001116inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001118tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119{
1120 return tuple<_Tp&...>(__t...);
1121}
1122
1123template <class _Up>
1124struct __ignore_t
1125{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001127 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1128 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129};
1130
Eric Fiselier24e70262017-02-06 01:25:31 +00001131namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001132 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001133}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001136inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001137tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138make_tuple(_Tp&&... __t)
1139{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001140 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141}
1142
Howard Hinnant3d203a32010-08-19 18:59:38 +00001143template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001144inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1145tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001146forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001147{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001148 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001149}
1150
Howard Hinnantc834c512011-11-29 18:15:50 +00001151template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152struct __tuple_equal
1153{
1154 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001155 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156 bool operator()(const _Tp& __x, const _Up& __y)
1157 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001158 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 }
1160};
1161
1162template <>
1163struct __tuple_equal<0>
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&, const _Up&)
1168 {
1169 return true;
1170 }
1171};
1172
1173template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175bool
1176operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1177{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001178 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1180}
1181
1182template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001183inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184bool
1185operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1186{
1187 return !(__x == __y);
1188}
1189
Howard Hinnantc834c512011-11-29 18:15:50 +00001190template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191struct __tuple_less
1192{
1193 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001194 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 bool operator()(const _Tp& __x, const _Up& __y)
1196 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001197 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1198 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1199 return true;
1200 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1201 return false;
1202 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 }
1204};
1205
1206template <>
1207struct __tuple_less<0>
1208{
1209 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001210 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211 bool operator()(const _Tp&, const _Up&)
1212 {
1213 return false;
1214 }
1215};
1216
1217template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001218inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219bool
1220operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1221{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001222 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1224}
1225
1226template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001227inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228bool
1229operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1230{
1231 return __y < __x;
1232}
1233
1234template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001235inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236bool
1237operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1238{
1239 return !(__x < __y);
1240}
1241
1242template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001243inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244bool
1245operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1246{
1247 return !(__y < __x);
1248}
1249
1250// tuple_cat
1251
Howard Hinnant6256ee72010-12-11 20:47:50 +00001252template <class _Tp, class _Up> struct __tuple_cat_type;
1253
1254template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001255struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001257 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001258};
1259
1260template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1261struct __tuple_cat_return_1
1262{
1263};
1264
1265template <class ..._Types, class _Tuple0>
1266struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1267{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001268 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001269 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001270 type;
1271};
1272
1273template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1274struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1275 : public __tuple_cat_return_1<
1276 typename __tuple_cat_type<
1277 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001278 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001279 >::type,
1280 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1281 _Tuple1, _Tuples...>
1282{
1283};
1284
1285template <class ..._Tuples> struct __tuple_cat_return;
1286
1287template <class _Tuple0, class ..._Tuples>
1288struct __tuple_cat_return<_Tuple0, _Tuples...>
1289 : public __tuple_cat_return_1<tuple<>,
1290 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1291 _Tuples...>
1292{
1293};
1294
1295template <>
1296struct __tuple_cat_return<>
1297{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001298 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001299};
1300
Marshall Clow2229cee2013-07-22 16:02:19 +00001301inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001302tuple<>
1303tuple_cat()
1304{
1305 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306}
1307
Howard Hinnantc834c512011-11-29 18:15:50 +00001308template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001309struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310
Howard Hinnant21376f62010-12-12 23:04:37 +00001311template <class ..._Types, size_t ..._I0, class _Tuple0>
1312struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001314 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001315 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1316 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1317};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001318
Howard Hinnant21376f62010-12-12 23:04:37 +00001319template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1320struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1321 _Tuple0, _Tuple1, _Tuples...>
1322 : public __tuple_cat_return_ref_imp<
1323 tuple<_Types..., typename __apply_cv<_Tuple0,
1324 typename tuple_element<_I0,
1325 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1326 typename __make_tuple_indices<tuple_size<typename
1327 remove_reference<_Tuple1>::type>::value>::type,
1328 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329{
Howard Hinnant21376f62010-12-12 23:04:37 +00001330};
1331
1332template <class _Tuple0, class ..._Tuples>
1333struct __tuple_cat_return_ref
1334 : public __tuple_cat_return_ref_imp<tuple<>,
1335 typename __make_tuple_indices<
1336 tuple_size<typename remove_reference<_Tuple0>::type>::value
1337 >::type, _Tuple0, _Tuples...>
1338{
1339};
1340
1341template <class _Types, class _I0, class _J0>
1342struct __tuple_cat;
1343
1344template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001345struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001346{
1347 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001348 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001349 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1350 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1351 {
David Blaikie699a5e22019-10-28 18:03:59 -07001352 return _VSTD::forward_as_tuple(
1353 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1354 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001355 }
1356
1357 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001359 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1360 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1361 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001362 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1363 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001364 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001365 tuple<_Types...,
1366 typename __apply_cv<_Tuple0, typename tuple_element<
1367 _J0, _T0>::type>::type&&...>,
1368 typename __make_tuple_indices<sizeof...(_Types) +
1369 tuple_size<_T0>::value>::type,
1370 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1371 _VSTD::forward_as_tuple(
1372 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1373 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1374 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001375 }
1376};
1377
1378template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001379inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001380typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1381tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1382{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001383 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001384 return __tuple_cat<tuple<>, __tuple_indices<>,
1385 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001386 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1387 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388}
1389
1390template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001391struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392 : true_type {};
1393
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394template <class _T1, class _T2>
1395template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001396inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397pair<_T1, _T2>::pair(piecewise_construct_t,
1398 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1399 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001400 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1401 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402{
1403}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404
Eric Fiselier8e892c52016-07-18 00:35:56 +00001405#if _LIBCPP_STD_VER > 14
1406template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001407_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001408
1409#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1410
1411template <class _Fn, class _Tuple, size_t ..._Id>
1412inline _LIBCPP_INLINE_VISIBILITY
1413constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1414 __tuple_indices<_Id...>)
1415_LIBCPP_NOEXCEPT_RETURN(
1416 _VSTD::__invoke_constexpr(
1417 _VSTD::forward<_Fn>(__f),
1418 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1419)
1420
1421template <class _Fn, class _Tuple>
1422inline _LIBCPP_INLINE_VISIBILITY
1423constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1424_LIBCPP_NOEXCEPT_RETURN(
1425 _VSTD::__apply_tuple_impl(
1426 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001427 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001428)
1429
1430template <class _Tp, class _Tuple, size_t... _Idx>
1431inline _LIBCPP_INLINE_VISIBILITY
1432constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1433_LIBCPP_NOEXCEPT_RETURN(
1434 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1435)
1436
1437template <class _Tp, class _Tuple>
1438inline _LIBCPP_INLINE_VISIBILITY
1439constexpr _Tp make_from_tuple(_Tuple&& __t)
1440_LIBCPP_NOEXCEPT_RETURN(
1441 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001442 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001443)
1444
1445#undef _LIBCPP_NOEXCEPT_RETURN
1446
1447#endif // _LIBCPP_STD_VER > 14
1448
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001449#endif // !defined(_LIBCPP_CXX03_LANG)
1450
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451_LIBCPP_END_NAMESPACE_STD
1452
1453#endif // _LIBCPP_TUPLE