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