tuple 65 KB

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