blob: b3d3bae6901917a72db7d8db8de4b8d141ec2830 [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&);
Louis Dionne6c0d5342018-07-31 11:56:20 -040058 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...);
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 template <class... U>
60 tuple& operator=(const tuple<U...>&);
61 template <class... U>
62 tuple& operator=(tuple<U...>&&);
63 template <class U1, class U2>
64 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
65 template <class U1, class U2>
Louis Dionnea6316ed2018-11-12 01:28:07 +000066 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Louis Dionne6c0d5342018-07-31 11:56:20 -040068 template<class U, size_t N>
69 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70 template<class U, size_t N>
71 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
Howard Hinnant89ef1212011-05-27 19:08:18 +000073 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
Howard Hinnantc51e1022010-05-11 19:42:16 +000074};
75
Louis Dionne616da2a2019-08-12 18:30:31 +000076template <class ...T>
77tuple(T...) -> tuple<T...>; // since C++17
78template <class T1, class T2>
79tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
80template <class Alloc, class ...T>
81tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
82template <class Alloc, class T1, class T2>
83tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
84template <class Alloc, class ...T>
85tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
86
Marshall Clowf1bf62f2018-01-02 17:17:01 +000087inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Marshall Clow2229cee2013-07-22 16:02:19 +000089template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000090template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000091template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000092template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000093
94// [tuple.apply], calling a function with a tuple of arguments:
95template <class F, class Tuple>
96 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
97template <class T, class Tuple>
98 constexpr T make_from_tuple(Tuple&& t); // C++17
99
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000101template <class T> struct tuple_size; // undefined
102template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000103template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000104 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000105template <size_t I, class T> struct tuple_element; // undefined
106template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000107template <size_t I, class T>
108 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000109
110// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000111template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000112 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000113 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000114template <size_t I, class... T>
115 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000116 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000117template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000118 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000119 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000120template <size_t I, class... T>
121 const typename tuple_element<I, tuple<T...>>::type&&
122 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Marshall Clow15b02e02013-07-13 02:54:05 +0000124template <class T1, class... T>
125 constexpr T1& get(tuple<T...>&) noexcept; // C++14
126template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000127 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000128template <class T1, class... T>
129 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000130template <class T1, class... T>
131 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000132
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000134template<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
136template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
137template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
138template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
139template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141template <class... Types, class Alloc>
142 struct uses_allocator<tuple<Types...>, Alloc>;
143
144template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000145 void
146 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148} // std
149
150*/
151
152#include <__config>
153#include <__tuple>
154#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000156#include <__functional_base>
157#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000158#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000162#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
164_LIBCPP_BEGIN_NAMESPACE_STD
165
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000166#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167
Marshall Clowf50d66f2014-03-03 06:18:11 +0000168
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169// __tuple_leaf
170
Eric Fiselierf7394302015-06-13 07:08:02 +0000171template <size_t _Ip, class _Hp,
172 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000173 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174class __tuple_leaf;
175
176template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000177inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000179 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180{
181 swap(__x.get(), __y.get());
182}
183
184template <size_t _Ip, class _Hp, bool>
185class __tuple_leaf
186{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000187 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188
Eric Fiselierca8bba12016-07-20 02:57:39 +0000189 template <class _Tp>
190 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000191#if __has_keyword(__reference_binds_to_temporary)
192 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000193#else
194 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000195#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000196 }
197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 __tuple_leaf& operator=(const __tuple_leaf&);
199public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000201 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202 {static_assert(!is_reference<_Hp>::value,
203 "Attempted to default construct a reference element in a tuple");}
204
205 template <class _Alloc>
206 _LIBCPP_INLINE_VISIBILITY
207 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000208 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209 {static_assert(!is_reference<_Hp>::value,
210 "Attempted to default construct a reference element in a tuple");}
211
212 template <class _Alloc>
213 _LIBCPP_INLINE_VISIBILITY
214 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000215 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216 {static_assert(!is_reference<_Hp>::value,
217 "Attempted to default construct a reference element in a tuple");}
218
219 template <class _Alloc>
220 _LIBCPP_INLINE_VISIBILITY
221 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000222 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223 {static_assert(!is_reference<_Hp>::value,
224 "Attempted to default construct a reference element in a tuple");}
225
Howard Hinnant693fc212010-09-27 17:54:17 +0000226 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000227 class = _EnableIf<
228 _And<
229 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
230 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000231 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000232 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000233 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000234 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000235 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000236 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000237 {static_assert(__can_bind_reference<_Tp&&>(),
238 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239
240 template <class _Tp, class _Alloc>
241 _LIBCPP_INLINE_VISIBILITY
242 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000243 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000244 {static_assert(__can_bind_reference<_Tp&&>(),
245 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246
247 template <class _Tp, class _Alloc>
248 _LIBCPP_INLINE_VISIBILITY
249 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000250 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000251 {static_assert(!is_reference<_Hp>::value,
252 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253
254 template <class _Tp, class _Alloc>
255 _LIBCPP_INLINE_VISIBILITY
256 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000257 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000258 {static_assert(!is_reference<_Hp>::value,
259 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
Marshall Clow47fcee52014-04-21 23:48:09 +0000261 __tuple_leaf(const __tuple_leaf& __t) = default;
262 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +0000265 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000267 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 return 0;
269 }
270
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
272 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273};
274
275template <size_t _Ip, class _Hp>
276class __tuple_leaf<_Ip, _Hp, true>
277 : private _Hp
278{
279
280 __tuple_leaf& operator=(const __tuple_leaf&);
281public:
Howard Hinnantaabb4202012-07-06 20:50:27 +0000282 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
283 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284
285 template <class _Alloc>
286 _LIBCPP_INLINE_VISIBILITY
287 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
288
289 template <class _Alloc>
290 _LIBCPP_INLINE_VISIBILITY
291 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
292 : _Hp(allocator_arg_t(), __a) {}
293
294 template <class _Alloc>
295 _LIBCPP_INLINE_VISIBILITY
296 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
297 : _Hp(__a) {}
298
Howard Hinnant693fc212010-09-27 17:54:17 +0000299 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000300 class = _EnableIf<
301 _And<
302 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
303 is_constructible<_Hp, _Tp>
304 >::value
305 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000306 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000308 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000309 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310
311 template <class _Tp, class _Alloc>
312 _LIBCPP_INLINE_VISIBILITY
313 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
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, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000319 : _Hp(allocator_arg_t(), __a, _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, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000324 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000326 __tuple_leaf(__tuple_leaf const &) = default;
327 __tuple_leaf(__tuple_leaf &&) = default;
328
Howard Hinnant89ef1212011-05-27 19:08:18 +0000329 _LIBCPP_INLINE_VISIBILITY
330 int
331 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000333 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 return 0;
335 }
336
Marshall Clow2229cee2013-07-22 16:02:19 +0000337 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
338 _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 +0000339};
340
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000341template <class ..._Tp>
342_LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +0000343void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
Marshall Clowc470eae2014-10-15 10:33:02 +0000345template <class _Tp>
346struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000347
Marshall Clowc470eae2014-10-15 10:33:02 +0000348template <class ..._Tp>
349struct __all_default_constructible<__tuple_types<_Tp...>>
350 : __all<is_default_constructible<_Tp>::value...>
351{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000352
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353// __tuple_impl
354
355template<class _Indx, class ..._Tp> struct __tuple_impl;
356
357template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000358struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 : public __tuple_leaf<_Indx, _Tp>...
360{
Howard Hinnant38469632012-07-06 20:39:45 +0000361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabb4202012-07-06 20:50:27 +0000362 _LIBCPP_CONSTEXPR __tuple_impl()
363 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000364
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365 template <size_t ..._Uf, class ..._Tf,
366 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 explicit
369 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
370 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000371 _Up&&... __u)
372 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
373 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000374 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 __tuple_leaf<_Ul, _Tl>()...
376 {}
377
378 template <class _Alloc, size_t ..._Uf, class ..._Tf,
379 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381 explicit
382 __tuple_impl(allocator_arg_t, const _Alloc& __a,
383 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
384 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
385 _Up&&... __u) :
386 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000387 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
389 {}
390
391 template <class _Tuple,
392 class = typename enable_if
393 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000394 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 >::type
396 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000397 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000398 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
399 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000400 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
401 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 {}
403
404 template <class _Alloc, class _Tuple,
405 class = typename enable_if
406 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000407 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 >::type
409 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
412 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000413 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000414 _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
Howard Hinnant0d032d12013-11-06 17:45:43 +0000418 __tuple_impl(const __tuple_impl&) = default;
419 __tuple_impl(__tuple_impl&&) = default;
420
421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000423 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400425 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 }
427};
428
Louis Dionne6c0d5342018-07-31 11:56:20 -0400429template<class _Dest, class _Source, size_t ..._Np>
430_LIBCPP_INLINE_VISIBILITY
431void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
432 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
433}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000434
Louis Dionne6c0d5342018-07-31 11:56:20 -0400435template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
436_LIBCPP_INLINE_VISIBILITY
437void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
438 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500439 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400440 ), void(), 0)...);
441}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000442
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000444class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000446 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000448 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Eric Fiselier41b686e2016-12-08 23:57:08 +0000450#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
451 static constexpr bool _EnableImplicitReducedArityExtension = true;
452#else
453 static constexpr bool _EnableImplicitReducedArityExtension = false;
454#endif
455
Eric Fiselier264d04a2016-04-15 18:05:59 +0000456 template <class ..._Args>
457 struct _PackExpandsToThisTuple : false_type {};
458
459 template <class _Arg>
460 struct _PackExpandsToThisTuple<_Arg>
461 : is_same<typename __uncvref<_Arg>::type, tuple> {};
462
463 template <bool _MaybeEnable, class _Dummy = void>
464 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
465
466 template <class _Dummy>
467 struct _CheckArgsConstructor<true, _Dummy>
468 {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000469 template <int&...>
470 static constexpr bool __enable_implicit_default() {
471 return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
472 }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000473
Eric Fiselier18d72a02019-09-30 20:55:30 +0000474 template <int&...>
475 static constexpr bool __enable_explicit_default() {
476 return
477 __all<is_default_constructible<_Tp>::value...>::value &&
478 !__enable_implicit_default< >();
479 }
480
Eric Fiseliere61db632016-07-25 04:32:07 +0000481
482 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000483 static constexpr bool __enable_explicit() {
484 return
485 __tuple_constructible<
486 tuple<_Args...>,
487 typename __make_tuple_types<tuple,
488 sizeof...(_Args) < sizeof...(_Tp) ?
489 sizeof...(_Args) :
490 sizeof...(_Tp)>::type
491 >::value &&
492 !__tuple_convertible<
493 tuple<_Args...>,
494 typename __make_tuple_types<tuple,
495 sizeof...(_Args) < sizeof...(_Tp) ?
496 sizeof...(_Args) :
497 sizeof...(_Tp)>::type
498 >::value &&
499 __all_default_constructible<
500 typename __make_tuple_types<tuple, sizeof...(_Tp),
501 sizeof...(_Args) < sizeof...(_Tp) ?
502 sizeof...(_Args) :
503 sizeof...(_Tp)>::type
504 >::value;
505 }
506
507 template <class ..._Args>
508 static constexpr bool __enable_implicit() {
509 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000510 __tuple_constructible<
511 tuple<_Args...>,
512 typename __make_tuple_types<tuple,
513 sizeof...(_Args) < sizeof...(_Tp) ?
514 sizeof...(_Args) :
515 sizeof...(_Tp)>::type
516 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000517 __tuple_convertible<
518 tuple<_Args...>,
519 typename __make_tuple_types<tuple,
520 sizeof...(_Args) < sizeof...(_Tp) ?
521 sizeof...(_Args) :
522 sizeof...(_Tp)>::type
523 >::value &&
524 __all_default_constructible<
525 typename __make_tuple_types<tuple, sizeof...(_Tp),
526 sizeof...(_Args) < sizeof...(_Tp) ?
527 sizeof...(_Args) :
528 sizeof...(_Tp)>::type
529 >::value;
530 }
531 };
532
533 template <bool _MaybeEnable,
534 bool = sizeof...(_Tp) == 1,
535 class _Dummy = void>
536 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
537
538 template <class _Dummy>
539 struct _CheckTupleLikeConstructor<true, false, _Dummy>
540 {
541 template <class _Tuple>
542 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000543 return __tuple_constructible<_Tuple, tuple>::value
544 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000545 }
546
547 template <class _Tuple>
548 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000549 return __tuple_constructible<_Tuple, tuple>::value
550 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000551 }
552 };
553
554 template <class _Dummy>
555 struct _CheckTupleLikeConstructor<true, true, _Dummy>
556 {
557 // This trait is used to disable the tuple-like constructor when
558 // the UTypes... constructor should be selected instead.
559 // See LWG issue #2549.
560 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000561 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000562 // Don't attempt the two checks below if the tuple we are given
563 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000564 _IsSame<__uncvref_t<_Tuple>, tuple>,
565 _Lazy<_And,
566 _Not<is_constructible<_Tp..., _Tuple>>,
567 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000568 >
569 >;
570
571 template <class _Tuple>
572 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000573 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000574 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000575 __tuple_convertible<_Tuple, tuple>,
576 _PreferTupleLikeConstructor<_Tuple>
577 >::value;
578 }
579
580 template <class _Tuple>
581 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000582 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000583 __tuple_constructible<_Tuple, tuple>,
584 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000585 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000586 >::value;
587 }
588 };
589
Eric Fiselierec5a2102019-07-12 23:01:48 +0000590 template <class _Tuple, bool _DisableIfLValue>
591 using _EnableImplicitTupleLikeConstructor = _EnableIf<
592 _CheckTupleLikeConstructor<
593 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
594 && !_PackExpandsToThisTuple<_Tuple>::value
595 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
596 >::template __enable_implicit<_Tuple>(),
597 bool
598 >;
599
600 template <class _Tuple, bool _DisableIfLValue>
601 using _EnableExplicitTupleLikeConstructor = _EnableIf<
602 _CheckTupleLikeConstructor<
603 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
604 && !_PackExpandsToThisTuple<_Tuple>::value
605 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
606 >::template __enable_explicit<_Tuple>(),
607 bool
608 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000609 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000610 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000611 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000612 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000613 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000614 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000615 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
616 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617public:
618
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000619 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000620 _CheckArgsConstructor<_Dummy>::__enable_implicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000621 , void*> = nullptr>
622 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
623 tuple()
624 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
625
626 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000627 _CheckArgsConstructor<_Dummy>::__enable_explicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000628 , void*> = nullptr>
629 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
630 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000631 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000632
Eric Fiselier737a16d2016-07-25 02:36:42 +0000633 tuple(tuple const&) = default;
634 tuple(tuple&&) = default;
635
Eric Fiselier18d72a02019-09-30 20:55:30 +0000636 template <class _AllocArgT, class _Alloc, _EnableIf<
637 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000638 , void*> = nullptr
Eric Fiselier3906a132019-06-23 20:28:29 +0000639 >
Eric Fiselierc170df52016-04-15 03:29:40 +0000640 _LIBCPP_INLINE_VISIBILITY
641 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000642 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000643 __tuple_indices<>(), __tuple_types<>(),
644 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
645 __tuple_types<_Tp...>()) {}
646
Eric Fiselier18d72a02019-09-30 20:55:30 +0000647 template <class _AllocArgT, class _Alloc, _EnableIf<
648 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000649 , void*> = nullptr
650 >
651 explicit _LIBCPP_INLINE_VISIBILITY
652 tuple(_AllocArgT, _Alloc const& __a)
653 : __base_(allocator_arg_t(), __a,
654 __tuple_indices<>(), __tuple_types<>(),
655 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
656 __tuple_types<_Tp...>()) {}
657
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000658 template <bool _Dummy = true,
659 typename enable_if
660 <
661 _CheckArgsConstructor<
662 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000663 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000664 bool
665 >::type = false
666 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000668 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000669 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
671 typename __make_tuple_indices<0>::type(),
672 typename __make_tuple_types<tuple, 0>::type(),
673 __t...
674 ) {}
675
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000676 template <bool _Dummy = true,
677 typename enable_if
678 <
679 _CheckArgsConstructor<
680 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000681 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000682 bool
683 >::type = false
684 >
685 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
686 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000687 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000688 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
689 typename __make_tuple_indices<0>::type(),
690 typename __make_tuple_types<tuple, 0>::type(),
691 __t...
692 ) {}
693
694 template <class _Alloc, bool _Dummy = true,
695 typename enable_if
696 <
697 _CheckArgsConstructor<
698 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000699 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000700 bool
701 >::type = false
702 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000705 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
707 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
708 typename __make_tuple_indices<0>::type(),
709 typename __make_tuple_types<tuple, 0>::type(),
710 __t...
711 ) {}
712
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000713 template <class _Alloc, bool _Dummy = true,
714 typename enable_if
715 <
716 _CheckArgsConstructor<
717 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000718 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000719 bool
720 >::type = false
721 >
722 _LIBCPP_INLINE_VISIBILITY
723 explicit
724 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000725 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000726 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
727 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
728 typename __make_tuple_indices<0>::type(),
729 typename __make_tuple_types<tuple, 0>::type(),
730 __t...
731 ) {}
732
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000734 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000735 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000737 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000738 sizeof...(_Up) == sizeof...(_Tp)
739 && !_PackIsTuple
740 >::template __enable_implicit<_Up...>() ||
741 _CheckArgsConstructor<
742 _EnableImplicitReducedArityExtension
743 && sizeof...(_Up) < sizeof...(_Tp)
744 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000745 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000746 bool
747 >::type = false
748 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000749 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000750 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000751 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000752 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000753 typename __make_tuple_indices<sizeof...(_Up)>::type,
754 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
755 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
756 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000757 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000758 >::value
759 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000760 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000761 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
762 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
763 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
764 _VSTD::forward<_Up>(__u)...) {}
765
766 template <class ..._Up,
767 typename enable_if
768 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000769 _CheckArgsConstructor<
770 sizeof...(_Up) <= sizeof...(_Tp)
771 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000772 >::template __enable_explicit<_Up...>() ||
773 _CheckArgsConstructor<
774 !_EnableImplicitReducedArityExtension
775 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000776 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000777 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000778 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000779 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000781 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 explicit
783 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,
790 _Up...
791 >::value
792 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000793 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +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(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000797 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798
799 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000800 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000802 _CheckArgsConstructor<
803 sizeof...(_Up) == sizeof...(_Tp) &&
804 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000805 >::template __enable_implicit<_Up...>(),
806 bool
807 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000811 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 typename __make_tuple_indices<sizeof...(_Up)>::type(),
813 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
814 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
815 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000816 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000818 template <class _Alloc, class ..._Up,
819 typename enable_if
820 <
821 _CheckArgsConstructor<
822 sizeof...(_Up) == sizeof...(_Tp) &&
823 !_PackExpandsToThisTuple<_Up...>::value
824 >::template __enable_explicit<_Up...>(),
825 bool
826 >::type = false
827 >
828 _LIBCPP_INLINE_VISIBILITY
829 explicit
830 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000831 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000832 typename __make_tuple_indices<sizeof...(_Up)>::type(),
833 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
834 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
835 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
836 _VSTD::forward<_Up>(__u)...) {}
837
Eric Fiselierec5a2102019-07-12 23:01:48 +0000838 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000839 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000840 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
841 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842
Eric Fiselierec5a2102019-07-12 23:01:48 +0000843 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
844 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
845 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
846 : __base_(__t) {}
847 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000849 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000850 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
851 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000852
Eric Fiselierec5a2102019-07-12 23:01:48 +0000853 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
854 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855 explicit
856 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
857 : __base_(__t) {}
858
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000860 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000862 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000863 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
864 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000865 bool
866 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000870 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000872 template <class _Alloc, class _Tuple,
873 typename enable_if
874 <
875 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000876 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
877 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000878 bool
879 >::type = false
880 >
881 _LIBCPP_INLINE_VISIBILITY
882 explicit
883 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000884 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000885
Louis Dionne6c0d5342018-07-31 11:56:20 -0400886 // [tuple.assign]
Eric Fiselier737a16d2016-07-25 02:36:42 +0000887 _LIBCPP_INLINE_VISIBILITY
Louis Dionne6c0d5342018-07-31 11:56:20 -0400888 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
889 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000890 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400891 _VSTD::__memberwise_copy_assign(*this, __tuple,
892 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000893 return *this;
894 }
895
896 _LIBCPP_INLINE_VISIBILITY
Louis Dionne6c0d5342018-07-31 11:56:20 -0400897 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
898 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000899 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400900 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
901 __tuple_types<_Tp...>(),
902 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000903 return *this;
904 }
905
Louis Dionne6c0d5342018-07-31 11:56:20 -0400906 template<class... _Up, _EnableIf<
907 _And<
908 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
909 is_assignable<_Tp&, _Up const&>...
910 >::value
911 ,int> = 0>
912 _LIBCPP_INLINE_VISIBILITY
913 tuple& operator=(tuple<_Up...> const& __tuple)
914 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
915 {
916 _VSTD::__memberwise_copy_assign(*this, __tuple,
917 typename __make_tuple_indices<sizeof...(_Tp)>::type());
918 return *this;
919 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920
Louis Dionne6c0d5342018-07-31 11:56:20 -0400921 template<class... _Up, _EnableIf<
922 _And<
923 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
924 is_assignable<_Tp&, _Up>...
925 >::value
926 ,int> = 0>
927 _LIBCPP_INLINE_VISIBILITY
928 tuple& operator=(tuple<_Up...>&& __tuple)
929 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
930 {
931 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
932 __tuple_types<_Up...>(),
933 typename __make_tuple_indices<sizeof...(_Tp)>::type());
934 return *this;
935 }
936
937 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
938 _And<_Dep,
939 _BoolConstant<sizeof...(_Tp) == 2>,
940 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
941 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
942 >::value
943 ,int> = 0>
944 _LIBCPP_INLINE_VISIBILITY
945 tuple& operator=(pair<_Up1, _Up2> const& __pair)
946 _NOEXCEPT_((_And<
947 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
948 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
949 >::value))
950 {
951 _VSTD::get<0>(*this) = __pair.first;
952 _VSTD::get<1>(*this) = __pair.second;
953 return *this;
954 }
955
956 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
957 _And<_Dep,
958 _BoolConstant<sizeof...(_Tp) == 2>,
959 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
960 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
961 >::value
962 ,int> = 0>
963 _LIBCPP_INLINE_VISIBILITY
964 tuple& operator=(pair<_Up1, _Up2>&& __pair)
965 _NOEXCEPT_((_And<
966 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
967 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
968 >::value))
969 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500970 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
971 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -0400972 return *this;
973 }
974
975 // EXTENSION
976 template<class _Up, size_t _Np, class = _EnableIf<
977 _And<
978 _BoolConstant<_Np == sizeof...(_Tp)>,
979 is_assignable<_Tp&, _Up const&>...
980 >::value
981 > >
982 _LIBCPP_INLINE_VISIBILITY
983 tuple& operator=(array<_Up, _Np> const& __array)
984 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
985 {
986 _VSTD::__memberwise_copy_assign(*this, __array,
987 typename __make_tuple_indices<sizeof...(_Tp)>::type());
988 return *this;
989 }
990
991 // EXTENSION
992 template<class _Up, size_t _Np, class = void, class = _EnableIf<
993 _And<
994 _BoolConstant<_Np == sizeof...(_Tp)>,
995 is_assignable<_Tp&, _Up>...
996 >::value
997 > >
998 _LIBCPP_INLINE_VISIBILITY
999 tuple& operator=(array<_Up, _Np>&& __array)
1000 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1001 {
1002 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1003 __tuple_types<_If<true, _Up, _Tp>...>(),
1004 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1005 return *this;
1006 }
1007
1008 // [tuple.swap]
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +00001010 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001011 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012};
1013
1014template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001015class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016{
1017public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001018 _LIBCPP_INLINE_VISIBILITY
Louis Dionne8083b052019-06-11 15:02:10 +00001019 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +00001022 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 template <class _Alloc>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +00001025 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001026 template <class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +00001028 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001029 template <class _Alloc, class _Up>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant62751642012-07-06 21:53:48 +00001031 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant89ef1212011-05-27 19:08:18 +00001033 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034};
1035
Eric Fiselier8df4ac62017-10-04 00:04:26 +00001036#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +00001037template <class ..._Tp>
1038tuple(_Tp...) -> tuple<_Tp...>;
1039template <class _Tp1, class _Tp2>
1040tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1041template <class _Alloc, class ..._Tp>
1042tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1043template <class _Alloc, class _Tp1, class _Tp2>
1044tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1045template <class _Alloc, class ..._Tp>
1046tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001047#endif
1048
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049template <class ..._Tp>
1050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +00001051typename enable_if
1052<
1053 __all<__is_swappable<_Tp>::value...>::value,
1054 void
1055>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001056swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1057 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1058 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059
1060// get
1061
1062template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001063inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001064typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001065get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001067 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001068 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069}
1070
1071template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001072inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001073const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001074get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001076 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001077 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078}
1079
Howard Hinnant22e97242010-11-17 19:52:17 +00001080template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001081inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001082typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001083get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001084{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001085 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001086 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001087 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001088}
1089
Eric Fiselier6dea8092015-12-18 00:36:55 +00001090template <size_t _Ip, class ..._Tp>
1091inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1092const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1093get(const tuple<_Tp...>&& __t) _NOEXCEPT
1094{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001095 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001096 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001097 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001098}
1099
Marshall Clow15b02e02013-07-13 02:54:05 +00001100#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001101
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001102namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001103
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001104static constexpr size_t __not_found = -1;
1105static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001106
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001107inline _LIBCPP_INLINE_VISIBILITY
1108constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1109 return !__matches ? __res :
1110 (__res == __not_found ? __curr_i : __ambiguous);
1111}
Marshall Clow15b02e02013-07-13 02:54:05 +00001112
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001113template <size_t _Nx>
1114inline _LIBCPP_INLINE_VISIBILITY
1115constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1116 return __i == _Nx ? __not_found :
1117 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1118}
1119
1120template <class _T1, class ..._Args>
1121struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001122 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001123 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001124 static_assert(value != __not_found, "type not found in type list" );
1125 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001126};
1127
Eric Fiselier8087d302016-07-02 03:46:08 +00001128template <class _T1>
1129struct __find_exactly_one_checked<_T1> {
1130 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1131};
1132
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001133} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001134
1135template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001136struct __find_exactly_one_t
1137 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1138};
Marshall Clow15b02e02013-07-13 02:54:05 +00001139
1140template <class _T1, class... _Args>
1141inline _LIBCPP_INLINE_VISIBILITY
1142constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1143{
1144 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1145}
1146
1147template <class _T1, class... _Args>
1148inline _LIBCPP_INLINE_VISIBILITY
1149constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1150{
1151 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1152}
1153
1154template <class _T1, class... _Args>
1155inline _LIBCPP_INLINE_VISIBILITY
1156constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1157{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001158 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001159}
1160
Eric Fiselier6dea8092015-12-18 00:36:55 +00001161template <class _T1, class... _Args>
1162inline _LIBCPP_INLINE_VISIBILITY
1163constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1164{
1165 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1166}
1167
Marshall Clow15b02e02013-07-13 02:54:05 +00001168#endif
1169
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170// tie
1171
1172template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001175tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176{
1177 return tuple<_Tp&...>(__t...);
1178}
1179
1180template <class _Up>
1181struct __ignore_t
1182{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001183 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001184 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1185 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186};
1187
Eric Fiselier24e70262017-02-06 01:25:31 +00001188namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001189 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001190}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001193inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001194tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195make_tuple(_Tp&&... __t)
1196{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001197 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198}
1199
Howard Hinnant3d203a32010-08-19 18:59:38 +00001200template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001201inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1202tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001203forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001204{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001205 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001206}
1207
Howard Hinnantc834c512011-11-29 18:15:50 +00001208template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209struct __tuple_equal
1210{
1211 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001212 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213 bool operator()(const _Tp& __x, const _Up& __y)
1214 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001215 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216 }
1217};
1218
1219template <>
1220struct __tuple_equal<0>
1221{
1222 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 bool operator()(const _Tp&, const _Up&)
1225 {
1226 return true;
1227 }
1228};
1229
1230template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001231inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232bool
1233operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1234{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001235 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1237}
1238
1239template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001240inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241bool
1242operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1243{
1244 return !(__x == __y);
1245}
1246
Howard Hinnantc834c512011-11-29 18:15:50 +00001247template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248struct __tuple_less
1249{
1250 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001251 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252 bool operator()(const _Tp& __x, const _Up& __y)
1253 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001254 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1255 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1256 return true;
1257 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1258 return false;
1259 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260 }
1261};
1262
1263template <>
1264struct __tuple_less<0>
1265{
1266 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 bool operator()(const _Tp&, const _Up&)
1269 {
1270 return false;
1271 }
1272};
1273
1274template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001275inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001276bool
1277operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1278{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001279 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1281}
1282
1283template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001284inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285bool
1286operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1287{
1288 return __y < __x;
1289}
1290
1291template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001292inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293bool
1294operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1295{
1296 return !(__x < __y);
1297}
1298
1299template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001300inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301bool
1302operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1303{
1304 return !(__y < __x);
1305}
1306
1307// tuple_cat
1308
Howard Hinnant6256ee72010-12-11 20:47:50 +00001309template <class _Tp, class _Up> struct __tuple_cat_type;
1310
1311template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001312struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001314 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001315};
1316
1317template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1318struct __tuple_cat_return_1
1319{
1320};
1321
1322template <class ..._Types, class _Tuple0>
1323struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1324{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001325 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001326 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001327 type;
1328};
1329
1330template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1331struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1332 : public __tuple_cat_return_1<
1333 typename __tuple_cat_type<
1334 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001335 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001336 >::type,
1337 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1338 _Tuple1, _Tuples...>
1339{
1340};
1341
1342template <class ..._Tuples> struct __tuple_cat_return;
1343
1344template <class _Tuple0, class ..._Tuples>
1345struct __tuple_cat_return<_Tuple0, _Tuples...>
1346 : public __tuple_cat_return_1<tuple<>,
1347 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1348 _Tuples...>
1349{
1350};
1351
1352template <>
1353struct __tuple_cat_return<>
1354{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001355 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001356};
1357
Marshall Clow2229cee2013-07-22 16:02:19 +00001358inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001359tuple<>
1360tuple_cat()
1361{
1362 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363}
1364
Howard Hinnantc834c512011-11-29 18:15:50 +00001365template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001366struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367
Howard Hinnant21376f62010-12-12 23:04:37 +00001368template <class ..._Types, size_t ..._I0, class _Tuple0>
1369struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001371 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001372 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1373 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1374};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375
Howard Hinnant21376f62010-12-12 23:04:37 +00001376template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1377struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1378 _Tuple0, _Tuple1, _Tuples...>
1379 : public __tuple_cat_return_ref_imp<
1380 tuple<_Types..., typename __apply_cv<_Tuple0,
1381 typename tuple_element<_I0,
1382 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1383 typename __make_tuple_indices<tuple_size<typename
1384 remove_reference<_Tuple1>::type>::value>::type,
1385 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386{
Howard Hinnant21376f62010-12-12 23:04:37 +00001387};
1388
1389template <class _Tuple0, class ..._Tuples>
1390struct __tuple_cat_return_ref
1391 : public __tuple_cat_return_ref_imp<tuple<>,
1392 typename __make_tuple_indices<
1393 tuple_size<typename remove_reference<_Tuple0>::type>::value
1394 >::type, _Tuple0, _Tuples...>
1395{
1396};
1397
1398template <class _Types, class _I0, class _J0>
1399struct __tuple_cat;
1400
1401template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001402struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001403{
1404 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001405 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001406 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1407 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1408 {
David Blaikie699a5e22019-10-28 18:03:59 -07001409 return _VSTD::forward_as_tuple(
1410 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1411 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001412 }
1413
1414 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001415 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001416 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1417 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1418 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001419 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1420 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001421 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001422 tuple<_Types...,
1423 typename __apply_cv<_Tuple0, typename tuple_element<
1424 _J0, _T0>::type>::type&&...>,
1425 typename __make_tuple_indices<sizeof...(_Types) +
1426 tuple_size<_T0>::value>::type,
1427 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1428 _VSTD::forward_as_tuple(
1429 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1430 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1431 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001432 }
1433};
1434
1435template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001436inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001437typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1438tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1439{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001440 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001441 return __tuple_cat<tuple<>, __tuple_indices<>,
1442 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001443 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1444 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445}
1446
1447template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001448struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449 : true_type {};
1450
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451template <class _T1, class _T2>
1452template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001453inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454pair<_T1, _T2>::pair(piecewise_construct_t,
1455 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1456 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001457 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1458 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459{
1460}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461
Eric Fiselier8e892c52016-07-18 00:35:56 +00001462#if _LIBCPP_STD_VER > 14
1463template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001464_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001465
1466#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1467
1468template <class _Fn, class _Tuple, size_t ..._Id>
1469inline _LIBCPP_INLINE_VISIBILITY
1470constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1471 __tuple_indices<_Id...>)
1472_LIBCPP_NOEXCEPT_RETURN(
1473 _VSTD::__invoke_constexpr(
1474 _VSTD::forward<_Fn>(__f),
1475 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1476)
1477
1478template <class _Fn, class _Tuple>
1479inline _LIBCPP_INLINE_VISIBILITY
1480constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1481_LIBCPP_NOEXCEPT_RETURN(
1482 _VSTD::__apply_tuple_impl(
1483 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001484 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001485)
1486
1487template <class _Tp, class _Tuple, size_t... _Idx>
1488inline _LIBCPP_INLINE_VISIBILITY
1489constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1490_LIBCPP_NOEXCEPT_RETURN(
1491 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1492)
1493
1494template <class _Tp, class _Tuple>
1495inline _LIBCPP_INLINE_VISIBILITY
1496constexpr _Tp make_from_tuple(_Tuple&& __t)
1497_LIBCPP_NOEXCEPT_RETURN(
1498 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001499 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001500)
1501
1502#undef _LIBCPP_NOEXCEPT_RETURN
1503
1504#endif // _LIBCPP_STD_VER > 14
1505
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001506#endif // !defined(_LIBCPP_CXX03_LANG)
1507
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508_LIBCPP_END_NAMESPACE_STD
1509
1510#endif // _LIBCPP_TUPLE