tuple 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  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. // tuple() constructors (including allocator_arg_t variants)
  513. template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
  514. _And<
  515. _IsImpDefault<_Tp>... // explicit check
  516. >::value
  517. , int> = 0>
  518. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  519. tuple()
  520. _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
  521. { }
  522. template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
  523. template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
  524. _And<
  525. _IsDefault<_Tp>...,
  526. _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
  527. >::value
  528. , int> = 0>
  529. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  530. explicit tuple()
  531. _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
  532. { }
  533. template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
  534. _And<
  535. _IsImpDefault<_Tp>... // explicit check
  536. >::value
  537. , int> = 0>
  538. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  539. tuple(allocator_arg_t, _Alloc const& __a)
  540. : __base_(allocator_arg_t(), __a,
  541. __tuple_indices<>(), __tuple_types<>(),
  542. typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
  543. __tuple_types<_Tp...>()) {}
  544. template <class _Alloc,
  545. template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
  546. template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
  547. _And<
  548. _IsDefault<_Tp>...,
  549. _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
  550. >::value
  551. , int> = 0>
  552. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  553. explicit tuple(allocator_arg_t, _Alloc const& __a)
  554. : __base_(allocator_arg_t(), __a,
  555. __tuple_indices<>(), __tuple_types<>(),
  556. typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
  557. __tuple_types<_Tp...>()) {}
  558. // tuple(const T&...) constructors (including allocator_arg_t variants)
  559. template <template<class...> class _And = _And, __enable_if_t<
  560. _And<
  561. _BoolConstant<sizeof...(_Tp) >= 1>,
  562. is_copy_constructible<_Tp>...,
  563. is_convertible<const _Tp&, _Tp>... // explicit check
  564. >::value
  565. , int> = 0>
  566. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  567. tuple(const _Tp& ... __t)
  568. _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
  569. : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
  570. typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
  571. typename __make_tuple_indices<0>::type(),
  572. typename __make_tuple_types<tuple, 0>::type(),
  573. __t...
  574. ) {}
  575. template <template<class...> class _And = _And, __enable_if_t<
  576. _And<
  577. _BoolConstant<sizeof...(_Tp) >= 1>,
  578. is_copy_constructible<_Tp>...,
  579. _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
  580. >::value
  581. , int> = 0>
  582. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  583. explicit tuple(const _Tp& ... __t)
  584. _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
  585. : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
  586. typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
  587. typename __make_tuple_indices<0>::type(),
  588. typename __make_tuple_types<tuple, 0>::type(),
  589. __t...
  590. ) {}
  591. template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
  592. _And<
  593. _BoolConstant<sizeof...(_Tp) >= 1>,
  594. is_copy_constructible<_Tp>...,
  595. is_convertible<const _Tp&, _Tp>... // explicit check
  596. >::value
  597. , int> = 0>
  598. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  599. tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
  600. : __base_(allocator_arg_t(), __a,
  601. typename __make_tuple_indices<sizeof...(_Tp)>::type(),
  602. typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
  603. typename __make_tuple_indices<0>::type(),
  604. typename __make_tuple_types<tuple, 0>::type(),
  605. __t...
  606. ) {}
  607. template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
  608. _And<
  609. _BoolConstant<sizeof...(_Tp) >= 1>,
  610. is_copy_constructible<_Tp>...,
  611. _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
  612. >::value
  613. , int> = 0>
  614. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  615. explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
  616. : __base_(allocator_arg_t(), __a,
  617. typename __make_tuple_indices<sizeof...(_Tp)>::type(),
  618. typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
  619. typename __make_tuple_indices<0>::type(),
  620. typename __make_tuple_types<tuple, 0>::type(),
  621. __t...
  622. ) {}
  623. // tuple(U&& ...) constructors (including allocator_arg_t variants)
  624. template <class ..._Up> struct _IsThisTuple : false_type { };
  625. template <class _Up> struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> { };
  626. template <class ..._Up>
  627. struct _EnableUTypesCtor : _And<
  628. _BoolConstant<sizeof...(_Tp) >= 1>,
  629. _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
  630. is_constructible<_Tp, _Up>...
  631. > { };
  632. template <class ..._Up, __enable_if_t<
  633. _And<
  634. _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
  635. _EnableUTypesCtor<_Up...>,
  636. is_convertible<_Up, _Tp>... // explicit check
  637. >::value
  638. , int> = 0>
  639. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  640. tuple(_Up&&... __u)
  641. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
  642. : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
  643. typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
  644. typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
  645. typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
  646. _VSTD::forward<_Up>(__u)...) {}
  647. template <class ..._Up, __enable_if_t<
  648. _And<
  649. _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
  650. _EnableUTypesCtor<_Up...>,
  651. _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
  652. >::value
  653. , int> = 0>
  654. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  655. explicit tuple(_Up&&... __u)
  656. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
  657. : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
  658. typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
  659. typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
  660. typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
  661. _VSTD::forward<_Up>(__u)...) {}
  662. template <class _Alloc, class ..._Up, __enable_if_t<
  663. _And<
  664. _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
  665. _EnableUTypesCtor<_Up...>,
  666. is_convertible<_Up, _Tp>... // explicit check
  667. >::value
  668. , int> = 0>
  669. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  670. tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
  671. : __base_(allocator_arg_t(), __a,
  672. typename __make_tuple_indices<sizeof...(_Up)>::type(),
  673. typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
  674. typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
  675. typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
  676. _VSTD::forward<_Up>(__u)...) {}
  677. template <class _Alloc, class ..._Up, __enable_if_t<
  678. _And<
  679. _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
  680. _EnableUTypesCtor<_Up...>,
  681. _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
  682. >::value
  683. , int> = 0>
  684. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  685. explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
  686. : __base_(allocator_arg_t(), __a,
  687. typename __make_tuple_indices<sizeof...(_Up)>::type(),
  688. typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
  689. typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
  690. typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
  691. _VSTD::forward<_Up>(__u)...) {}
  692. // Copy and move constructors (including the allocator_arg_t variants)
  693. tuple(const tuple&) = default;
  694. tuple(tuple&&) = default;
  695. template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
  696. _And<is_copy_constructible<_Tp>...>::value
  697. , int> = 0>
  698. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  699. tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
  700. : __base_(allocator_arg_t(), __alloc, __t)
  701. { }
  702. template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
  703. _And<is_move_constructible<_Tp>...>::value
  704. , int> = 0>
  705. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  706. tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
  707. : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
  708. { }
  709. // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
  710. template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void>
  711. struct _EnableCtorFromUTypesTuple : false_type {};
  712. template <class _OtherTuple, class... _Up>
  713. struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
  714. // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
  715. __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
  716. // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
  717. // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
  718. _Not<is_same<_OtherTuple, const tuple&> >,
  719. _Not<is_same<_OtherTuple, tuple&&> >,
  720. is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
  721. _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
  722. // _Tp and _Up are 1-element packs - the pack expansions look
  723. // weird to avoid tripping up the type traits in degenerate cases
  724. _Lazy<_And,
  725. _Not<is_same<_Tp, _Up> >...,
  726. _Not<is_convertible<_OtherTuple, _Tp> >...,
  727. _Not<is_constructible<_Tp, _OtherTuple> >...
  728. >
  729. >
  730. > {};
  731. template <class ..._Up, __enable_if_t<
  732. _And<
  733. _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
  734. is_convertible<const _Up&, _Tp>... // explicit check
  735. >::value
  736. , int> = 0>
  737. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  738. tuple(const tuple<_Up...>& __t)
  739. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
  740. : __base_(__t)
  741. { }
  742. template <class ..._Up, __enable_if_t<
  743. _And<
  744. _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
  745. _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
  746. >::value
  747. , int> = 0>
  748. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  749. explicit tuple(const tuple<_Up...>& __t)
  750. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
  751. : __base_(__t)
  752. { }
  753. template <class ..._Up, class _Alloc, __enable_if_t<
  754. _And<
  755. _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
  756. is_convertible<const _Up&, _Tp>... // explicit check
  757. >::value
  758. , int> = 0>
  759. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  760. tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
  761. : __base_(allocator_arg_t(), __a, __t)
  762. { }
  763. template <class ..._Up, class _Alloc, __enable_if_t<
  764. _And<
  765. _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
  766. _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
  767. >::value
  768. , int> = 0>
  769. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  770. explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
  771. : __base_(allocator_arg_t(), __a, __t)
  772. { }
  773. #if _LIBCPP_STD_VER >= 23
  774. // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
  775. template <class... _Up, enable_if_t<
  776. _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
  777. _LIBCPP_HIDE_FROM_ABI constexpr
  778. explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
  779. tuple(tuple<_Up...>& __t) : __base_(__t) {}
  780. template <class _Alloc, class... _Up, enable_if_t<
  781. _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
  782. _LIBCPP_HIDE_FROM_ABI constexpr
  783. explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
  784. tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
  785. #endif // _LIBCPP_STD_VER >= 23
  786. // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
  787. template <class ..._Up, __enable_if_t<
  788. _And<
  789. _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
  790. is_convertible<_Up, _Tp>... // explicit check
  791. >::value
  792. , int> = 0>
  793. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  794. tuple(tuple<_Up...>&& __t)
  795. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
  796. : __base_(_VSTD::move(__t))
  797. { }
  798. template <class ..._Up, __enable_if_t<
  799. _And<
  800. _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
  801. _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
  802. >::value
  803. , int> = 0>
  804. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  805. explicit tuple(tuple<_Up...>&& __t)
  806. _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
  807. : __base_(_VSTD::move(__t))
  808. { }
  809. template <class _Alloc, class ..._Up, __enable_if_t<
  810. _And<
  811. _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
  812. is_convertible<_Up, _Tp>... // explicit check
  813. >::value
  814. , int> = 0>
  815. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  816. tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
  817. : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
  818. { }
  819. template <class _Alloc, class ..._Up, __enable_if_t<
  820. _And<
  821. _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
  822. _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
  823. >::value
  824. , int> = 0>
  825. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  826. explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
  827. : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
  828. { }
  829. #if _LIBCPP_STD_VER >= 23
  830. // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
  831. template <class... _Up, enable_if_t<
  832. _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
  833. _LIBCPP_HIDE_FROM_ABI constexpr
  834. explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
  835. tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
  836. template <class _Alloc, class... _Up, enable_if_t<
  837. _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
  838. _LIBCPP_HIDE_FROM_ABI constexpr
  839. explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
  840. tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
  841. : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
  842. #endif // _LIBCPP_STD_VER >= 23
  843. // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
  844. template <template <class...> class _Pred, class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
  845. struct _CtorPredicateFromPair : false_type{};
  846. template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
  847. struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
  848. _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
  849. _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
  850. > {};
  851. template <class _Pair>
  852. struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
  853. template <class _Pair>
  854. struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
  855. template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
  856. struct _BothImplicitlyConvertible : false_type{};
  857. template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
  858. struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
  859. is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
  860. is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
  861. > {};
  862. template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  863. _And<
  864. _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
  865. _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
  866. >::value
  867. , int> = 0>
  868. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  869. tuple(const pair<_Up1, _Up2>& __p)
  870. _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
  871. : __base_(__p)
  872. { }
  873. template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  874. _And<
  875. _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
  876. _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
  877. >::value
  878. , int> = 0>
  879. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  880. explicit tuple(const pair<_Up1, _Up2>& __p)
  881. _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
  882. : __base_(__p)
  883. { }
  884. template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  885. _And<
  886. _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
  887. _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
  888. >::value
  889. , int> = 0>
  890. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  891. tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
  892. : __base_(allocator_arg_t(), __a, __p)
  893. { }
  894. template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  895. _And<
  896. _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
  897. _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
  898. >::value
  899. , int> = 0>
  900. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  901. explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
  902. : __base_(allocator_arg_t(), __a, __p)
  903. { }
  904. #if _LIBCPP_STD_VER >= 23
  905. // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
  906. template <class _U1, class _U2, enable_if_t<
  907. _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
  908. _LIBCPP_HIDE_FROM_ABI constexpr
  909. explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
  910. tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
  911. template <class _Alloc, class _U1, class _U2, enable_if_t<
  912. _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
  913. _LIBCPP_HIDE_FROM_ABI constexpr
  914. explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
  915. tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
  916. #endif
  917. // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
  918. template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  919. _And<
  920. _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
  921. _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
  922. >::value
  923. , int> = 0>
  924. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  925. tuple(pair<_Up1, _Up2>&& __p)
  926. _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
  927. : __base_(_VSTD::move(__p))
  928. { }
  929. template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  930. _And<
  931. _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
  932. _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
  933. >::value
  934. , int> = 0>
  935. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  936. explicit tuple(pair<_Up1, _Up2>&& __p)
  937. _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
  938. : __base_(_VSTD::move(__p))
  939. { }
  940. template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  941. _And<
  942. _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
  943. _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
  944. >::value
  945. , int> = 0>
  946. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  947. tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
  948. : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
  949. { }
  950. template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
  951. _And<
  952. _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
  953. _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
  954. >::value
  955. , int> = 0>
  956. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  957. explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
  958. : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
  959. { }
  960. #if _LIBCPP_STD_VER >= 23
  961. // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
  962. template <class _U1, class _U2, enable_if_t<
  963. _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
  964. _LIBCPP_HIDE_FROM_ABI constexpr
  965. explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
  966. tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
  967. template <class _Alloc, class _U1, class _U2, enable_if_t<
  968. _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
  969. _LIBCPP_HIDE_FROM_ABI constexpr
  970. explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
  971. tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
  972. : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
  973. #endif // _LIBCPP_STD_VER >= 23
  974. // [tuple.assign]
  975. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  976. tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
  977. _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
  978. {
  979. _VSTD::__memberwise_copy_assign(*this, __tuple,
  980. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  981. return *this;
  982. }
  983. #if _LIBCPP_STD_VER >= 23
  984. _LIBCPP_HIDE_FROM_ABI constexpr
  985. const tuple& operator=(tuple const& __tuple) const
  986. requires (_And<is_copy_assignable<const _Tp>...>::value) {
  987. std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
  988. return *this;
  989. }
  990. _LIBCPP_HIDE_FROM_ABI constexpr
  991. const tuple& operator=(tuple&& __tuple) const
  992. requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
  993. std::__memberwise_forward_assign(*this,
  994. std::move(__tuple),
  995. __tuple_types<_Tp...>(),
  996. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  997. return *this;
  998. }
  999. #endif // _LIBCPP_STD_VER >= 23
  1000. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1001. tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
  1002. _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
  1003. {
  1004. _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
  1005. __tuple_types<_Tp...>(),
  1006. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1007. return *this;
  1008. }
  1009. template<class... _Up, __enable_if_t<
  1010. _And<
  1011. _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
  1012. is_assignable<_Tp&, _Up const&>...
  1013. >::value
  1014. ,int> = 0>
  1015. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1016. tuple& operator=(tuple<_Up...> const& __tuple)
  1017. _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
  1018. {
  1019. _VSTD::__memberwise_copy_assign(*this, __tuple,
  1020. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1021. return *this;
  1022. }
  1023. template<class... _Up, __enable_if_t<
  1024. _And<
  1025. _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
  1026. is_assignable<_Tp&, _Up>...
  1027. >::value
  1028. ,int> = 0>
  1029. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1030. tuple& operator=(tuple<_Up...>&& __tuple)
  1031. _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
  1032. {
  1033. _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
  1034. __tuple_types<_Up...>(),
  1035. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1036. return *this;
  1037. }
  1038. #if _LIBCPP_STD_VER >= 23
  1039. template <class... _UTypes, enable_if_t<
  1040. _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
  1041. is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
  1042. _LIBCPP_HIDE_FROM_ABI constexpr
  1043. const tuple& operator=(const tuple<_UTypes...>& __u) const {
  1044. std::__memberwise_copy_assign(*this,
  1045. __u,
  1046. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1047. return *this;
  1048. }
  1049. template <class... _UTypes, enable_if_t<
  1050. _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
  1051. is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
  1052. _LIBCPP_HIDE_FROM_ABI constexpr
  1053. const tuple& operator=(tuple<_UTypes...>&& __u) const {
  1054. std::__memberwise_forward_assign(*this,
  1055. __u,
  1056. __tuple_types<_UTypes...>(),
  1057. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1058. return *this;
  1059. }
  1060. #endif // _LIBCPP_STD_VER >= 23
  1061. template <template<class...> class _Pred, bool _Const,
  1062. class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple>
  1063. struct _AssignPredicateFromPair : false_type {};
  1064. template <template<class...> class _Pred, bool _Const,
  1065. class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
  1066. struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
  1067. _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
  1068. _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
  1069. > {};
  1070. template <bool _Const, class _Pair>
  1071. struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
  1072. template <bool _Const, class _Pair>
  1073. struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
  1074. #if _LIBCPP_STD_VER >= 23
  1075. template <class _U1, class _U2, enable_if_t<
  1076. _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
  1077. _LIBCPP_HIDE_FROM_ABI constexpr
  1078. const tuple& operator=(const pair<_U1, _U2>& __pair) const
  1079. noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
  1080. std::get<0>(*this) = __pair.first;
  1081. std::get<1>(*this) = __pair.second;
  1082. return *this;
  1083. }
  1084. template <class _U1, class _U2, enable_if_t<
  1085. _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
  1086. _LIBCPP_HIDE_FROM_ABI constexpr
  1087. const tuple& operator=(pair<_U1, _U2>&& __pair) const
  1088. noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
  1089. std::get<0>(*this) = std::move(__pair.first);
  1090. std::get<1>(*this) = std::move(__pair.second);
  1091. return *this;
  1092. }
  1093. #endif // _LIBCPP_STD_VER >= 23
  1094. template<class _Up1, class _Up2, __enable_if_t<
  1095. _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
  1096. ,int> = 0>
  1097. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1098. tuple& operator=(pair<_Up1, _Up2> const& __pair)
  1099. _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
  1100. {
  1101. _VSTD::get<0>(*this) = __pair.first;
  1102. _VSTD::get<1>(*this) = __pair.second;
  1103. return *this;
  1104. }
  1105. template<class _Up1, class _Up2, __enable_if_t<
  1106. _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
  1107. ,int> = 0>
  1108. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1109. tuple& operator=(pair<_Up1, _Up2>&& __pair)
  1110. _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
  1111. {
  1112. _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
  1113. _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
  1114. return *this;
  1115. }
  1116. // EXTENSION
  1117. template<class _Up, size_t _Np, class = __enable_if_t<
  1118. _And<
  1119. _BoolConstant<_Np == sizeof...(_Tp)>,
  1120. is_assignable<_Tp&, _Up const&>...
  1121. >::value
  1122. > >
  1123. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1124. tuple& operator=(array<_Up, _Np> const& __array)
  1125. _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
  1126. {
  1127. _VSTD::__memberwise_copy_assign(*this, __array,
  1128. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1129. return *this;
  1130. }
  1131. // EXTENSION
  1132. template<class _Up, size_t _Np, class = void, class = __enable_if_t<
  1133. _And<
  1134. _BoolConstant<_Np == sizeof...(_Tp)>,
  1135. is_assignable<_Tp&, _Up>...
  1136. >::value
  1137. > >
  1138. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1139. tuple& operator=(array<_Up, _Np>&& __array)
  1140. _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
  1141. {
  1142. _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
  1143. __tuple_types<_If<true, _Up, _Tp>...>(),
  1144. typename __make_tuple_indices<sizeof...(_Tp)>::type());
  1145. return *this;
  1146. }
  1147. // [tuple.swap]
  1148. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1149. void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
  1150. {__base_.swap(__t.__base_);}
  1151. #if _LIBCPP_STD_VER >= 23
  1152. _LIBCPP_HIDE_FROM_ABI constexpr
  1153. void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
  1154. __base_.swap(__t.__base_);
  1155. }
  1156. #endif // _LIBCPP_STD_VER >= 23
  1157. };
  1158. template <>
  1159. class _LIBCPP_TEMPLATE_VIS tuple<>
  1160. {
  1161. public:
  1162. constexpr tuple() _NOEXCEPT = default;
  1163. template <class _Alloc>
  1164. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1165. tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
  1166. template <class _Alloc>
  1167. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1168. tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
  1169. template <class _Up>
  1170. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1171. tuple(array<_Up, 0>) _NOEXCEPT {}
  1172. template <class _Alloc, class _Up>
  1173. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1174. tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
  1175. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1176. void swap(tuple&) _NOEXCEPT {}
  1177. #if _LIBCPP_STD_VER >= 23
  1178. _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
  1179. #endif
  1180. };
  1181. #if _LIBCPP_STD_VER >= 23
  1182. template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
  1183. requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
  1184. struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
  1185. using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
  1186. };
  1187. template <class... _TTypes, class... _UTypes>
  1188. requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
  1189. struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
  1190. using type = tuple<common_type_t<_TTypes, _UTypes>...>;
  1191. };
  1192. #endif // _LIBCPP_STD_VER >= 23
  1193. #if _LIBCPP_STD_VER >= 17
  1194. template <class ..._Tp>
  1195. tuple(_Tp...) -> tuple<_Tp...>;
  1196. template <class _Tp1, class _Tp2>
  1197. tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
  1198. template <class _Alloc, class ..._Tp>
  1199. tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
  1200. template <class _Alloc, class _Tp1, class _Tp2>
  1201. tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
  1202. template <class _Alloc, class ..._Tp>
  1203. tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
  1204. #endif
  1205. template <class ..._Tp, __enable_if_t<__all<__is_swappable<_Tp>::value...>::value, int> = 0>
  1206. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1207. void
  1208. swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
  1209. _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
  1210. {__t.swap(__u);}
  1211. #if _LIBCPP_STD_VER >= 23
  1212. template <class... _Tp>
  1213. _LIBCPP_HIDE_FROM_ABI constexpr
  1214. enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
  1215. swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
  1216. noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
  1217. __lhs.swap(__rhs);
  1218. }
  1219. #endif
  1220. // get
  1221. template <size_t _Ip, class ..._Tp>
  1222. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1223. typename tuple_element<_Ip, tuple<_Tp...> >::type&
  1224. get(tuple<_Tp...>& __t) _NOEXCEPT
  1225. {
  1226. typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
  1227. return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
  1228. }
  1229. template <size_t _Ip, class ..._Tp>
  1230. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1231. const typename tuple_element<_Ip, tuple<_Tp...> >::type&
  1232. get(const tuple<_Tp...>& __t) _NOEXCEPT
  1233. {
  1234. typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
  1235. return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
  1236. }
  1237. template <size_t _Ip, class ..._Tp>
  1238. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1239. typename tuple_element<_Ip, tuple<_Tp...> >::type&&
  1240. get(tuple<_Tp...>&& __t) _NOEXCEPT
  1241. {
  1242. typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
  1243. return static_cast<type&&>(
  1244. static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
  1245. }
  1246. template <size_t _Ip, class ..._Tp>
  1247. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1248. const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
  1249. get(const tuple<_Tp...>&& __t) _NOEXCEPT
  1250. {
  1251. typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
  1252. return static_cast<const type&&>(
  1253. static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
  1254. }
  1255. #if _LIBCPP_STD_VER >= 14
  1256. namespace __find_detail {
  1257. static constexpr size_t __not_found = static_cast<size_t>(-1);
  1258. static constexpr size_t __ambiguous = __not_found - 1;
  1259. inline _LIBCPP_INLINE_VISIBILITY
  1260. constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
  1261. return !__matches ? __res :
  1262. (__res == __not_found ? __curr_i : __ambiguous);
  1263. }
  1264. template <size_t _Nx>
  1265. inline _LIBCPP_INLINE_VISIBILITY
  1266. constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
  1267. return __i == _Nx ? __not_found :
  1268. __find_detail::__find_idx_return(__i, __find_detail::__find_idx(__i + 1, __matches), __matches[__i]);
  1269. }
  1270. template <class _T1, class ..._Args>
  1271. struct __find_exactly_one_checked {
  1272. static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
  1273. static constexpr size_t value = __find_detail::__find_idx(0, __matches);
  1274. static_assert(value != __not_found, "type not found in type list" );
  1275. static_assert(value != __ambiguous, "type occurs more than once in type list");
  1276. };
  1277. template <class _T1>
  1278. struct __find_exactly_one_checked<_T1> {
  1279. static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
  1280. };
  1281. } // namespace __find_detail
  1282. template <typename _T1, typename... _Args>
  1283. struct __find_exactly_one_t
  1284. : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
  1285. };
  1286. template <class _T1, class... _Args>
  1287. inline _LIBCPP_INLINE_VISIBILITY
  1288. constexpr _T1& get(tuple<_Args...>& __tup) noexcept
  1289. {
  1290. return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
  1291. }
  1292. template <class _T1, class... _Args>
  1293. inline _LIBCPP_INLINE_VISIBILITY
  1294. constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
  1295. {
  1296. return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
  1297. }
  1298. template <class _T1, class... _Args>
  1299. inline _LIBCPP_INLINE_VISIBILITY
  1300. constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
  1301. {
  1302. return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
  1303. }
  1304. template <class _T1, class... _Args>
  1305. inline _LIBCPP_INLINE_VISIBILITY
  1306. constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
  1307. {
  1308. return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
  1309. }
  1310. #endif
  1311. // tie
  1312. template <class ..._Tp>
  1313. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1314. tuple<_Tp&...>
  1315. tie(_Tp&... __t) _NOEXCEPT
  1316. {
  1317. return tuple<_Tp&...>(__t...);
  1318. }
  1319. template <class _Up>
  1320. struct __ignore_t
  1321. {
  1322. template <class _Tp>
  1323. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1324. const __ignore_t& operator=(_Tp&&) const {return *this;}
  1325. };
  1326. # if _LIBCPP_STD_VER >= 17
  1327. inline constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
  1328. # else
  1329. namespace {
  1330. constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
  1331. } // namespace
  1332. # endif
  1333. template <class... _Tp>
  1334. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1335. tuple<typename __unwrap_ref_decay<_Tp>::type...>
  1336. make_tuple(_Tp&&... __t)
  1337. {
  1338. return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
  1339. }
  1340. template <class... _Tp>
  1341. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1342. tuple<_Tp&&...>
  1343. forward_as_tuple(_Tp&&... __t) _NOEXCEPT
  1344. {
  1345. return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
  1346. }
  1347. template <size_t _Ip>
  1348. struct __tuple_equal
  1349. {
  1350. template <class _Tp, class _Up>
  1351. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1352. bool operator()(const _Tp& __x, const _Up& __y)
  1353. {
  1354. return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
  1355. }
  1356. };
  1357. template <>
  1358. struct __tuple_equal<0>
  1359. {
  1360. template <class _Tp, class _Up>
  1361. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1362. bool operator()(const _Tp&, const _Up&)
  1363. {
  1364. return true;
  1365. }
  1366. };
  1367. template <class ..._Tp, class ..._Up>
  1368. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1369. bool
  1370. operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1371. {
  1372. static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
  1373. return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
  1374. }
  1375. #if _LIBCPP_STD_VER >= 20
  1376. // operator<=>
  1377. template <class ..._Tp, class ..._Up, size_t ..._Is>
  1378. _LIBCPP_HIDE_FROM_ABI constexpr
  1379. auto
  1380. __tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
  1381. common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
  1382. static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
  1383. return __result;
  1384. }
  1385. template <class ..._Tp, class ..._Up>
  1386. requires (sizeof...(_Tp) == sizeof...(_Up))
  1387. _LIBCPP_HIDE_FROM_ABI constexpr
  1388. common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
  1389. operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1390. {
  1391. return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
  1392. }
  1393. #else // _LIBCPP_STD_VER >= 20
  1394. template <class ..._Tp, class ..._Up>
  1395. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1396. bool
  1397. operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1398. {
  1399. return !(__x == __y);
  1400. }
  1401. template <size_t _Ip>
  1402. struct __tuple_less
  1403. {
  1404. template <class _Tp, class _Up>
  1405. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1406. bool operator()(const _Tp& __x, const _Up& __y)
  1407. {
  1408. const size_t __idx = tuple_size<_Tp>::value - _Ip;
  1409. if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
  1410. return true;
  1411. if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
  1412. return false;
  1413. return __tuple_less<_Ip-1>()(__x, __y);
  1414. }
  1415. };
  1416. template <>
  1417. struct __tuple_less<0>
  1418. {
  1419. template <class _Tp, class _Up>
  1420. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1421. bool operator()(const _Tp&, const _Up&)
  1422. {
  1423. return false;
  1424. }
  1425. };
  1426. template <class ..._Tp, class ..._Up>
  1427. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1428. bool
  1429. operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1430. {
  1431. static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
  1432. return __tuple_less<sizeof...(_Tp)>()(__x, __y);
  1433. }
  1434. template <class ..._Tp, class ..._Up>
  1435. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1436. bool
  1437. operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1438. {
  1439. return __y < __x;
  1440. }
  1441. template <class ..._Tp, class ..._Up>
  1442. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1443. bool
  1444. operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1445. {
  1446. return !(__x < __y);
  1447. }
  1448. template <class ..._Tp, class ..._Up>
  1449. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1450. bool
  1451. operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
  1452. {
  1453. return !(__y < __x);
  1454. }
  1455. #endif // _LIBCPP_STD_VER >= 20
  1456. // tuple_cat
  1457. template <class _Tp, class _Up> struct __tuple_cat_type;
  1458. template <class ..._Ttypes, class ..._Utypes>
  1459. struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
  1460. {
  1461. typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
  1462. };
  1463. template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
  1464. struct __tuple_cat_return_1
  1465. {
  1466. };
  1467. template <class ..._Types, class _Tuple0>
  1468. struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
  1469. {
  1470. using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
  1471. tuple<_Types...>,
  1472. typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type
  1473. >::type;
  1474. };
  1475. template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
  1476. struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
  1477. : public __tuple_cat_return_1<
  1478. typename __tuple_cat_type<
  1479. tuple<_Types...>,
  1480. typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type
  1481. >::type,
  1482. __tuple_like_ext<__libcpp_remove_reference_t<_Tuple1> >::value,
  1483. _Tuple1, _Tuples...>
  1484. {
  1485. };
  1486. template <class ..._Tuples> struct __tuple_cat_return;
  1487. template <class _Tuple0, class ..._Tuples>
  1488. struct __tuple_cat_return<_Tuple0, _Tuples...>
  1489. : public __tuple_cat_return_1<tuple<>,
  1490. __tuple_like_ext<__libcpp_remove_reference_t<_Tuple0> >::value, _Tuple0,
  1491. _Tuples...>
  1492. {
  1493. };
  1494. template <>
  1495. struct __tuple_cat_return<>
  1496. {
  1497. typedef _LIBCPP_NODEBUG tuple<> type;
  1498. };
  1499. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1500. tuple<>
  1501. tuple_cat()
  1502. {
  1503. return tuple<>();
  1504. }
  1505. template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
  1506. struct __tuple_cat_return_ref_imp;
  1507. template <class ..._Types, size_t ..._I0, class _Tuple0>
  1508. struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
  1509. {
  1510. typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
  1511. typedef tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
  1512. };
  1513. template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
  1514. struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
  1515. _Tuple0, _Tuple1, _Tuples...>
  1516. : public __tuple_cat_return_ref_imp<
  1517. tuple<_Types..., __apply_cv_t<_Tuple0,
  1518. typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
  1519. typename __make_tuple_indices<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>::type,
  1520. _Tuple1, _Tuples...>
  1521. {
  1522. };
  1523. template <class _Tuple0, class ..._Tuples>
  1524. struct __tuple_cat_return_ref
  1525. : public __tuple_cat_return_ref_imp<tuple<>,
  1526. typename __make_tuple_indices<
  1527. tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value
  1528. >::type, _Tuple0, _Tuples...>
  1529. {
  1530. };
  1531. template <class _Types, class _I0, class _J0>
  1532. struct __tuple_cat;
  1533. template <class ..._Types, size_t ..._I0, size_t ..._J0>
  1534. struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
  1535. {
  1536. template <class _Tuple0>
  1537. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1538. typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
  1539. operator()(tuple<_Types...> __t, _Tuple0&& __t0)
  1540. {
  1541. (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
  1542. return _VSTD::forward_as_tuple(
  1543. _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
  1544. _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
  1545. }
  1546. template <class _Tuple0, class _Tuple1, class ..._Tuples>
  1547. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1548. typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
  1549. operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
  1550. {
  1551. (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
  1552. typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
  1553. typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1;
  1554. return __tuple_cat<tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
  1555. typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type,
  1556. typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
  1557. _VSTD::forward_as_tuple(
  1558. _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
  1559. _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
  1560. _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
  1561. }
  1562. };
  1563. template <class _Tuple0, class... _Tuples>
  1564. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  1565. typename __tuple_cat_return<_Tuple0, _Tuples...>::type
  1566. tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
  1567. {
  1568. typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
  1569. return __tuple_cat<tuple<>, __tuple_indices<>,
  1570. typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
  1571. (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
  1572. _VSTD::forward<_Tuples>(__tpls)...);
  1573. }
  1574. template <class ..._Tp, class _Alloc>
  1575. struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
  1576. : true_type {};
  1577. template <class _T1, class _T2>
  1578. template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
  1579. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  1580. pair<_T1, _T2>::pair(piecewise_construct_t,
  1581. tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
  1582. __tuple_indices<_I1...>, __tuple_indices<_I2...>)
  1583. : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
  1584. second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
  1585. {
  1586. }
  1587. #if _LIBCPP_STD_VER >= 17
  1588. template <class _Tp>
  1589. inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
  1590. #define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
  1591. template <class _Fn, class _Tuple, size_t ..._Id>
  1592. inline _LIBCPP_INLINE_VISIBILITY
  1593. constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
  1594. __tuple_indices<_Id...>)
  1595. _LIBCPP_NOEXCEPT_RETURN(
  1596. _VSTD::__invoke(
  1597. _VSTD::forward<_Fn>(__f),
  1598. _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
  1599. )
  1600. template <class _Fn, class _Tuple>
  1601. inline _LIBCPP_INLINE_VISIBILITY
  1602. constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
  1603. _LIBCPP_NOEXCEPT_RETURN(
  1604. _VSTD::__apply_tuple_impl(
  1605. _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
  1606. typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
  1607. )
  1608. template <class _Tp, class _Tuple, size_t... _Idx>
  1609. inline _LIBCPP_INLINE_VISIBILITY
  1610. constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
  1611. _LIBCPP_NOEXCEPT_RETURN(
  1612. _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
  1613. )
  1614. template <class _Tp, class _Tuple>
  1615. inline _LIBCPP_INLINE_VISIBILITY
  1616. constexpr _Tp make_from_tuple(_Tuple&& __t)
  1617. _LIBCPP_NOEXCEPT_RETURN(
  1618. _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
  1619. typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
  1620. )
  1621. #undef _LIBCPP_NOEXCEPT_RETURN
  1622. #endif // _LIBCPP_STD_VER >= 17
  1623. #endif // !defined(_LIBCPP_CXX03_LANG)
  1624. _LIBCPP_END_NAMESPACE_STD
  1625. _LIBCPP_POP_MACROS
  1626. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  1627. # include <exception>
  1628. # include <iosfwd>
  1629. # include <new>
  1630. # include <type_traits>
  1631. # include <typeinfo>
  1632. # include <utility>
  1633. #endif
  1634. #endif // _LIBCPP_TUPLE