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_same.h>
256# include <__type_traits/is_swappable.h>
257# include <__type_traits/is_trivially_relocatable.h>
258# include <__type_traits/lazy.h>
259# include <__type_traits/maybe_const.h>
260# include <__type_traits/nat.h>
261# include <__type_traits/negation.h>
262# include <__type_traits/reference_constructs_from_temporary.h>
263# include <__type_traits/remove_cv.h>
264# include <__type_traits/remove_cvref.h>
265# include <__type_traits/remove_reference.h>
266# include <__type_traits/type_list.h>
267# include <__type_traits/unwrap_ref.h>
268# include <__utility/declval.h>
269# include <__utility/forward.h>
270# include <__utility/integer_sequence.h>
271# include <__utility/move.h>
272# include <__utility/swap.h>
273# include <version>
274
275// standard-mandated includes
276
277// [tuple.syn]
278# include <compare>
279
280# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
281# pragma GCC system_header
282# endif
283
284_LIBCPP_PUSH_MACROS
285# include <__undef_macros>
286
287_LIBCPP_BEGIN_NAMESPACE_STD
288
289# ifndef _LIBCPP_CXX03_LANG
290
291template <size_t _Ip, class _Tp, class _Up>
292_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __tuple_compare_equal(const _Tp& __x, const _Up& __y) {
293 if constexpr (_Ip == 0)
294 return true;
295 else
296 return std::__tuple_compare_equal<_Ip - 1>(__x, __y) && std::get<_Ip - 1>(__x) == std::get<_Ip - 1>(__y);
297}
298
299# if _LIBCPP_STD_VER >= 26
300template <class _Tp, class _Up, class _IndexSeq = make_index_sequence<tuple_size_v<_Tp>>>
301inline constexpr bool __can_tuple_compare_equal = false;
302
303// TODO(LLVM 23): Remove `tuple_size_v<_Tp> == tuple_size_v<_Up>` here once once LLVM-20 support ends
304// because the resolution of CWG2369 landed in LLVM-21.
305template <class _Tp, class _Up, size_t... _Is>
306 requires(tuple_size_v<_Tp> == tuple_size_v<_Up>)
307inline constexpr bool __can_tuple_compare_equal<_Tp, _Up, index_sequence<_Is...>> =
308 __all<requires(const tuple_element_t<_Is, _Tp>& __t, const tuple_element_t<_Is, _Up>& __u) {
309 { __t == __u } -> __boolean_testable;
310 }...>::value;
311# endif // _LIBCPP_STD_VER >= 26
312
313# if _LIBCPP_STD_VER >= 20
314template <class _Ret, class _Tp, class _Up, size_t... _Is>
315_LIBCPP_HIDE_FROM_ABI constexpr _Ret __tuple_compare_three_way(const _Tp& __x, const _Up& __y, index_sequence<_Is...>) {
316 _Ret __result = strong_ordering::equal;
317 static_cast<void>(
318 ((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...));
319 return __result;
320}
321# endif // _LIBCPP_STD_VER >= 20
322
323# if _LIBCPP_STD_VER >= 23
324template <class _Tp>
325concept __tuple_like_no_tuple = __tuple_like<_Tp> && !__is_tuple_v<_Tp>;
326
327template <class _Tp, class _Up, class _IndexSeq>
328struct __tuple_common_comparison_category_impl {};
329
330// TODO(LLVM 23): Remove `tuple_size_v<_Tp> == tuple_size_v<_Up>` here once once LLVM-20 support ends
331// because the resolution of CWG2369 landed in LLVM-21.
332template <class _Tp, class _Up, size_t... _Is>
333 requires(tuple_size_v<_Tp> == tuple_size_v<_Up>) && requires {
334 typename common_comparison_category_t<
335 __synth_three_way_result<tuple_element_t<_Is, _Tp>, tuple_element_t<_Is, _Up>>...>;
336 }
337struct __tuple_common_comparison_category_impl<_Tp, _Up, index_sequence<_Is...>> {
338 using type _LIBCPP_NODEBUG =
339 common_comparison_category_t<__synth_three_way_result<tuple_element_t<_Is, _Tp>, tuple_element_t<_Is, _Up>>...>;
340};
341
342template <__tuple_like _Tp, __tuple_like _Up>
343using __tuple_common_comparison_category _LIBCPP_NODEBUG =
344 __tuple_common_comparison_category_impl<_Tp, _Up, make_index_sequence<tuple_size_v<_Tp>>>::type;
345# endif // _LIBCPP_STD_VER >= 23
346
347// __tuple_leaf
348
349template <size_t _Ip, class _Hp, bool = is_empty<_Hp>::value && !__is_final_v<_Hp> >
350class __tuple_leaf;
351
352template <size_t _Ip, class _Hp, bool _Ep>
353inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
354swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<_Hp>) {
355 swap(__x.get(), __y.get());
356}
357
358template <size_t _Ip, class _Hp, bool _Ep>
359_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
360swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x,
361 const __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<const _Hp>) {
362 swap(__x.get(), __y.get());
363}
364
365template <size_t _Ip, class _Hp, bool>
366class __tuple_leaf {
367 _Hp __value_;
368
369public:
370 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
371
372 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) : __value_() {
373 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
374 }
375
376 template <class _Alloc>
377 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) : __value_() {
378 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
379 }
380
381 template <class _Alloc>
382 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
383 : __value_(allocator_arg_t(), __a) {
384 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
385 }
386
387 template <class _Alloc>
388 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : __value_(__a) {
389 static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
390 }
391
392 template <
393 class _Tp,
394 __enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int> = 0>
395 _LIBCPP_HIDE_FROM_ABI
396 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
397 : __value_(std::forward<_Tp>(__t)) {
398 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
399 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
400 }
401
402 template <class _Tp, class _Alloc>
403 _LIBCPP_HIDE_FROM_ABI
404 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
405 : __value_(std::forward<_Tp>(__t)) {
406 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
407 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
408 }
409
410 template <class _Tp, class _Alloc>
411 _LIBCPP_HIDE_FROM_ABI
412 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
413 : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {
414 static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
415 }
416
417 template <class _Tp, class _Alloc>
418 _LIBCPP_HIDE_FROM_ABI
419 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
420 : __value_(std::forward<_Tp>(__t), __a) {
421 static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple");
422 }
423
424 _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default;
425 _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t) = default;
426
427 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
428 swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
429 std::swap(*this, __t);
430 return 0;
431 }
432
433 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __t) const
434 noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
435 std::swap(*this, __t);
436 return 0;
437 }
438
439 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return __value_; }
440 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT { return __value_; }
441};
442
443template <size_t _Ip, class _Hp>
444class __tuple_leaf<_Ip, _Hp, true> : private __remove_cv_t<_Hp> {
445public:
446 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
447
448 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {}
449
450 template <class _Alloc>
451 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
452
453 template <class _Alloc>
454 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
455 : _Hp(allocator_arg_t(), __a) {}
456
457 template <class _Alloc>
458 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : _Hp(__a) {}
459
460 template <class _Tp,
461 __enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value,
462 int> = 0>
463 _LIBCPP_HIDE_FROM_ABI
464 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
465 : _Hp(std::forward<_Tp>(__t)) {}
466
467 template <class _Tp, class _Alloc>
468 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
469 : _Hp(std::forward<_Tp>(__t)) {}
470
471 template <class _Tp, class _Alloc>
472 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
473 : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {}
474
475 template <class _Tp, class _Alloc>
476 _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
477 : _Hp(std::forward<_Tp>(__t), __a) {}
478
479 __tuple_leaf(__tuple_leaf const&) = default;
480 __tuple_leaf(__tuple_leaf&&) = default;
481
482 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
483 swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) {
484 std::swap(*this, __t);
485 return 0;
486 }
487
488 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __rhs) const
489 noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) {
490 std::swap(*this, __rhs);
491 return 0;
492 }
493
494 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return static_cast<_Hp&>(*this); }
495 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT {
496 return static_cast<const _Hp&>(*this);
497 }
498};
499
500template <class... _Tp>
501_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swallow(_Tp&&...) _NOEXCEPT {}
502
503// __tuple_impl
504
505template <class _Indx, class... _Tp>
506struct __tuple_impl;
507
508struct __forward_args {};
509struct __value_init {};
510struct __from_tuple {};
511
512template <size_t... _Indx, class... _Tp>
513struct _LIBCPP_DECLSPEC_EMPTY_BASES
514 __tuple_impl<__index_sequence<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... {
515 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(
516 __all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
517
518 template <class... _Args>
519 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(__forward_args, _Args&&... __args)
520 : __tuple_leaf<_Indx, _Tp>(std::forward<_Args>(__args))... {}
521
522 template <class _Alloc>
523 _LIBCPP_HIDE_FROM_ABI
524 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(allocator_arg_t, const _Alloc& __alloc, __value_init)
525 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc>(), __alloc)... {}
526
527 template <class _Alloc, class... _Args>
528 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl(
529 allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)
530 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}
531
532 template <class _Tuple>
533 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(__from_tuple, _Tuple&& __t) noexcept(
534 (__all<is_nothrow_constructible<_Tp, __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>::
535 value...>::value))
536 : __tuple_leaf<_Indx, _Tp>(
537 std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
538 std::get<_Indx>(__t)))... {}
539
540 template <class _Alloc, class _Tuple>
541 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
542 __tuple_impl(allocator_arg_t, const _Alloc& __a, __from_tuple, _Tuple&& __t)
543 : __tuple_leaf<_Indx, _Tp>(
544 __uses_alloc_ctor<_Tp,
545 _Alloc,
546 __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(),
547 __a,
548 std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
549 std::get<_Indx>(__t)))... {}
550
551 __tuple_impl(const __tuple_impl&) = default;
552 __tuple_impl(__tuple_impl&&) = default;
553
554 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
555 swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
556 std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
557 }
558
559 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(const __tuple_impl& __t) const
560 noexcept(__all<__is_nothrow_swappable_v<const _Tp>...>::value) {
561 std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
562 }
563};
564
565template <class _Dest, class _Source, size_t... _Np>
566_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
567__memberwise_copy_assign(_Dest& __dest, _Source const& __source, __index_sequence<_Np...>) {
568 std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...);
569}
570
571template <class _Dest, class _Source, class... _Up, size_t... _Np>
572_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
573__memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up...>, __index_sequence<_Np...>) {
574 std::__swallow(((std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source))), void(), 0)...);
575}
576
577template <class... _Tp>
578class _LIBCPP_NO_SPECIALIZATIONS tuple {
579 typedef __tuple_impl<__index_sequence_for<_Tp...>, _Tp...> _BaseT;
580
581 _BaseT __base_;
582
583 template <size_t _Jp, class... _Up>
584 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
585 template <size_t _Jp, class... _Up>
586 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&
587 get(const tuple<_Up...>&) _NOEXCEPT;
588 template <size_t _Jp, class... _Up>
589 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type&&
590 get(tuple<_Up...>&&) _NOEXCEPT;
591 template <size_t _Jp, class... _Up>
592 friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&&
593 get(const tuple<_Up...>&&) _NOEXCEPT;
594
595public:
596 using __trivially_relocatable _LIBCPP_NODEBUG =
597 __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
598
599 // [tuple.cnstr]
600
601 // tuple() constructors (including allocator_arg_t variants)
602 template <template <class...> class _IsImpDefault = __is_implicitly_default_constructible,
603 template <class...> class _IsDefault = is_default_constructible,
604 __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
605 _LIBCPP_HIDE_FROM_ABI constexpr explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)
606 tuple() noexcept(_And<is_nothrow_default_constructible<_Tp>...>::value) {}
607
608 template <class _Alloc,
609 template <class...> class _IsImpDefault = __is_implicitly_default_constructible,
610 template <class...> class _IsDefault = is_default_constructible,
611 __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0>
612 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value)
613 tuple(allocator_arg_t, _Alloc const& __a)
614 : __base_(allocator_arg_t(), __a, __value_init{}) {}
615
616 // tuple(const T&...) constructors (including allocator_arg_t variants)
617 template <template <class...> class _And = _And,
618 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
619 _LIBCPP_HIDE_FROM_ABI
620 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)
621 tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value)
622 : __base_(__forward_args{}, __t...) {}
623
624 template <class _Alloc,
625 template <class...> class _And = _And,
626 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
627 _LIBCPP_HIDE_FROM_ABI
628 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value)
629 tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t)
630 : __base_(allocator_arg_t(), __a, __forward_args{}, __t...) {}
631
632 // tuple(U&& ...) constructors (including allocator_arg_t variants)
633 template <class... _Up>
634 struct _IsThisTuple : false_type {};
635 template <class _Up>
636 struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> {};
637
638 template <class... _Up>
639 struct _EnableUTypesCtor
640 : _And< _BoolConstant<sizeof...(_Tp) >= 1>,
641 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
642 is_constructible<_Tp, _Up>... > {};
643
644 template <class... _Up,
645 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
646 int> = 0>
647 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
648 tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
649 : __base_(__forward_args{}, std::forward<_Up>(__u)...) {}
650
651 template <class _Alloc,
652 class... _Up,
653 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
654 int> = 0>
655 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
656 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
657 : __base_(allocator_arg_t(), __a, __forward_args{}, std::forward<_Up>(__u)...) {}
658
659 // Copy and move constructors (including the allocator_arg_t variants)
660 tuple(const tuple&) = default;
661 tuple(tuple&&) = default;
662
663 template <class _Alloc,
664 template <class...> class _And = _And,
665 __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0>
666 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
667 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
668
669 template <class _Alloc,
670 template <class...> class _And = _And,
671 __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0>
672 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
673 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
674
675 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
676
677 template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>
678 struct _EnableCtorFromUTypesTuple : false_type {};
679
680 template <class _OtherTuple, class... _Up>
681 struct _EnableCtorFromUTypesTuple<
682 _OtherTuple,
683 tuple<_Up...>,
684 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
685 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>>
686 : _And<
687 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor
688 // can work. Otherwise, is_constructible can trigger hard error in those cases
689 // https://godbolt.org/z/M94cGdKcE
690 _Not<is_same<_OtherTuple, const tuple&> >,
691 _Not<is_same<_OtherTuple, tuple&&> >,
692 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
693 _Lazy<_Or,
694 _BoolConstant<sizeof...(_Tp) != 1>,
695 // _Tp and _Up are 1-element packs - the pack expansions look
696 // weird to avoid tripping up the type traits in degenerate cases
697 _Lazy<_And,
698 _Not<is_same<_Tp, _Up> >...,
699 _Not<is_convertible<_OtherTuple, _Tp> >...,
700 _Not<is_constructible<_Tp, _OtherTuple> >... > > > {};
701
702 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
703 _LIBCPP_HIDE_FROM_ABI
704 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)
705 tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)
706 : __base_(__from_tuple(), __t) {}
707
708 template <class... _Up,
709 class _Alloc,
710 __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
711 _LIBCPP_HIDE_FROM_ABI
712 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value)
713 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
714 : __base_(allocator_arg_t(), __a, __from_tuple(), __t) {}
715
716# if _LIBCPP_STD_VER >= 23
717 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
718
719 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
720 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t)
721 : __base_(__from_tuple(), __t) {}
722
723 template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
724 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
725 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)
726 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
727# endif // _LIBCPP_STD_VER >= 23
728
729 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
730 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
731 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
732 tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
733 : __base_(__from_tuple(), std::move(__t)) {}
734
735 template <class _Alloc,
736 class... _Up,
737 __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
738 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value)
739 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
740 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__t)) {}
741
742# if _LIBCPP_STD_VER >= 23
743 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
744
745 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
746 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
747 tuple(const tuple<_Up...>&& __t)
748 : __base_(__from_tuple(), std::move(__t)) {}
749
750 template <class _Alloc,
751 class... _Up,
752 enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
753 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
754 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
755 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
756# endif // _LIBCPP_STD_VER >= 23
757
758 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
759
760 template <template <class...> class _Pred,
761 class _Pair,
762 class _DecayedPair = __remove_cvref_t<_Pair>,
763 class _Tuple = tuple>
764 struct _CtorPredicateFromPair : false_type {};
765
766 template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
767 struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
768 : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {};
769
770 template <class _Pair>
771 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {};
772
773 template <class _Pair>
774 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {};
775
776 template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
777 struct _BothImplicitlyConvertible : false_type {};
778
779 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
780 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
781 : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {};
782
783 template <class _Up1,
784 class _Up2,
785 template <class...> class _And = _And,
786 __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
787 _LIBCPP_HIDE_FROM_ABI
788 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
789 tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)
790 : __base_(__from_tuple(), __p) {}
791
792 template <class _Alloc,
793 class _Up1,
794 class _Up2,
795 template <class...> class _And = _And,
796 __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
797 _LIBCPP_HIDE_FROM_ABI
798 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
799 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
800 : __base_(allocator_arg_t(), __a, __from_tuple(), __p) {}
801
802# if _LIBCPP_STD_VER >= 23
803 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
804
805 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
806 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
807 tuple(pair<_U1, _U2>& __p)
808 : __base_(__from_tuple(), __p) {}
809
810 template <class _Alloc,
811 class _U1,
812 class _U2,
813 enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
814 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
815 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)
816 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __p) {}
817# endif
818
819 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
820
821 template <class _Up1,
822 class _Up2,
823 template <class...> class _And = _And,
824 __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
825 _LIBCPP_HIDE_FROM_ABI
826 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
827 tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)
828 : __base_(__from_tuple(), std::move(__p)) {}
829
830 template <class _Alloc,
831 class _Up1,
832 class _Up2,
833 template <class...> class _And = _And,
834 __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
835 _LIBCPP_HIDE_FROM_ABI
836 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
837 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
838 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__p)) {}
839
840# if _LIBCPP_STD_VER >= 23
841 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
842
843 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
844 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
845 tuple(const pair<_U1, _U2>&& __p)
846 : __base_(__from_tuple(), std::move(__p)) {}
847
848 template <class _Alloc,
849 class _U1,
850 class _U2,
851 enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
852 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
853 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
854 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__p)) {}
855# endif // _LIBCPP_STD_VER >= 23
856
857 // [tuple.assign]
858 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
859 operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(
860 _And<is_nothrow_copy_assignable<_Tp>...>::value) {
861 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
862 return *this;
863 }
864
865# if _LIBCPP_STD_VER >= 23
866 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
867 requires(_And<is_copy_assignable<const _Tp>...>::value)
868 {
869 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
870 return *this;
871 }
872
873 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
874 requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
875 {
876 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
877 return *this;
878 }
879# endif // _LIBCPP_STD_VER >= 23
880
881 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
882 operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
883 _And<is_nothrow_move_assignable<_Tp>...>::value) {
884 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
885 return *this;
886 }
887
888 template <
889 class... _Up,
890 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,
891 int> = 0>
892 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
893 operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
894 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
895 return *this;
896 }
897
898 template <class... _Up,
899 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,
900 int> = 0>
901 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
902 operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
903 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>());
904 return *this;
905 }
906
907# if _LIBCPP_STD_VER >= 23
908 template <class... _UTypes,
909 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
910 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
911 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
912 std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>());
913 return *this;
914 }
915
916 template <class... _UTypes,
917 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
918 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
919 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
920 std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>());
921 return *this;
922 }
923# endif // _LIBCPP_STD_VER >= 23
924
925 template <template <class...> class _Pred,
926 bool _Const,
927 class _Pair,
928 class _DecayedPair = __remove_cvref_t<_Pair>,
929 class _Tuple = tuple>
930 struct _AssignPredicateFromPair : false_type {};
931
932 template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
933 struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
934 : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
935 _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {};
936
937 template <bool _Const, class _Pair>
938 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
939
940 template <bool _Const, class _Pair>
941 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
942
943# if _LIBCPP_STD_VER >= 23
944 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
945 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const
946 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
947 std::get<0>(*this) = __pair.first;
948 std::get<1>(*this) = __pair.second;
949 return *this;
950 }
951
952 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
953 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const
954 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
955 std::get<0>(*this) = std::move(__pair.first);
956 std::get<1>(*this) = std::move(__pair.second);
957 return *this;
958 }
959# endif // _LIBCPP_STD_VER >= 23
960
961 template <class _Up1,
962 class _Up2,
963 __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>
964 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
965 operator=(pair<_Up1, _Up2> const& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
966 std::get<0>(*this) = __pair.first;
967 std::get<1>(*this) = __pair.second;
968 return *this;
969 }
970
971 template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>
972 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
973 operator=(pair<_Up1, _Up2>&& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
974 std::get<0>(*this) = std::forward<_Up1>(__pair.first);
975 std::get<1>(*this) = std::forward<_Up2>(__pair.second);
976 return *this;
977 }
978
979 // EXTENSION
980 template <
981 class _Up,
982 size_t _Np,
983 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
984 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
985 operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
986 std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>());
987 return *this;
988 }
989
990 // EXTENSION
991 template <class _Up,
992 size_t _Np,
993 class = void,
994 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>
995 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
996 operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
997 std::__memberwise_forward_assign(
998 *this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __index_sequence_for<_Tp...>());
999 return *this;
1000 }
1001
1002 // [tuple.swap]
1003 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
1004 swap(tuple& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1005 __base_.swap(__t.__base_);
1006 }
1007
1008# if _LIBCPP_STD_VER >= 23
1009 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const
1010 noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
1011 __base_.swap(__t.__base_);
1012 }
1013
1014 template <__tuple_like_no_tuple _UTuple>
1015# if _LIBCPP_STD_VER >= 26
1016 requires __can_tuple_compare_equal<tuple, _UTuple> && (sizeof...(_Tp) == tuple_size_v<_UTuple>)
1017# endif // _LIBCPP_STD_VER >= 26
1018 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple& __x, const _UTuple& __y) {
1019 static_assert(sizeof...(_Tp) == tuple_size_v<_UTuple>, "Can't compare tuple-like values of different sizes");
1020 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
1021 }
1022
1023 template <__tuple_like_no_tuple _UTuple>
1024 requires(sizeof...(_Tp) == tuple_size_v<_UTuple>)
1025 _LIBCPP_HIDE_FROM_ABI friend constexpr __tuple_common_comparison_category<tuple, _UTuple>
1026 operator<=>(const tuple& __x, const _UTuple& __y) {
1027 return std::__tuple_compare_three_way<__tuple_common_comparison_category<tuple, _UTuple>>(
1028 __x, __y, index_sequence_for<_Tp...>{});
1029 }
1030# endif // _LIBCPP_STD_VER >= 23
1031};
1032
1033_LIBCPP_DIAGNOSTIC_PUSH
1034# if __has_warning("-Winvalid-specialization")
1035_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
1036# endif
1037template <>
1038class tuple<> {
1039public:
1040 constexpr tuple() _NOEXCEPT = default;
1041 template <class _Alloc>
1042 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
1043 template <class _Alloc>
1044 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
1045 template <class _Up>
1046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) _NOEXCEPT {}
1047 template <class _Alloc, class _Up>
1048 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
1049 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {}
1050# if _LIBCPP_STD_VER >= 23
1051 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1052
1053 template <__tuple_like_no_tuple _UTuple>
1054# if _LIBCPP_STD_VER >= 26
1055 requires(tuple_size_v<_UTuple> == 0)
1056# endif // _LIBCPP_STD_VER >= 26
1057 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple&, const _UTuple&) {
1058 static_assert(tuple_size_v<_UTuple> == 0, "Can't compare tuple-like values of different sizes");
1059 return true;
1060 }
1061
1062 template <__tuple_like_no_tuple _UTuple>
1063 requires(tuple_size_v<_UTuple> == 0)
1064 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const tuple&, const _UTuple&) {
1065 return strong_ordering::equal;
1066 }
1067# endif
1068};
1069_LIBCPP_DIAGNOSTIC_POP
1070
1071# if _LIBCPP_STD_VER >= 23
1072template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
1073 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1074struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1075 using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1076};
1077
1078template <class... _TTypes, class... _UTypes>
1079 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1080struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1081 using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;
1082};
1083# endif // _LIBCPP_STD_VER >= 23
1084
1085# if _LIBCPP_STD_VER >= 17
1086template <class... _Tp>
1087tuple(_Tp...) -> tuple<_Tp...>;
1088template <class _Tp1, class _Tp2>
1089tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1090template <class _Alloc, class... _Tp>
1091tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1092template <class _Alloc, class _Tp1, class _Tp2>
1093tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1094template <class _Alloc, class... _Tp>
1095tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
1096# endif
1097
1098template <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>
1099inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
1100swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1101 __t.swap(__u);
1102}
1103
1104# if _LIBCPP_STD_VER >= 23
1105template <class... _Tp>
1106_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1107swap(const tuple<_Tp...>& __lhs,
1108 const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1109 __lhs.swap(__rhs);
1110}
1111# endif
1112
1113// get
1114
1115template <size_t _Ip, class... _Tp>
1116[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1117typename tuple_element<_Ip, tuple<_Tp...> >::type&
1118get(tuple<_Tp...>& __t) _NOEXCEPT {
1119 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1120 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
1121}
1122
1123template <size_t _Ip, class... _Tp>
1124[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1125_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
1126get(const tuple<_Tp...>& __t) _NOEXCEPT {
1127 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1128 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
1129}
1130
1131template <size_t _Ip, class... _Tp>
1132[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1133typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1134get(tuple<_Tp...>&& __t) _NOEXCEPT {
1135 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1136 return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1137}
1138
1139template <size_t _Ip, class... _Tp>
1140[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1141_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1142get(const tuple<_Tp...>&& __t) _NOEXCEPT {
1143 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1144 return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1145}
1146
1147# if _LIBCPP_STD_VER >= 14
1148
1149template <class _T1, class... _Args>
1150[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {
1151 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1152}
1153
1154template <class _T1, class... _Args>
1155[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept {
1156 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1157}
1158
1159template <class _T1, class... _Args>
1160[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept {
1161 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1162}
1163
1164template <class _T1, class... _Args>
1165[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept {
1166 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1167}
1168
1169# endif
1170
1171// tie
1172
1173template <class... _Tp>
1174[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) _NOEXCEPT {
1175 return tuple<_Tp&...>(__t...);
1176}
1177
1178template <class... _Tp>
1179[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<__unwrap_ref_decay_t<_Tp>...>
1180make_tuple(_Tp&&... __t) {
1181 return tuple<__unwrap_ref_decay_t<_Tp>...>(std::forward<_Tp>(__t)...);
1182}
1183
1184template <class... _Tp>
1185[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...>
1186forward_as_tuple(_Tp&&... __t) _NOEXCEPT {
1187 return tuple<_Tp&&...>(std::forward<_Tp>(__t)...);
1188}
1189
1190template <class... _Tp, class... _Up>
1191# if _LIBCPP_STD_VER >= 26
1192 requires(__all<requires(const _Tp& __t, const _Up& __u) {
1193 { __t == __u } -> __boolean_testable;
1194 }...>::value && (sizeof...(_Tp) == sizeof...(_Up)))
1195# endif
1196inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1197operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1198 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1199 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
1200}
1201
1202# if _LIBCPP_STD_VER >= 20
1203
1204// operator<=>
1205
1206template <class... _Tp, class... _Up>
1207 requires(sizeof...(_Tp) == sizeof...(_Up))
1208_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1209operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1210 return std::__tuple_compare_three_way<common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>>(
1211 __x, __y, index_sequence_for<_Tp...>{});
1212}
1213
1214# else // _LIBCPP_STD_VER >= 20
1215
1216template <class... _Tp, class... _Up>
1217inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1218operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1219 return !(__x == __y);
1220}
1221
1222template <size_t _Ip>
1223struct __tuple_less {
1224 template <class _Tp, class _Up>
1225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {
1226 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1227 if (std::get<__idx>(__x) < std::get<__idx>(__y))
1228 return true;
1229 if (std::get<__idx>(__y) < std::get<__idx>(__x))
1230 return false;
1231 return __tuple_less<_Ip - 1>()(__x, __y);
1232 }
1233};
1234
1235template <>
1236struct __tuple_less<0> {
1237 template <class _Tp, class _Up>
1238 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {
1239 return false;
1240 }
1241};
1242
1243template <class... _Tp, class... _Up>
1244inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1245operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1246 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1247 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1248}
1249
1250template <class... _Tp, class... _Up>
1251inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1252operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1253 return __y < __x;
1254}
1255
1256template <class... _Tp, class... _Up>
1257inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1258operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1259 return !(__x < __y);
1260}
1261
1262template <class... _Tp, class... _Up>
1263inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1264operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1265 return !(__y < __x);
1266}
1267
1268# endif // _LIBCPP_STD_VER >= 20
1269
1270// tuple_cat
1271
1272template <class... _Tuples>
1273struct __tuple_cat_return_impl;
1274
1275template <class... _Types>
1276struct __tuple_cat_return_impl<tuple<_Types...>> {
1277 using type _LIBCPP_NODEBUG = tuple<_Types...>;
1278};
1279
1280template <class... _Types0, class... _Types1, class... _Tuples>
1281struct __tuple_cat_return_impl<tuple<_Types0...>, tuple<_Types1...>, _Tuples...>
1282 : __tuple_cat_return_impl<tuple<_Types0..., _Types1...>, _Tuples...> {};
1283
1284template <class... _Types0, class _Tp, class _Up, class... _Tuples>
1285struct __tuple_cat_return_impl<tuple<_Types0...>, pair<_Tp, _Up>, _Tuples...>
1286 : __tuple_cat_return_impl<tuple<_Types0..., _Tp, _Up>, _Tuples...> {};
1287
1288template <class, class, class>
1289struct __tuple_cat_array;
1290
1291template <class... _Types, class _ValueT, size_t... _Indices>
1292struct __tuple_cat_array<tuple<_Types...>, _ValueT, __index_sequence<_Indices...>> {
1293 template <size_t>
1294 using __value_type _LIBCPP_NODEBUG = _ValueT;
1295
1296 using type _LIBCPP_NODEBUG = tuple<_Types..., __value_type<_Indices>...>;
1297};
1298
1299template <class... _Types, class _ValueT, size_t _Np, class... _Tuples>
1300struct __tuple_cat_return_impl<tuple<_Types...>, array<_ValueT, _Np>, _Tuples...>
1301 : __tuple_cat_return_impl<typename __tuple_cat_array<tuple<_Types...>, _ValueT, __make_index_sequence<_Np>>::type,
1302 _Tuples...> {};
1303
1304template <class... _Tuples>
1305using __tuple_cat_return_t _LIBCPP_NODEBUG =
1306 typename __tuple_cat_return_impl<tuple<>, __remove_cvref_t<_Tuples>...>::type;
1307
1308[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
1309
1310template <class _Rp, class _Indices, class _Tuple0, class... _Tuples>
1311struct __tuple_cat_return_ref_imp;
1312
1313template <class... _Types, size_t... _I0, class _Tuple0>
1314struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0> {
1315 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1316 typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
1317};
1318
1319template <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>
1320struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0, _Tuple1, _Tuples...>
1321 : public __tuple_cat_return_ref_imp<
1322 tuple<_Types...,
1323 __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
1324 __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>,
1325 _Tuple1,
1326 _Tuples...> {};
1327
1328template <class _Tuple0, class... _Tuples>
1329struct __tuple_cat_return_ref
1330 : public __tuple_cat_return_ref_imp<
1331 tuple<>,
1332 __make_index_sequence< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >,
1333 _Tuple0,
1334 _Tuples...> {};
1335
1336template <class _Types, class _I0, class _J0>
1337struct __tuple_cat;
1338
1339template <class... _Types, size_t... _I0, size_t... _J0>
1340struct __tuple_cat<tuple<_Types...>, __index_sequence<_I0...>, __index_sequence<_J0...>> {
1341 template <class _Tuple0>
1342 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1343 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1344 operator()(tuple<_Types...> __t, _Tuple0&& __t0) {
1345 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1346 return std::forward_as_tuple(
1347 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...);
1348 }
1349
1350 template <class _Tuple0, class _Tuple1, class... _Tuples>
1351 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1352 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1353 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {
1354 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1355 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1356 using _T1 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple1>;
1357 return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
1358 __make_index_sequence<sizeof...(_Types) + tuple_size<_T0>::value>,
1359 __make_index_sequence<tuple_size<_T1>::value>>()(
1360 std::forward_as_tuple(
1361 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...),
1362 std::forward<_Tuple1>(__t1),
1363 std::forward<_Tuples>(__tpls)...);
1364 }
1365};
1366
1367template <class _TupleDst, class _TupleSrc, size_t... _Indices>
1368inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _TupleDst
1369__tuple_cat_select_element_wise(_TupleSrc&& __src, __index_sequence<_Indices...>) {
1370 static_assert(tuple_size<_TupleDst>::value == tuple_size<_TupleSrc>::value,
1371 "misuse of __tuple_cat_select_element_wise with tuples of different sizes");
1372 return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);
1373}
1374
1375template <class _Tuple0, class... _Tuples>
1376[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_cat_return_t<_Tuple0, _Tuples...>
1377tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
1378 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1379 using _TRet _LIBCPP_NODEBUG = __tuple_cat_return_t<_Tuple0, _Tuples...>;
1380 using _T0Indices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_T0>::value>;
1381 using _TRetIndices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_TRet>::value>;
1382 return std::__tuple_cat_select_element_wise<_TRet>(
1383 __tuple_cat<tuple<>, __index_sequence<>, _T0Indices>()(
1384 tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...),
1385 _TRetIndices());
1386}
1387
1388template <class... _Tp, class _Alloc>
1389struct uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
1390
1391# if _LIBCPP_STD_VER >= 17
1392# define _LIBCPP_NOEXCEPT_RETURN(...) \
1393 noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1394
1395// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting.
1396// clang-format off
1397template <class _Fn, class _Tuple, size_t... _Id>
1398inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto)
1399__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Id...>)
1400 _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...))
1401
1402template <class _Fn, class _Tuple>
1403inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t)
1404 _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl(
1405 std::forward<_Fn>(__f),
1406 std::forward<_Tuple>(__t),
1407 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))
1408
1409#if _LIBCPP_STD_VER >= 20
1410template <class _Tp, class _Tuple, size_t... _Idx>
1411inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
1412 noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
1413 requires is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> {
1414 return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
1415}
1416#else
1417template <class _Tp, class _Tuple, size_t... _Idx>
1418inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>,
1419 enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr)
1420 _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
1421#endif // _LIBCPP_STD_VER >= 20
1422#undef _LIBCPP_NOEXCEPT_RETURN
1423
1424template <class _Tp, class _Tuple,
1425 class _Seq = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>, class = void>
1426inline constexpr bool __can_make_from_tuple = false;
1427
1428template <class _Tp, class _Tuple, size_t... _Idx>
1429inline constexpr bool __can_make_from_tuple<_Tp, _Tuple, index_sequence<_Idx...>,
1430 enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>>> = true;
1431
1432// Based on LWG3528(https://wg21.link/LWG3528) and http://eel.is/c++draft/description#structure.requirements-9,
1433// the standard allows to impose requirements, we constraint std::make_from_tuple to make std::make_from_tuple
1434// SFINAE friendly and also avoid worse diagnostic messages. We still keep the constraints of std::__make_from_tuple_impl
1435// so that std::__make_from_tuple_impl will have the same advantages when used alone.
1436#if _LIBCPP_STD_VER >= 20
1437template <class _Tp, class _Tuple>
1438 requires __can_make_from_tuple<_Tp, _Tuple> // strengthen
1439#else
1440template <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen
1441#endif // _LIBCPP_STD_VER >= 20
1442
1443[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)
1444 noexcept(noexcept(std::__make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t),
1445 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))) {
1446#if _LIBCPP_STD_VER >= 23
1447 if constexpr (tuple_size_v<remove_reference_t<_Tuple>> == 1) {
1448 static_assert(!std::reference_constructs_from_temporary_v<_Tp, decltype(std::get<0>(std::declval<_Tuple>()))>,
1449 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
1450 }
1451#endif // _LIBCPP_STD_VER >= 23
1452 return std::__make_from_tuple_impl<_Tp>(
1453 std::forward<_Tuple>(__t), make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>());
1454}
1455
1456# endif // _LIBCPP_STD_VER >= 17
1457
1458#endif // !defined(_LIBCPP_CXX03_LANG)
1459
1460_LIBCPP_END_NAMESPACE_STD
1461
1462_LIBCPP_POP_MACROS
1463
1464// clang-format on
1465
1466# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1467# include <cstddef>
1468# include <exception>
1469# include <iosfwd>
1470# include <new>
1471# include <type_traits>
1472# include <typeinfo>
1473# include <utility>
1474# endif
1475#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1476
1477#endif // _LIBCPP_TUPLE
1478