tuple 75 KB

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