tuple 62 KB

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