tuple 65 KB

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