tuple 68 KB

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