blob: c33b48ab54c6e9a419f18dd6e27386cf1467c40e [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 Dionnea7a2beb2019-09-26 14:51:10 +0000503 static constexpr bool __enable_implicit_default() {
504 // In C++03, there's no way to implement the resolution of LWG2510.
505#ifdef _LIBCPP_CXX03_LANG
506 return true;
507#else
508 return __all<__is_implicitly_default_constructible<_Args>::value...>::value;
509#endif
510 }
511
512 template <class ..._Args>
513 static constexpr bool __enable_explicit_default() {
514 return __all<is_default_constructible<_Args>::value...>::value
515 && !__enable_implicit_default<_Args...>();
Ilya Biryukov6c42b1a2019-09-25 09:10:38 +0000516 }
Eric Fiseliere61db632016-07-25 04:32:07 +0000517
518 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000519 static constexpr bool __enable_explicit() {
520 return
521 __tuple_constructible<
522 tuple<_Args...>,
523 typename __make_tuple_types<tuple,
524 sizeof...(_Args) < sizeof...(_Tp) ?
525 sizeof...(_Args) :
526 sizeof...(_Tp)>::type
527 >::value &&
528 !__tuple_convertible<
529 tuple<_Args...>,
530 typename __make_tuple_types<tuple,
531 sizeof...(_Args) < sizeof...(_Tp) ?
532 sizeof...(_Args) :
533 sizeof...(_Tp)>::type
534 >::value &&
535 __all_default_constructible<
536 typename __make_tuple_types<tuple, sizeof...(_Tp),
537 sizeof...(_Args) < sizeof...(_Tp) ?
538 sizeof...(_Args) :
539 sizeof...(_Tp)>::type
540 >::value;
541 }
542
543 template <class ..._Args>
544 static constexpr bool __enable_implicit() {
545 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000546 __tuple_constructible<
547 tuple<_Args...>,
548 typename __make_tuple_types<tuple,
549 sizeof...(_Args) < sizeof...(_Tp) ?
550 sizeof...(_Args) :
551 sizeof...(_Tp)>::type
552 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000553 __tuple_convertible<
554 tuple<_Args...>,
555 typename __make_tuple_types<tuple,
556 sizeof...(_Args) < sizeof...(_Tp) ?
557 sizeof...(_Args) :
558 sizeof...(_Tp)>::type
559 >::value &&
560 __all_default_constructible<
561 typename __make_tuple_types<tuple, sizeof...(_Tp),
562 sizeof...(_Args) < sizeof...(_Tp) ?
563 sizeof...(_Args) :
564 sizeof...(_Tp)>::type
565 >::value;
566 }
567 };
568
569 template <bool _MaybeEnable,
570 bool = sizeof...(_Tp) == 1,
571 class _Dummy = void>
572 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
573
574 template <class _Dummy>
575 struct _CheckTupleLikeConstructor<true, false, _Dummy>
576 {
577 template <class _Tuple>
578 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000579 return __tuple_constructible<_Tuple, tuple>::value
580 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000581 }
582
583 template <class _Tuple>
584 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000585 return __tuple_constructible<_Tuple, tuple>::value
586 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000587 }
588 };
589
590 template <class _Dummy>
591 struct _CheckTupleLikeConstructor<true, true, _Dummy>
592 {
593 // This trait is used to disable the tuple-like constructor when
594 // the UTypes... constructor should be selected instead.
595 // See LWG issue #2549.
596 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000597 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000598 // Don't attempt the two checks below if the tuple we are given
599 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000600 _IsSame<__uncvref_t<_Tuple>, tuple>,
601 _Lazy<_And,
602 _Not<is_constructible<_Tp..., _Tuple>>,
603 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000604 >
605 >;
606
607 template <class _Tuple>
608 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000609 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000610 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000611 __tuple_convertible<_Tuple, tuple>,
612 _PreferTupleLikeConstructor<_Tuple>
613 >::value;
614 }
615
616 template <class _Tuple>
617 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000618 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000619 __tuple_constructible<_Tuple, tuple>,
620 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000621 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000622 >::value;
623 }
624 };
625
Eric Fiselierec5a2102019-07-12 23:01:48 +0000626 template <class _Tuple, bool _DisableIfLValue>
627 using _EnableImplicitTupleLikeConstructor = _EnableIf<
628 _CheckTupleLikeConstructor<
629 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
630 && !_PackExpandsToThisTuple<_Tuple>::value
631 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
632 >::template __enable_implicit<_Tuple>(),
633 bool
634 >;
635
636 template <class _Tuple, bool _DisableIfLValue>
637 using _EnableExplicitTupleLikeConstructor = _EnableIf<
638 _CheckTupleLikeConstructor<
639 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
640 && !_PackExpandsToThisTuple<_Tuple>::value
641 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
642 >::template __enable_explicit<_Tuple>(),
643 bool
644 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000645 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000646 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const 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 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000651 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
652 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653public:
654
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000655 template <bool _Dummy = true, _EnableIf<
656 _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>()
657 , void*> = nullptr>
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
659 tuple()
660 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
661
662 template <bool _Dummy = true, _EnableIf<
663 _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>()
664 , void*> = nullptr>
665 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
666 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000667 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000668
Eric Fiselier737a16d2016-07-25 02:36:42 +0000669 tuple(tuple const&) = default;
670 tuple(tuple&&) = default;
671
Ilya Biryukov6c42b1a2019-09-25 09:10:38 +0000672 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf<
Eric Fiselier3906a132019-06-23 20:28:29 +0000673 _And<
674 _IsSame<allocator_arg_t, _AllocArgT>,
Ilya Biryukov6c42b1a2019-09-25 09:10:38 +0000675 __dependent_type<is_default_constructible<_Tp>, _Dummy>...
Eric Fiselierc170df52016-04-15 03:29:40 +0000676 >::value
Ilya Biryukov6c42b1a2019-09-25 09:10:38 +0000677 >
Eric Fiselier3906a132019-06-23 20:28:29 +0000678 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000679 _LIBCPP_INLINE_VISIBILITY
680 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000681 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000682 __tuple_indices<>(), __tuple_types<>(),
683 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
684 __tuple_types<_Tp...>()) {}
685
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000686 template <bool _Dummy = true,
687 typename enable_if
688 <
689 _CheckArgsConstructor<
690 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000691 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000692 bool
693 >::type = false
694 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000695 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000696 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000697 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
699 typename __make_tuple_indices<0>::type(),
700 typename __make_tuple_types<tuple, 0>::type(),
701 __t...
702 ) {}
703
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000704 template <bool _Dummy = true,
705 typename enable_if
706 <
707 _CheckArgsConstructor<
708 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000709 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000710 bool
711 >::type = false
712 >
713 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
714 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000715 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000716 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
717 typename __make_tuple_indices<0>::type(),
718 typename __make_tuple_types<tuple, 0>::type(),
719 __t...
720 ) {}
721
722 template <class _Alloc, bool _Dummy = true,
723 typename enable_if
724 <
725 _CheckArgsConstructor<
726 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000727 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000728 bool
729 >::type = false
730 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000733 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
735 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
736 typename __make_tuple_indices<0>::type(),
737 typename __make_tuple_types<tuple, 0>::type(),
738 __t...
739 ) {}
740
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000741 template <class _Alloc, bool _Dummy = true,
742 typename enable_if
743 <
744 _CheckArgsConstructor<
745 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000746 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000747 bool
748 >::type = false
749 >
750 _LIBCPP_INLINE_VISIBILITY
751 explicit
752 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000753 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000754 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
755 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
756 typename __make_tuple_indices<0>::type(),
757 typename __make_tuple_types<tuple, 0>::type(),
758 __t...
759 ) {}
760
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000762 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000763 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000765 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000766 sizeof...(_Up) == sizeof...(_Tp)
767 && !_PackIsTuple
768 >::template __enable_implicit<_Up...>() ||
769 _CheckArgsConstructor<
770 _EnableImplicitReducedArityExtension
771 && sizeof...(_Up) < sizeof...(_Tp)
772 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000773 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000774 bool
775 >::type = false
776 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000777 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000778 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000779 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000780 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000781 typename __make_tuple_indices<sizeof...(_Up)>::type,
782 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
783 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
784 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000785 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000786 >::value
787 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000788 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000789 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
790 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
791 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
792 _VSTD::forward<_Up>(__u)...) {}
793
794 template <class ..._Up,
795 typename enable_if
796 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000797 _CheckArgsConstructor<
798 sizeof...(_Up) <= sizeof...(_Tp)
799 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000800 >::template __enable_explicit<_Up...>() ||
801 _CheckArgsConstructor<
802 !_EnableImplicitReducedArityExtension
803 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000804 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000805 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000806 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000807 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 explicit
811 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000812 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000813 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000814 typename __make_tuple_indices<sizeof...(_Up)>::type,
815 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
816 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
817 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
818 _Up...
819 >::value
820 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000821 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
823 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
824 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000825 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826
827 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000828 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000830 _CheckArgsConstructor<
831 sizeof...(_Up) == sizeof...(_Tp) &&
832 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000833 >::template __enable_implicit<_Up...>(),
834 bool
835 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000839 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 typename __make_tuple_indices<sizeof...(_Up)>::type(),
841 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
842 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
843 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000844 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000846 template <class _Alloc, class ..._Up,
847 typename enable_if
848 <
849 _CheckArgsConstructor<
850 sizeof...(_Up) == sizeof...(_Tp) &&
851 !_PackExpandsToThisTuple<_Up...>::value
852 >::template __enable_explicit<_Up...>(),
853 bool
854 >::type = false
855 >
856 _LIBCPP_INLINE_VISIBILITY
857 explicit
858 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000859 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000860 typename __make_tuple_indices<sizeof...(_Up)>::type(),
861 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
862 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
863 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
864 _VSTD::forward<_Up>(__u)...) {}
865
Eric Fiselierec5a2102019-07-12 23:01:48 +0000866 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000867 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000868 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
869 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870
Eric Fiselierec5a2102019-07-12 23:01:48 +0000871 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
872 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
873 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
874 : __base_(__t) {}
875 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000876 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000877 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000878 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
879 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000880
Eric Fiselierec5a2102019-07-12 23:01:48 +0000881 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
882 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
883 explicit
884 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
885 : __base_(__t) {}
886
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000888 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000890 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000891 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
892 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000893 bool
894 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000898 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000900 template <class _Alloc, class _Tuple,
901 typename enable_if
902 <
903 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000904 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
905 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000906 bool
907 >::type = false
908 >
909 _LIBCPP_INLINE_VISIBILITY
910 explicit
911 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000912 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000913
Eric Fiselier737a16d2016-07-25 02:36:42 +0000914 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
915 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
916
917 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb3225562016-12-15 06:34:54 +0000918 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000919 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
920 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000921 __base_.operator=(__t.__base_);
Eric Fiselier737a16d2016-07-25 02:36:42 +0000922 return *this;
923 }
924
925 _LIBCPP_INLINE_VISIBILITY
926 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
927 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
928 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000929 __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
Eric Fiselier737a16d2016-07-25 02:36:42 +0000930 return *this;
931 }
932
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 template <class _Tuple,
934 class = typename enable_if
935 <
Eric Fiselierb3225562016-12-15 06:34:54 +0000936 __tuple_assignable<_Tuple, tuple>::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 >::type
938 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 tuple&
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000941 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 {
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000943 __base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 return *this;
945 }
946
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000948 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000949 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950};
951
952template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000953class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954{
955public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000956 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +0000957 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000960 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000963 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000964 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000966 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +0000967 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000969 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000971 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972};
973
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000974#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +0000975template <class ..._Tp>
976tuple(_Tp...) -> tuple<_Tp...>;
977template <class _Tp1, class _Tp2>
978tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
979template <class _Alloc, class ..._Tp>
980tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
981template <class _Alloc, class _Tp1, class _Tp2>
982tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
983template <class _Alloc, class ..._Tp>
984tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +0000985#endif
986
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987template <class ..._Tp>
988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000989typename enable_if
990<
991 __all<__is_swappable<_Tp>::value...>::value,
992 void
993>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +0000994swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
995 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
996 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997
998// get
999
1000template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001001inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001002typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001003get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001005 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001006 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007}
1008
1009template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001010inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001011const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001012get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001014 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001015 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016}
1017
Howard Hinnant22e97242010-11-17 19:52:17 +00001018template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001019inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001020typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001021get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001022{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001023 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001024 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001025 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001026}
1027
Eric Fiselier6dea8092015-12-18 00:36:55 +00001028template <size_t _Ip, class ..._Tp>
1029inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1030const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1031get(const tuple<_Tp...>&& __t) _NOEXCEPT
1032{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001033 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001034 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001035 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001036}
1037
Marshall Clow15b02e02013-07-13 02:54:05 +00001038#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001039
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001040namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001041
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001042static constexpr size_t __not_found = -1;
1043static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001044
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001045inline _LIBCPP_INLINE_VISIBILITY
1046constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1047 return !__matches ? __res :
1048 (__res == __not_found ? __curr_i : __ambiguous);
1049}
Marshall Clow15b02e02013-07-13 02:54:05 +00001050
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001051template <size_t _Nx>
1052inline _LIBCPP_INLINE_VISIBILITY
1053constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1054 return __i == _Nx ? __not_found :
1055 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1056}
1057
1058template <class _T1, class ..._Args>
1059struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001060 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001061 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001062 static_assert(value != __not_found, "type not found in type list" );
1063 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001064};
1065
Eric Fiselier8087d302016-07-02 03:46:08 +00001066template <class _T1>
1067struct __find_exactly_one_checked<_T1> {
1068 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1069};
1070
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001071} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001072
1073template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001074struct __find_exactly_one_t
1075 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1076};
Marshall Clow15b02e02013-07-13 02:54:05 +00001077
1078template <class _T1, class... _Args>
1079inline _LIBCPP_INLINE_VISIBILITY
1080constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1081{
1082 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1083}
1084
1085template <class _T1, class... _Args>
1086inline _LIBCPP_INLINE_VISIBILITY
1087constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1088{
1089 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1090}
1091
1092template <class _T1, class... _Args>
1093inline _LIBCPP_INLINE_VISIBILITY
1094constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1095{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001096 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001097}
1098
Eric Fiselier6dea8092015-12-18 00:36:55 +00001099template <class _T1, class... _Args>
1100inline _LIBCPP_INLINE_VISIBILITY
1101constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1102{
1103 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1104}
1105
Marshall Clow15b02e02013-07-13 02:54:05 +00001106#endif
1107
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108// tie
1109
1110template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001111inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001113tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114{
1115 return tuple<_Tp&...>(__t...);
1116}
1117
1118template <class _Up>
1119struct __ignore_t
1120{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1123 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124};
1125
Eric Fiselier24e70262017-02-06 01:25:31 +00001126namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001127 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001128}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001131inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001132tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133make_tuple(_Tp&&... __t)
1134{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001135 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136}
1137
Howard Hinnant3d203a32010-08-19 18:59:38 +00001138template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001139inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1140tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001141forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001142{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001143 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001144}
1145
Howard Hinnantc834c512011-11-29 18:15:50 +00001146template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147struct __tuple_equal
1148{
1149 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001150 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151 bool operator()(const _Tp& __x, const _Up& __y)
1152 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001153 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154 }
1155};
1156
1157template <>
1158struct __tuple_equal<0>
1159{
1160 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 bool operator()(const _Tp&, const _Up&)
1163 {
1164 return true;
1165 }
1166};
1167
1168template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001169inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170bool
1171operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1172{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001173 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1175}
1176
1177template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179bool
1180operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1181{
1182 return !(__x == __y);
1183}
1184
Howard Hinnantc834c512011-11-29 18:15:50 +00001185template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186struct __tuple_less
1187{
1188 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001189 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 bool operator()(const _Tp& __x, const _Up& __y)
1191 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001192 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1193 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1194 return true;
1195 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1196 return false;
1197 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 }
1199};
1200
1201template <>
1202struct __tuple_less<0>
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&, const _Up&)
1207 {
1208 return false;
1209 }
1210};
1211
1212template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001213inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214bool
1215operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1216{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001217 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1219}
1220
1221template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001222inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223bool
1224operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1225{
1226 return __y < __x;
1227}
1228
1229template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001230inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231bool
1232operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1233{
1234 return !(__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
1245// tuple_cat
1246
Howard Hinnant6256ee72010-12-11 20:47:50 +00001247template <class _Tp, class _Up> struct __tuple_cat_type;
1248
1249template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001250struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001252 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001253};
1254
1255template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1256struct __tuple_cat_return_1
1257{
1258};
1259
1260template <class ..._Types, class _Tuple0>
1261struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1262{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001263 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001264 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001265 type;
1266};
1267
1268template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1269struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1270 : public __tuple_cat_return_1<
1271 typename __tuple_cat_type<
1272 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001273 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001274 >::type,
1275 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1276 _Tuple1, _Tuples...>
1277{
1278};
1279
1280template <class ..._Tuples> struct __tuple_cat_return;
1281
1282template <class _Tuple0, class ..._Tuples>
1283struct __tuple_cat_return<_Tuple0, _Tuples...>
1284 : public __tuple_cat_return_1<tuple<>,
1285 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1286 _Tuples...>
1287{
1288};
1289
1290template <>
1291struct __tuple_cat_return<>
1292{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001293 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001294};
1295
Marshall Clow2229cee2013-07-22 16:02:19 +00001296inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001297tuple<>
1298tuple_cat()
1299{
1300 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301}
1302
Howard Hinnantc834c512011-11-29 18:15:50 +00001303template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001304struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305
Howard Hinnant21376f62010-12-12 23:04:37 +00001306template <class ..._Types, size_t ..._I0, class _Tuple0>
1307struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001309 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001310 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1311 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1312};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313
Howard Hinnant21376f62010-12-12 23:04:37 +00001314template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1315struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1316 _Tuple0, _Tuple1, _Tuples...>
1317 : public __tuple_cat_return_ref_imp<
1318 tuple<_Types..., typename __apply_cv<_Tuple0,
1319 typename tuple_element<_I0,
1320 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1321 typename __make_tuple_indices<tuple_size<typename
1322 remove_reference<_Tuple1>::type>::value>::type,
1323 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324{
Howard Hinnant21376f62010-12-12 23:04:37 +00001325};
1326
1327template <class _Tuple0, class ..._Tuples>
1328struct __tuple_cat_return_ref
1329 : public __tuple_cat_return_ref_imp<tuple<>,
1330 typename __make_tuple_indices<
1331 tuple_size<typename remove_reference<_Tuple0>::type>::value
1332 >::type, _Tuple0, _Tuples...>
1333{
1334};
1335
1336template <class _Types, class _I0, class _J0>
1337struct __tuple_cat;
1338
1339template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001340struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001341{
1342 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001344 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1345 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1346 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001347 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1348 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001349 }
1350
1351 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001353 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1354 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1355 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001356 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1357 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001358 return __tuple_cat<
1359 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1360 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1361 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clowded420b2013-10-05 18:46:37 +00001362 (forward_as_tuple(
Marshall Clow60e4aa72014-06-24 00:46:19 +00001363 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1364 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnant21376f62010-12-12 23:04:37 +00001365 ),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001366 _VSTD::forward<_Tuple1>(__t1),
1367 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001368 }
1369};
1370
1371template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001372inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001373typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1374tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1375{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001376 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001377 return __tuple_cat<tuple<>, __tuple_indices<>,
1378 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001379 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1380 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381}
1382
1383template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001384struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385 : true_type {};
1386
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387template <class _T1, class _T2>
1388template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1389inline _LIBCPP_INLINE_VISIBILITY
1390pair<_T1, _T2>::pair(piecewise_construct_t,
1391 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1392 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001393 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1394 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395{
1396}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397
Eric Fiselier8e892c52016-07-18 00:35:56 +00001398#if _LIBCPP_STD_VER > 14
1399template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001400_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001401
1402#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1403
1404template <class _Fn, class _Tuple, size_t ..._Id>
1405inline _LIBCPP_INLINE_VISIBILITY
1406constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1407 __tuple_indices<_Id...>)
1408_LIBCPP_NOEXCEPT_RETURN(
1409 _VSTD::__invoke_constexpr(
1410 _VSTD::forward<_Fn>(__f),
1411 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1412)
1413
1414template <class _Fn, class _Tuple>
1415inline _LIBCPP_INLINE_VISIBILITY
1416constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1417_LIBCPP_NOEXCEPT_RETURN(
1418 _VSTD::__apply_tuple_impl(
1419 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001420 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001421)
1422
1423template <class _Tp, class _Tuple, size_t... _Idx>
1424inline _LIBCPP_INLINE_VISIBILITY
1425constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1426_LIBCPP_NOEXCEPT_RETURN(
1427 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1428)
1429
1430template <class _Tp, class _Tuple>
1431inline _LIBCPP_INLINE_VISIBILITY
1432constexpr _Tp make_from_tuple(_Tuple&& __t)
1433_LIBCPP_NOEXCEPT_RETURN(
1434 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001435 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001436)
1437
1438#undef _LIBCPP_NOEXCEPT_RETURN
1439
1440#endif // _LIBCPP_STD_VER > 14
1441
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001442#endif // !defined(_LIBCPP_CXX03_LANG)
1443
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444_LIBCPP_END_NAMESPACE_STD
1445
1446#endif // _LIBCPP_TUPLE