tuple 64 KB

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