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/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<_And<__libcpp_is_trivially_relocatable<_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,
595 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
596 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<const _Tp&, _Tp>...>::value)
597 tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value)
598 : __base_(__forward_args{}, __t...) {}
599
600 template <class _Alloc,
601 template <class...> class _And = _And,
602 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0>
603 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<const _Tp&, _Tp>...>::value)
604 tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t)
605 : __base_(allocator_arg_t(), __a, __forward_args{}, __t...) {}
606
607 // tuple(U&& ...) constructors (including allocator_arg_t variants)
608 template <class... _Up>
609 struct _IsThisTuple : false_type {};
610 template <class _Up>
611 struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> {};
612
613 template <class... _Up>
614 struct _EnableUTypesCtor
615 : _And< _BoolConstant<sizeof...(_Tp) >= 1>,
616 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
617 is_constructible<_Tp, _Up>... > {};
618
619 template <class... _Up,
620 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
621 int> = 0>
622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
623 tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
624 : __base_(__forward_args{}, std::forward<_Up>(__u)...) {}
625
626 template <class _Alloc,
627 class... _Up,
628 __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value,
629 int> = 0>
630 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
631 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
632 : __base_(allocator_arg_t(), __a, __forward_args{}, std::forward<_Up>(__u)...) {}
633
634 // Copy and move constructors (including the allocator_arg_t variants)
635 tuple(const tuple&) = default;
636 tuple(tuple&&) = default;
637
638 template <class _Alloc,
639 template <class...> class _And = _And,
640 __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0>
641 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
642 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
643
644 template <class _Alloc,
645 template <class...> class _And = _And,
646 __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0>
647 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
648 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
649
650 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
651
652 template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>
653 struct _EnableCtorFromUTypesTuple : false_type {};
654
655 template <class _OtherTuple, class... _Up>
656 struct _EnableCtorFromUTypesTuple<
657 _OtherTuple,
658 tuple<_Up...>,
659 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
660 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>>
661 : _And<
662 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor
663 // can work. Otherwise, is_constructible can trigger hard error in those cases
664 // https://godbolt.org/z/M94cGdKcE
665 _Not<is_same<_OtherTuple, const tuple&> >,
666 _Not<is_same<_OtherTuple, tuple&&> >,
667 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
668 _Or<_BoolConstant<sizeof...(_Tp) != 1>,
669 // _Tp and _Up are 1-element packs - the pack expansions look
670 // weird to avoid tripping up the type traits in degenerate cases
671 _And<_Not<is_same<_Tp, _Up> >...,
672 _Not<is_convertible<_OtherTuple, _Tp> >...,
673 _Not<is_constructible<_Tp, _OtherTuple> >... > > > {};
674
675 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
676 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<const _Up&, _Tp>...>::value)
677 tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)
678 : __base_(__from_tuple(), __t) {}
679
680 template <class... _Up,
681 class _Alloc,
682 __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0>
683 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<const _Up&, _Tp>...>::value)
684 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
685 : __base_(allocator_arg_t(), __a, __from_tuple(), __t) {}
686
687# if _LIBCPP_STD_VER >= 23
688 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
689
690 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
691 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t)
692 : __base_(__from_tuple(), __t) {}
693
694 template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
695 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<_Up&, _Tp>...>::value)
696 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)
697 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __t) {}
698# endif // _LIBCPP_STD_VER >= 23
699
700 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
701 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
702 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
703 tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value)
704 : __base_(__from_tuple(), std::move(__t)) {}
705
706 template <class _Alloc,
707 class... _Up,
708 __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
709 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(!_And<is_convertible<_Up, _Tp>...>::value)
710 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
711 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__t)) {}
712
713# if _LIBCPP_STD_VER >= 23
714 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
715
716 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
717 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<const _Up&&, _Tp>...>::value)
718 tuple(const tuple<_Up...>&& __t)
719 : __base_(__from_tuple(), std::move(__t)) {}
720
721 template <class _Alloc,
722 class... _Up,
723 enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
724 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_And<is_convertible<const _Up&&, _Tp>...>::value)
725 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
726 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__t)) {}
727# endif // _LIBCPP_STD_VER >= 23
728
729 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
730
731 template <template <class...> class _Pred,
732 class _Pair,
733 class _DecayedPair = __remove_cvref_t<_Pair>,
734 class _Tuple = tuple>
735 struct _CtorPredicateFromPair : false_type {};
736
737 template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
738 struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
739 : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {};
740
741 template <class _Pair>
742 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {};
743
744 template <class _Pair>
745 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {};
746
747 template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
748 struct _BothImplicitlyConvertible : false_type {};
749
750 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
751 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
752 : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {};
753
754 template <class _Up1,
755 class _Up2,
756 template <class...> class _And = _And,
757 __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
758 _LIBCPP_HIDE_FROM_ABI
759 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
760 tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)
761 : __base_(__from_tuple(), __p) {}
762
763 template <class _Alloc,
764 class _Up1,
765 class _Up2,
766 template <class...> class _And = _And,
767 __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0>
768 _LIBCPP_HIDE_FROM_ABI
769 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value)
770 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
771 : __base_(allocator_arg_t(), __a, __from_tuple(), __p) {}
772
773# if _LIBCPP_STD_VER >= 23
774 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
775
776 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
777 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
778 tuple(pair<_U1, _U2>& __p)
779 : __base_(__from_tuple(), __p) {}
780
781 template <class _Alloc,
782 class _U1,
783 class _U2,
784 enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
785 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
786 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)
787 : __base_(allocator_arg_t(), __alloc, __from_tuple(), __p) {}
788# endif
789
790 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
791
792 template <class _Up1,
793 class _Up2,
794 template <class...> class _And = _And,
795 __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
796 _LIBCPP_HIDE_FROM_ABI
797 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
798 tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)
799 : __base_(__from_tuple(), std::move(__p)) {}
800
801 template <class _Alloc,
802 class _Up1,
803 class _Up2,
804 template <class...> class _And = _And,
805 __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0>
806 _LIBCPP_HIDE_FROM_ABI
807 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value)
808 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
809 : __base_(allocator_arg_t(), __a, __from_tuple(), std::move(__p)) {}
810
811# if _LIBCPP_STD_VER >= 23
812 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
813
814 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
815 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
816 tuple(const pair<_U1, _U2>&& __p)
817 : __base_(__from_tuple(), std::move(__p)) {}
818
819 template <class _Alloc,
820 class _U1,
821 class _U2,
822 enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
823 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
824 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
825 : __base_(allocator_arg_t(), __alloc, __from_tuple(), std::move(__p)) {}
826# endif // _LIBCPP_STD_VER >= 23
827
828 // [tuple.assign]
829 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
830 operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(
831 _And<is_nothrow_copy_assignable<_Tp>...>::value) {
832 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
833 return *this;
834 }
835
836# if _LIBCPP_STD_VER >= 23
837 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
838 requires(_And<is_copy_assignable<const _Tp>...>::value)
839 {
840 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
841 return *this;
842 }
843
844 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
845 requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
846 {
847 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
848 return *this;
849 }
850# endif // _LIBCPP_STD_VER >= 23
851
852 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
853 operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
854 _And<is_nothrow_move_assignable<_Tp>...>::value) {
855 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
856 return *this;
857 }
858
859 template <
860 class... _Up,
861 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,
862 int> = 0>
863 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
864 operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
865 std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
866 return *this;
867 }
868
869 template <class... _Up,
870 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,
871 int> = 0>
872 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
873 operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
874 std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>());
875 return *this;
876 }
877
878# if _LIBCPP_STD_VER >= 23
879 template <class... _UTypes,
880 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
881 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
882 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
883 std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>());
884 return *this;
885 }
886
887 template <class... _UTypes,
888 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
889 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
890 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
891 std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>());
892 return *this;
893 }
894# endif // _LIBCPP_STD_VER >= 23
895
896 template <template <class...> class _Pred,
897 bool _Const,
898 class _Pair,
899 class _DecayedPair = __remove_cvref_t<_Pair>,
900 class _Tuple = tuple>
901 struct _AssignPredicateFromPair : false_type {};
902
903 template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
904 struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> >
905 : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
906 _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {};
907
908 template <bool _Const, class _Pair>
909 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
910
911 template <bool _Const, class _Pair>
912 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
913
914# if _LIBCPP_STD_VER >= 23
915 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
916 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const
917 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
918 std::get<0>(*this) = __pair.first;
919 std::get<1>(*this) = __pair.second;
920 return *this;
921 }
922
923 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
924 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const
925 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
926 std::get<0>(*this) = std::move(__pair.first);
927 std::get<1>(*this) = std::move(__pair.second);
928 return *this;
929 }
930# endif // _LIBCPP_STD_VER >= 23
931
932 template <class _Up1,
933 class _Up2,
934 __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>
935 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
936 operator=(pair<_Up1, _Up2> const& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
937 std::get<0>(*this) = __pair.first;
938 std::get<1>(*this) = __pair.second;
939 return *this;
940 }
941
942 template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>
943 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
944 operator=(pair<_Up1, _Up2>&& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
945 std::get<0>(*this) = std::forward<_Up1>(__pair.first);
946 std::get<1>(*this) = std::forward<_Up2>(__pair.second);
947 return *this;
948 }
949
950 // EXTENSION
951 template <
952 class _Up,
953 size_t _Np,
954 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
955 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
956 operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
957 std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>());
958 return *this;
959 }
960
961 // EXTENSION
962 template <class _Up,
963 size_t _Np,
964 class = void,
965 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>
966 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
967 operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
968 std::__memberwise_forward_assign(
969 *this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __index_sequence_for<_Tp...>());
970 return *this;
971 }
972
973 // [tuple.swap]
974 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
975 swap(tuple& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
976 __base_.swap(__t.__base_);
977 }
978
979# if _LIBCPP_STD_VER >= 23
980 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const
981 noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
982 __base_.swap(__t.__base_);
983 }
984
985 template <class _Tuple>
986 static constexpr bool __can_compare_equal = false;
987
988 template <class... _Up>
989 static constexpr bool __can_compare_equal<tuple<_Up...>> = __all<requires(const _Tp& __t, const _Up& __u) {
990 { __t == __u } -> __boolean_testable;
991 }...>::value;
992
993 template <__tuple_like_no_tuple _UTuple>
994# if _LIBCPP_STD_VER >= 26
995 requires(sizeof...(_Tp) == tuple_size_v<_UTuple>) && __can_compare_equal<__to_tuple_t<_UTuple>>
996# endif // _LIBCPP_STD_VER >= 26
997 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple& __x, const _UTuple& __y) {
998 static_assert(sizeof...(_Tp) == tuple_size_v<_UTuple>, "Can't compare tuple-like values of different sizes");
999 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
1000 }
1001
1002 template <class _Tuple>
1003 struct __common_comparison_category_with;
1004
1005 template <class... _Up>
1006 requires requires { typename common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>; }
1007 struct __common_comparison_category_with<tuple<_Up...>> {
1008 using type _LIBCPP_NODEBUG = common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>;
1009 };
1010
1011 template <__tuple_like_no_tuple _UTuple>
1012 requires(sizeof...(_Tp) == tuple_size_v<_UTuple>)
1013 _LIBCPP_HIDE_FROM_ABI friend constexpr typename __common_comparison_category_with<__to_tuple_t<_UTuple>>::type
1014 operator<=>(const tuple& __x, const _UTuple& __y) {
1015 return std::__tuple_compare_three_way<typename __common_comparison_category_with<__to_tuple_t<_UTuple>>::type>(
1016 __x, __y, index_sequence_for<_Tp...>{});
1017 }
1018# endif // _LIBCPP_STD_VER >= 23
1019};
1020
1021_LIBCPP_DIAGNOSTIC_PUSH
1022# if __has_warning("-Winvalid-specialization")
1023_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
1024# endif
1025template <>
1026class tuple<> {
1027public:
1028 constexpr tuple() _NOEXCEPT = default;
1029 template <class _Alloc>
1030 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
1031 template <class _Alloc>
1032 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
1033 template <class _Up>
1034 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) _NOEXCEPT {}
1035 template <class _Alloc, class _Up>
1036 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
1037 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {}
1038# if _LIBCPP_STD_VER >= 23
1039 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1040
1041 template <__tuple_like_no_tuple _UTuple>
1042# if _LIBCPP_STD_VER >= 26
1043 requires(tuple_size_v<_UTuple> == 0)
1044# endif // _LIBCPP_STD_VER >= 26
1045 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const tuple&, const _UTuple&) {
1046 static_assert(tuple_size_v<_UTuple> == 0, "Can't compare tuple-like values of different sizes");
1047 return true;
1048 }
1049
1050 template <__tuple_like_no_tuple _UTuple>
1051 requires(tuple_size_v<_UTuple> == 0)
1052 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const tuple&, const _UTuple&) {
1053 return strong_ordering::equal;
1054 }
1055# endif
1056};
1057_LIBCPP_DIAGNOSTIC_POP
1058
1059# if _LIBCPP_STD_VER >= 23
1060template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
1061 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1062struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1063 using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1064};
1065
1066template <class... _TTypes, class... _UTypes>
1067 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1068struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1069 using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;
1070};
1071# endif // _LIBCPP_STD_VER >= 23
1072
1073# if _LIBCPP_STD_VER >= 17
1074template <class... _Tp>
1075tuple(_Tp...) -> tuple<_Tp...>;
1076template <class _Tp1, class _Tp2>
1077tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1078template <class _Alloc, class... _Tp>
1079tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1080template <class _Alloc, class _Tp1, class _Tp2>
1081tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1082template <class _Alloc, class... _Tp>
1083tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
1084# endif
1085
1086template <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>
1087inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
1088swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1089 __t.swap(__u);
1090}
1091
1092# if _LIBCPP_STD_VER >= 23
1093template <class... _Tp>
1094_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1095swap(const tuple<_Tp...>& __lhs,
1096 const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1097 __lhs.swap(__rhs);
1098}
1099# endif
1100
1101// get
1102
1103template <size_t _Ip, class... _Tp>
1104[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1105typename tuple_element<_Ip, tuple<_Tp...> >::type&
1106get(tuple<_Tp...>& __t) _NOEXCEPT {
1107 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1108 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
1109}
1110
1111template <size_t _Ip, class... _Tp>
1112[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1113_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
1114get(const tuple<_Tp...>& __t) _NOEXCEPT {
1115 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1116 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
1117}
1118
1119template <size_t _Ip, class... _Tp>
1120[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1121typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1122get(tuple<_Tp...>&& __t) _NOEXCEPT {
1123 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1124 return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1125}
1126
1127template <size_t _Ip, class... _Tp>
1128[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
1129_LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1130get(const tuple<_Tp...>&& __t) _NOEXCEPT {
1131 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
1132 return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
1133}
1134
1135# if _LIBCPP_STD_VER >= 14
1136
1137template <class _T1, class... _Args>
1138[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {
1139 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1140}
1141
1142template <class _T1, class... _Args>
1143[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept {
1144 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1145}
1146
1147template <class _T1, class... _Args>
1148[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept {
1149 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1150}
1151
1152template <class _T1, class... _Args>
1153[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept {
1154 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
1155}
1156
1157# endif
1158
1159// tie
1160
1161template <class... _Tp>
1162[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) _NOEXCEPT {
1163 return tuple<_Tp&...>(__t...);
1164}
1165
1166template <class... _Tp>
1167[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<__unwrap_ref_decay_t<_Tp>...>
1168make_tuple(_Tp&&... __t) {
1169 return tuple<__unwrap_ref_decay_t<_Tp>...>(std::forward<_Tp>(__t)...);
1170}
1171
1172template <class... _Tp>
1173[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...>
1174forward_as_tuple(_Tp&&... __t) _NOEXCEPT {
1175 return tuple<_Tp&&...>(std::forward<_Tp>(__t)...);
1176}
1177
1178template <class... _Tp, class... _Up>
1179# if _LIBCPP_STD_VER >= 26
1180 requires(__all<requires(const _Tp& __t, const _Up& __u) {
1181 { __t == __u } -> __boolean_testable;
1182 }...>::value && (sizeof...(_Tp) == sizeof...(_Up)))
1183# endif
1184inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1185operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1186 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1187 return std::__tuple_compare_equal<sizeof...(_Tp)>(__x, __y);
1188}
1189
1190# if _LIBCPP_STD_VER >= 20
1191
1192// operator<=>
1193
1194template <class... _Tp, class... _Up>
1195 requires(sizeof...(_Tp) == sizeof...(_Up))
1196_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1197operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1198 return std::__tuple_compare_three_way<common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>>(
1199 __x, __y, index_sequence_for<_Tp...>{});
1200}
1201
1202# else // _LIBCPP_STD_VER >= 20
1203
1204template <class... _Tp, class... _Up>
1205inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1206operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1207 return !(__x == __y);
1208}
1209
1210template <size_t _Ip>
1211struct __tuple_less {
1212 template <class _Tp, class _Up>
1213 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) {
1214 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1215 if (std::get<__idx>(__x) < std::get<__idx>(__y))
1216 return true;
1217 if (std::get<__idx>(__y) < std::get<__idx>(__x))
1218 return false;
1219 return __tuple_less<_Ip - 1>()(__x, __y);
1220 }
1221};
1222
1223template <>
1224struct __tuple_less<0> {
1225 template <class _Tp, class _Up>
1226 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) {
1227 return false;
1228 }
1229};
1230
1231template <class... _Tp, class... _Up>
1232inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1233operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1234 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
1235 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1236}
1237
1238template <class... _Tp, class... _Up>
1239inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1240operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1241 return __y < __x;
1242}
1243
1244template <class... _Tp, class... _Up>
1245inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
1246operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
1247 return !(__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
1256# endif // _LIBCPP_STD_VER >= 20
1257
1258// tuple_cat
1259
1260template <class... _Tuples>
1261struct __tuple_cat_return_impl;
1262
1263template <class... _Types>
1264struct __tuple_cat_return_impl<tuple<_Types...>> {
1265 using type _LIBCPP_NODEBUG = tuple<_Types...>;
1266};
1267
1268template <class... _Types0, class... _Types1, class... _Tuples>
1269struct __tuple_cat_return_impl<tuple<_Types0...>, tuple<_Types1...>, _Tuples...>
1270 : __tuple_cat_return_impl<tuple<_Types0..., _Types1...>, _Tuples...> {};
1271
1272template <class... _Types0, class _Tp, class _Up, class... _Tuples>
1273struct __tuple_cat_return_impl<tuple<_Types0...>, pair<_Tp, _Up>, _Tuples...>
1274 : __tuple_cat_return_impl<tuple<_Types0..., _Tp, _Up>, _Tuples...> {};
1275
1276template <class, class, class>
1277struct __tuple_cat_array;
1278
1279template <class... _Types, class _ValueT, size_t... _Indices>
1280struct __tuple_cat_array<tuple<_Types...>, _ValueT, __index_sequence<_Indices...>> {
1281 template <size_t>
1282 using __value_type _LIBCPP_NODEBUG = _ValueT;
1283
1284 using type _LIBCPP_NODEBUG = tuple<_Types..., __value_type<_Indices>...>;
1285};
1286
1287template <class... _Types, class _ValueT, size_t _Np, class... _Tuples>
1288struct __tuple_cat_return_impl<tuple<_Types...>, array<_ValueT, _Np>, _Tuples...>
1289 : __tuple_cat_return_impl<typename __tuple_cat_array<tuple<_Types...>, _ValueT, __make_index_sequence<_Np>>::type,
1290 _Tuples...> {};
1291
1292template <class... _Tuples>
1293using __tuple_cat_return_t _LIBCPP_NODEBUG =
1294 typename __tuple_cat_return_impl<tuple<>, __remove_cvref_t<_Tuples>...>::type;
1295
1296[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
1297
1298template <class _Rp, class _Indices, class _Tuple0, class... _Tuples>
1299struct __tuple_cat_return_ref_imp;
1300
1301template <class... _Types, size_t... _I0, class _Tuple0>
1302struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0> {
1303 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1304 typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
1305};
1306
1307template <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>
1308struct __tuple_cat_return_ref_imp<tuple<_Types...>, __index_sequence<_I0...>, _Tuple0, _Tuple1, _Tuples...>
1309 : public __tuple_cat_return_ref_imp<
1310 tuple<_Types...,
1311 __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
1312 __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>,
1313 _Tuple1,
1314 _Tuples...> {};
1315
1316template <class _Tuple0, class... _Tuples>
1317struct __tuple_cat_return_ref
1318 : public __tuple_cat_return_ref_imp<
1319 tuple<>,
1320 __make_index_sequence< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >,
1321 _Tuple0,
1322 _Tuples...> {};
1323
1324template <class _Types, class _I0, class _J0>
1325struct __tuple_cat;
1326
1327template <class... _Types, size_t... _I0, size_t... _J0>
1328struct __tuple_cat<tuple<_Types...>, __index_sequence<_I0...>, __index_sequence<_J0...>> {
1329 template <class _Tuple0>
1330 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1331 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1332 operator()(tuple<_Types...> __t, _Tuple0&& __t0) {
1333 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1334 return std::forward_as_tuple(
1335 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...);
1336 }
1337
1338 template <class _Tuple0, class _Tuple1, class... _Tuples>
1339 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
1340 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1341 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {
1342 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1343 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1344 using _T1 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple1>;
1345 return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
1346 __make_index_sequence<sizeof...(_Types) + tuple_size<_T0>::value>,
1347 __make_index_sequence<tuple_size<_T1>::value>>()(
1348 std::forward_as_tuple(
1349 std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...),
1350 std::forward<_Tuple1>(__t1),
1351 std::forward<_Tuples>(__tpls)...);
1352 }
1353};
1354
1355template <class _TupleDst, class _TupleSrc, size_t... _Indices>
1356inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _TupleDst
1357__tuple_cat_select_element_wise(_TupleSrc&& __src, __index_sequence<_Indices...>) {
1358 static_assert(tuple_size<_TupleDst>::value == tuple_size<_TupleSrc>::value,
1359 "misuse of __tuple_cat_select_element_wise with tuples of different sizes");
1360 return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);
1361}
1362
1363template <class _Tuple0, class... _Tuples>
1364[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_cat_return_t<_Tuple0, _Tuples...>
1365tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
1366 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1367 using _TRet _LIBCPP_NODEBUG = __tuple_cat_return_t<_Tuple0, _Tuples...>;
1368 using _T0Indices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_T0>::value>;
1369 using _TRetIndices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_TRet>::value>;
1370 return std::__tuple_cat_select_element_wise<_TRet>(
1371 __tuple_cat<tuple<>, __index_sequence<>, _T0Indices>()(
1372 tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...),
1373 _TRetIndices());
1374}
1375
1376template <class... _Tp, class _Alloc>
1377struct uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
1378
1379# if _LIBCPP_STD_VER >= 17
1380# define _LIBCPP_NOEXCEPT_RETURN(...) \
1381 noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1382
1383// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting.
1384// clang-format off
1385template <class _Fn, class _Tuple, size_t... _Id>
1386inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto)
1387__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Id...>)
1388 _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...))
1389
1390template <class _Fn, class _Tuple>
1391inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t)
1392 _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl(
1393 std::forward<_Fn>(__f),
1394 std::forward<_Tuple>(__t),
1395 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))
1396
1397#if _LIBCPP_STD_VER >= 20
1398template <class _Tp, class _Tuple, size_t... _Idx>
1399inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
1400 noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
1401 requires is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> {
1402 return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
1403}
1404#else
1405template <class _Tp, class _Tuple, size_t... _Idx>
1406inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>,
1407 enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr)
1408 _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
1409#endif // _LIBCPP_STD_VER >= 20
1410#undef _LIBCPP_NOEXCEPT_RETURN
1411
1412template <class _Tp, class _Tuple,
1413 class _Seq = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>, class = void>
1414inline constexpr bool __can_make_from_tuple = false;
1415
1416template <class _Tp, class _Tuple, size_t... _Idx>
1417inline constexpr bool __can_make_from_tuple<_Tp, _Tuple, index_sequence<_Idx...>,
1418 enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>>> = true;
1419
1420// Based on LWG3528(https://wg21.link/LWG3528) and http://eel.is/c++draft/description#structure.requirements-9,
1421// the standard allows to impose requirements, we constraint std::make_from_tuple to make std::make_from_tuple
1422// SFINAE friendly and also avoid worse diagnostic messages. We still keep the constraints of std::__make_from_tuple_impl
1423// so that std::__make_from_tuple_impl will have the same advantages when used alone.
1424#if _LIBCPP_STD_VER >= 20
1425template <class _Tp, class _Tuple>
1426 requires __can_make_from_tuple<_Tp, _Tuple> // strengthen
1427#else
1428template <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen
1429#endif // _LIBCPP_STD_VER >= 20
1430
1431[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)
1432 noexcept(noexcept(std::__make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t),
1433 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))) {
1434#if _LIBCPP_STD_VER >= 23
1435 if constexpr (tuple_size_v<remove_reference_t<_Tuple>> == 1) {
1436 static_assert(!std::reference_constructs_from_temporary_v<_Tp, decltype(std::get<0>(std::declval<_Tuple>()))>,
1437 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
1438 }
1439#endif // _LIBCPP_STD_VER >= 23
1440 return std::__make_from_tuple_impl<_Tp>(
1441 std::forward<_Tuple>(__t), make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>());
1442}
1443
1444# endif // _LIBCPP_STD_VER >= 17
1445
1446_LIBCPP_END_NAMESPACE_STD
1447
1448#endif // !defined(_LIBCPP_CXX03_LANG)
1449
1450_LIBCPP_POP_MACROS
1451
1452// clang-format on
1453
1454# if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20
1455# include <cstddef>
1456# include <exception>
1457# include <iosfwd>
1458# include <new>
1459# include <type_traits>
1460# include <typeinfo>
1461# include <utility>
1462# endif
1463#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1464
1465#endif // _LIBCPP_TUPLE
1466