tuple 65 KB

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