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