tuple 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  1. // <tuple> -*- C++ -*-
  2. // Copyright (C) 2007-2023 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/tuple
  21. * This is a Standard C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_TUPLE
  24. #define _GLIBCXX_TUPLE 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <bits/stl_pair.h> // for std::pair
  30. #include <bits/uses_allocator.h> // for std::allocator_arg_t
  31. #include <bits/utility.h> // for std::tuple_size etc.
  32. #include <bits/invoke.h> // for std::__invoke
  33. #if __cplusplus > 201703L
  34. # include <compare>
  35. # include <bits/ranges_util.h> // for std::ranges::subrange
  36. # define __cpp_lib_constexpr_tuple 201811L
  37. #endif
  38. namespace std _GLIBCXX_VISIBILITY(default)
  39. {
  40. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  41. /**
  42. * @addtogroup utilities
  43. * @{
  44. */
  45. template<typename... _Elements>
  46. class tuple;
  47. template<typename _Tp>
  48. struct __is_empty_non_tuple : is_empty<_Tp> { };
  49. // Using EBO for elements that are tuples causes ambiguous base errors.
  50. template<typename _El0, typename... _El>
  51. struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
  52. // Use the Empty Base-class Optimization for empty, non-final types.
  53. template<typename _Tp>
  54. using __empty_not_final
  55. = __conditional_t<__is_final(_Tp), false_type,
  56. __is_empty_non_tuple<_Tp>>;
  57. template<size_t _Idx, typename _Head,
  58. bool = __empty_not_final<_Head>::value>
  59. struct _Head_base;
  60. #if __has_cpp_attribute(__no_unique_address__)
  61. template<size_t _Idx, typename _Head>
  62. struct _Head_base<_Idx, _Head, true>
  63. {
  64. constexpr _Head_base()
  65. : _M_head_impl() { }
  66. constexpr _Head_base(const _Head& __h)
  67. : _M_head_impl(__h) { }
  68. constexpr _Head_base(const _Head_base&) = default;
  69. constexpr _Head_base(_Head_base&&) = default;
  70. template<typename _UHead>
  71. constexpr _Head_base(_UHead&& __h)
  72. : _M_head_impl(std::forward<_UHead>(__h)) { }
  73. _GLIBCXX20_CONSTEXPR
  74. _Head_base(allocator_arg_t, __uses_alloc0)
  75. : _M_head_impl() { }
  76. template<typename _Alloc>
  77. _GLIBCXX20_CONSTEXPR
  78. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  79. : _M_head_impl(allocator_arg, *__a._M_a) { }
  80. template<typename _Alloc>
  81. _GLIBCXX20_CONSTEXPR
  82. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  83. : _M_head_impl(*__a._M_a) { }
  84. template<typename _UHead>
  85. _GLIBCXX20_CONSTEXPR
  86. _Head_base(__uses_alloc0, _UHead&& __uhead)
  87. : _M_head_impl(std::forward<_UHead>(__uhead)) { }
  88. template<typename _Alloc, typename _UHead>
  89. _GLIBCXX20_CONSTEXPR
  90. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  91. : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
  92. { }
  93. template<typename _Alloc, typename _UHead>
  94. _GLIBCXX20_CONSTEXPR
  95. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  96. : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
  97. static constexpr _Head&
  98. _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
  99. static constexpr const _Head&
  100. _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
  101. [[__no_unique_address__]] _Head _M_head_impl;
  102. };
  103. #else
  104. template<size_t _Idx, typename _Head>
  105. struct _Head_base<_Idx, _Head, true>
  106. : public _Head
  107. {
  108. constexpr _Head_base()
  109. : _Head() { }
  110. constexpr _Head_base(const _Head& __h)
  111. : _Head(__h) { }
  112. constexpr _Head_base(const _Head_base&) = default;
  113. constexpr _Head_base(_Head_base&&) = default;
  114. template<typename _UHead>
  115. constexpr _Head_base(_UHead&& __h)
  116. : _Head(std::forward<_UHead>(__h)) { }
  117. _GLIBCXX20_CONSTEXPR
  118. _Head_base(allocator_arg_t, __uses_alloc0)
  119. : _Head() { }
  120. template<typename _Alloc>
  121. _GLIBCXX20_CONSTEXPR
  122. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  123. : _Head(allocator_arg, *__a._M_a) { }
  124. template<typename _Alloc>
  125. _GLIBCXX20_CONSTEXPR
  126. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  127. : _Head(*__a._M_a) { }
  128. template<typename _UHead>
  129. _GLIBCXX20_CONSTEXPR
  130. _Head_base(__uses_alloc0, _UHead&& __uhead)
  131. : _Head(std::forward<_UHead>(__uhead)) { }
  132. template<typename _Alloc, typename _UHead>
  133. _GLIBCXX20_CONSTEXPR
  134. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  135. : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
  136. template<typename _Alloc, typename _UHead>
  137. _GLIBCXX20_CONSTEXPR
  138. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  139. : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
  140. static constexpr _Head&
  141. _M_head(_Head_base& __b) noexcept { return __b; }
  142. static constexpr const _Head&
  143. _M_head(const _Head_base& __b) noexcept { return __b; }
  144. };
  145. #endif
  146. template<size_t _Idx, typename _Head>
  147. struct _Head_base<_Idx, _Head, false>
  148. {
  149. constexpr _Head_base()
  150. : _M_head_impl() { }
  151. constexpr _Head_base(const _Head& __h)
  152. : _M_head_impl(__h) { }
  153. constexpr _Head_base(const _Head_base&) = default;
  154. constexpr _Head_base(_Head_base&&) = default;
  155. template<typename _UHead>
  156. constexpr _Head_base(_UHead&& __h)
  157. : _M_head_impl(std::forward<_UHead>(__h)) { }
  158. _GLIBCXX20_CONSTEXPR
  159. _Head_base(allocator_arg_t, __uses_alloc0)
  160. : _M_head_impl() { }
  161. template<typename _Alloc>
  162. _GLIBCXX20_CONSTEXPR
  163. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  164. : _M_head_impl(allocator_arg, *__a._M_a) { }
  165. template<typename _Alloc>
  166. _GLIBCXX20_CONSTEXPR
  167. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  168. : _M_head_impl(*__a._M_a) { }
  169. template<typename _UHead>
  170. _GLIBCXX20_CONSTEXPR
  171. _Head_base(__uses_alloc0, _UHead&& __uhead)
  172. : _M_head_impl(std::forward<_UHead>(__uhead)) { }
  173. template<typename _Alloc, typename _UHead>
  174. _GLIBCXX20_CONSTEXPR
  175. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  176. : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
  177. { }
  178. template<typename _Alloc, typename _UHead>
  179. _GLIBCXX20_CONSTEXPR
  180. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  181. : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
  182. static constexpr _Head&
  183. _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
  184. static constexpr const _Head&
  185. _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
  186. _Head _M_head_impl;
  187. };
  188. /**
  189. * Contains the actual implementation of the @c tuple template, stored
  190. * as a recursive inheritance hierarchy from the first element (most
  191. * derived class) to the last (least derived class). The @c Idx
  192. * parameter gives the 0-based index of the element stored at this
  193. * point in the hierarchy; we use it to implement a constant-time
  194. * get() operation.
  195. */
  196. template<size_t _Idx, typename... _Elements>
  197. struct _Tuple_impl;
  198. /**
  199. * Recursive tuple implementation. Here we store the @c Head element
  200. * and derive from a @c Tuple_impl containing the remaining elements
  201. * (which contains the @c Tail).
  202. */
  203. template<size_t _Idx, typename _Head, typename... _Tail>
  204. struct _Tuple_impl<_Idx, _Head, _Tail...>
  205. : public _Tuple_impl<_Idx + 1, _Tail...>,
  206. private _Head_base<_Idx, _Head>
  207. {
  208. template<size_t, typename...> friend struct _Tuple_impl;
  209. typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
  210. typedef _Head_base<_Idx, _Head> _Base;
  211. static constexpr _Head&
  212. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  213. static constexpr const _Head&
  214. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  215. static constexpr _Inherited&
  216. _M_tail(_Tuple_impl& __t) noexcept { return __t; }
  217. static constexpr const _Inherited&
  218. _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
  219. constexpr _Tuple_impl()
  220. : _Inherited(), _Base() { }
  221. explicit constexpr
  222. _Tuple_impl(const _Head& __head, const _Tail&... __tail)
  223. : _Inherited(__tail...), _Base(__head)
  224. { }
  225. template<typename _UHead, typename... _UTail,
  226. typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
  227. explicit constexpr
  228. _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
  229. : _Inherited(std::forward<_UTail>(__tail)...),
  230. _Base(std::forward<_UHead>(__head))
  231. { }
  232. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  233. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  234. // 2729. Missing SFINAE on std::pair::operator=
  235. _Tuple_impl& operator=(const _Tuple_impl&) = delete;
  236. _Tuple_impl(_Tuple_impl&&) = default;
  237. template<typename... _UElements>
  238. constexpr
  239. _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
  240. : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  241. _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
  242. { }
  243. template<typename _UHead, typename... _UTails>
  244. constexpr
  245. _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  246. : _Inherited(std::move
  247. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  248. _Base(std::forward<_UHead>
  249. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
  250. { }
  251. #if __cplusplus > 202002L
  252. template<typename... _UElements>
  253. constexpr
  254. _Tuple_impl(_Tuple_impl<_Idx, _UElements...>& __in)
  255. : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  256. _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
  257. { }
  258. template<typename _UHead, typename... _UTails>
  259. constexpr
  260. _Tuple_impl(const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  261. : _Inherited(std::move
  262. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  263. _Base(std::forward<const _UHead>
  264. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
  265. { }
  266. #endif // C++23
  267. template<typename _Alloc>
  268. _GLIBCXX20_CONSTEXPR
  269. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  270. : _Inherited(__tag, __a),
  271. _Base(__tag, __use_alloc<_Head>(__a))
  272. { }
  273. template<typename _Alloc>
  274. _GLIBCXX20_CONSTEXPR
  275. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  276. const _Head& __head, const _Tail&... __tail)
  277. : _Inherited(__tag, __a, __tail...),
  278. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head)
  279. { }
  280. template<typename _Alloc, typename _UHead, typename... _UTail,
  281. typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
  282. _GLIBCXX20_CONSTEXPR
  283. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  284. _UHead&& __head, _UTail&&... __tail)
  285. : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
  286. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  287. std::forward<_UHead>(__head))
  288. { }
  289. template<typename _Alloc>
  290. _GLIBCXX20_CONSTEXPR
  291. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  292. const _Tuple_impl& __in)
  293. : _Inherited(__tag, __a, _M_tail(__in)),
  294. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in))
  295. { }
  296. template<typename _Alloc>
  297. _GLIBCXX20_CONSTEXPR
  298. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  299. _Tuple_impl&& __in)
  300. : _Inherited(__tag, __a, std::move(_M_tail(__in))),
  301. _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  302. std::forward<_Head>(_M_head(__in)))
  303. { }
  304. template<typename _Alloc, typename _UHead, typename... _UTails>
  305. _GLIBCXX20_CONSTEXPR
  306. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  307. const _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
  308. : _Inherited(__tag, __a,
  309. _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
  310. _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
  311. _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
  312. { }
  313. template<typename _Alloc, typename _UHead, typename... _UTails>
  314. _GLIBCXX20_CONSTEXPR
  315. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  316. _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  317. : _Inherited(__tag, __a, std::move
  318. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  319. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  320. std::forward<_UHead>
  321. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
  322. { }
  323. #if __cplusplus > 202002L
  324. template<typename _Alloc, typename _UHead, typename... _UTails>
  325. constexpr
  326. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  327. _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
  328. : _Inherited(__tag, __a,
  329. _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
  330. _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a),
  331. _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
  332. { }
  333. template<typename _Alloc, typename _UHead, typename... _UTails>
  334. constexpr
  335. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  336. const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  337. : _Inherited(__tag, __a, std::move
  338. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  339. _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a),
  340. std::forward<const _UHead>
  341. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
  342. { }
  343. #endif // C++23
  344. template<typename... _UElements>
  345. _GLIBCXX20_CONSTEXPR
  346. void
  347. _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
  348. {
  349. _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
  350. _M_tail(*this)._M_assign(
  351. _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
  352. }
  353. template<typename _UHead, typename... _UTails>
  354. _GLIBCXX20_CONSTEXPR
  355. void
  356. _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  357. {
  358. _M_head(*this) = std::forward<_UHead>
  359. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
  360. _M_tail(*this)._M_assign(
  361. std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
  362. }
  363. #if __cplusplus > 202002L
  364. template<typename... _UElements>
  365. constexpr void
  366. _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in) const
  367. {
  368. _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
  369. _M_tail(*this)._M_assign(
  370. _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
  371. }
  372. template<typename _UHead, typename... _UTails>
  373. constexpr void
  374. _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) const
  375. {
  376. _M_head(*this) = std::forward<_UHead>
  377. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
  378. _M_tail(*this)._M_assign(
  379. std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
  380. }
  381. #endif // C++23
  382. protected:
  383. _GLIBCXX20_CONSTEXPR
  384. void
  385. _M_swap(_Tuple_impl& __in)
  386. {
  387. using std::swap;
  388. swap(_M_head(*this), _M_head(__in));
  389. _Inherited::_M_swap(_M_tail(__in));
  390. }
  391. #if __cplusplus > 202002L
  392. constexpr void
  393. _M_swap(const _Tuple_impl& __in) const
  394. {
  395. using std::swap;
  396. swap(_M_head(*this), _M_head(__in));
  397. _Inherited::_M_swap(_M_tail(__in));
  398. }
  399. #endif // C++23
  400. };
  401. // Basis case of inheritance recursion.
  402. template<size_t _Idx, typename _Head>
  403. struct _Tuple_impl<_Idx, _Head>
  404. : private _Head_base<_Idx, _Head>
  405. {
  406. template<size_t, typename...> friend struct _Tuple_impl;
  407. typedef _Head_base<_Idx, _Head> _Base;
  408. static constexpr _Head&
  409. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  410. static constexpr const _Head&
  411. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  412. constexpr
  413. _Tuple_impl()
  414. : _Base() { }
  415. explicit constexpr
  416. _Tuple_impl(const _Head& __head)
  417. : _Base(__head)
  418. { }
  419. template<typename _UHead>
  420. explicit constexpr
  421. _Tuple_impl(_UHead&& __head)
  422. : _Base(std::forward<_UHead>(__head))
  423. { }
  424. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  425. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  426. // 2729. Missing SFINAE on std::pair::operator=
  427. _Tuple_impl& operator=(const _Tuple_impl&) = delete;
  428. #if _GLIBCXX_INLINE_VERSION
  429. _Tuple_impl(_Tuple_impl&&) = default;
  430. #else
  431. constexpr
  432. _Tuple_impl(_Tuple_impl&& __in)
  433. noexcept(is_nothrow_move_constructible<_Head>::value)
  434. : _Base(static_cast<_Base&&>(__in))
  435. { }
  436. #endif
  437. template<typename _UHead>
  438. constexpr
  439. _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
  440. : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
  441. { }
  442. template<typename _UHead>
  443. constexpr
  444. _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
  445. : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  446. { }
  447. #if __cplusplus > 202002L
  448. template<typename _UHead>
  449. constexpr
  450. _Tuple_impl(_Tuple_impl<_Idx, _UHead>& __in)
  451. : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
  452. { }
  453. template<typename _UHead>
  454. constexpr
  455. _Tuple_impl(const _Tuple_impl<_Idx, _UHead>&& __in)
  456. : _Base(std::forward<const _UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  457. { }
  458. #endif // C++23
  459. template<typename _Alloc>
  460. _GLIBCXX20_CONSTEXPR
  461. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  462. : _Base(__tag, __use_alloc<_Head>(__a))
  463. { }
  464. template<typename _Alloc>
  465. _GLIBCXX20_CONSTEXPR
  466. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  467. const _Head& __head)
  468. : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
  469. { }
  470. template<typename _Alloc, typename _UHead>
  471. _GLIBCXX20_CONSTEXPR
  472. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  473. _UHead&& __head)
  474. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  475. std::forward<_UHead>(__head))
  476. { }
  477. template<typename _Alloc>
  478. _GLIBCXX20_CONSTEXPR
  479. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  480. const _Tuple_impl& __in)
  481. : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), _M_head(__in))
  482. { }
  483. template<typename _Alloc>
  484. _GLIBCXX20_CONSTEXPR
  485. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  486. _Tuple_impl&& __in)
  487. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  488. std::forward<_Head>(_M_head(__in)))
  489. { }
  490. template<typename _Alloc, typename _UHead>
  491. _GLIBCXX20_CONSTEXPR
  492. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  493. const _Tuple_impl<_Idx, _UHead>& __in)
  494. : _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
  495. _Tuple_impl<_Idx, _UHead>::_M_head(__in))
  496. { }
  497. template<typename _Alloc, typename _UHead>
  498. _GLIBCXX20_CONSTEXPR
  499. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  500. _Tuple_impl<_Idx, _UHead>&& __in)
  501. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  502. std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  503. { }
  504. #if __cplusplus > 202002L
  505. template<typename _Alloc, typename _UHead>
  506. constexpr
  507. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  508. _Tuple_impl<_Idx, _UHead>& __in)
  509. : _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a),
  510. _Tuple_impl<_Idx, _UHead>::_M_head(__in))
  511. { }
  512. template<typename _Alloc, typename _UHead>
  513. constexpr
  514. _Tuple_impl(allocator_arg_t, const _Alloc& __a,
  515. const _Tuple_impl<_Idx, _UHead>&& __in)
  516. : _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a),
  517. std::forward<const _UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  518. { }
  519. #endif // C++23
  520. template<typename _UHead>
  521. _GLIBCXX20_CONSTEXPR
  522. void
  523. _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
  524. {
  525. _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
  526. }
  527. template<typename _UHead>
  528. _GLIBCXX20_CONSTEXPR
  529. void
  530. _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
  531. {
  532. _M_head(*this)
  533. = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
  534. }
  535. #if __cplusplus > 202002L
  536. template<typename _UHead>
  537. constexpr void
  538. _M_assign(const _Tuple_impl<_Idx, _UHead>& __in) const
  539. {
  540. _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
  541. }
  542. template<typename _UHead>
  543. constexpr void
  544. _M_assign(_Tuple_impl<_Idx, _UHead>&& __in) const
  545. {
  546. _M_head(*this)
  547. = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
  548. }
  549. #endif // C++23
  550. protected:
  551. _GLIBCXX20_CONSTEXPR
  552. void
  553. _M_swap(_Tuple_impl& __in)
  554. {
  555. using std::swap;
  556. swap(_M_head(*this), _M_head(__in));
  557. }
  558. #if __cplusplus > 202002L
  559. constexpr void
  560. _M_swap(const _Tuple_impl& __in) const
  561. {
  562. using std::swap;
  563. swap(_M_head(*this), _M_head(__in));
  564. }
  565. #endif // C++23
  566. };
  567. // Concept utility functions, reused in conditionally-explicit
  568. // constructors.
  569. template<bool, typename... _Types>
  570. struct _TupleConstraints
  571. {
  572. template<typename... _UTypes>
  573. using __constructible = __and_<is_constructible<_Types, _UTypes>...>;
  574. template<typename... _UTypes>
  575. using __convertible = __and_<is_convertible<_UTypes, _Types>...>;
  576. // Constraint for a non-explicit constructor.
  577. // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
  578. // and every Ui is implicitly convertible to Ti.
  579. template<typename... _UTypes>
  580. static constexpr bool __is_implicitly_constructible()
  581. {
  582. return __and_<__constructible<_UTypes...>,
  583. __convertible<_UTypes...>
  584. >::value;
  585. }
  586. // Constraint for a non-explicit constructor.
  587. // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
  588. // but not every Ui is implicitly convertible to Ti.
  589. template<typename... _UTypes>
  590. static constexpr bool __is_explicitly_constructible()
  591. {
  592. return __and_<__constructible<_UTypes...>,
  593. __not_<__convertible<_UTypes...>>
  594. >::value;
  595. }
  596. static constexpr bool __is_implicitly_default_constructible()
  597. {
  598. return __and_<std::__is_implicitly_default_constructible<_Types>...
  599. >::value;
  600. }
  601. static constexpr bool __is_explicitly_default_constructible()
  602. {
  603. return __and_<is_default_constructible<_Types>...,
  604. __not_<__and_<
  605. std::__is_implicitly_default_constructible<_Types>...>
  606. >>::value;
  607. }
  608. };
  609. // Partial specialization used when a required precondition isn't met,
  610. // e.g. when sizeof...(_Types) != sizeof...(_UTypes).
  611. template<typename... _Types>
  612. struct _TupleConstraints<false, _Types...>
  613. {
  614. template<typename... _UTypes>
  615. static constexpr bool __is_implicitly_constructible()
  616. { return false; }
  617. template<typename... _UTypes>
  618. static constexpr bool __is_explicitly_constructible()
  619. { return false; }
  620. };
  621. /// Primary class template, tuple
  622. template<typename... _Elements>
  623. class tuple : public _Tuple_impl<0, _Elements...>
  624. {
  625. typedef _Tuple_impl<0, _Elements...> _Inherited;
  626. template<bool _Cond>
  627. using _TCC = _TupleConstraints<_Cond, _Elements...>;
  628. // Constraint for non-explicit default constructor
  629. template<bool _Dummy>
  630. using _ImplicitDefaultCtor = __enable_if_t<
  631. _TCC<_Dummy>::__is_implicitly_default_constructible(),
  632. bool>;
  633. // Constraint for explicit default constructor
  634. template<bool _Dummy>
  635. using _ExplicitDefaultCtor = __enable_if_t<
  636. _TCC<_Dummy>::__is_explicitly_default_constructible(),
  637. bool>;
  638. // Constraint for non-explicit constructors
  639. template<bool _Cond, typename... _Args>
  640. using _ImplicitCtor = __enable_if_t<
  641. _TCC<_Cond>::template __is_implicitly_constructible<_Args...>(),
  642. bool>;
  643. // Constraint for non-explicit constructors
  644. template<bool _Cond, typename... _Args>
  645. using _ExplicitCtor = __enable_if_t<
  646. _TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
  647. bool>;
  648. template<typename... _UElements>
  649. static constexpr
  650. __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
  651. __assignable()
  652. { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
  653. // Condition for noexcept-specifier of an assignment operator.
  654. template<typename... _UElements>
  655. static constexpr bool __nothrow_assignable()
  656. {
  657. return
  658. __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
  659. }
  660. // Condition for noexcept-specifier of a constructor.
  661. template<typename... _UElements>
  662. static constexpr bool __nothrow_constructible()
  663. {
  664. return
  665. __and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
  666. }
  667. // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
  668. template<typename _Up>
  669. static constexpr bool __valid_args()
  670. {
  671. return sizeof...(_Elements) == 1
  672. && !is_same<tuple, __remove_cvref_t<_Up>>::value;
  673. }
  674. // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) > 1.
  675. template<typename, typename, typename... _Tail>
  676. static constexpr bool __valid_args()
  677. { return (sizeof...(_Tail) + 2) == sizeof...(_Elements); }
  678. /* Constraint for constructors with a tuple<UTypes...> parameter ensures
  679. * that the constructor is only viable when it would not interfere with
  680. * tuple(UTypes&&...) or tuple(const tuple&) or tuple(tuple&&).
  681. * Such constructors are only viable if:
  682. * either sizeof...(Types) != 1,
  683. * or (when Types... expands to T and UTypes... expands to U)
  684. * is_convertible_v<TUPLE, T>, is_constructible_v<T, TUPLE>,
  685. * and is_same_v<T, U> are all false.
  686. */
  687. template<typename _Tuple, typename = tuple,
  688. typename = __remove_cvref_t<_Tuple>>
  689. struct _UseOtherCtor
  690. : false_type
  691. { };
  692. // If TUPLE is convertible to the single element in *this,
  693. // then TUPLE should match tuple(UTypes&&...) instead.
  694. template<typename _Tuple, typename _Tp, typename _Up>
  695. struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Up>>
  696. : __or_<is_convertible<_Tuple, _Tp>, is_constructible<_Tp, _Tuple>>::type
  697. { };
  698. // If TUPLE and *this each have a single element of the same type,
  699. // then TUPLE should match a copy/move constructor instead.
  700. template<typename _Tuple, typename _Tp>
  701. struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Tp>>
  702. : true_type
  703. { };
  704. // Return true iff sizeof...(Types) == 1 && tuple_size_v<TUPLE> == 1
  705. // and the single element in Types can be initialized from TUPLE,
  706. // or is the same type as tuple_element_t<0, TUPLE>.
  707. template<typename _Tuple>
  708. static constexpr bool __use_other_ctor()
  709. { return _UseOtherCtor<_Tuple>::value; }
  710. #if __cplusplus > 202002L
  711. template<typename... _Args>
  712. static constexpr bool __constructible
  713. = _TCC<true>::template __constructible<_Args...>::value;
  714. template<typename... _Args>
  715. static constexpr bool __convertible
  716. = _TCC<true>::template __convertible<_Args...>::value;
  717. #endif // C++23
  718. public:
  719. template<typename _Dummy = void,
  720. _ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
  721. constexpr
  722. tuple()
  723. noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
  724. : _Inherited() { }
  725. template<typename _Dummy = void,
  726. _ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
  727. explicit constexpr
  728. tuple()
  729. noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
  730. : _Inherited() { }
  731. template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
  732. _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
  733. constexpr
  734. tuple(const _Elements&... __elements)
  735. noexcept(__nothrow_constructible<const _Elements&...>())
  736. : _Inherited(__elements...) { }
  737. template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
  738. _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
  739. explicit constexpr
  740. tuple(const _Elements&... __elements)
  741. noexcept(__nothrow_constructible<const _Elements&...>())
  742. : _Inherited(__elements...) { }
  743. template<typename... _UElements,
  744. bool _Valid = __valid_args<_UElements...>(),
  745. _ImplicitCtor<_Valid, _UElements...> = true>
  746. constexpr
  747. tuple(_UElements&&... __elements)
  748. noexcept(__nothrow_constructible<_UElements...>())
  749. : _Inherited(std::forward<_UElements>(__elements)...) { }
  750. template<typename... _UElements,
  751. bool _Valid = __valid_args<_UElements...>(),
  752. _ExplicitCtor<_Valid, _UElements...> = false>
  753. explicit constexpr
  754. tuple(_UElements&&... __elements)
  755. noexcept(__nothrow_constructible<_UElements...>())
  756. : _Inherited(std::forward<_UElements>(__elements)...) { }
  757. constexpr tuple(const tuple&) = default;
  758. constexpr tuple(tuple&&) = default;
  759. template<typename... _UElements,
  760. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  761. && !__use_other_ctor<const tuple<_UElements...>&>(),
  762. _ImplicitCtor<_Valid, const _UElements&...> = true>
  763. constexpr
  764. tuple(const tuple<_UElements...>& __in)
  765. noexcept(__nothrow_constructible<const _UElements&...>())
  766. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  767. { }
  768. template<typename... _UElements,
  769. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  770. && !__use_other_ctor<const tuple<_UElements...>&>(),
  771. _ExplicitCtor<_Valid, const _UElements&...> = false>
  772. explicit constexpr
  773. tuple(const tuple<_UElements...>& __in)
  774. noexcept(__nothrow_constructible<const _UElements&...>())
  775. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  776. { }
  777. template<typename... _UElements,
  778. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  779. && !__use_other_ctor<tuple<_UElements...>&&>(),
  780. _ImplicitCtor<_Valid, _UElements...> = true>
  781. constexpr
  782. tuple(tuple<_UElements...>&& __in)
  783. noexcept(__nothrow_constructible<_UElements...>())
  784. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
  785. template<typename... _UElements,
  786. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  787. && !__use_other_ctor<tuple<_UElements...>&&>(),
  788. _ExplicitCtor<_Valid, _UElements...> = false>
  789. explicit constexpr
  790. tuple(tuple<_UElements...>&& __in)
  791. noexcept(__nothrow_constructible<_UElements...>())
  792. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
  793. #if __cplusplus > 202002L
  794. template<typename... _UElements>
  795. requires (sizeof...(_Elements) == sizeof...(_UElements))
  796. && (!__use_other_ctor<tuple<_UElements...>&>())
  797. && __constructible<_UElements&...>
  798. explicit(!__convertible<_UElements&...>)
  799. constexpr
  800. tuple(tuple<_UElements...>& __in)
  801. noexcept(__nothrow_constructible<_UElements&...>())
  802. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&>(__in))
  803. { }
  804. template<typename... _UElements>
  805. requires (sizeof...(_Elements) == sizeof...(_UElements))
  806. && (!__use_other_ctor<const tuple<_UElements...>&&>())
  807. && __constructible<const _UElements...>
  808. explicit(!__convertible<const _UElements...>)
  809. constexpr
  810. tuple(const tuple<_UElements...>&& __in)
  811. noexcept(__nothrow_constructible<const _UElements...>())
  812. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&&>(__in)) { }
  813. #endif // C++23
  814. // Allocator-extended constructors.
  815. template<typename _Alloc,
  816. _ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
  817. _GLIBCXX20_CONSTEXPR
  818. tuple(allocator_arg_t __tag, const _Alloc& __a)
  819. : _Inherited(__tag, __a) { }
  820. template<typename _Alloc,
  821. _ExplicitDefaultCtor<is_object<_Alloc>::value> = false>
  822. _GLIBCXX20_CONSTEXPR
  823. explicit
  824. tuple(allocator_arg_t __tag, const _Alloc& __a)
  825. : _Inherited(__tag, __a) { }
  826. template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
  827. _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
  828. _GLIBCXX20_CONSTEXPR
  829. tuple(allocator_arg_t __tag, const _Alloc& __a,
  830. const _Elements&... __elements)
  831. : _Inherited(__tag, __a, __elements...) { }
  832. template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
  833. _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
  834. _GLIBCXX20_CONSTEXPR
  835. explicit
  836. tuple(allocator_arg_t __tag, const _Alloc& __a,
  837. const _Elements&... __elements)
  838. : _Inherited(__tag, __a, __elements...) { }
  839. template<typename _Alloc, typename... _UElements,
  840. bool _Valid = __valid_args<_UElements...>(),
  841. _ImplicitCtor<_Valid, _UElements...> = true>
  842. _GLIBCXX20_CONSTEXPR
  843. tuple(allocator_arg_t __tag, const _Alloc& __a,
  844. _UElements&&... __elements)
  845. : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
  846. { }
  847. template<typename _Alloc, typename... _UElements,
  848. bool _Valid = __valid_args<_UElements...>(),
  849. _ExplicitCtor<_Valid, _UElements...> = false>
  850. _GLIBCXX20_CONSTEXPR
  851. explicit
  852. tuple(allocator_arg_t __tag, const _Alloc& __a,
  853. _UElements&&... __elements)
  854. : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
  855. { }
  856. template<typename _Alloc>
  857. _GLIBCXX20_CONSTEXPR
  858. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  859. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  860. template<typename _Alloc>
  861. _GLIBCXX20_CONSTEXPR
  862. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  863. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  864. template<typename _Alloc, typename... _UElements,
  865. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  866. && !__use_other_ctor<const tuple<_UElements...>&>(),
  867. _ImplicitCtor<_Valid, const _UElements&...> = true>
  868. _GLIBCXX20_CONSTEXPR
  869. tuple(allocator_arg_t __tag, const _Alloc& __a,
  870. const tuple<_UElements...>& __in)
  871. : _Inherited(__tag, __a,
  872. static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  873. { }
  874. template<typename _Alloc, typename... _UElements,
  875. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  876. && !__use_other_ctor<const tuple<_UElements...>&>(),
  877. _ExplicitCtor<_Valid, const _UElements&...> = false>
  878. _GLIBCXX20_CONSTEXPR
  879. explicit
  880. tuple(allocator_arg_t __tag, const _Alloc& __a,
  881. const tuple<_UElements...>& __in)
  882. : _Inherited(__tag, __a,
  883. static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  884. { }
  885. template<typename _Alloc, typename... _UElements,
  886. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  887. && !__use_other_ctor<tuple<_UElements...>&&>(),
  888. _ImplicitCtor<_Valid, _UElements...> = true>
  889. _GLIBCXX20_CONSTEXPR
  890. tuple(allocator_arg_t __tag, const _Alloc& __a,
  891. tuple<_UElements...>&& __in)
  892. : _Inherited(__tag, __a,
  893. static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
  894. { }
  895. template<typename _Alloc, typename... _UElements,
  896. bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
  897. && !__use_other_ctor<tuple<_UElements...>&&>(),
  898. _ExplicitCtor<_Valid, _UElements...> = false>
  899. _GLIBCXX20_CONSTEXPR
  900. explicit
  901. tuple(allocator_arg_t __tag, const _Alloc& __a,
  902. tuple<_UElements...>&& __in)
  903. : _Inherited(__tag, __a,
  904. static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
  905. { }
  906. #if __cplusplus > 202002L
  907. template<typename _Alloc, typename... _UElements>
  908. requires (sizeof...(_Elements) == sizeof...(_UElements))
  909. && (!__use_other_ctor<tuple<_UElements...>&>())
  910. && __constructible<_UElements&...>
  911. explicit(!__convertible<_UElements&...>)
  912. constexpr
  913. tuple(allocator_arg_t __tag, const _Alloc& __a,
  914. tuple<_UElements...>& __in)
  915. : _Inherited(__tag, __a,
  916. static_cast<_Tuple_impl<0, _UElements...>&>(__in))
  917. { }
  918. template<typename _Alloc, typename... _UElements>
  919. requires (sizeof...(_Elements) == sizeof...(_UElements))
  920. && (!__use_other_ctor<const tuple<_UElements...>>())
  921. && __constructible<const _UElements...>
  922. explicit(!__convertible<const _UElements...>)
  923. constexpr
  924. tuple(allocator_arg_t __tag, const _Alloc& __a,
  925. const tuple<_UElements...>&& __in)
  926. : _Inherited(__tag, __a,
  927. static_cast<const _Tuple_impl<0, _UElements...>&&>(__in))
  928. { }
  929. #endif // C++23
  930. // tuple assignment
  931. _GLIBCXX20_CONSTEXPR
  932. tuple&
  933. operator=(__conditional_t<__assignable<const _Elements&...>(),
  934. const tuple&,
  935. const __nonesuch&> __in)
  936. noexcept(__nothrow_assignable<const _Elements&...>())
  937. {
  938. this->_M_assign(__in);
  939. return *this;
  940. }
  941. _GLIBCXX20_CONSTEXPR
  942. tuple&
  943. operator=(__conditional_t<__assignable<_Elements...>(),
  944. tuple&&,
  945. __nonesuch&&> __in)
  946. noexcept(__nothrow_assignable<_Elements...>())
  947. {
  948. this->_M_assign(std::move(__in));
  949. return *this;
  950. }
  951. template<typename... _UElements>
  952. _GLIBCXX20_CONSTEXPR
  953. __enable_if_t<__assignable<const _UElements&...>(), tuple&>
  954. operator=(const tuple<_UElements...>& __in)
  955. noexcept(__nothrow_assignable<const _UElements&...>())
  956. {
  957. this->_M_assign(__in);
  958. return *this;
  959. }
  960. template<typename... _UElements>
  961. _GLIBCXX20_CONSTEXPR
  962. __enable_if_t<__assignable<_UElements...>(), tuple&>
  963. operator=(tuple<_UElements...>&& __in)
  964. noexcept(__nothrow_assignable<_UElements...>())
  965. {
  966. this->_M_assign(std::move(__in));
  967. return *this;
  968. }
  969. #if __cplusplus > 202002L
  970. constexpr const tuple&
  971. operator=(const tuple& __in) const
  972. requires (is_copy_assignable_v<const _Elements> && ...)
  973. {
  974. this->_M_assign(__in);
  975. return *this;
  976. }
  977. constexpr const tuple&
  978. operator=(tuple&& __in) const
  979. requires (is_assignable_v<const _Elements&, _Elements> && ...)
  980. {
  981. this->_M_assign(std::move(__in));
  982. return *this;
  983. }
  984. template<typename... _UElements>
  985. constexpr const tuple&
  986. operator=(const tuple<_UElements...>& __in) const
  987. requires (sizeof...(_Elements) == sizeof...(_UElements))
  988. && (is_assignable_v<const _Elements&, const _UElements&> && ...)
  989. {
  990. this->_M_assign(__in);
  991. return *this;
  992. }
  993. template<typename... _UElements>
  994. constexpr const tuple&
  995. operator=(tuple<_UElements...>&& __in) const
  996. requires (sizeof...(_Elements) == sizeof...(_UElements))
  997. && (is_assignable_v<const _Elements&, _UElements> && ...)
  998. {
  999. this->_M_assign(std::move(__in));
  1000. return *this;
  1001. }
  1002. #endif // C++23
  1003. // tuple swap
  1004. _GLIBCXX20_CONSTEXPR
  1005. void
  1006. swap(tuple& __in)
  1007. noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
  1008. { _Inherited::_M_swap(__in); }
  1009. #if __cplusplus > 202002L
  1010. // As an extension, we constrain the const swap member function in order
  1011. // to continue accepting explicit instantiation of tuples whose elements
  1012. // are not all const swappable. Without this constraint, such an
  1013. // explicit instantiation would also instantiate the ill-formed body of
  1014. // this function and yield a hard error. This constraint shouldn't
  1015. // affect the behavior of valid programs.
  1016. constexpr void
  1017. swap(const tuple& __in) const
  1018. noexcept(__and_v<__is_nothrow_swappable<const _Elements>...>)
  1019. requires (is_swappable_v<const _Elements> && ...)
  1020. { _Inherited::_M_swap(__in); }
  1021. #endif // C++23
  1022. };
  1023. #if __cpp_deduction_guides >= 201606
  1024. template<typename... _UTypes>
  1025. tuple(_UTypes...) -> tuple<_UTypes...>;
  1026. template<typename _T1, typename _T2>
  1027. tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
  1028. template<typename _Alloc, typename... _UTypes>
  1029. tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
  1030. template<typename _Alloc, typename _T1, typename _T2>
  1031. tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
  1032. template<typename _Alloc, typename... _UTypes>
  1033. tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
  1034. #endif
  1035. // Explicit specialization, zero-element tuple.
  1036. template<>
  1037. class tuple<>
  1038. {
  1039. public:
  1040. _GLIBCXX20_CONSTEXPR
  1041. void swap(tuple&) noexcept { /* no-op */ }
  1042. #if __cplusplus > 202002L
  1043. constexpr void swap(const tuple&) const noexcept { /* no-op */ }
  1044. #endif
  1045. // We need the default since we're going to define no-op
  1046. // allocator constructors.
  1047. tuple() = default;
  1048. // No-op allocator constructors.
  1049. template<typename _Alloc>
  1050. _GLIBCXX20_CONSTEXPR
  1051. tuple(allocator_arg_t, const _Alloc&) noexcept { }
  1052. template<typename _Alloc>
  1053. _GLIBCXX20_CONSTEXPR
  1054. tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept { }
  1055. };
  1056. /// Partial specialization, 2-element tuple.
  1057. /// Includes construction and assignment from a pair.
  1058. template<typename _T1, typename _T2>
  1059. class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
  1060. {
  1061. typedef _Tuple_impl<0, _T1, _T2> _Inherited;
  1062. // Constraint for non-explicit default constructor
  1063. template<bool _Dummy, typename _U1, typename _U2>
  1064. using _ImplicitDefaultCtor = __enable_if_t<
  1065. _TupleConstraints<_Dummy, _U1, _U2>::
  1066. __is_implicitly_default_constructible(),
  1067. bool>;
  1068. // Constraint for explicit default constructor
  1069. template<bool _Dummy, typename _U1, typename _U2>
  1070. using _ExplicitDefaultCtor = __enable_if_t<
  1071. _TupleConstraints<_Dummy, _U1, _U2>::
  1072. __is_explicitly_default_constructible(),
  1073. bool>;
  1074. template<bool _Dummy>
  1075. using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
  1076. // Constraint for non-explicit constructors
  1077. template<bool _Cond, typename _U1, typename _U2>
  1078. using _ImplicitCtor = __enable_if_t<
  1079. _TCC<_Cond>::template __is_implicitly_constructible<_U1, _U2>(),
  1080. bool>;
  1081. // Constraint for non-explicit constructors
  1082. template<bool _Cond, typename _U1, typename _U2>
  1083. using _ExplicitCtor = __enable_if_t<
  1084. _TCC<_Cond>::template __is_explicitly_constructible<_U1, _U2>(),
  1085. bool>;
  1086. template<typename _U1, typename _U2>
  1087. static constexpr bool __assignable()
  1088. {
  1089. return __and_<is_assignable<_T1&, _U1>,
  1090. is_assignable<_T2&, _U2>>::value;
  1091. }
  1092. template<typename _U1, typename _U2>
  1093. static constexpr bool __nothrow_assignable()
  1094. {
  1095. return __and_<is_nothrow_assignable<_T1&, _U1>,
  1096. is_nothrow_assignable<_T2&, _U2>>::value;
  1097. }
  1098. template<typename _U1, typename _U2>
  1099. static constexpr bool __nothrow_constructible()
  1100. {
  1101. return __and_<is_nothrow_constructible<_T1, _U1>,
  1102. is_nothrow_constructible<_T2, _U2>>::value;
  1103. }
  1104. static constexpr bool __nothrow_default_constructible()
  1105. {
  1106. return __and_<is_nothrow_default_constructible<_T1>,
  1107. is_nothrow_default_constructible<_T2>>::value;
  1108. }
  1109. template<typename _U1>
  1110. static constexpr bool __is_alloc_arg()
  1111. { return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; }
  1112. #if __cplusplus > 202002L
  1113. template<typename _U1, typename _U2>
  1114. static constexpr bool __constructible
  1115. = _TCC<true>::template __constructible<_U1, _U2>::value;
  1116. template<typename _U1, typename _U2>
  1117. static constexpr bool __convertible
  1118. = _TCC<true>::template __convertible<_U1, _U2>::value;
  1119. #endif // C++23
  1120. public:
  1121. template<bool _Dummy = true,
  1122. _ImplicitDefaultCtor<_Dummy, _T1, _T2> = true>
  1123. constexpr
  1124. tuple()
  1125. noexcept(__nothrow_default_constructible())
  1126. : _Inherited() { }
  1127. template<bool _Dummy = true,
  1128. _ExplicitDefaultCtor<_Dummy, _T1, _T2> = false>
  1129. explicit constexpr
  1130. tuple()
  1131. noexcept(__nothrow_default_constructible())
  1132. : _Inherited() { }
  1133. template<bool _Dummy = true,
  1134. _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
  1135. constexpr
  1136. tuple(const _T1& __a1, const _T2& __a2)
  1137. noexcept(__nothrow_constructible<const _T1&, const _T2&>())
  1138. : _Inherited(__a1, __a2) { }
  1139. template<bool _Dummy = true,
  1140. _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
  1141. explicit constexpr
  1142. tuple(const _T1& __a1, const _T2& __a2)
  1143. noexcept(__nothrow_constructible<const _T1&, const _T2&>())
  1144. : _Inherited(__a1, __a2) { }
  1145. template<typename _U1, typename _U2,
  1146. _ImplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = true>
  1147. constexpr
  1148. tuple(_U1&& __a1, _U2&& __a2)
  1149. noexcept(__nothrow_constructible<_U1, _U2>())
  1150. : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
  1151. template<typename _U1, typename _U2,
  1152. _ExplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = false>
  1153. explicit constexpr
  1154. tuple(_U1&& __a1, _U2&& __a2)
  1155. noexcept(__nothrow_constructible<_U1, _U2>())
  1156. : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
  1157. constexpr tuple(const tuple&) = default;
  1158. constexpr tuple(tuple&&) = default;
  1159. template<typename _U1, typename _U2,
  1160. _ImplicitCtor<true, const _U1&, const _U2&> = true>
  1161. constexpr
  1162. tuple(const tuple<_U1, _U2>& __in)
  1163. noexcept(__nothrow_constructible<const _U1&, const _U2&>())
  1164. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
  1165. template<typename _U1, typename _U2,
  1166. _ExplicitCtor<true, const _U1&, const _U2&> = false>
  1167. explicit constexpr
  1168. tuple(const tuple<_U1, _U2>& __in)
  1169. noexcept(__nothrow_constructible<const _U1&, const _U2&>())
  1170. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
  1171. template<typename _U1, typename _U2,
  1172. _ImplicitCtor<true, _U1, _U2> = true>
  1173. constexpr
  1174. tuple(tuple<_U1, _U2>&& __in)
  1175. noexcept(__nothrow_constructible<_U1, _U2>())
  1176. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  1177. template<typename _U1, typename _U2,
  1178. _ExplicitCtor<true, _U1, _U2> = false>
  1179. explicit constexpr
  1180. tuple(tuple<_U1, _U2>&& __in)
  1181. noexcept(__nothrow_constructible<_U1, _U2>())
  1182. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  1183. #if __cplusplus > 202002L
  1184. template<typename _U1, typename _U2>
  1185. requires __constructible<_U1&, _U2&>
  1186. explicit(!__convertible<_U1&, _U2&>)
  1187. constexpr
  1188. tuple(tuple<_U1, _U2>& __in)
  1189. noexcept(__nothrow_constructible<_U1&, _U2&>())
  1190. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&>(__in)) { }
  1191. template<typename _U1, typename _U2>
  1192. requires __constructible<const _U1, const _U2>
  1193. explicit(!__convertible<const _U1, const _U2>)
  1194. constexpr
  1195. tuple(const tuple<_U1, _U2>&& __in)
  1196. noexcept(__nothrow_constructible<const _U1, const _U2>())
  1197. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  1198. #endif // C++23
  1199. template<typename _U1, typename _U2,
  1200. _ImplicitCtor<true, const _U1&, const _U2&> = true>
  1201. constexpr
  1202. tuple(const pair<_U1, _U2>& __in)
  1203. noexcept(__nothrow_constructible<const _U1&, const _U2&>())
  1204. : _Inherited(__in.first, __in.second) { }
  1205. template<typename _U1, typename _U2,
  1206. _ExplicitCtor<true, const _U1&, const _U2&> = false>
  1207. explicit constexpr
  1208. tuple(const pair<_U1, _U2>& __in)
  1209. noexcept(__nothrow_constructible<const _U1&, const _U2&>())
  1210. : _Inherited(__in.first, __in.second) { }
  1211. template<typename _U1, typename _U2,
  1212. _ImplicitCtor<true, _U1, _U2> = true>
  1213. constexpr
  1214. tuple(pair<_U1, _U2>&& __in)
  1215. noexcept(__nothrow_constructible<_U1, _U2>())
  1216. : _Inherited(std::forward<_U1>(__in.first),
  1217. std::forward<_U2>(__in.second)) { }
  1218. template<typename _U1, typename _U2,
  1219. _ExplicitCtor<true, _U1, _U2> = false>
  1220. explicit constexpr
  1221. tuple(pair<_U1, _U2>&& __in)
  1222. noexcept(__nothrow_constructible<_U1, _U2>())
  1223. : _Inherited(std::forward<_U1>(__in.first),
  1224. std::forward<_U2>(__in.second)) { }
  1225. #if __cplusplus > 202002L
  1226. template<typename _U1, typename _U2>
  1227. requires __constructible<_U1&, _U2&>
  1228. explicit(!__convertible<_U1&, _U2&>)
  1229. constexpr
  1230. tuple(pair<_U1, _U2>& __in)
  1231. noexcept(__nothrow_constructible<_U1&, _U2&>())
  1232. : _Inherited(__in.first, __in.second) { }
  1233. template<typename _U1, typename _U2>
  1234. requires __constructible<const _U1, const _U2>
  1235. explicit(!__convertible<const _U1, const _U2>)
  1236. constexpr
  1237. tuple(const pair<_U1, _U2>&& __in)
  1238. noexcept(__nothrow_constructible<const _U1, const _U2>())
  1239. : _Inherited(std::forward<const _U1>(__in.first),
  1240. std::forward<const _U2>(__in.second)) { }
  1241. #endif // C++23
  1242. // Allocator-extended constructors.
  1243. template<typename _Alloc,
  1244. _ImplicitDefaultCtor<is_object<_Alloc>::value, _T1, _T2> = true>
  1245. _GLIBCXX20_CONSTEXPR
  1246. tuple(allocator_arg_t __tag, const _Alloc& __a)
  1247. : _Inherited(__tag, __a) { }
  1248. template<typename _Alloc,
  1249. _ExplicitDefaultCtor<is_object<_Alloc>::value, _T1, _T2> = false>
  1250. _GLIBCXX20_CONSTEXPR
  1251. explicit
  1252. tuple(allocator_arg_t __tag, const _Alloc& __a)
  1253. : _Inherited(__tag, __a) { }
  1254. template<typename _Alloc, bool _Dummy = true,
  1255. _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
  1256. _GLIBCXX20_CONSTEXPR
  1257. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1258. const _T1& __a1, const _T2& __a2)
  1259. : _Inherited(__tag, __a, __a1, __a2) { }
  1260. template<typename _Alloc, bool _Dummy = true,
  1261. _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
  1262. explicit
  1263. _GLIBCXX20_CONSTEXPR
  1264. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1265. const _T1& __a1, const _T2& __a2)
  1266. : _Inherited(__tag, __a, __a1, __a2) { }
  1267. template<typename _Alloc, typename _U1, typename _U2,
  1268. _ImplicitCtor<true, _U1, _U2> = true>
  1269. _GLIBCXX20_CONSTEXPR
  1270. tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
  1271. : _Inherited(__tag, __a, std::forward<_U1>(__a1),
  1272. std::forward<_U2>(__a2)) { }
  1273. template<typename _Alloc, typename _U1, typename _U2,
  1274. _ExplicitCtor<true, _U1, _U2> = false>
  1275. explicit
  1276. _GLIBCXX20_CONSTEXPR
  1277. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1278. _U1&& __a1, _U2&& __a2)
  1279. : _Inherited(__tag, __a, std::forward<_U1>(__a1),
  1280. std::forward<_U2>(__a2)) { }
  1281. template<typename _Alloc>
  1282. _GLIBCXX20_CONSTEXPR
  1283. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  1284. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  1285. template<typename _Alloc>
  1286. _GLIBCXX20_CONSTEXPR
  1287. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  1288. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  1289. template<typename _Alloc, typename _U1, typename _U2,
  1290. _ImplicitCtor<true, const _U1&, const _U2&> = true>
  1291. _GLIBCXX20_CONSTEXPR
  1292. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1293. const tuple<_U1, _U2>& __in)
  1294. : _Inherited(__tag, __a,
  1295. static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
  1296. { }
  1297. template<typename _Alloc, typename _U1, typename _U2,
  1298. _ExplicitCtor<true, const _U1&, const _U2&> = false>
  1299. explicit
  1300. _GLIBCXX20_CONSTEXPR
  1301. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1302. const tuple<_U1, _U2>& __in)
  1303. : _Inherited(__tag, __a,
  1304. static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
  1305. { }
  1306. template<typename _Alloc, typename _U1, typename _U2,
  1307. _ImplicitCtor<true, _U1, _U2> = true>
  1308. _GLIBCXX20_CONSTEXPR
  1309. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
  1310. : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
  1311. { }
  1312. template<typename _Alloc, typename _U1, typename _U2,
  1313. _ExplicitCtor<true, _U1, _U2> = false>
  1314. explicit
  1315. _GLIBCXX20_CONSTEXPR
  1316. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
  1317. : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
  1318. { }
  1319. #if __cplusplus > 202002L
  1320. template<typename _Alloc, typename _U1, typename _U2>
  1321. requires __constructible<_U1&, _U2&>
  1322. explicit(!__convertible<_U1&, _U2&>)
  1323. constexpr
  1324. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1325. tuple<_U1, _U2>& __in)
  1326. : _Inherited(__tag, __a,
  1327. static_cast<_Tuple_impl<0, _U1, _U2>&>(__in))
  1328. { }
  1329. template<typename _Alloc, typename _U1, typename _U2>
  1330. requires __constructible<const _U1, const _U2>
  1331. explicit(!__convertible<const _U1, const _U2>)
  1332. constexpr
  1333. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1334. const tuple<_U1, _U2>&& __in)
  1335. : _Inherited(__tag, __a,
  1336. static_cast<const _Tuple_impl<0, _U1, _U2>&&>(__in))
  1337. { }
  1338. #endif // C++23
  1339. template<typename _Alloc, typename _U1, typename _U2,
  1340. _ImplicitCtor<true, const _U1&, const _U2&> = true>
  1341. _GLIBCXX20_CONSTEXPR
  1342. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1343. const pair<_U1, _U2>& __in)
  1344. : _Inherited(__tag, __a, __in.first, __in.second) { }
  1345. template<typename _Alloc, typename _U1, typename _U2,
  1346. _ExplicitCtor<true, const _U1&, const _U2&> = false>
  1347. explicit
  1348. _GLIBCXX20_CONSTEXPR
  1349. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1350. const pair<_U1, _U2>& __in)
  1351. : _Inherited(__tag, __a, __in.first, __in.second) { }
  1352. template<typename _Alloc, typename _U1, typename _U2,
  1353. _ImplicitCtor<true, _U1, _U2> = true>
  1354. _GLIBCXX20_CONSTEXPR
  1355. tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
  1356. : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
  1357. std::forward<_U2>(__in.second)) { }
  1358. template<typename _Alloc, typename _U1, typename _U2,
  1359. _ExplicitCtor<true, _U1, _U2> = false>
  1360. explicit
  1361. _GLIBCXX20_CONSTEXPR
  1362. tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
  1363. : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
  1364. std::forward<_U2>(__in.second)) { }
  1365. #if __cplusplus > 202002L
  1366. template<typename _Alloc, typename _U1, typename _U2>
  1367. requires __constructible<_U1&, _U2&>
  1368. explicit(!__convertible<_U1&, _U2&>)
  1369. constexpr
  1370. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1371. pair<_U1, _U2>& __in)
  1372. : _Inherited(__tag, __a, __in.first, __in.second) { }
  1373. template<typename _Alloc, typename _U1, typename _U2>
  1374. requires __constructible<const _U1, const _U2>
  1375. explicit(!__convertible<const _U1, const _U2>)
  1376. constexpr
  1377. tuple(allocator_arg_t __tag, const _Alloc& __a, const pair<_U1, _U2>&& __in)
  1378. : _Inherited(__tag, __a, std::forward<const _U1>(__in.first),
  1379. std::forward<const _U2>(__in.second)) { }
  1380. #endif // C++23
  1381. // Tuple assignment.
  1382. _GLIBCXX20_CONSTEXPR
  1383. tuple&
  1384. operator=(__conditional_t<__assignable<const _T1&, const _T2&>(),
  1385. const tuple&,
  1386. const __nonesuch&> __in)
  1387. noexcept(__nothrow_assignable<const _T1&, const _T2&>())
  1388. {
  1389. this->_M_assign(__in);
  1390. return *this;
  1391. }
  1392. _GLIBCXX20_CONSTEXPR
  1393. tuple&
  1394. operator=(__conditional_t<__assignable<_T1, _T2>(),
  1395. tuple&&,
  1396. __nonesuch&&> __in)
  1397. noexcept(__nothrow_assignable<_T1, _T2>())
  1398. {
  1399. this->_M_assign(std::move(__in));
  1400. return *this;
  1401. }
  1402. template<typename _U1, typename _U2>
  1403. _GLIBCXX20_CONSTEXPR
  1404. __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
  1405. operator=(const tuple<_U1, _U2>& __in)
  1406. noexcept(__nothrow_assignable<const _U1&, const _U2&>())
  1407. {
  1408. this->_M_assign(__in);
  1409. return *this;
  1410. }
  1411. template<typename _U1, typename _U2>
  1412. _GLIBCXX20_CONSTEXPR
  1413. __enable_if_t<__assignable<_U1, _U2>(), tuple&>
  1414. operator=(tuple<_U1, _U2>&& __in)
  1415. noexcept(__nothrow_assignable<_U1, _U2>())
  1416. {
  1417. this->_M_assign(std::move(__in));
  1418. return *this;
  1419. }
  1420. #if __cplusplus > 202002L
  1421. constexpr const tuple&
  1422. operator=(const tuple& __in) const
  1423. requires is_copy_assignable_v<const _T1> && is_copy_assignable_v<const _T2>
  1424. {
  1425. this->_M_assign(__in);
  1426. return *this;
  1427. }
  1428. constexpr const tuple&
  1429. operator=(tuple&& __in) const
  1430. requires is_assignable_v<const _T1&, _T1> && is_assignable_v<const _T2, _T2>
  1431. {
  1432. this->_M_assign(std::move(__in));
  1433. return *this;
  1434. }
  1435. template<typename _U1, typename _U2>
  1436. constexpr const tuple&
  1437. operator=(const tuple<_U1, _U2>& __in) const
  1438. requires is_assignable_v<const _T1&, const _U1&>
  1439. && is_assignable_v<const _T2&, const _U2&>
  1440. {
  1441. this->_M_assign(__in);
  1442. return *this;
  1443. }
  1444. template<typename _U1, typename _U2>
  1445. constexpr const tuple&
  1446. operator=(tuple<_U1, _U2>&& __in) const
  1447. requires is_assignable_v<const _T1&, _U1>
  1448. && is_assignable_v<const _T2&, _U2>
  1449. {
  1450. this->_M_assign(std::move(__in));
  1451. return *this;
  1452. }
  1453. #endif // C++23
  1454. template<typename _U1, typename _U2>
  1455. _GLIBCXX20_CONSTEXPR
  1456. __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
  1457. operator=(const pair<_U1, _U2>& __in)
  1458. noexcept(__nothrow_assignable<const _U1&, const _U2&>())
  1459. {
  1460. this->_M_head(*this) = __in.first;
  1461. this->_M_tail(*this)._M_head(*this) = __in.second;
  1462. return *this;
  1463. }
  1464. template<typename _U1, typename _U2>
  1465. _GLIBCXX20_CONSTEXPR
  1466. __enable_if_t<__assignable<_U1, _U2>(), tuple&>
  1467. operator=(pair<_U1, _U2>&& __in)
  1468. noexcept(__nothrow_assignable<_U1, _U2>())
  1469. {
  1470. this->_M_head(*this) = std::forward<_U1>(__in.first);
  1471. this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
  1472. return *this;
  1473. }
  1474. #if __cplusplus > 202002L
  1475. template<typename _U1, typename _U2>
  1476. constexpr const tuple&
  1477. operator=(const pair<_U1, _U2>& __in) const
  1478. requires is_assignable_v<const _T1&, const _U1&>
  1479. && is_assignable_v<const _T2&, const _U2&>
  1480. {
  1481. this->_M_head(*this) = __in.first;
  1482. this->_M_tail(*this)._M_head(*this) = __in.second;
  1483. return *this;
  1484. }
  1485. template<typename _U1, typename _U2>
  1486. constexpr const tuple&
  1487. operator=(pair<_U1, _U2>&& __in) const
  1488. requires is_assignable_v<const _T1&, _U1>
  1489. && is_assignable_v<const _T2&, _U2>
  1490. {
  1491. this->_M_head(*this) = std::forward<_U1>(__in.first);
  1492. this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
  1493. return *this;
  1494. }
  1495. #endif // C++23
  1496. _GLIBCXX20_CONSTEXPR
  1497. void
  1498. swap(tuple& __in)
  1499. noexcept(__and_<__is_nothrow_swappable<_T1>,
  1500. __is_nothrow_swappable<_T2>>::value)
  1501. { _Inherited::_M_swap(__in); }
  1502. #if __cplusplus > 202002L
  1503. constexpr void
  1504. swap(const tuple& __in) const
  1505. noexcept(__and_v<__is_nothrow_swappable<const _T1>,
  1506. __is_nothrow_swappable<const _T2>>)
  1507. requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
  1508. { _Inherited::_M_swap(__in); }
  1509. #endif // C++23
  1510. };
  1511. /// class tuple_size
  1512. template<typename... _Elements>
  1513. struct tuple_size<tuple<_Elements...>>
  1514. : public integral_constant<size_t, sizeof...(_Elements)> { };
  1515. #if __cplusplus >= 201703L
  1516. template<typename... _Types>
  1517. inline constexpr size_t tuple_size_v<tuple<_Types...>>
  1518. = sizeof...(_Types);
  1519. template<typename... _Types>
  1520. inline constexpr size_t tuple_size_v<const tuple<_Types...>>
  1521. = sizeof...(_Types);
  1522. #endif
  1523. /// Trait to get the Ith element type from a tuple.
  1524. template<size_t __i, typename... _Types>
  1525. struct tuple_element<__i, tuple<_Types...>>
  1526. {
  1527. static_assert(__i < sizeof...(_Types), "tuple index must be in range");
  1528. using type = typename _Nth_type<__i, _Types...>::type;
  1529. };
  1530. template<size_t __i, typename _Head, typename... _Tail>
  1531. constexpr _Head&
  1532. __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1533. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1534. template<size_t __i, typename _Head, typename... _Tail>
  1535. constexpr const _Head&
  1536. __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1537. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1538. // Deleted overload to improve diagnostics for invalid indices
  1539. template<size_t __i, typename... _Types>
  1540. __enable_if_t<(__i >= sizeof...(_Types))>
  1541. __get_helper(const tuple<_Types...>&) = delete;
  1542. /// Return a reference to the ith element of a tuple.
  1543. template<size_t __i, typename... _Elements>
  1544. constexpr __tuple_element_t<__i, tuple<_Elements...>>&
  1545. get(tuple<_Elements...>& __t) noexcept
  1546. { return std::__get_helper<__i>(__t); }
  1547. /// Return a const reference to the ith element of a const tuple.
  1548. template<size_t __i, typename... _Elements>
  1549. constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
  1550. get(const tuple<_Elements...>& __t) noexcept
  1551. { return std::__get_helper<__i>(__t); }
  1552. /// Return an rvalue reference to the ith element of a tuple rvalue.
  1553. template<size_t __i, typename... _Elements>
  1554. constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
  1555. get(tuple<_Elements...>&& __t) noexcept
  1556. {
  1557. typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
  1558. return std::forward<__element_type>(std::__get_helper<__i>(__t));
  1559. }
  1560. /// Return a const rvalue reference to the ith element of a const tuple rvalue.
  1561. template<size_t __i, typename... _Elements>
  1562. constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
  1563. get(const tuple<_Elements...>&& __t) noexcept
  1564. {
  1565. typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
  1566. return std::forward<const __element_type>(std::__get_helper<__i>(__t));
  1567. }
  1568. /// @cond undocumented
  1569. // Deleted overload chosen for invalid indices.
  1570. template<size_t __i, typename... _Elements>
  1571. constexpr __enable_if_t<(__i >= sizeof...(_Elements))>
  1572. get(const tuple<_Elements...>&) = delete;
  1573. /// @endcond
  1574. #if __cplusplus >= 201402L
  1575. #define __cpp_lib_tuples_by_type 201304L
  1576. /// Return a reference to the unique element of type _Tp of a tuple.
  1577. template <typename _Tp, typename... _Types>
  1578. constexpr _Tp&
  1579. get(tuple<_Types...>& __t) noexcept
  1580. {
  1581. constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
  1582. static_assert(__idx < sizeof...(_Types),
  1583. "the type T in std::get<T> must occur exactly once in the tuple");
  1584. return std::__get_helper<__idx>(__t);
  1585. }
  1586. /// Return a reference to the unique element of type _Tp of a tuple rvalue.
  1587. template <typename _Tp, typename... _Types>
  1588. constexpr _Tp&&
  1589. get(tuple<_Types...>&& __t) noexcept
  1590. {
  1591. constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
  1592. static_assert(__idx < sizeof...(_Types),
  1593. "the type T in std::get<T> must occur exactly once in the tuple");
  1594. return std::forward<_Tp>(std::__get_helper<__idx>(__t));
  1595. }
  1596. /// Return a const reference to the unique element of type _Tp of a tuple.
  1597. template <typename _Tp, typename... _Types>
  1598. constexpr const _Tp&
  1599. get(const tuple<_Types...>& __t) noexcept
  1600. {
  1601. constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
  1602. static_assert(__idx < sizeof...(_Types),
  1603. "the type T in std::get<T> must occur exactly once in the tuple");
  1604. return std::__get_helper<__idx>(__t);
  1605. }
  1606. /// Return a const reference to the unique element of type _Tp of
  1607. /// a const tuple rvalue.
  1608. template <typename _Tp, typename... _Types>
  1609. constexpr const _Tp&&
  1610. get(const tuple<_Types...>&& __t) noexcept
  1611. {
  1612. constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
  1613. static_assert(__idx < sizeof...(_Types),
  1614. "the type T in std::get<T> must occur exactly once in the tuple");
  1615. return std::forward<const _Tp>(std::__get_helper<__idx>(__t));
  1616. }
  1617. #endif
  1618. // This class performs the comparison operations on tuples
  1619. template<typename _Tp, typename _Up, size_t __i, size_t __size>
  1620. struct __tuple_compare
  1621. {
  1622. static constexpr bool
  1623. __eq(const _Tp& __t, const _Up& __u)
  1624. {
  1625. return bool(std::get<__i>(__t) == std::get<__i>(__u))
  1626. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
  1627. }
  1628. static constexpr bool
  1629. __less(const _Tp& __t, const _Up& __u)
  1630. {
  1631. return bool(std::get<__i>(__t) < std::get<__i>(__u))
  1632. || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
  1633. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
  1634. }
  1635. };
  1636. template<typename _Tp, typename _Up, size_t __size>
  1637. struct __tuple_compare<_Tp, _Up, __size, __size>
  1638. {
  1639. static constexpr bool
  1640. __eq(const _Tp&, const _Up&) { return true; }
  1641. static constexpr bool
  1642. __less(const _Tp&, const _Up&) { return false; }
  1643. };
  1644. template<typename... _TElements, typename... _UElements>
  1645. constexpr bool
  1646. operator==(const tuple<_TElements...>& __t,
  1647. const tuple<_UElements...>& __u)
  1648. {
  1649. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  1650. "tuple objects can only be compared if they have equal sizes.");
  1651. using __compare = __tuple_compare<tuple<_TElements...>,
  1652. tuple<_UElements...>,
  1653. 0, sizeof...(_TElements)>;
  1654. return __compare::__eq(__t, __u);
  1655. }
  1656. #if __cpp_lib_three_way_comparison
  1657. template<typename _Cat, typename _Tp, typename _Up>
  1658. constexpr _Cat
  1659. __tuple_cmp(const _Tp&, const _Up&, index_sequence<>)
  1660. { return _Cat::equivalent; }
  1661. template<typename _Cat, typename _Tp, typename _Up,
  1662. size_t _Idx0, size_t... _Idxs>
  1663. constexpr _Cat
  1664. __tuple_cmp(const _Tp& __t, const _Up& __u,
  1665. index_sequence<_Idx0, _Idxs...>)
  1666. {
  1667. auto __c
  1668. = __detail::__synth3way(std::get<_Idx0>(__t), std::get<_Idx0>(__u));
  1669. if (__c != 0)
  1670. return __c;
  1671. return std::__tuple_cmp<_Cat>(__t, __u, index_sequence<_Idxs...>());
  1672. }
  1673. template<typename... _Tps, typename... _Ups>
  1674. constexpr
  1675. common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>
  1676. operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)
  1677. {
  1678. using _Cat
  1679. = common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>;
  1680. return std::__tuple_cmp<_Cat>(__t, __u, index_sequence_for<_Tps...>());
  1681. }
  1682. #else
  1683. template<typename... _TElements, typename... _UElements>
  1684. constexpr bool
  1685. operator<(const tuple<_TElements...>& __t,
  1686. const tuple<_UElements...>& __u)
  1687. {
  1688. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  1689. "tuple objects can only be compared if they have equal sizes.");
  1690. using __compare = __tuple_compare<tuple<_TElements...>,
  1691. tuple<_UElements...>,
  1692. 0, sizeof...(_TElements)>;
  1693. return __compare::__less(__t, __u);
  1694. }
  1695. template<typename... _TElements, typename... _UElements>
  1696. constexpr bool
  1697. operator!=(const tuple<_TElements...>& __t,
  1698. const tuple<_UElements...>& __u)
  1699. { return !(__t == __u); }
  1700. template<typename... _TElements, typename... _UElements>
  1701. constexpr bool
  1702. operator>(const tuple<_TElements...>& __t,
  1703. const tuple<_UElements...>& __u)
  1704. { return __u < __t; }
  1705. template<typename... _TElements, typename... _UElements>
  1706. constexpr bool
  1707. operator<=(const tuple<_TElements...>& __t,
  1708. const tuple<_UElements...>& __u)
  1709. { return !(__u < __t); }
  1710. template<typename... _TElements, typename... _UElements>
  1711. constexpr bool
  1712. operator>=(const tuple<_TElements...>& __t,
  1713. const tuple<_UElements...>& __u)
  1714. { return !(__t < __u); }
  1715. #endif // three_way_comparison
  1716. // NB: DR 705.
  1717. /// Create a tuple containing copies of the arguments
  1718. template<typename... _Elements>
  1719. constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
  1720. make_tuple(_Elements&&... __args)
  1721. {
  1722. typedef tuple<typename __decay_and_strip<_Elements>::__type...>
  1723. __result_type;
  1724. return __result_type(std::forward<_Elements>(__args)...);
  1725. }
  1726. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1727. // 2275. Why is forward_as_tuple not constexpr?
  1728. /// Create a tuple of lvalue or rvalue references to the arguments
  1729. template<typename... _Elements>
  1730. constexpr tuple<_Elements&&...>
  1731. forward_as_tuple(_Elements&&... __args) noexcept
  1732. { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
  1733. // Declarations of std::array and its std::get overloads, so that
  1734. // std::tuple_cat can use them if <tuple> is included before <array>.
  1735. template<typename _Tp, size_t _Nm> struct array;
  1736. template<size_t _Int, typename _Tp, size_t _Nm>
  1737. constexpr _Tp&
  1738. get(array<_Tp, _Nm>&) noexcept;
  1739. template<size_t _Int, typename _Tp, size_t _Nm>
  1740. constexpr _Tp&&
  1741. get(array<_Tp, _Nm>&&) noexcept;
  1742. template<size_t _Int, typename _Tp, size_t _Nm>
  1743. constexpr const _Tp&
  1744. get(const array<_Tp, _Nm>&) noexcept;
  1745. template<size_t _Int, typename _Tp, size_t _Nm>
  1746. constexpr const _Tp&&
  1747. get(const array<_Tp, _Nm>&&) noexcept;
  1748. /// @cond undocumented
  1749. template<size_t, typename, typename, size_t>
  1750. struct __make_tuple_impl;
  1751. template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
  1752. struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
  1753. : __make_tuple_impl<_Idx + 1,
  1754. tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
  1755. _Tuple, _Nm>
  1756. { };
  1757. template<size_t _Nm, typename _Tuple, typename... _Tp>
  1758. struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
  1759. {
  1760. typedef tuple<_Tp...> __type;
  1761. };
  1762. template<typename _Tuple>
  1763. struct __do_make_tuple
  1764. : __make_tuple_impl<0, tuple<>, _Tuple, tuple_size<_Tuple>::value>
  1765. { };
  1766. // Returns the std::tuple equivalent of a tuple-like type.
  1767. template<typename _Tuple>
  1768. struct __make_tuple
  1769. : public __do_make_tuple<__remove_cvref_t<_Tuple>>
  1770. { };
  1771. // Combines several std::tuple's into a single one.
  1772. template<typename...>
  1773. struct __combine_tuples;
  1774. template<>
  1775. struct __combine_tuples<>
  1776. {
  1777. typedef tuple<> __type;
  1778. };
  1779. template<typename... _Ts>
  1780. struct __combine_tuples<tuple<_Ts...>>
  1781. {
  1782. typedef tuple<_Ts...> __type;
  1783. };
  1784. template<typename... _T1s, typename... _T2s, typename... _Rem>
  1785. struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
  1786. {
  1787. typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
  1788. _Rem...>::__type __type;
  1789. };
  1790. // Computes the result type of tuple_cat given a set of tuple-like types.
  1791. template<typename... _Tpls>
  1792. struct __tuple_cat_result
  1793. {
  1794. typedef typename __combine_tuples
  1795. <typename __make_tuple<_Tpls>::__type...>::__type __type;
  1796. };
  1797. // Helper to determine the index set for the first tuple-like
  1798. // type of a given set.
  1799. template<typename...>
  1800. struct __make_1st_indices;
  1801. template<>
  1802. struct __make_1st_indices<>
  1803. {
  1804. typedef _Index_tuple<> __type;
  1805. };
  1806. template<typename _Tp, typename... _Tpls>
  1807. struct __make_1st_indices<_Tp, _Tpls...>
  1808. {
  1809. typedef typename _Build_index_tuple<tuple_size<
  1810. typename remove_reference<_Tp>::type>::value>::__type __type;
  1811. };
  1812. // Performs the actual concatenation by step-wise expanding tuple-like
  1813. // objects into the elements, which are finally forwarded into the
  1814. // result tuple.
  1815. template<typename _Ret, typename _Indices, typename... _Tpls>
  1816. struct __tuple_concater;
  1817. template<typename _Ret, size_t... _Is, typename _Tp, typename... _Tpls>
  1818. struct __tuple_concater<_Ret, _Index_tuple<_Is...>, _Tp, _Tpls...>
  1819. {
  1820. template<typename... _Us>
  1821. static constexpr _Ret
  1822. _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
  1823. {
  1824. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  1825. typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
  1826. return __next::_S_do(std::forward<_Tpls>(__tps)...,
  1827. std::forward<_Us>(__us)...,
  1828. std::get<_Is>(std::forward<_Tp>(__tp))...);
  1829. }
  1830. };
  1831. template<typename _Ret>
  1832. struct __tuple_concater<_Ret, _Index_tuple<>>
  1833. {
  1834. template<typename... _Us>
  1835. static constexpr _Ret
  1836. _S_do(_Us&&... __us)
  1837. {
  1838. return _Ret(std::forward<_Us>(__us)...);
  1839. }
  1840. };
  1841. template<typename... _Tps>
  1842. struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
  1843. { };
  1844. /// @endcond
  1845. /// Create a `tuple` containing all elements from multiple tuple-like objects
  1846. template<typename... _Tpls, typename = typename
  1847. enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
  1848. constexpr auto
  1849. tuple_cat(_Tpls&&... __tpls)
  1850. -> typename __tuple_cat_result<_Tpls...>::__type
  1851. {
  1852. typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
  1853. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  1854. typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
  1855. return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
  1856. }
  1857. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1858. // 2301. Why is tie not constexpr?
  1859. /// Return a tuple of lvalue references bound to the arguments
  1860. template<typename... _Elements>
  1861. constexpr tuple<_Elements&...>
  1862. tie(_Elements&... __args) noexcept
  1863. { return tuple<_Elements&...>(__args...); }
  1864. /// Exchange the values of two tuples
  1865. template<typename... _Elements>
  1866. _GLIBCXX20_CONSTEXPR
  1867. inline
  1868. #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
  1869. // Constrained free swap overload, see p0185r1
  1870. typename enable_if<__and_<__is_swappable<_Elements>...>::value
  1871. >::type
  1872. #else
  1873. void
  1874. #endif
  1875. swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
  1876. noexcept(noexcept(__x.swap(__y)))
  1877. { __x.swap(__y); }
  1878. #if __cplusplus > 202002L
  1879. template<typename... _Elements>
  1880. requires (is_swappable_v<const _Elements> && ...)
  1881. constexpr void
  1882. swap(const tuple<_Elements...>& __x, const tuple<_Elements...>& __y)
  1883. noexcept(noexcept(__x.swap(__y)))
  1884. { __x.swap(__y); }
  1885. #endif // C++23
  1886. #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
  1887. /// Exchange the values of two const tuples (if const elements can be swapped)
  1888. template<typename... _Elements>
  1889. _GLIBCXX20_CONSTEXPR
  1890. typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
  1891. swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
  1892. #endif
  1893. // A class (and instance) which can be used in 'tie' when an element
  1894. // of a tuple is not required.
  1895. // _GLIBCXX14_CONSTEXPR
  1896. // 2933. PR for LWG 2773 could be clearer
  1897. struct _Swallow_assign
  1898. {
  1899. template<class _Tp>
  1900. _GLIBCXX14_CONSTEXPR const _Swallow_assign&
  1901. operator=(const _Tp&) const
  1902. { return *this; }
  1903. };
  1904. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1905. // 2773. Making std::ignore constexpr
  1906. /** Used with `std::tie` to ignore an element of a tuple
  1907. *
  1908. * When using `std::tie` to assign the elements of a tuple to variables,
  1909. * unwanted elements can be ignored by using `std::ignore`. For example:
  1910. *
  1911. * ```
  1912. * int x, y;
  1913. * std::tie(x, std::ignore, y) = std::make_tuple(1, 2, 3);
  1914. * ```
  1915. *
  1916. * This assignment will perform `x=1; std::ignore=2; y=3;` which results
  1917. * in the second element being ignored.
  1918. *
  1919. * @since C++11
  1920. */
  1921. _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
  1922. /// Partial specialization for tuples
  1923. template<typename... _Types, typename _Alloc>
  1924. struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
  1925. // See stl_pair.h...
  1926. /** "piecewise construction" using a tuple of arguments for each member.
  1927. *
  1928. * @param __first Arguments for the first member of the pair.
  1929. * @param __second Arguments for the second member of the pair.
  1930. *
  1931. * The elements of each tuple will be used as the constructor arguments
  1932. * for the data members of the pair.
  1933. */
  1934. template<class _T1, class _T2>
  1935. template<typename... _Args1, typename... _Args2>
  1936. _GLIBCXX20_CONSTEXPR
  1937. inline
  1938. pair<_T1, _T2>::
  1939. pair(piecewise_construct_t,
  1940. tuple<_Args1...> __first, tuple<_Args2...> __second)
  1941. : pair(__first, __second,
  1942. typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
  1943. typename _Build_index_tuple<sizeof...(_Args2)>::__type())
  1944. { }
  1945. template<class _T1, class _T2>
  1946. template<typename... _Args1, size_t... _Indexes1,
  1947. typename... _Args2, size_t... _Indexes2>
  1948. _GLIBCXX20_CONSTEXPR inline
  1949. pair<_T1, _T2>::
  1950. pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
  1951. _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
  1952. : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
  1953. second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
  1954. { }
  1955. #if __cplusplus >= 201703L
  1956. // Unpack a std::tuple into a type trait and use its value.
  1957. // For cv std::tuple<_Up> the result is _Trait<_Tp, cv _Up...>::value.
  1958. // For cv std::tuple<_Up>& the result is _Trait<_Tp, cv _Up&...>::value.
  1959. // Otherwise the result is false (because we don't know if std::get throws).
  1960. template<template<typename...> class _Trait, typename _Tp, typename _Tuple>
  1961. inline constexpr bool __unpack_std_tuple = false;
  1962. template<template<typename...> class _Trait, typename _Tp, typename... _Up>
  1963. inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>>
  1964. = _Trait<_Tp, _Up...>::value;
  1965. template<template<typename...> class _Trait, typename _Tp, typename... _Up>
  1966. inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>&>
  1967. = _Trait<_Tp, _Up&...>::value;
  1968. template<template<typename...> class _Trait, typename _Tp, typename... _Up>
  1969. inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>>
  1970. = _Trait<_Tp, const _Up...>::value;
  1971. template<template<typename...> class _Trait, typename _Tp, typename... _Up>
  1972. inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>&>
  1973. = _Trait<_Tp, const _Up&...>::value;
  1974. # define __cpp_lib_apply 201603L
  1975. template <typename _Fn, typename _Tuple, size_t... _Idx>
  1976. constexpr decltype(auto)
  1977. __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
  1978. {
  1979. return std::__invoke(std::forward<_Fn>(__f),
  1980. std::get<_Idx>(std::forward<_Tuple>(__t))...);
  1981. }
  1982. template <typename _Fn, typename _Tuple>
  1983. constexpr decltype(auto)
  1984. apply(_Fn&& __f, _Tuple&& __t)
  1985. noexcept(__unpack_std_tuple<is_nothrow_invocable, _Fn, _Tuple>)
  1986. {
  1987. using _Indices
  1988. = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>;
  1989. return std::__apply_impl(std::forward<_Fn>(__f),
  1990. std::forward<_Tuple>(__t),
  1991. _Indices{});
  1992. }
  1993. #define __cpp_lib_make_from_tuple 201606L
  1994. template <typename _Tp, typename _Tuple, size_t... _Idx>
  1995. constexpr _Tp
  1996. __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
  1997. { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
  1998. template <typename _Tp, typename _Tuple>
  1999. constexpr _Tp
  2000. make_from_tuple(_Tuple&& __t)
  2001. noexcept(__unpack_std_tuple<is_nothrow_constructible, _Tp, _Tuple>)
  2002. {
  2003. constexpr size_t __n = tuple_size_v<remove_reference_t<_Tuple>>;
  2004. #if __has_builtin(__reference_constructs_from_temporary)
  2005. if constexpr (__n == 1)
  2006. {
  2007. using _Elt = decltype(std::get<0>(std::declval<_Tuple>()));
  2008. static_assert(!__reference_constructs_from_temporary(_Tp, _Elt));
  2009. }
  2010. #endif
  2011. return __make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t),
  2012. make_index_sequence<__n>{});
  2013. }
  2014. #endif // C++17
  2015. #if __cplusplus > 202002L
  2016. template<typename... _TTypes, typename... _UTypes,
  2017. template<typename> class _TQual, template<typename> class _UQual>
  2018. requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
  2019. struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual>
  2020. { using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; };
  2021. template<typename... _TTypes, typename... _UTypes>
  2022. requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
  2023. struct common_type<tuple<_TTypes...>, tuple<_UTypes...>>
  2024. { using type = tuple<common_type_t<_TTypes, _UTypes>...>; };
  2025. #endif // C++23
  2026. /// @}
  2027. _GLIBCXX_END_NAMESPACE_VERSION
  2028. } // namespace std
  2029. #endif // C++11
  2030. #endif // _GLIBCXX_TUPLE