1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// 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
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13// clang-format off
14
15/*
16 tuple synopsis
17
18namespace std
19{
20
21template <class... T>
22class tuple {
23public:
24 explicit(see-below) constexpr tuple();
25 explicit(see-below) tuple(const T&...); // constexpr in C++14
26 template <class... U>
27 explicit(see-below) tuple(U&&...); // constexpr in C++14
28 tuple(const tuple&) = default;
29 tuple(tuple&&) = default;
30
31 template<class... UTypes>
32 constexpr explicit(see-below) tuple(tuple<UTypes...>&); // C++23
33 template <class... U>
34 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
35 template <class... U>
36 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
37 template<class... UTypes>
38 constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23
39
40 template<class U1, class U2>
41 constexpr explicit(see-below) tuple(pair<U1, U2>&); // iff sizeof...(Types) == 2 // C++23
42 template <class U1, class U2>
43 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
44 template <class U1, class U2>
45 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
46 template<class U1, class U2>
47 constexpr explicit(see-below) tuple(const pair<U1, U2>&&); // iff sizeof...(Types) == 2 // C++23
48
49 // allocator-extended constructors
50 template <class Alloc>
51 tuple(allocator_arg_t, const Alloc& a);
52 template <class Alloc>
53 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
54 template <class Alloc, class... U>
55 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
56 template <class Alloc>
57 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
58 template <class Alloc>
59 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
60 template<class Alloc, class... UTypes>
61 constexpr explicit(see-below)
62 tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&); // C++23
63 template <class Alloc, class... U>
64 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
65 template <class Alloc, class... U>
66 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
67 template<class Alloc, class... UTypes>
68 constexpr explicit(see-below)
69 tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&); // C++23
70 template<class Alloc, class U1, class U2>
71 constexpr explicit(see-below)
72 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&); // C++23
73 template <class Alloc, class U1, class U2>
74 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
75 template <class Alloc, class U1, class U2>
76 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
77 template<class Alloc, class U1, class U2>
78 constexpr explicit(see-below)
79 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&); // C++23
80
81 tuple& operator=(const tuple&); // constexpr in C++20
82 constexpr const tuple& operator=(const tuple&) const; // C++23
83 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
84 constexpr const tuple& operator=(tuple&&) const; // C++23
85 template <class... U>
86 tuple& operator=(const tuple<U...>&); // constexpr in C++20
87 template<class... UTypes>
88 constexpr const tuple& operator=(const tuple<UTypes...>&) const; // C++23
89 template <class... U>
90 tuple& operator=(tuple<U...>&&); // constexpr in C++20
91 template<class... UTypes>
92 constexpr const tuple& operator=(tuple<UTypes...>&&) const; // C++23
93 template <class U1, class U2>
94 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
95 template<class U1, class U2>
96 constexpr const tuple& operator=(const pair<U1, U2>&) const; // iff sizeof...(Types) == 2 // C++23
97 template <class U1, class U2>
98 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
99 template<class U1, class U2>
100 constexpr const tuple& operator=(pair<U1, U2>&&) const; // iff sizeof...(Types) == 2 // C++23
101
102 template<class U, size_t N>
103 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
104 template<class U, size_t N>
105 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
106
107 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
108 constexpr void swap(const tuple&) const noexcept(see-below); // C++23
109
110 template<tuple-like UTuple>
111 friend constexpr bool operator==(const tuple& t, const UTuple& u); // C++23
112 template<tuple-like UTuple>
113 friend constexpr auto operator<=>(const tuple& t, const UTuple& u); // C++23
114};
115
116
117template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
118 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
119struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
120 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
121};
122
123template<class... TTypes, class... UTypes> // since C++23
124 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
125struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
126 using type = tuple<common_type_t<TTypes, UTypes>...>;
127};
128
129template <class ...T>
130tuple(T...) -> tuple<T...>; // since C++17
131template <class T1, class T2>
132tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
133template <class Alloc, class ...T>
134tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
135template <class Alloc, class T1, class T2>
136tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
137template <class Alloc, class ...T>
138tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
139
140struct ignore-type { // exposition only // Since C++26
141 constexpr const ignore-type&
142 operator=(const auto &) const noexcept
143 { return *this; }
144};
145inline constexpr ignore-type ignore;
146
147template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
148template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
149template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
150template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
151
152// [tuple.apply], calling a function with a tuple of arguments:
153template <class F, class Tuple>
154 constexpr decltype(auto) apply(F&& f, Tuple&& t) noexcept(see below); // C++17 noexcept since C++23
155template <class T, class Tuple>
156 constexpr T make_from_tuple(Tuple&& t); // C++17
157
158// 20.4.1.4, tuple helper classes:
159template <class T> struct tuple_size; // undefined
160template <class... T> struct tuple_size<tuple<T...>>;
161template <class T>
162 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
163template <size_t I, class T> struct tuple_element; // undefined
164template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
165template <size_t I, class T>
166 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
167
168// 20.4.1.5, element access:
169template <size_t I, class... T>
170 typename tuple_element<I, tuple<T...>>::type&
171 get(tuple<T...>&) noexcept; // constexpr in C++14
172template <size_t I, class... T>
173 const typename tuple_element<I, tuple<T...>>::type&
174 get(const tuple<T...>&) noexcept; // constexpr in C++14
175template <size_t I, class... T>
176 typename tuple_element<I, tuple<T...>>::type&&
177 get(tuple<T...>&&) noexcept; // constexpr in C++14
178template <size_t I, class... T>
179 const typename tuple_element<I, tuple<T...>>::type&&
180 get(const tuple<T...>&&) noexcept; // constexpr in C++14
181
182template <class T1, class... T>
183 constexpr T1& get(tuple<T...>&) noexcept; // C++14
184template <class T1, class... T>
185 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
186template <class T1, class... T>
187 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
188template <class T1, class... T>
189 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
190
191// 20.4.1.6, relational operators:
192template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
193template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
194template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
195template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
196template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
197template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
198template<class... T, class... U>
199 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
200 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
201
202template <class... Types, class Alloc>
203 struct uses_allocator<tuple<Types...>, Alloc>;
204
205template <class... Types>
206 void
207 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
208
209template <class... Types>
210 constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23
211
212} // std
213
214*/
215
216// clang-format on
217
218#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
219# include <__cxx03/__config>
220#else
221# include <__compare/common_comparison_category.h>
222# include <__compare/ordering.h>
223# include <__compare/synth_three_way.h>
224# include <__concepts/boolean_testable.h>
225# include <__config>
226# include <__cstddef/size_t.h>
227# include <__fwd/array.h>
228# include <__fwd/get.h>
229# include <__fwd/pair.h>
230# include <__fwd/tuple.h>
231# include <__memory/allocator_arg_t.h>
232# include <__memory/uses_allocator.h>
233# include <__tuple/find_index.h>
234# include <__tuple/ignore.h>
235# include <__tuple/tuple_element.h>
236# include <__tuple/tuple_like.h>
237# include <__tuple/tuple_size.h>
238# include <__type_traits/common_reference.h>
239# include <__type_traits/common_type.h>
240# include <__type_traits/conditional.h>
241# include <__type_traits/conjunction.h>
242# include <__type_traits/copy_cvref.h>
243# include <__type_traits/disjunction.h>
244# include <__type_traits/enable_if.h>
245# include <__type_traits/invoke.h>
246# include <__type_traits/is_assignable.h>
247# include <__type_traits/is_constructible.h>
248# include <__type_traits/is_convertible.h>
249# include <__type_traits/is_empty.h>
250# include <__type_traits/is_final.h>
251# include <__type_traits/is_implicitly_default_constructible.h>
252# include <__type_traits/is_nothrow_assignable.h>
253# include <__type_traits/is_nothrow_constructible.h>
254# include <__type_traits/is_reference.h>
255# include <__type_traits/is_relocatable.h>
256# include <__type_traits/is_same.h>
257# include <__type_traits/is_swappable.h>
258# include <__type_traits/maybe_const.h>
259# include <__type_traits/nat.h>
260# include <__type_traits/negation.h>
261# include <__type_traits/reference_constructs_from_temporary.h>
262# include <__type_traits/remove_cv.h>
263# include <__type_traits/remove_cvref.h>
264# include <__type_traits/remove_reference.h>
265# include <__type_traits/type_list.h>
266# include <__type_traits/unwrap_ref.h>
267# include <__utility/declval.h>
268# include <__utility/forward.h>
269# include <__utility/integer_sequence.h>
270# include <__utility/move.h>
271# include <__utility/swap.h>
272# include <version>
273
274// standard-mandated includes
275
276// [tuple.syn]
277# include <compare>
278
279# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
280# pragma GCC system_header
281# endif
282
283_LIBCPP_PUSH_MACROS
284# include <__undef_macros>
285
286# ifndef _LIBCPP_CXX03_LANG
287
288_LIBCPP_BEGIN_NAMESPACE_STD
289
290template <size_t _Ip, class _Tp, class _Up>
291_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __tuple_compare_equal(const _Tp& __x, const _Up& __y) {
292 if constexpr (_Ip == 0)
293 return true;
294 else
295 return std::__tuple_compare_equal<_Ip - 1>(__x, __y) && std::get<_Ip - 1>(__x) == std::get<_Ip - 1>(__y);
296}
297
298# if _LIBCPP_STD_VER >= 20
299template <class _Ret, class _Tp, class _Up, size_t... _Is>
300_LIBCPP_HIDE_FROM_ABI constexpr _Ret __tuple_compare_three_way(const _Tp& __x, const _Up& __y, index_sequence<_Is...>) {
301 _Ret __result = strong_ordering::equal;
302 static_cast<void>(
303 ((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...));
304 return __result;
305}
306# endif // _LIBCPP_STD_VER >= 20
307
308# if _LIBCPP_STD_VER >= 23
309template <class _Tp>
310concept __tuple_like_no_tuple = __tuple_like<_Tp> && !__is_tuple_v<_Tp>;
311
312template <__tuple_like _Tp, class _IndexSequence = make_index_sequence<tuple_size_v<_Tp>>>
313struct __to_tuple;
314
315template <__tuple_like _Tp, size_t... _Index>
316struct __to_tuple<_Tp, index_sequence<_Index...>> {
317 using type _LIBCPP_NODEBUG = tuple<tuple_element_t<_Index, _Tp>...>;
318};
319
320template <__tuple_like _Tp>
321using __to_tuple_t _LIBCPP_NODEBUG = typename __to_tuple<_Tp>::type;
322# endif // _LIBCPP_STD_VER >= 23
323
324// __tuple_leaf
325
326template <size_t _Ip, class _Hp, bool = is_empty<_Hp>::value && !__is_final_v<_Hp> >
327class __tuple_leaf;
328
329template <size_t _Ip, class _Hp, bool _Ep>
330inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
331swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<_Hp>) {
332 swap(__x.get(), __y.get());
333}
334
335template <size_t _Ip, class _Hp, bool _Ep>
336_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
337swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x,
338 const __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<const _Hp>) {
339 swap(__x.get(), __y.get());
340}
341
342template <size_t _Ip, class _Hp, bool>
343class __tuple_leaf {
344 _Hp __value_;
345
346public:
347 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
348
349 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) : __value_() {
350 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
351 }
352
353 template <class _Alloc>
354 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) : __value_() {
355 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
356 }
357
358 template <class _Alloc>
359 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
360 : __value_(allocator_arg_t(), __a) {
361 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
362 }
363
364 template <class _Alloc>
365 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : __value_(__a) {
366 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
367 }
368
369 template <
370 class _Tp,
371 __enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int> = 0>
372 _LIBCPP_HIDE_FROM_ABI
373 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
374 : __value_(std::forward<_Tp>(__t)) {
375 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
376 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
377 }
378
379 template <class _Tp, class _Alloc>
380 _LIBCPP_HIDE_FROM_ABI
381 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
382 : __value_(std::forward<_Tp>(__t)) {
383 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
384 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
385 }
386
387 template <class _Tp, class _Alloc>
388 _LIBCPP_HIDE_FROM_ABI
389 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
390 : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {
391 static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
392 }
393
394 template <class _Tp, class _Alloc>
395 _LIBCPP_HIDE_FROM_ABI
396 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
397 : __value_(std::forward<_Tp>(__t), __a) {
398 static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
399 }
400
401 _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default;
402 _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t) = default;
403
404 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
405 swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
406 std::swap(*this, __t);
407 return 0;
408 }
409
410 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __t) const
411 noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
412 std::swap(*this, __t);
413 return 0;
414 }
415
416 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() noexcept { return __value_; }
417 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const noexcept { return __value_; }
418};
419
420template <size_t _Ip, class _Hp>
421class __tuple_leaf<_Ip, _Hp, true> : private __remove_cv_t<_Hp> {
422public:
423 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
424
425 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {}
426
427 template <class _Alloc>
428 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
429
430 template <class _Alloc>
431 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
432 : _Hp(allocator_arg_t(), __a) {}
433
434 template <class _Alloc>
435 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : _Hp(__a) {}
436
437 template <class _Tp,
438 __enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value,
439 int> = 0>
440 _LIBCPP_HIDE_FROM_ABI
441 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
442 : _Hp(std::forward<_Tp>(__t)) {}
443
444 template <class _Tp, class _Alloc>
445 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
446 : _Hp(std::forward<_Tp>(__t)) {}
447
448 template <class _Tp, class _Alloc>
449 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
450 : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {}
451
452 template <class _Tp, class _Alloc>
453 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
454 : _Hp(std::forward<_Tp>(__t), __a) {}
455
456 __tuple_leaf(__tuple_leaf const&) = default;
457 __tuple_leaf(__tuple_leaf&&) = default;
458
459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
460 swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
461 std::swap(*this, __t);
462 return 0;
463 }
464
465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __rhs) const
466 noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
467 std::swap(*this, __rhs);
468 return 0;
469 }
470
471 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() noexcept { return static_cast<_Hp&>(*this); }
472 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const noexcept {
473 return static_cast<const _Hp&>(*this);
474 }
475};
476
477template <class... _Tp>
478_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swallow(_Tp&&...) noexcept {}
479
480// __tuple_impl
481
482template <class _Indx, class... _Tp>
483struct __tuple_impl;
484
485struct __forward_args {};
486struct __value_init {};
487struct __from_tuple {};
488
489template <size_t... _Indx, class... _Tp>
490struct _LIBCPP_DECLSPEC_EMPTY_BASES
491 __tuple_impl<__index_sequence<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... {
492 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(
493 __all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
494
495 template <class... _Args>
496 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(__forward_args, _Args&&... __args)
497 : __tuple_leaf<_Indx, _Tp>(std::forward<_Args>(__args))... {}
498
499 template <class _Alloc>
500 _LIBCPP_HIDE_FROM_ABI
501 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(allocator_arg_t, const _Alloc& __alloc, __value_init)
502 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc>(), __alloc)... {}
503
504 template <class _Alloc, class... _Args>
505 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(
506 allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)
507 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}
508
509 template <class _Tuple>
510 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(__from_tuple, _Tuple&& __t) noexcept(
511 (__all<is_nothrow_constructible<_Tp, __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>::
512 value...>::value))
513 : __tuple_leaf<_Indx, _Tp>(
514 std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
515 std::get<_Indx>(__t)))... {}
516
517 template <class _Alloc, class _Tuple>
518 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
519 __tuple_impl(allocator_arg_t, const _Alloc& __a, __from_tuple, _Tuple&& __t)
520 : __tuple_leaf<_Indx, _Tp>(
521 __uses_alloc_ctor<_Tp,
522 _Alloc,
523 __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(),
524 __a,
525 std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
526 std::get<_Indx>(__t)))... {}
527
528 __tuple_impl(const __tuple_impl&) = default;
529 __tuple_impl(__tuple_impl&&) = default;
530
531 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
532 swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
533 std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
534 }
535
536 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(const __tuple_impl& __t) const
537 noexcept(__all<__is_nothrow_swappable_v<const _Tp>...>::value) {
538 std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
539 }
540};
541
542template <class _Dest, class _Source, size_t... _Np>
543_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
544__memberwise_copy_assign(_Dest& __dest, _Source const& __source, __index_sequence<_Np...>) {
545 std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...);
546}
547
548template <class _Dest, class _Source, class... _Up, size_t... _Np>
549_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
550__memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up...>, __index_sequence<_Np...>) {
551 std::__swallow(((std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source))), void(), 0)...);
552}
553
554template <class... _Tp>
555class _LIBCPP_NO_SPECIALIZATIONS tuple {
556 typedef __tuple_impl<__index_sequence_for<_Tp...>, _Tp...> _BaseT;
557
558 _BaseT __base_;
559
560 template <size_t _Jp, class... _Up>
561 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) noexcept;
562 template <size_t _Jp, class... _Up>
563 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&
564 get(const tuple<_Up...>&) noexcept;
565 template <size_t _Jp, class... _Up>
566 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type&&
567 get(tuple<_Up...>&&) noexcept;
568 template <size_t _Jp, class... _Up>
569 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&&
570 get(const tuple<_Up...>&&) noexcept;
571
572public:
573 using __trivially_relocatable _LIBCPP_NODEBUG =
574 __conditional_t<__all<__is_trivially_relocatable_v<_Tp>...>::value, tuple, void>;
575
576 // [tuple.cnstr]
577
578 // tuple() constructors (including allocator_arg_t variants)
579 template <template <class...> class _IsImpDefault = __is_implicitly_default_constructible,
580 template <class...> class _IsDefault = is_default_constructible,
581 __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
582 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<_IsImpDefault<_Tp>...>::value)
583 tuple() noexcept(_And<is_nothrow_default_constructible<_Tp>...>::value) {}
584
585 template <class _Alloc,
586 template <class...> class _IsImpDefault = __is_implicitly_default_constructible,
587 template <class...> class _IsDefault = is_default_constructible,
588 __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
589 _LIBCPP_HIDE_FROM_ABI
590 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<_IsImpDefault<_Tp>...>::value) tuple(allocator_arg_t, _Alloc const& __a)
591 : __base_(allocator_arg_t(), __a, __value_init{}) {}
592
593 // tuple(const T&...) constructors (including allocator_arg_t variants)
594 template <template <class...> class _And = _And, __enable_if_t<_And<is_copy_constructible<_Tp>...>::value, int> = 0>
595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<const _Tp&, _Tp>...>::value)
596 tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value)
597 : __base_(__forward_args{}, __t...) {}
598
599 template <class _Alloc,
600 template <class...> class _And = _And,
601 __enable_if_t<_And<is_copy_constructible<_Tp>...>::value, int> = 0>
602 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<const _Tp&, _Tp>...>::value)
603 tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t)
604 : __base_(allocator_arg_t(), __a, __forward_args{}, __t...) {}
605
606 // tuple(U&& ...) constructors (including allocator_arg_t variants)
607 template <class... _Up>
608 struct _EnableUTypesCtor
609 : _And<_Or<integral_constant<bool, sizeof...(_Up) != 1>,
610 _IsNotSame<__remove_cvref_t<_Up...[0]>, tuple>>, // extension to allow mis-behaved user constructors
611 is_constructible<_Tp, _Up>... > {};
612
613 template <class... _Up,
614 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
615 int> = 0>
616 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
617 tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
618 : __base_(__forward_args{}, std::forward<_Up>(__u)...) {}
619
620 template <class _Alloc,
621 class... _Up,
622 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
623 int> = 0>
624 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
625 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
626 : __base_(allocator_arg_t(), __a, __forward_args{}, std::forward<_Up>(__u)...) {}
627
628 // Copy and move constructors (including the allocator_arg_t variants)
629 tuple(const tuple&) = default;
630 tuple(tuple&&) = default;
631
632 template <class _Alloc,
633 template <class...> class _And = _And,
634 __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0>
635 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
636 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
637
638 template <class _Alloc,
639 template <class...> class _And = _And,
640 __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0>
641 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
642 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
643
644 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
645
646 template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>
647 struct _EnableCtorFromUTypesTuple : false_type {};
648
649 template <class _OtherTuple, class... _Up>
650 struct _EnableCtorFromUTypesTuple<
651 _OtherTuple,
652 tuple<_Up...>,
653 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
654 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>>
655 : _And<
656 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor
657 // can work. Otherwise, is_constructible can trigger hard error in those cases
658 // https://godbolt.org/z/M94cGdKcE
659 _Not<is_same<_OtherTuple, const tuple&> >,
660 _Not<is_same<_OtherTuple, tuple&&> >,
661 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
662 _Or<_BoolConstant<sizeof...(_Tp) != 1>,
663 // _Tp and _Up are 1-element packs - the pack expansions look
664 // weird to avoid tripping up the type traits in degenerate cases
665 _And<_Not<is_same<_Tp, _Up> >...,
666 _Not<is_convertible<_OtherTuple, _Tp> >...,
667 _Not<is_constructible<_Tp, _OtherTuple> >... > > > {};
668
669 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
670 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<const _Up&, _Tp>...>::value)
671 tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)
672 : __base_(__from_tuple(), __t) {}
673
674 template <class... _Up, class _Alloc, __enable_if_t<_EnableCtorFromUTypesTuple<const tuple<_Up...>&>::value, int> = 0>
675 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<const _Up&, _Tp>...>::value)
676 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
677 : __base_(allocator_arg_t(), __a, __from_tuple(), __t) {}
678
679# if _LIBCPP_STD_VER >= 23
680 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
681
682 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
683 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t)
684 : __base_(__from_tuple(), __t) {}
685
686 template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
687 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<_Up&, _Tp>...>::value)
688 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)
689 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
690# endif // _LIBCPP_STD_VER >= 23
691
692 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
693 template <class... _Up, __enable_if_t<_EnableCtorFromUTypesTuple<tuple<_Up...>&&>::value, int> = 0>
694 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
695 tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
696 : __base_(__from_tuple(), std::move(__t)) {}
697
698 template <class _Alloc, class... _Up, __enable_if_t<_EnableCtorFromUTypesTuple<tuple<_Up...>&&>::value, int> = 0>
699 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
700 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
701 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__t)) {}
702
703# if _LIBCPP_STD_VER >= 23
704 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
705
706 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
707 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<const _Up&&, _Tp>...>::value)
708 tuple(const tuple<_Up...>&& __t)
709 : __base_(__from_tuple(), std::move(__t)) {}
710
711 template <class _Alloc,
712 class... _Up,
713 enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
714 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<const _Up&&, _Tp>...>::value)
715 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
716 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
717# endif // _LIBCPP_STD_VER >= 23
718
719 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
720
721 template <template <class...> class _Pred,
722 class _Pair,
723 class _DecayedPair = __remove_cvref_t<_Pair>,
724 class _Tuple = tuple>
725 struct _CtorPredicateFromPair : false_type {};
726
727 template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
728 struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
729 : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {};
730
731 template <class _Pair>
732 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {};
733
734 template <class _Pair>
735 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {};
736
737 template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
738 struct _BothImplicitlyConvertible : false_type {};
739
740 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
741 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
742 : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {};
743
744 template <class _Up1, class _Up2, __enable_if_t<_EnableCtorFromPair<const pair<_Up1, _Up2>&>::value, int> = 0>
745 _LIBCPP_HIDE_FROM_ABI
746 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_BothImplicitlyConvertible<const pair<_Up1, _Up2>&>::value)
747 tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)
748 : __base_(__from_tuple(), __p) {}
749
750 template <class _Alloc,
751 class _Up1,
752 class _Up2,
753 __enable_if_t<_EnableCtorFromPair<const pair<_Up1, _Up2>&>::value, int> = 0>
754 _LIBCPP_HIDE_FROM_ABI
755 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_BothImplicitlyConvertible<const pair<_Up1, _Up2>&>::value)
756 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
757 : __base_(allocator_arg_t(), __a, __from_tuple(), __p) {}
758
759# if _LIBCPP_STD_VER >= 23
760 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
761
762 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
763 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
764 tuple(pair<_U1, _U2>& __p)
765 : __base_(__from_tuple(), __p) {}
766
767 template <class _Alloc,
768 class _U1,
769 class _U2,
770 enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
771 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
772 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)
773 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __p) {}
774# endif
775
776 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
777
778 template <class _Up1, class _Up2, __enable_if_t<_EnableCtorFromPair<pair<_Up1, _Up2>&&>::value, int> = 0>
779 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_BothImplicitlyConvertible<pair<_Up1, _Up2>&&>::value)
780 tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)
781 : __base_(__from_tuple(), std::move(__p)) {}
782
783 template <class _Alloc,
784 class _Up1,
785 class _Up2,
786 __enable_if_t<_EnableCtorFromPair<pair<_Up1, _Up2>&&>::value, int> = 0>
787 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_BothImplicitlyConvertible<pair<_Up1, _Up2>&&>::value)
788 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
789 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__p)) {}
790
791# if _LIBCPP_STD_VER >= 23
792 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
793
794 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
795 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
796 tuple(const pair<_U1, _U2>&& __p)
797 : __base_(__from_tuple(), std::move(__p)) {}
798
799 template <class _Alloc,
800 class _U1,
801 class _U2,
802 enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
803 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
804 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
805 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__p)) {}
806# endif // _LIBCPP_STD_VER >= 23
807
808 // [tuple.assign]
809 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
810 operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(
811 _And<is_nothrow_copy_assignable<_Tp>...>::value) {
812 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
813 return *this;
814 }
815
816# if _LIBCPP_STD_VER >= 23
817 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
818 requires(_And<is_copy_assignable<const _Tp>...>::value)
819 {
820 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
821 return *this;
822 }
823
824 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
825 requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
826 {
827 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
828 return *this;
829 }
830# endif // _LIBCPP_STD_VER >= 23
831
832 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
833 operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
834 _And<is_nothrow_move_assignable<_Tp>...>::value) {
835 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
836 return *this;
837 }
838
839 template <
840 class... _Up,
841 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,
842 int> = 0>
843 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
844 operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
845 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
846 return *this;
847 }
848
849 template <class... _Up,
850 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,
851 int> = 0>
852 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
853 operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
854 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>());
855 return *this;
856 }
857
858# if _LIBCPP_STD_VER >= 23
859 template <class... _UTypes,
860 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
861 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
862 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
863 std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>());
864 return *this;
865 }
866
867 template <class... _UTypes,
868 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
869 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
870 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
871 std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>());
872 return *this;
873 }
874# endif // _LIBCPP_STD_VER >= 23
875
876 template <template <class...> class _Pred,
877 bool _Const,
878 class _Pair,
879 class _DecayedPair = __remove_cvref_t<_Pair>,
880 class _Tuple = tuple>
881 struct _AssignPredicateFromPair : false_type {};
882
883 template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
884 struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
885 : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
886 _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {};
887
888 template <bool _Const, class _Pair>
889 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
890
891 template <bool _Const, class _Pair>
892 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
893
894# if _LIBCPP_STD_VER >= 23
895 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
896 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const
897 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
898 std::get<0>(*this) = __pair.first;
899 std::get<1>(*this) = __pair.second;
900 return *this;
901 }
902
903 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
904 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const
905 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
906 std::get<0>(*this) = std::move(__pair.first);
907 std::get<1>(*this) = std::move(__pair.second);
908 return *this;
909 }
910# endif // _LIBCPP_STD_VER >= 23
911
912 template <class _Up1,
913 class _Up2,
914 __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>
915 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
916 operator=(pair<_Up1, _Up2> const& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
917 std::get<0>(*this) = __pair.first;
918 std::get<1>(*this) = __pair.second;
919 return *this;
920 }
921
922 template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>
923 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
924 operator=(pair<_Up1, _Up2>&& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
925 std::get<0>(*this) = std::forward<_Up1>(__pair.first);
926 std::get<1>(*this) = std::forward<_Up2>(__pair.second);
927 return *this;
928 }
929
930 // EXTENSION
931 template <
932 class _Up,
933 size_t _Np,
934 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
935 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
936 operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
937 std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>());
938 return *this;
939 }
940
941 // EXTENSION
942 template <class _Up,
943 size_t _Np,
944 class = void,
945 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>
946 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
947 operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
948 std::__memberwise_forward_assign(
949 *this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __index_sequence_for<_Tp...>());
950 return *this;
951 }
952
953 // [tuple.swap]
954 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
955 swap(tuple& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
956 __base_.swap(__t.__base_);
957 }
958
959# if _LIBCPP_STD_VER >= 23
960 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const
961 noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
962 __base_.swap(__t.__base_);
963 }
964
965 template <class _Tuple>
966 static constexpr bool __can_compare_equal = false;
967
968 template <class... _Up>
969 static constexpr bool __can_compare_equal<tuple<_Up...>> = __all<requires(const _Tp& __t, const _Up& __u) {
970 { __t == __u } -> __boolean_testable;
971 }...>::value;
972
973 template <__tuple_like_no_tuple _UTuple>
974# if _LIBCPP_STD_VER >= 26
975 requires(sizeof...(_Tp) == tuple_size_v<_UTuple>) && __can_compare_equal<__to_tuple_t<_UTuple>>
976# endif // _LIBCPP_STD_VER >= 26
977 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple& __x, const _UTuple& __y) {
978 static_assert(sizeof...(_Tp) == tuple_size_v<_UTuple>, "Can't compare tuple-like values of different sizes");
979 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
980 }
981
982 template <class _Tuple>
983 struct __common_comparison_category_with;
984
985 template <class... _Up>
986 requires requires { typename common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>; }
987 struct __common_comparison_category_with<tuple<_Up...>> {
988 using type _LIBCPP_NODEBUG = common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>;
989 };
990
991 template <__tuple_like_no_tuple _UTuple>
992 requires(sizeof...(_Tp) == tuple_size_v<_UTuple>)
993 _LIBCPP_HIDE_FROM_ABI friend constexpr typename __common_comparison_category_with<__to_tuple_t<_UTuple>>::type
994 operator<=>(const tuple& __x, const _UTuple& __y) {
995 return std::__tuple_compare_three_way<typename __common_comparison_category_with<__to_tuple_t<_UTuple>>::type>(
996 __x, __y, index_sequence_for<_Tp...>{});
997 }
998# endif // _LIBCPP_STD_VER >= 23
999};
1000
1001_LIBCPP_DIAGNOSTIC_PUSH
1002# if __has_warning("-Winvalid-specialization")
1003_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
1004# endif
1005template <>
1006class tuple<> {
1007public:
1008 constexpr tuple() noexcept = default;
1009 template <class _Alloc>
1010 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) noexcept {}
1011 template <class _Alloc>
1012 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept {}
1013 template <class _Up>
1014 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) noexcept {}
1015 template <class _Alloc, class _Up>
1016 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) noexcept {}
1017 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) noexcept {}
1018# if _LIBCPP_STD_VER >= 23
1019 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1020
1021 template <__tuple_like_no_tuple _UTuple>
1022# if _LIBCPP_STD_VER >= 26
1023 requires(tuple_size_v<_UTuple> == 0)
1024# endif // _LIBCPP_STD_VER >= 26
1025 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple&, const _UTuple&) {
1026 static_assert(tuple_size_v<_UTuple> == 0, "Can't compare tuple-like values of different sizes");
1027 return true;
1028 }
1029
1030 template <__tuple_like_no_tuple _UTuple>
1031 requires(tuple_size_v<_UTuple> == 0)
1032 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const tuple&, const _UTuple&) {
1033 return strong_ordering::equal;
1034 }
1035# endif
1036};
1037_LIBCPP_DIAGNOSTIC_POP
1038
1039# if _LIBCPP_STD_VER >= 23
1040template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
1041 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1042struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1043 using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1044};
1045
1046template <class... _TTypes, class... _UTypes>
1047 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1048struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1049 using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;
1050};
1051# endif // _LIBCPP_STD_VER >= 23
1052
1053# if _LIBCPP_STD_VER >= 17
1054template <class... _Tp>
1055tuple(_Tp...) -> tuple<_Tp...>;
1056template <class _Tp1, class _Tp2>
1057tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1058template <class _Alloc, class... _Tp>
1059tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1060template <class _Alloc, class _Tp1, class _Tp2>
1061tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1062template <class _Alloc, class... _Tp>
1063tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
1064# endif
1065
1066template <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>
1067inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
1068swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1069 __t.swap(__u);
1070}
1071
1072# if _LIBCPP_STD_VER >= 23
1073template <class... _Tp>
1074_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1075swap(const tuple<_Tp...>& __lhs,
1076 const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1077 __lhs.swap(__rhs);
1078}
1079# endif
1080
1081// get
1082
1083template <size_t _Ip, class... _Tp>
1084[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1085typename tuple_element<_Ip, tuple<_Tp...> >::type&
1086get(tuple<_Tp...>& __t) noexcept {
1087 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1088 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
1089}
1090
1091template <size_t _Ip, class... _Tp>
1092[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1093_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
1094get(const tuple<_Tp...>& __t) noexcept {
1095 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1096 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
1097}
1098
1099template <size_t _Ip, class... _Tp>
1100[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1101typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1102get(tuple<_Tp...>&& __t) noexcept {
1103 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1104 return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1105}
1106
1107template <size_t _Ip, class... _Tp>
1108[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1109_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1110get(const tuple<_Tp...>&& __t) noexcept {
1111 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1112 return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1113}
1114
1115# if _LIBCPP_STD_VER >= 14
1116
1117template <class _T1, class... _Args>
1118[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {
1119 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1120}
1121
1122template <class _T1, class... _Args>
1123[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept {
1124 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1125}
1126
1127template <class _T1, class... _Args>
1128[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept {
1129 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1130}
1131
1132template <class _T1, class... _Args>
1133[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept {
1134 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1135}
1136
1137# endif
1138
1139// tie
1140
1141template <class... _Tp>
1142[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) noexcept {
1143 return tuple<_Tp&...>(__t...);
1144}
1145
1146template <class... _Tp>
1147[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<__unwrap_ref_decay_t<_Tp>...>
1148make_tuple(_Tp&&... __t) {
1149 return tuple<__unwrap_ref_decay_t<_Tp>...>(std::forward<_Tp>(__t)...);
1150}
1151
1152template <class... _Tp>
1153[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...>
1154forward_as_tuple(_Tp&&... __t) noexcept {
1155 return tuple<_Tp&&...>(std::forward<_Tp>(__t)...);
1156}
1157
1158template <class... _Tp, class... _Up>
1159# if _LIBCPP_STD_VER >= 26
1160 requires(__all<requires(const _Tp& __t, const _Up& __u) {
1161 { __t == __u } -> __boolean_testable;
1162 }...>::value && (sizeof...(_Tp) == sizeof...(_Up)))
1163# endif
1164inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1165operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1166 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1167 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
1168}
1169
1170# if _LIBCPP_STD_VER >= 20
1171
1172// operator<=>
1173
1174template <class... _Tp, class... _Up>
1175 requires(sizeof...(_Tp) == sizeof...(_Up))
1176_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1177operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1178 return std::__tuple_compare_three_way<common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>>(
1179 __x, __y, index_sequence_for<_Tp...>{});
1180}
1181
1182# else // _LIBCPP_STD_VER >= 20
1183
1184template <class... _Tp, class... _Up>
1185inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1186operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1187 return !(__x == __y);
1188}
1189
1190template <size_t _Ip>
1191struct __tuple_less {
1192 template <class _Tp, class _Up>
1193 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {
1194 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1195 const auto& __a = std::get<__idx>(__x);
1196 const auto& __b = std::get<__idx>(__y);
1197 if (__a < __b)
1198 return true;
1199 if (__b < __a)
1200 return false;
1201 return __tuple_less<_Ip - 1>()(__x, __y);
1202 }
1203};
1204
1205template <>
1206struct __tuple_less<0> {
1207 template <class _Tp, class _Up>
1208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {
1209 return false;
1210 }
1211};
1212
1213template <class... _Tp, class... _Up>
1214inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1215operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1216 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1217 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1218}
1219
1220template <class... _Tp, class... _Up>
1221inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1222operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1223 return __y < __x;
1224}
1225
1226template <class... _Tp, class... _Up>
1227inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1228operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1229 return !(__x < __y);
1230}
1231
1232template <class... _Tp, class... _Up>
1233inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1234operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1235 return !(__y < __x);
1236}
1237
1238# endif // _LIBCPP_STD_VER >= 20
1239
1240// tuple_cat
1241
1242template <class... _Tuples>
1243struct __tuple_cat_return_impl;
1244
1245template <class... _Types>
1246struct __tuple_cat_return_impl<tuple<_Types...>> {
1247 using type _LIBCPP_NODEBUG = tuple<_Types...>;
1248};
1249
1250template <class... _Types0, class... _Types1, class... _Tuples>
1251struct __tuple_cat_return_impl<tuple<_Types0...>, tuple<_Types1...>, _Tuples...>
1252 : __tuple_cat_return_impl<tuple<_Types0..., _Types1...>, _Tuples...> {};
1253
1254template <class... _Types0, class _Tp, class _Up, class... _Tuples>
1255struct __tuple_cat_return_impl<tuple<_Types0...>, pair<_Tp, _Up>, _Tuples...>
1256 : __tuple_cat_return_impl<tuple<_Types0..., _Tp, _Up>, _Tuples...> {};
1257
1258template <class, class, class>
1259struct __tuple_cat_array;
1260
1261template <class... _Types, class _ValueT, size_t... _Indices>
1262struct __tuple_cat_array<tuple<_Types...>, _ValueT, __index_sequence<_Indices...>> {
1263 template <size_t>
1264 using __value_type _LIBCPP_NODEBUG = _ValueT;
1265
1266 using type _LIBCPP_NODEBUG = tuple<_Types..., __value_type<_Indices>...>;
1267};
1268
1269template <class... _Types, class _ValueT, size_t _Np, class... _Tuples>
1270struct __tuple_cat_return_impl<tuple<_Types...>, array<_ValueT, _Np>, _Tuples...>
1271 : __tuple_cat_return_impl<typename __tuple_cat_array<tuple<_Types...>, _ValueT, __make_index_sequence<_Np>>::type,
1272 _Tuples...> {};
1273
1274template <class... _Tuples>
1275using __tuple_cat_return_t _LIBCPP_NODEBUG =
1276 typename __tuple_cat_return_impl<tuple<>, __remove_cvref_t<_Tuples>...>::type;
1277
1278[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
1279
1280template <class _Rp, class _Indices, class _Tuple0, class... _Tuples>
1281struct __tuple_cat_return_ref_imp;
1282
1283template <class... _Types, size_t... _I0, class _Tuple0>
1284struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0> {
1285 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1286 typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
1287};
1288
1289template <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>
1290struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0, _Tuple1, _Tuples...>
1291 : public __tuple_cat_return_ref_imp<
1292 tuple<_Types...,
1293 __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
1294 __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>,
1295 _Tuple1,
1296 _Tuples...> {};
1297
1298template <class _Tuple0, class... _Tuples>
1299struct __tuple_cat_return_ref
1300 : public __tuple_cat_return_ref_imp<
1301 tuple<>,
1302 __make_index_sequence< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >,
1303 _Tuple0,
1304 _Tuples...> {};
1305
1306template <class _Types, class _I0, class _J0>
1307struct __tuple_cat;
1308
1309template <class... _Types, size_t... _I0, size_t... _J0>
1310struct __tuple_cat<tuple<_Types...>, __index_sequence<_I0...>, __index_sequence<_J0...>> {
1311 template <class _Tuple0>
1312 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1313 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1314 operator()(tuple<_Types...> __t, _Tuple0&& __t0) {
1315 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1316 return std::forward_as_tuple(
1317 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...);
1318 }
1319
1320 template <class _Tuple0, class _Tuple1, class... _Tuples>
1321 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1322 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1323 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {
1324 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1325 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1326 using _T1 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple1>;
1327 return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
1328 __make_index_sequence<sizeof...(_Types) + tuple_size<_T0>::value>,
1329 __make_index_sequence<tuple_size<_T1>::value>>()(
1330 std::forward_as_tuple(
1331 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...),
1332 std::forward<_Tuple1>(__t1),
1333 std::forward<_Tuples>(__tpls)...);
1334 }
1335};
1336
1337template <class _TupleDst, class _TupleSrc, size_t... _Indices>
1338inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _TupleDst
1339__tuple_cat_select_element_wise(_TupleSrc&& __src, __index_sequence<_Indices...>) {
1340 static_assert(tuple_size<_TupleDst>::value == tuple_size<_TupleSrc>::value,
1341 "misuse of __tuple_cat_select_element_wise with tuples of different sizes");
1342 return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);
1343}
1344
1345template <class _Tuple0, class... _Tuples>
1346[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_cat_return_t<_Tuple0, _Tuples...>
1347tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
1348 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1349 using _TRet _LIBCPP_NODEBUG = __tuple_cat_return_t<_Tuple0, _Tuples...>;
1350 using _T0Indices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_T0>::value>;
1351 using _TRetIndices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_TRet>::value>;
1352 return std::__tuple_cat_select_element_wise<_TRet>(
1353 __tuple_cat<tuple<>, __index_sequence<>, _T0Indices>()(
1354 tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...),
1355 _TRetIndices());
1356}
1357
1358template <class... _Tp, class _Alloc>
1359struct uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
1360
1361# if _LIBCPP_STD_VER >= 17
1362# define _LIBCPP_NOEXCEPT_RETURN(...) \
1363 noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } \
1364 static_assert(true)
1365
1366template <class _Fn, class _Tuple, size_t... _Id>
1367inline
1368 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __apply_tuple_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Id...>)
1369 _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...));
1370
1371template <class _Fn, class _Tuple>
1372inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t)
1373 _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl(std::forward<_Fn>(__f),
1374 std::forward<_Tuple>(__t),
1375 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()));
1376# undef _LIBCPP_NOEXCEPT_RETURN
1377
1378template <class _Tp, class _Tuple, class _Seq = make_index_sequence<tuple_size_v<__remove_cvref_t<_Tuple>>>>
1379inline constexpr bool __can_make_from_tuple_v = false;
1380
1381template <class _Tp, class _Tuple, size_t... _Idx>
1382inline constexpr bool __can_make_from_tuple_v< _Tp, _Tuple, index_sequence<_Idx...>> =
1383 is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>;
1384
1385template <class _Tp, class _Tuple, class _Seq = make_index_sequence<tuple_size_v<__remove_cvref_t<_Tuple>>>>
1386inline constexpr bool __can_nothrow_make_from_tuple_v = false;
1387
1388template <class _Tp, class _Tuple, size_t... _Idx>
1389inline constexpr bool __can_nothrow_make_from_tuple_v< _Tp, _Tuple, index_sequence<_Idx...>> =
1390 is_nothrow_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>;
1391
1392template <class _Tp, class _Tuple, enable_if_t<__can_make_from_tuple_v<_Tp, _Tuple>, int> = 0>
1393[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp
1394make_from_tuple(_Tuple&& __tuple) noexcept(__can_nothrow_make_from_tuple_v<_Tp, _Tuple>) {
1395# if _LIBCPP_STD_VER >= 23
1396 if constexpr (tuple_size_v<remove_reference_t<_Tuple>> == 1) {
1397 static_assert(!std::reference_constructs_from_temporary_v<_Tp, decltype(std::get<0>(std::declval<_Tuple>()))>,
1398 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
1399 }
1400# endif // _LIBCPP_STD_VER >= 23
1401 return std::apply([]<class... _Args>(_Args&&... __args) { return _Tp(std::forward<_Args>(__args)...); },
1402 std::forward<_Tuple>(__tuple));
1403}
1404
1405# endif // _LIBCPP_STD_VER >= 17
1406
1407_LIBCPP_END_NAMESPACE_STD
1408
1409# endif // !defined(_LIBCPP_CXX03_LANG)
1410
1411_LIBCPP_POP_MACROS
1412
1413#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1414
1415#endif // _LIBCPP_TUPLE
1416