tuple 65 KB

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