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