tuple 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. // <tuple> -*- C++ -*-
  2. // Copyright (C) 2007-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/tuple
  21. * This is a Standard C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_TUPLE
  24. #define _GLIBCXX_TUPLE 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <utility>
  30. #include <array>
  31. #include <bits/uses_allocator.h>
  32. #include <bits/invoke.h>
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. /**
  37. * @addtogroup utilities
  38. * @{
  39. */
  40. template<typename... _Elements>
  41. class tuple;
  42. template<typename _Tp>
  43. struct __is_empty_non_tuple : is_empty<_Tp> { };
  44. // Using EBO for elements that are tuples causes ambiguous base errors.
  45. template<typename _El0, typename... _El>
  46. struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
  47. // Use the Empty Base-class Optimization for empty, non-final types.
  48. template<typename _Tp>
  49. using __empty_not_final
  50. = typename conditional<__is_final(_Tp), false_type,
  51. __is_empty_non_tuple<_Tp>>::type;
  52. template<std::size_t _Idx, typename _Head,
  53. bool = __empty_not_final<_Head>::value>
  54. struct _Head_base;
  55. template<std::size_t _Idx, typename _Head>
  56. struct _Head_base<_Idx, _Head, true>
  57. : public _Head
  58. {
  59. constexpr _Head_base()
  60. : _Head() { }
  61. constexpr _Head_base(const _Head& __h)
  62. : _Head(__h) { }
  63. constexpr _Head_base(const _Head_base&) = default;
  64. constexpr _Head_base(_Head_base&&) = default;
  65. template<typename _UHead>
  66. constexpr _Head_base(_UHead&& __h)
  67. : _Head(std::forward<_UHead>(__h)) { }
  68. _Head_base(allocator_arg_t, __uses_alloc0)
  69. : _Head() { }
  70. template<typename _Alloc>
  71. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  72. : _Head(allocator_arg, *__a._M_a) { }
  73. template<typename _Alloc>
  74. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  75. : _Head(*__a._M_a) { }
  76. template<typename _UHead>
  77. _Head_base(__uses_alloc0, _UHead&& __uhead)
  78. : _Head(std::forward<_UHead>(__uhead)) { }
  79. template<typename _Alloc, typename _UHead>
  80. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  81. : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
  82. template<typename _Alloc, typename _UHead>
  83. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  84. : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
  85. static constexpr _Head&
  86. _M_head(_Head_base& __b) noexcept { return __b; }
  87. static constexpr const _Head&
  88. _M_head(const _Head_base& __b) noexcept { return __b; }
  89. };
  90. template<std::size_t _Idx, typename _Head>
  91. struct _Head_base<_Idx, _Head, false>
  92. {
  93. constexpr _Head_base()
  94. : _M_head_impl() { }
  95. constexpr _Head_base(const _Head& __h)
  96. : _M_head_impl(__h) { }
  97. constexpr _Head_base(const _Head_base&) = default;
  98. constexpr _Head_base(_Head_base&&) = default;
  99. template<typename _UHead>
  100. constexpr _Head_base(_UHead&& __h)
  101. : _M_head_impl(std::forward<_UHead>(__h)) { }
  102. _Head_base(allocator_arg_t, __uses_alloc0)
  103. : _M_head_impl() { }
  104. template<typename _Alloc>
  105. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  106. : _M_head_impl(allocator_arg, *__a._M_a) { }
  107. template<typename _Alloc>
  108. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  109. : _M_head_impl(*__a._M_a) { }
  110. template<typename _UHead>
  111. _Head_base(__uses_alloc0, _UHead&& __uhead)
  112. : _M_head_impl(std::forward<_UHead>(__uhead)) { }
  113. template<typename _Alloc, typename _UHead>
  114. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  115. : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
  116. { }
  117. template<typename _Alloc, typename _UHead>
  118. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  119. : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
  120. static constexpr _Head&
  121. _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
  122. static constexpr const _Head&
  123. _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
  124. _Head _M_head_impl;
  125. };
  126. /**
  127. * Contains the actual implementation of the @c tuple template, stored
  128. * as a recursive inheritance hierarchy from the first element (most
  129. * derived class) to the last (least derived class). The @c Idx
  130. * parameter gives the 0-based index of the element stored at this
  131. * point in the hierarchy; we use it to implement a constant-time
  132. * get() operation.
  133. */
  134. template<std::size_t _Idx, typename... _Elements>
  135. struct _Tuple_impl;
  136. /**
  137. * Recursive tuple implementation. Here we store the @c Head element
  138. * and derive from a @c Tuple_impl containing the remaining elements
  139. * (which contains the @c Tail).
  140. */
  141. template<std::size_t _Idx, typename _Head, typename... _Tail>
  142. struct _Tuple_impl<_Idx, _Head, _Tail...>
  143. : public _Tuple_impl<_Idx + 1, _Tail...>,
  144. private _Head_base<_Idx, _Head>
  145. {
  146. template<std::size_t, typename...> friend class _Tuple_impl;
  147. typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
  148. typedef _Head_base<_Idx, _Head> _Base;
  149. static constexpr _Head&
  150. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  151. static constexpr const _Head&
  152. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  153. static constexpr _Inherited&
  154. _M_tail(_Tuple_impl& __t) noexcept { return __t; }
  155. static constexpr const _Inherited&
  156. _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
  157. constexpr _Tuple_impl()
  158. : _Inherited(), _Base() { }
  159. explicit
  160. constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
  161. : _Inherited(__tail...), _Base(__head) { }
  162. template<typename _UHead, typename... _UTail, typename = typename
  163. enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
  164. explicit
  165. constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
  166. : _Inherited(std::forward<_UTail>(__tail)...),
  167. _Base(std::forward<_UHead>(__head)) { }
  168. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  169. constexpr
  170. _Tuple_impl(_Tuple_impl&& __in)
  171. noexcept(__and_<is_nothrow_move_constructible<_Head>,
  172. is_nothrow_move_constructible<_Inherited>>::value)
  173. : _Inherited(std::move(_M_tail(__in))),
  174. _Base(std::forward<_Head>(_M_head(__in))) { }
  175. template<typename... _UElements>
  176. constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
  177. : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  178. _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
  179. template<typename _UHead, typename... _UTails>
  180. constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  181. : _Inherited(std::move
  182. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  183. _Base(std::forward<_UHead>
  184. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
  185. template<typename _Alloc>
  186. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  187. : _Inherited(__tag, __a),
  188. _Base(__tag, __use_alloc<_Head>(__a)) { }
  189. template<typename _Alloc>
  190. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  191. const _Head& __head, const _Tail&... __tail)
  192. : _Inherited(__tag, __a, __tail...),
  193. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
  194. template<typename _Alloc, typename _UHead, typename... _UTail,
  195. typename = typename enable_if<sizeof...(_Tail)
  196. == sizeof...(_UTail)>::type>
  197. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  198. _UHead&& __head, _UTail&&... __tail)
  199. : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
  200. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  201. std::forward<_UHead>(__head)) { }
  202. template<typename _Alloc>
  203. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  204. const _Tuple_impl& __in)
  205. : _Inherited(__tag, __a, _M_tail(__in)),
  206. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
  207. template<typename _Alloc>
  208. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  209. _Tuple_impl&& __in)
  210. : _Inherited(__tag, __a, std::move(_M_tail(__in))),
  211. _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  212. std::forward<_Head>(_M_head(__in))) { }
  213. template<typename _Alloc, typename... _UElements>
  214. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  215. const _Tuple_impl<_Idx, _UElements...>& __in)
  216. : _Inherited(__tag, __a,
  217. _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  218. _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  219. _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
  220. template<typename _Alloc, typename _UHead, typename... _UTails>
  221. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  222. _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  223. : _Inherited(__tag, __a, std::move
  224. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  225. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  226. std::forward<_UHead>
  227. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
  228. _Tuple_impl&
  229. operator=(const _Tuple_impl& __in)
  230. {
  231. _M_head(*this) = _M_head(__in);
  232. _M_tail(*this) = _M_tail(__in);
  233. return *this;
  234. }
  235. _Tuple_impl&
  236. operator=(_Tuple_impl&& __in)
  237. noexcept(__and_<is_nothrow_move_assignable<_Head>,
  238. is_nothrow_move_assignable<_Inherited>>::value)
  239. {
  240. _M_head(*this) = std::forward<_Head>(_M_head(__in));
  241. _M_tail(*this) = std::move(_M_tail(__in));
  242. return *this;
  243. }
  244. template<typename... _UElements>
  245. _Tuple_impl&
  246. operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
  247. {
  248. _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
  249. _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
  250. return *this;
  251. }
  252. template<typename _UHead, typename... _UTails>
  253. _Tuple_impl&
  254. operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  255. {
  256. _M_head(*this) = std::forward<_UHead>
  257. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
  258. _M_tail(*this) = std::move
  259. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in));
  260. return *this;
  261. }
  262. protected:
  263. void
  264. _M_swap(_Tuple_impl& __in)
  265. noexcept(__is_nothrow_swappable<_Head>::value
  266. && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
  267. {
  268. using std::swap;
  269. swap(_M_head(*this), _M_head(__in));
  270. _Inherited::_M_swap(_M_tail(__in));
  271. }
  272. };
  273. // Basis case of inheritance recursion.
  274. template<std::size_t _Idx, typename _Head>
  275. struct _Tuple_impl<_Idx, _Head>
  276. : private _Head_base<_Idx, _Head>
  277. {
  278. template<std::size_t, typename...> friend class _Tuple_impl;
  279. typedef _Head_base<_Idx, _Head> _Base;
  280. static constexpr _Head&
  281. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  282. static constexpr const _Head&
  283. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  284. constexpr _Tuple_impl()
  285. : _Base() { }
  286. explicit
  287. constexpr _Tuple_impl(const _Head& __head)
  288. : _Base(__head) { }
  289. template<typename _UHead>
  290. explicit
  291. constexpr _Tuple_impl(_UHead&& __head)
  292. : _Base(std::forward<_UHead>(__head)) { }
  293. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  294. constexpr
  295. _Tuple_impl(_Tuple_impl&& __in)
  296. noexcept(is_nothrow_move_constructible<_Head>::value)
  297. : _Base(std::forward<_Head>(_M_head(__in))) { }
  298. template<typename _UHead>
  299. constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
  300. : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
  301. template<typename _UHead>
  302. constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
  303. : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  304. { }
  305. template<typename _Alloc>
  306. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  307. : _Base(__tag, __use_alloc<_Head>(__a)) { }
  308. template<typename _Alloc>
  309. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  310. const _Head& __head)
  311. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
  312. template<typename _Alloc, typename _UHead>
  313. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  314. _UHead&& __head)
  315. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  316. std::forward<_UHead>(__head)) { }
  317. template<typename _Alloc>
  318. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  319. const _Tuple_impl& __in)
  320. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
  321. template<typename _Alloc>
  322. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  323. _Tuple_impl&& __in)
  324. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  325. std::forward<_Head>(_M_head(__in))) { }
  326. template<typename _Alloc, typename _UHead>
  327. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  328. const _Tuple_impl<_Idx, _UHead>& __in)
  329. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  330. _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
  331. template<typename _Alloc, typename _UHead>
  332. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  333. _Tuple_impl<_Idx, _UHead>&& __in)
  334. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  335. std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  336. { }
  337. _Tuple_impl&
  338. operator=(const _Tuple_impl& __in)
  339. {
  340. _M_head(*this) = _M_head(__in);
  341. return *this;
  342. }
  343. _Tuple_impl&
  344. operator=(_Tuple_impl&& __in)
  345. noexcept(is_nothrow_move_assignable<_Head>::value)
  346. {
  347. _M_head(*this) = std::forward<_Head>(_M_head(__in));
  348. return *this;
  349. }
  350. template<typename _UHead>
  351. _Tuple_impl&
  352. operator=(const _Tuple_impl<_Idx, _UHead>& __in)
  353. {
  354. _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
  355. return *this;
  356. }
  357. template<typename _UHead>
  358. _Tuple_impl&
  359. operator=(_Tuple_impl<_Idx, _UHead>&& __in)
  360. {
  361. _M_head(*this)
  362. = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
  363. return *this;
  364. }
  365. protected:
  366. void
  367. _M_swap(_Tuple_impl& __in)
  368. noexcept(__is_nothrow_swappable<_Head>::value)
  369. {
  370. using std::swap;
  371. swap(_M_head(*this), _M_head(__in));
  372. }
  373. };
  374. // Concept utility functions, reused in conditionally-explicit
  375. // constructors.
  376. template<bool, typename... _Elements>
  377. struct _TC
  378. {
  379. template<typename... _UElements>
  380. static constexpr bool _ConstructibleTuple()
  381. {
  382. return __and_<is_constructible<_Elements, const _UElements&>...>::value;
  383. }
  384. template<typename... _UElements>
  385. static constexpr bool _ImplicitlyConvertibleTuple()
  386. {
  387. return __and_<is_convertible<const _UElements&, _Elements>...>::value;
  388. }
  389. template<typename... _UElements>
  390. static constexpr bool _MoveConstructibleTuple()
  391. {
  392. return __and_<is_constructible<_Elements, _UElements&&>...>::value;
  393. }
  394. template<typename... _UElements>
  395. static constexpr bool _ImplicitlyMoveConvertibleTuple()
  396. {
  397. return __and_<is_convertible<_UElements&&, _Elements>...>::value;
  398. }
  399. template<typename _SrcTuple>
  400. static constexpr bool _NonNestedTuple()
  401. {
  402. return __and_<__not_<is_same<tuple<_Elements...>,
  403. typename remove_cv<
  404. typename remove_reference<_SrcTuple>::type
  405. >::type>>,
  406. __not_<is_convertible<_SrcTuple, _Elements...>>,
  407. __not_<is_constructible<_Elements..., _SrcTuple>>
  408. >::value;
  409. }
  410. template<typename... _UElements>
  411. static constexpr bool _NotSameTuple()
  412. {
  413. return __not_<is_same<tuple<_Elements...>,
  414. typename remove_const<
  415. typename remove_reference<_UElements...>::type
  416. >::type>>::value;
  417. }
  418. };
  419. template<typename... _Elements>
  420. struct _TC<false, _Elements...>
  421. {
  422. template<typename... _UElements>
  423. static constexpr bool _ConstructibleTuple()
  424. {
  425. return false;
  426. }
  427. template<typename... _UElements>
  428. static constexpr bool _ImplicitlyConvertibleTuple()
  429. {
  430. return false;
  431. }
  432. template<typename... _UElements>
  433. static constexpr bool _MoveConstructibleTuple()
  434. {
  435. return false;
  436. }
  437. template<typename... _UElements>
  438. static constexpr bool _ImplicitlyMoveConvertibleTuple()
  439. {
  440. return false;
  441. }
  442. template<typename... _UElements>
  443. static constexpr bool _NonNestedTuple()
  444. {
  445. return true;
  446. }
  447. template<typename... _UElements>
  448. static constexpr bool _NotSameTuple()
  449. {
  450. return true;
  451. }
  452. };
  453. /// Primary class template, tuple
  454. template<typename... _Elements>
  455. class tuple : public _Tuple_impl<0, _Elements...>
  456. {
  457. typedef _Tuple_impl<0, _Elements...> _Inherited;
  458. // Used for constraining the default constructor so
  459. // that it becomes dependent on the constraints.
  460. template<typename _Dummy>
  461. struct _TC2
  462. {
  463. static constexpr bool _DefaultConstructibleTuple()
  464. {
  465. return __and_<is_default_constructible<_Elements>...>::value;
  466. }
  467. static constexpr bool _ImplicitlyDefaultConstructibleTuple()
  468. {
  469. return __and_<__is_implicitly_default_constructible<_Elements>...>
  470. ::value;
  471. }
  472. };
  473. public:
  474. template<typename _Dummy = void,
  475. typename enable_if<_TC2<_Dummy>::
  476. _ImplicitlyDefaultConstructibleTuple(),
  477. bool>::type = true>
  478. constexpr tuple()
  479. : _Inherited() { }
  480. template<typename _Dummy = void,
  481. typename enable_if<_TC2<_Dummy>::
  482. _DefaultConstructibleTuple()
  483. &&
  484. !_TC2<_Dummy>::
  485. _ImplicitlyDefaultConstructibleTuple(),
  486. bool>::type = false>
  487. explicit constexpr tuple()
  488. : _Inherited() { }
  489. // Shortcut for the cases where constructors taking _Elements...
  490. // need to be constrained.
  491. template<typename _Dummy> using _TCC =
  492. _TC<is_same<_Dummy, void>::value,
  493. _Elements...>;
  494. template<typename _Dummy = void,
  495. typename enable_if<
  496. _TCC<_Dummy>::template
  497. _ConstructibleTuple<_Elements...>()
  498. && _TCC<_Dummy>::template
  499. _ImplicitlyConvertibleTuple<_Elements...>()
  500. && (sizeof...(_Elements) >= 1),
  501. bool>::type=true>
  502. constexpr tuple(const _Elements&... __elements)
  503. : _Inherited(__elements...) { }
  504. template<typename _Dummy = void,
  505. typename enable_if<
  506. _TCC<_Dummy>::template
  507. _ConstructibleTuple<_Elements...>()
  508. && !_TCC<_Dummy>::template
  509. _ImplicitlyConvertibleTuple<_Elements...>()
  510. && (sizeof...(_Elements) >= 1),
  511. bool>::type=false>
  512. explicit constexpr tuple(const _Elements&... __elements)
  513. : _Inherited(__elements...) { }
  514. // Shortcut for the cases where constructors taking _UElements...
  515. // need to be constrained.
  516. template<typename... _UElements> using _TMC =
  517. _TC<(sizeof...(_Elements) == sizeof...(_UElements))
  518. && (_TC<(sizeof...(_UElements)==1), _Elements...>::
  519. template _NotSameTuple<_UElements...>()),
  520. _Elements...>;
  521. // Shortcut for the cases where constructors taking tuple<_UElements...>
  522. // need to be constrained.
  523. template<typename... _UElements> using _TMCT =
  524. _TC<(sizeof...(_Elements) == sizeof...(_UElements))
  525. && !is_same<tuple<_Elements...>,
  526. tuple<_UElements...>>::value,
  527. _Elements...>;
  528. template<typename... _UElements, typename
  529. enable_if<
  530. _TMC<_UElements...>::template
  531. _MoveConstructibleTuple<_UElements...>()
  532. && _TMC<_UElements...>::template
  533. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  534. && (sizeof...(_Elements) >= 1),
  535. bool>::type=true>
  536. constexpr tuple(_UElements&&... __elements)
  537. : _Inherited(std::forward<_UElements>(__elements)...) { }
  538. template<typename... _UElements, typename
  539. enable_if<
  540. _TMC<_UElements...>::template
  541. _MoveConstructibleTuple<_UElements...>()
  542. && !_TMC<_UElements...>::template
  543. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  544. && (sizeof...(_Elements) >= 1),
  545. bool>::type=false>
  546. explicit constexpr tuple(_UElements&&... __elements)
  547. : _Inherited(std::forward<_UElements>(__elements)...) { }
  548. constexpr tuple(const tuple&) = default;
  549. constexpr tuple(tuple&&) = default;
  550. // Shortcut for the cases where constructors taking tuples
  551. // must avoid creating temporaries.
  552. template<typename _Dummy> using _TNTC =
  553. _TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1,
  554. _Elements...>;
  555. template<typename... _UElements, typename _Dummy = void, typename
  556. enable_if<_TMCT<_UElements...>::template
  557. _ConstructibleTuple<_UElements...>()
  558. && _TMCT<_UElements...>::template
  559. _ImplicitlyConvertibleTuple<_UElements...>()
  560. && _TNTC<_Dummy>::template
  561. _NonNestedTuple<const tuple<_UElements...>&>(),
  562. bool>::type=true>
  563. constexpr tuple(const tuple<_UElements...>& __in)
  564. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  565. { }
  566. template<typename... _UElements, typename _Dummy = void, typename
  567. enable_if<_TMCT<_UElements...>::template
  568. _ConstructibleTuple<_UElements...>()
  569. && !_TMCT<_UElements...>::template
  570. _ImplicitlyConvertibleTuple<_UElements...>()
  571. && _TNTC<_Dummy>::template
  572. _NonNestedTuple<const tuple<_UElements...>&>(),
  573. bool>::type=false>
  574. explicit constexpr tuple(const tuple<_UElements...>& __in)
  575. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  576. { }
  577. template<typename... _UElements, typename _Dummy = void, typename
  578. enable_if<_TMCT<_UElements...>::template
  579. _MoveConstructibleTuple<_UElements...>()
  580. && _TMCT<_UElements...>::template
  581. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  582. && _TNTC<_Dummy>::template
  583. _NonNestedTuple<tuple<_UElements...>&&>(),
  584. bool>::type=true>
  585. constexpr tuple(tuple<_UElements...>&& __in)
  586. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
  587. template<typename... _UElements, typename _Dummy = void, typename
  588. enable_if<_TMCT<_UElements...>::template
  589. _MoveConstructibleTuple<_UElements...>()
  590. && !_TMCT<_UElements...>::template
  591. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  592. && _TNTC<_Dummy>::template
  593. _NonNestedTuple<tuple<_UElements...>&&>(),
  594. bool>::type=false>
  595. explicit constexpr tuple(tuple<_UElements...>&& __in)
  596. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
  597. // Allocator-extended constructors.
  598. template<typename _Alloc>
  599. tuple(allocator_arg_t __tag, const _Alloc& __a)
  600. : _Inherited(__tag, __a) { }
  601. template<typename _Alloc, typename _Dummy = void,
  602. typename enable_if<
  603. _TCC<_Dummy>::template
  604. _ConstructibleTuple<_Elements...>()
  605. && _TCC<_Dummy>::template
  606. _ImplicitlyConvertibleTuple<_Elements...>(),
  607. bool>::type=true>
  608. tuple(allocator_arg_t __tag, const _Alloc& __a,
  609. const _Elements&... __elements)
  610. : _Inherited(__tag, __a, __elements...) { }
  611. template<typename _Alloc, typename _Dummy = void,
  612. typename enable_if<
  613. _TCC<_Dummy>::template
  614. _ConstructibleTuple<_Elements...>()
  615. && !_TCC<_Dummy>::template
  616. _ImplicitlyConvertibleTuple<_Elements...>(),
  617. bool>::type=false>
  618. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  619. const _Elements&... __elements)
  620. : _Inherited(__tag, __a, __elements...) { }
  621. template<typename _Alloc, typename... _UElements, typename
  622. enable_if<_TMC<_UElements...>::template
  623. _MoveConstructibleTuple<_UElements...>()
  624. && _TMC<_UElements...>::template
  625. _ImplicitlyMoveConvertibleTuple<_UElements...>(),
  626. bool>::type=true>
  627. tuple(allocator_arg_t __tag, const _Alloc& __a,
  628. _UElements&&... __elements)
  629. : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
  630. { }
  631. template<typename _Alloc, typename... _UElements, typename
  632. enable_if<_TMC<_UElements...>::template
  633. _MoveConstructibleTuple<_UElements...>()
  634. && !_TMC<_UElements...>::template
  635. _ImplicitlyMoveConvertibleTuple<_UElements...>(),
  636. bool>::type=false>
  637. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  638. _UElements&&... __elements)
  639. : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
  640. { }
  641. template<typename _Alloc>
  642. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  643. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  644. template<typename _Alloc>
  645. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  646. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  647. template<typename _Alloc, typename _Dummy = void,
  648. typename... _UElements, typename
  649. enable_if<_TMCT<_UElements...>::template
  650. _ConstructibleTuple<_UElements...>()
  651. && _TMCT<_UElements...>::template
  652. _ImplicitlyConvertibleTuple<_UElements...>()
  653. && _TNTC<_Dummy>::template
  654. _NonNestedTuple<tuple<_UElements...>&&>(),
  655. bool>::type=true>
  656. tuple(allocator_arg_t __tag, const _Alloc& __a,
  657. const tuple<_UElements...>& __in)
  658. : _Inherited(__tag, __a,
  659. static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  660. { }
  661. template<typename _Alloc, typename _Dummy = void,
  662. typename... _UElements, typename
  663. enable_if<_TMCT<_UElements...>::template
  664. _ConstructibleTuple<_UElements...>()
  665. && !_TMCT<_UElements...>::template
  666. _ImplicitlyConvertibleTuple<_UElements...>()
  667. && _TNTC<_Dummy>::template
  668. _NonNestedTuple<tuple<_UElements...>&&>(),
  669. bool>::type=false>
  670. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  671. const tuple<_UElements...>& __in)
  672. : _Inherited(__tag, __a,
  673. static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  674. { }
  675. template<typename _Alloc, typename _Dummy = void,
  676. typename... _UElements, typename
  677. enable_if<_TMCT<_UElements...>::template
  678. _MoveConstructibleTuple<_UElements...>()
  679. && _TMCT<_UElements...>::template
  680. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  681. && _TNTC<_Dummy>::template
  682. _NonNestedTuple<tuple<_UElements...>&&>(),
  683. bool>::type=true>
  684. tuple(allocator_arg_t __tag, const _Alloc& __a,
  685. tuple<_UElements...>&& __in)
  686. : _Inherited(__tag, __a,
  687. static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
  688. { }
  689. template<typename _Alloc, typename _Dummy = void,
  690. typename... _UElements, typename
  691. enable_if<_TMCT<_UElements...>::template
  692. _MoveConstructibleTuple<_UElements...>()
  693. && !_TMCT<_UElements...>::template
  694. _ImplicitlyMoveConvertibleTuple<_UElements...>()
  695. && _TNTC<_Dummy>::template
  696. _NonNestedTuple<tuple<_UElements...>&&>(),
  697. bool>::type=false>
  698. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  699. tuple<_UElements...>&& __in)
  700. : _Inherited(__tag, __a,
  701. static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
  702. { }
  703. tuple&
  704. operator=(const tuple& __in)
  705. {
  706. static_cast<_Inherited&>(*this) = __in;
  707. return *this;
  708. }
  709. tuple&
  710. operator=(tuple&& __in)
  711. noexcept(is_nothrow_move_assignable<_Inherited>::value)
  712. {
  713. static_cast<_Inherited&>(*this) = std::move(__in);
  714. return *this;
  715. }
  716. template<typename... _UElements>
  717. typename
  718. enable_if<sizeof...(_UElements)
  719. == sizeof...(_Elements), tuple&>::type
  720. operator=(const tuple<_UElements...>& __in)
  721. {
  722. static_cast<_Inherited&>(*this) = __in;
  723. return *this;
  724. }
  725. template<typename... _UElements>
  726. typename
  727. enable_if<sizeof...(_UElements)
  728. == sizeof...(_Elements), tuple&>::type
  729. operator=(tuple<_UElements...>&& __in)
  730. {
  731. static_cast<_Inherited&>(*this) = std::move(__in);
  732. return *this;
  733. }
  734. void
  735. swap(tuple& __in)
  736. noexcept(noexcept(__in._M_swap(__in)))
  737. { _Inherited::_M_swap(__in); }
  738. };
  739. #if __cpp_deduction_guides >= 201606
  740. template<typename... _UTypes>
  741. tuple(_UTypes...) -> tuple<_UTypes...>;
  742. template<typename _T1, typename _T2>
  743. tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
  744. template<typename _Alloc, typename... _UTypes>
  745. tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
  746. template<typename _Alloc, typename _T1, typename _T2>
  747. tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
  748. template<typename _Alloc, typename... _UTypes>
  749. tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
  750. #endif
  751. // Explicit specialization, zero-element tuple.
  752. template<>
  753. class tuple<>
  754. {
  755. public:
  756. void swap(tuple&) noexcept { /* no-op */ }
  757. // We need the default since we're going to define no-op
  758. // allocator constructors.
  759. tuple() = default;
  760. // No-op allocator constructors.
  761. template<typename _Alloc>
  762. tuple(allocator_arg_t, const _Alloc&) { }
  763. template<typename _Alloc>
  764. tuple(allocator_arg_t, const _Alloc&, const tuple&) { }
  765. };
  766. /// Partial specialization, 2-element tuple.
  767. /// Includes construction and assignment from a pair.
  768. template<typename _T1, typename _T2>
  769. class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
  770. {
  771. typedef _Tuple_impl<0, _T1, _T2> _Inherited;
  772. public:
  773. template <typename _U1 = _T1,
  774. typename _U2 = _T2,
  775. typename enable_if<__and_<
  776. __is_implicitly_default_constructible<_U1>,
  777. __is_implicitly_default_constructible<_U2>>
  778. ::value, bool>::type = true>
  779. constexpr tuple()
  780. : _Inherited() { }
  781. template <typename _U1 = _T1,
  782. typename _U2 = _T2,
  783. typename enable_if<
  784. __and_<
  785. is_default_constructible<_U1>,
  786. is_default_constructible<_U2>,
  787. __not_<
  788. __and_<__is_implicitly_default_constructible<_U1>,
  789. __is_implicitly_default_constructible<_U2>>>>
  790. ::value, bool>::type = false>
  791. explicit constexpr tuple()
  792. : _Inherited() { }
  793. // Shortcut for the cases where constructors taking _T1, _T2
  794. // need to be constrained.
  795. template<typename _Dummy> using _TCC =
  796. _TC<is_same<_Dummy, void>::value, _T1, _T2>;
  797. template<typename _Dummy = void, typename
  798. enable_if<_TCC<_Dummy>::template
  799. _ConstructibleTuple<_T1, _T2>()
  800. && _TCC<_Dummy>::template
  801. _ImplicitlyConvertibleTuple<_T1, _T2>(),
  802. bool>::type = true>
  803. constexpr tuple(const _T1& __a1, const _T2& __a2)
  804. : _Inherited(__a1, __a2) { }
  805. template<typename _Dummy = void, typename
  806. enable_if<_TCC<_Dummy>::template
  807. _ConstructibleTuple<_T1, _T2>()
  808. && !_TCC<_Dummy>::template
  809. _ImplicitlyConvertibleTuple<_T1, _T2>(),
  810. bool>::type = false>
  811. explicit constexpr tuple(const _T1& __a1, const _T2& __a2)
  812. : _Inherited(__a1, __a2) { }
  813. // Shortcut for the cases where constructors taking _U1, _U2
  814. // need to be constrained.
  815. using _TMC = _TC<true, _T1, _T2>;
  816. template<typename _U1, typename _U2, typename
  817. enable_if<_TMC::template
  818. _MoveConstructibleTuple<_U1, _U2>()
  819. && _TMC::template
  820. _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
  821. && !is_same<typename decay<_U1>::type,
  822. allocator_arg_t>::value,
  823. bool>::type = true>
  824. constexpr tuple(_U1&& __a1, _U2&& __a2)
  825. : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
  826. template<typename _U1, typename _U2, typename
  827. enable_if<_TMC::template
  828. _MoveConstructibleTuple<_U1, _U2>()
  829. && !_TMC::template
  830. _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
  831. && !is_same<typename decay<_U1>::type,
  832. allocator_arg_t>::value,
  833. bool>::type = false>
  834. explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
  835. : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
  836. constexpr tuple(const tuple&) = default;
  837. constexpr tuple(tuple&&) = default;
  838. template<typename _U1, typename _U2, typename
  839. enable_if<_TMC::template
  840. _ConstructibleTuple<_U1, _U2>()
  841. && _TMC::template
  842. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  843. bool>::type = true>
  844. constexpr tuple(const tuple<_U1, _U2>& __in)
  845. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
  846. template<typename _U1, typename _U2, typename
  847. enable_if<_TMC::template
  848. _ConstructibleTuple<_U1, _U2>()
  849. && !_TMC::template
  850. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  851. bool>::type = false>
  852. explicit constexpr tuple(const tuple<_U1, _U2>& __in)
  853. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
  854. template<typename _U1, typename _U2, typename
  855. enable_if<_TMC::template
  856. _MoveConstructibleTuple<_U1, _U2>()
  857. && _TMC::template
  858. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  859. bool>::type = true>
  860. constexpr tuple(tuple<_U1, _U2>&& __in)
  861. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  862. template<typename _U1, typename _U2, typename
  863. enable_if<_TMC::template
  864. _MoveConstructibleTuple<_U1, _U2>()
  865. && !_TMC::template
  866. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  867. bool>::type = false>
  868. explicit constexpr tuple(tuple<_U1, _U2>&& __in)
  869. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  870. template<typename _U1, typename _U2, typename
  871. enable_if<_TMC::template
  872. _ConstructibleTuple<_U1, _U2>()
  873. && _TMC::template
  874. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  875. bool>::type = true>
  876. constexpr tuple(const pair<_U1, _U2>& __in)
  877. : _Inherited(__in.first, __in.second) { }
  878. template<typename _U1, typename _U2, typename
  879. enable_if<_TMC::template
  880. _ConstructibleTuple<_U1, _U2>()
  881. && !_TMC::template
  882. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  883. bool>::type = false>
  884. explicit constexpr tuple(const pair<_U1, _U2>& __in)
  885. : _Inherited(__in.first, __in.second) { }
  886. template<typename _U1, typename _U2, typename
  887. enable_if<_TMC::template
  888. _MoveConstructibleTuple<_U1, _U2>()
  889. && _TMC::template
  890. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  891. bool>::type = true>
  892. constexpr tuple(pair<_U1, _U2>&& __in)
  893. : _Inherited(std::forward<_U1>(__in.first),
  894. std::forward<_U2>(__in.second)) { }
  895. template<typename _U1, typename _U2, typename
  896. enable_if<_TMC::template
  897. _MoveConstructibleTuple<_U1, _U2>()
  898. && !_TMC::template
  899. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  900. bool>::type = false>
  901. explicit constexpr tuple(pair<_U1, _U2>&& __in)
  902. : _Inherited(std::forward<_U1>(__in.first),
  903. std::forward<_U2>(__in.second)) { }
  904. // Allocator-extended constructors.
  905. template<typename _Alloc>
  906. tuple(allocator_arg_t __tag, const _Alloc& __a)
  907. : _Inherited(__tag, __a) { }
  908. template<typename _Alloc, typename _Dummy = void,
  909. typename enable_if<
  910. _TCC<_Dummy>::template
  911. _ConstructibleTuple<_T1, _T2>()
  912. && _TCC<_Dummy>::template
  913. _ImplicitlyConvertibleTuple<_T1, _T2>(),
  914. bool>::type=true>
  915. tuple(allocator_arg_t __tag, const _Alloc& __a,
  916. const _T1& __a1, const _T2& __a2)
  917. : _Inherited(__tag, __a, __a1, __a2) { }
  918. template<typename _Alloc, typename _Dummy = void,
  919. typename enable_if<
  920. _TCC<_Dummy>::template
  921. _ConstructibleTuple<_T1, _T2>()
  922. && !_TCC<_Dummy>::template
  923. _ImplicitlyConvertibleTuple<_T1, _T2>(),
  924. bool>::type=false>
  925. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  926. const _T1& __a1, const _T2& __a2)
  927. : _Inherited(__tag, __a, __a1, __a2) { }
  928. template<typename _Alloc, typename _U1, typename _U2, typename
  929. enable_if<_TMC::template
  930. _MoveConstructibleTuple<_U1, _U2>()
  931. && _TMC::template
  932. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  933. bool>::type = true>
  934. tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
  935. : _Inherited(__tag, __a, std::forward<_U1>(__a1),
  936. std::forward<_U2>(__a2)) { }
  937. template<typename _Alloc, typename _U1, typename _U2, typename
  938. enable_if<_TMC::template
  939. _MoveConstructibleTuple<_U1, _U2>()
  940. && !_TMC::template
  941. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  942. bool>::type = false>
  943. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  944. _U1&& __a1, _U2&& __a2)
  945. : _Inherited(__tag, __a, std::forward<_U1>(__a1),
  946. std::forward<_U2>(__a2)) { }
  947. template<typename _Alloc>
  948. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  949. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  950. template<typename _Alloc>
  951. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  952. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  953. template<typename _Alloc, typename _U1, typename _U2, typename
  954. enable_if<_TMC::template
  955. _ConstructibleTuple<_U1, _U2>()
  956. && _TMC::template
  957. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  958. bool>::type = true>
  959. tuple(allocator_arg_t __tag, const _Alloc& __a,
  960. const tuple<_U1, _U2>& __in)
  961. : _Inherited(__tag, __a,
  962. static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
  963. { }
  964. template<typename _Alloc, typename _U1, typename _U2, typename
  965. enable_if<_TMC::template
  966. _ConstructibleTuple<_U1, _U2>()
  967. && !_TMC::template
  968. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  969. bool>::type = false>
  970. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  971. const tuple<_U1, _U2>& __in)
  972. : _Inherited(__tag, __a,
  973. static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
  974. { }
  975. template<typename _Alloc, typename _U1, typename _U2, typename
  976. enable_if<_TMC::template
  977. _MoveConstructibleTuple<_U1, _U2>()
  978. && _TMC::template
  979. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  980. bool>::type = true>
  981. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
  982. : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
  983. { }
  984. template<typename _Alloc, typename _U1, typename _U2, typename
  985. enable_if<_TMC::template
  986. _MoveConstructibleTuple<_U1, _U2>()
  987. && !_TMC::template
  988. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  989. bool>::type = false>
  990. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  991. tuple<_U1, _U2>&& __in)
  992. : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
  993. { }
  994. template<typename _Alloc, typename _U1, typename _U2, typename
  995. enable_if<_TMC::template
  996. _ConstructibleTuple<_U1, _U2>()
  997. && _TMC::template
  998. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  999. bool>::type = true>
  1000. tuple(allocator_arg_t __tag, const _Alloc& __a,
  1001. const pair<_U1, _U2>& __in)
  1002. : _Inherited(__tag, __a, __in.first, __in.second) { }
  1003. template<typename _Alloc, typename _U1, typename _U2, typename
  1004. enable_if<_TMC::template
  1005. _ConstructibleTuple<_U1, _U2>()
  1006. && !_TMC::template
  1007. _ImplicitlyConvertibleTuple<_U1, _U2>(),
  1008. bool>::type = false>
  1009. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  1010. const pair<_U1, _U2>& __in)
  1011. : _Inherited(__tag, __a, __in.first, __in.second) { }
  1012. template<typename _Alloc, typename _U1, typename _U2, typename
  1013. enable_if<_TMC::template
  1014. _MoveConstructibleTuple<_U1, _U2>()
  1015. && _TMC::template
  1016. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  1017. bool>::type = true>
  1018. tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
  1019. : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
  1020. std::forward<_U2>(__in.second)) { }
  1021. template<typename _Alloc, typename _U1, typename _U2, typename
  1022. enable_if<_TMC::template
  1023. _MoveConstructibleTuple<_U1, _U2>()
  1024. && !_TMC::template
  1025. _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
  1026. bool>::type = false>
  1027. explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
  1028. pair<_U1, _U2>&& __in)
  1029. : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
  1030. std::forward<_U2>(__in.second)) { }
  1031. tuple&
  1032. operator=(const tuple& __in)
  1033. {
  1034. static_cast<_Inherited&>(*this) = __in;
  1035. return *this;
  1036. }
  1037. tuple&
  1038. operator=(tuple&& __in)
  1039. noexcept(is_nothrow_move_assignable<_Inherited>::value)
  1040. {
  1041. static_cast<_Inherited&>(*this) = std::move(__in);
  1042. return *this;
  1043. }
  1044. template<typename _U1, typename _U2>
  1045. tuple&
  1046. operator=(const tuple<_U1, _U2>& __in)
  1047. {
  1048. static_cast<_Inherited&>(*this) = __in;
  1049. return *this;
  1050. }
  1051. template<typename _U1, typename _U2>
  1052. tuple&
  1053. operator=(tuple<_U1, _U2>&& __in)
  1054. {
  1055. static_cast<_Inherited&>(*this) = std::move(__in);
  1056. return *this;
  1057. }
  1058. template<typename _U1, typename _U2>
  1059. tuple&
  1060. operator=(const pair<_U1, _U2>& __in)
  1061. {
  1062. this->_M_head(*this) = __in.first;
  1063. this->_M_tail(*this)._M_head(*this) = __in.second;
  1064. return *this;
  1065. }
  1066. template<typename _U1, typename _U2>
  1067. tuple&
  1068. operator=(pair<_U1, _U2>&& __in)
  1069. {
  1070. this->_M_head(*this) = std::forward<_U1>(__in.first);
  1071. this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
  1072. return *this;
  1073. }
  1074. void
  1075. swap(tuple& __in)
  1076. noexcept(noexcept(__in._M_swap(__in)))
  1077. { _Inherited::_M_swap(__in); }
  1078. };
  1079. /// class tuple_size
  1080. template<typename... _Elements>
  1081. struct tuple_size<tuple<_Elements...>>
  1082. : public integral_constant<std::size_t, sizeof...(_Elements)> { };
  1083. #if __cplusplus > 201402L
  1084. template <typename _Tp>
  1085. inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
  1086. #endif
  1087. /**
  1088. * Recursive case for tuple_element: strip off the first element in
  1089. * the tuple and retrieve the (i-1)th element of the remaining tuple.
  1090. */
  1091. template<std::size_t __i, typename _Head, typename... _Tail>
  1092. struct tuple_element<__i, tuple<_Head, _Tail...> >
  1093. : tuple_element<__i - 1, tuple<_Tail...> > { };
  1094. /**
  1095. * Basis case for tuple_element: The first element is the one we're seeking.
  1096. */
  1097. template<typename _Head, typename... _Tail>
  1098. struct tuple_element<0, tuple<_Head, _Tail...> >
  1099. {
  1100. typedef _Head type;
  1101. };
  1102. /**
  1103. * Error case for tuple_element: invalid index.
  1104. */
  1105. template<size_t __i>
  1106. struct tuple_element<__i, tuple<>>
  1107. {
  1108. static_assert(__i < tuple_size<tuple<>>::value,
  1109. "tuple index is in range");
  1110. };
  1111. template<std::size_t __i, typename _Head, typename... _Tail>
  1112. constexpr _Head&
  1113. __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1114. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1115. template<std::size_t __i, typename _Head, typename... _Tail>
  1116. constexpr const _Head&
  1117. __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1118. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1119. /// Return a reference to the ith element of a tuple.
  1120. template<std::size_t __i, typename... _Elements>
  1121. constexpr __tuple_element_t<__i, tuple<_Elements...>>&
  1122. get(tuple<_Elements...>& __t) noexcept
  1123. { return std::__get_helper<__i>(__t); }
  1124. /// Return a const reference to the ith element of a const tuple.
  1125. template<std::size_t __i, typename... _Elements>
  1126. constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
  1127. get(const tuple<_Elements...>& __t) noexcept
  1128. { return std::__get_helper<__i>(__t); }
  1129. /// Return an rvalue reference to the ith element of a tuple rvalue.
  1130. template<std::size_t __i, typename... _Elements>
  1131. constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
  1132. get(tuple<_Elements...>&& __t) noexcept
  1133. {
  1134. typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
  1135. return std::forward<__element_type&&>(std::get<__i>(__t));
  1136. }
  1137. /// Return a const rvalue reference to the ith element of a const tuple rvalue.
  1138. template<std::size_t __i, typename... _Elements>
  1139. constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
  1140. get(const tuple<_Elements...>&& __t) noexcept
  1141. {
  1142. typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
  1143. return std::forward<const __element_type&&>(std::get<__i>(__t));
  1144. }
  1145. #if __cplusplus > 201103L
  1146. #define __cpp_lib_tuples_by_type 201304
  1147. template<typename _Head, size_t __i, typename... _Tail>
  1148. constexpr _Head&
  1149. __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1150. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1151. template<typename _Head, size_t __i, typename... _Tail>
  1152. constexpr const _Head&
  1153. __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  1154. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  1155. /// Return a reference to the unique element of type _Tp of a tuple.
  1156. template <typename _Tp, typename... _Types>
  1157. constexpr _Tp&
  1158. get(tuple<_Types...>& __t) noexcept
  1159. { return std::__get_helper2<_Tp>(__t); }
  1160. /// Return a reference to the unique element of type _Tp of a tuple rvalue.
  1161. template <typename _Tp, typename... _Types>
  1162. constexpr _Tp&&
  1163. get(tuple<_Types...>&& __t) noexcept
  1164. { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
  1165. /// Return a const reference to the unique element of type _Tp of a tuple.
  1166. template <typename _Tp, typename... _Types>
  1167. constexpr const _Tp&
  1168. get(const tuple<_Types...>& __t) noexcept
  1169. { return std::__get_helper2<_Tp>(__t); }
  1170. /// Return a const reference to the unique element of type _Tp of
  1171. /// a const tuple rvalue.
  1172. template <typename _Tp, typename... _Types>
  1173. constexpr const _Tp&&
  1174. get(const tuple<_Types...>&& __t) noexcept
  1175. { return std::forward<const _Tp&&>(std::__get_helper2<_Tp>(__t)); }
  1176. #endif
  1177. // This class performs the comparison operations on tuples
  1178. template<typename _Tp, typename _Up, size_t __i, size_t __size>
  1179. struct __tuple_compare
  1180. {
  1181. static constexpr bool
  1182. __eq(const _Tp& __t, const _Up& __u)
  1183. {
  1184. return bool(std::get<__i>(__t) == std::get<__i>(__u))
  1185. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
  1186. }
  1187. static constexpr bool
  1188. __less(const _Tp& __t, const _Up& __u)
  1189. {
  1190. return bool(std::get<__i>(__t) < std::get<__i>(__u))
  1191. || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
  1192. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
  1193. }
  1194. };
  1195. template<typename _Tp, typename _Up, size_t __size>
  1196. struct __tuple_compare<_Tp, _Up, __size, __size>
  1197. {
  1198. static constexpr bool
  1199. __eq(const _Tp&, const _Up&) { return true; }
  1200. static constexpr bool
  1201. __less(const _Tp&, const _Up&) { return false; }
  1202. };
  1203. template<typename... _TElements, typename... _UElements>
  1204. constexpr bool
  1205. operator==(const tuple<_TElements...>& __t,
  1206. const tuple<_UElements...>& __u)
  1207. {
  1208. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  1209. "tuple objects can only be compared if they have equal sizes.");
  1210. using __compare = __tuple_compare<tuple<_TElements...>,
  1211. tuple<_UElements...>,
  1212. 0, sizeof...(_TElements)>;
  1213. return __compare::__eq(__t, __u);
  1214. }
  1215. template<typename... _TElements, typename... _UElements>
  1216. constexpr bool
  1217. operator<(const tuple<_TElements...>& __t,
  1218. const tuple<_UElements...>& __u)
  1219. {
  1220. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  1221. "tuple objects can only be compared if they have equal sizes.");
  1222. using __compare = __tuple_compare<tuple<_TElements...>,
  1223. tuple<_UElements...>,
  1224. 0, sizeof...(_TElements)>;
  1225. return __compare::__less(__t, __u);
  1226. }
  1227. template<typename... _TElements, typename... _UElements>
  1228. constexpr bool
  1229. operator!=(const tuple<_TElements...>& __t,
  1230. const tuple<_UElements...>& __u)
  1231. { return !(__t == __u); }
  1232. template<typename... _TElements, typename... _UElements>
  1233. constexpr bool
  1234. operator>(const tuple<_TElements...>& __t,
  1235. const tuple<_UElements...>& __u)
  1236. { return __u < __t; }
  1237. template<typename... _TElements, typename... _UElements>
  1238. constexpr bool
  1239. operator<=(const tuple<_TElements...>& __t,
  1240. const tuple<_UElements...>& __u)
  1241. { return !(__u < __t); }
  1242. template<typename... _TElements, typename... _UElements>
  1243. constexpr bool
  1244. operator>=(const tuple<_TElements...>& __t,
  1245. const tuple<_UElements...>& __u)
  1246. { return !(__t < __u); }
  1247. // NB: DR 705.
  1248. template<typename... _Elements>
  1249. constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
  1250. make_tuple(_Elements&&... __args)
  1251. {
  1252. typedef tuple<typename __decay_and_strip<_Elements>::__type...>
  1253. __result_type;
  1254. return __result_type(std::forward<_Elements>(__args)...);
  1255. }
  1256. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1257. // 2275. Why is forward_as_tuple not constexpr?
  1258. template<typename... _Elements>
  1259. constexpr tuple<_Elements&&...>
  1260. forward_as_tuple(_Elements&&... __args) noexcept
  1261. { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
  1262. template<size_t, typename, typename, size_t>
  1263. struct __make_tuple_impl;
  1264. template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
  1265. struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
  1266. : __make_tuple_impl<_Idx + 1,
  1267. tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
  1268. _Tuple, _Nm>
  1269. { };
  1270. template<std::size_t _Nm, typename _Tuple, typename... _Tp>
  1271. struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
  1272. {
  1273. typedef tuple<_Tp...> __type;
  1274. };
  1275. template<typename _Tuple>
  1276. struct __do_make_tuple
  1277. : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
  1278. { };
  1279. // Returns the std::tuple equivalent of a tuple-like type.
  1280. template<typename _Tuple>
  1281. struct __make_tuple
  1282. : public __do_make_tuple<typename std::remove_cv
  1283. <typename std::remove_reference<_Tuple>::type>::type>
  1284. { };
  1285. // Combines several std::tuple's into a single one.
  1286. template<typename...>
  1287. struct __combine_tuples;
  1288. template<>
  1289. struct __combine_tuples<>
  1290. {
  1291. typedef tuple<> __type;
  1292. };
  1293. template<typename... _Ts>
  1294. struct __combine_tuples<tuple<_Ts...>>
  1295. {
  1296. typedef tuple<_Ts...> __type;
  1297. };
  1298. template<typename... _T1s, typename... _T2s, typename... _Rem>
  1299. struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
  1300. {
  1301. typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
  1302. _Rem...>::__type __type;
  1303. };
  1304. // Computes the result type of tuple_cat given a set of tuple-like types.
  1305. template<typename... _Tpls>
  1306. struct __tuple_cat_result
  1307. {
  1308. typedef typename __combine_tuples
  1309. <typename __make_tuple<_Tpls>::__type...>::__type __type;
  1310. };
  1311. // Helper to determine the index set for the first tuple-like
  1312. // type of a given set.
  1313. template<typename...>
  1314. struct __make_1st_indices;
  1315. template<>
  1316. struct __make_1st_indices<>
  1317. {
  1318. typedef std::_Index_tuple<> __type;
  1319. };
  1320. template<typename _Tp, typename... _Tpls>
  1321. struct __make_1st_indices<_Tp, _Tpls...>
  1322. {
  1323. typedef typename std::_Build_index_tuple<std::tuple_size<
  1324. typename std::remove_reference<_Tp>::type>::value>::__type __type;
  1325. };
  1326. // Performs the actual concatenation by step-wise expanding tuple-like
  1327. // objects into the elements, which are finally forwarded into the
  1328. // result tuple.
  1329. template<typename _Ret, typename _Indices, typename... _Tpls>
  1330. struct __tuple_concater;
  1331. template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
  1332. struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
  1333. {
  1334. template<typename... _Us>
  1335. static constexpr _Ret
  1336. _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
  1337. {
  1338. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  1339. typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
  1340. return __next::_S_do(std::forward<_Tpls>(__tps)...,
  1341. std::forward<_Us>(__us)...,
  1342. std::get<_Is>(std::forward<_Tp>(__tp))...);
  1343. }
  1344. };
  1345. template<typename _Ret>
  1346. struct __tuple_concater<_Ret, std::_Index_tuple<>>
  1347. {
  1348. template<typename... _Us>
  1349. static constexpr _Ret
  1350. _S_do(_Us&&... __us)
  1351. {
  1352. return _Ret(std::forward<_Us>(__us)...);
  1353. }
  1354. };
  1355. /// tuple_cat
  1356. template<typename... _Tpls, typename = typename
  1357. enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
  1358. constexpr auto
  1359. tuple_cat(_Tpls&&... __tpls)
  1360. -> typename __tuple_cat_result<_Tpls...>::__type
  1361. {
  1362. typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
  1363. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  1364. typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
  1365. return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
  1366. }
  1367. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1368. // 2301. Why is tie not constexpr?
  1369. /// tie
  1370. template<typename... _Elements>
  1371. constexpr tuple<_Elements&...>
  1372. tie(_Elements&... __args) noexcept
  1373. { return tuple<_Elements&...>(__args...); }
  1374. /// swap
  1375. template<typename... _Elements>
  1376. inline
  1377. #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
  1378. // Constrained free swap overload, see p0185r1
  1379. typename enable_if<__and_<__is_swappable<_Elements>...>::value
  1380. >::type
  1381. #else
  1382. void
  1383. #endif
  1384. swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
  1385. noexcept(noexcept(__x.swap(__y)))
  1386. { __x.swap(__y); }
  1387. #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
  1388. template<typename... _Elements>
  1389. typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
  1390. swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
  1391. #endif
  1392. // A class (and instance) which can be used in 'tie' when an element
  1393. // of a tuple is not required.
  1394. // _GLIBCXX14_CONSTEXPR
  1395. // 2933. PR for LWG 2773 could be clearer
  1396. struct _Swallow_assign
  1397. {
  1398. template<class _Tp>
  1399. _GLIBCXX14_CONSTEXPR const _Swallow_assign&
  1400. operator=(const _Tp&) const
  1401. { return *this; }
  1402. };
  1403. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  1404. // 2773. Making std::ignore constexpr
  1405. _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
  1406. /// Partial specialization for tuples
  1407. template<typename... _Types, typename _Alloc>
  1408. struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
  1409. // See stl_pair.h...
  1410. template<class _T1, class _T2>
  1411. template<typename... _Args1, typename... _Args2>
  1412. inline
  1413. pair<_T1, _T2>::
  1414. pair(piecewise_construct_t,
  1415. tuple<_Args1...> __first, tuple<_Args2...> __second)
  1416. : pair(__first, __second,
  1417. typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
  1418. typename _Build_index_tuple<sizeof...(_Args2)>::__type())
  1419. { }
  1420. template<class _T1, class _T2>
  1421. template<typename... _Args1, std::size_t... _Indexes1,
  1422. typename... _Args2, std::size_t... _Indexes2>
  1423. inline
  1424. pair<_T1, _T2>::
  1425. pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
  1426. _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
  1427. : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
  1428. second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
  1429. { }
  1430. #if __cplusplus > 201402L
  1431. # define __cpp_lib_apply 201603
  1432. template <typename _Fn, typename _Tuple, size_t... _Idx>
  1433. constexpr decltype(auto)
  1434. __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
  1435. {
  1436. return std::__invoke(std::forward<_Fn>(__f),
  1437. std::get<_Idx>(std::forward<_Tuple>(__t))...);
  1438. }
  1439. template <typename _Fn, typename _Tuple>
  1440. constexpr decltype(auto)
  1441. apply(_Fn&& __f, _Tuple&& __t)
  1442. {
  1443. using _Indices = make_index_sequence<tuple_size_v<decay_t<_Tuple>>>;
  1444. return std::__apply_impl(std::forward<_Fn>(__f),
  1445. std::forward<_Tuple>(__t),
  1446. _Indices{});
  1447. }
  1448. #define __cpp_lib_make_from_tuple 201606
  1449. template <typename _Tp, typename _Tuple, size_t... _Idx>
  1450. constexpr _Tp
  1451. __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
  1452. { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
  1453. template <typename _Tp, typename _Tuple>
  1454. constexpr _Tp
  1455. make_from_tuple(_Tuple&& __t)
  1456. {
  1457. return __make_from_tuple_impl<_Tp>(
  1458. std::forward<_Tuple>(__t),
  1459. make_index_sequence<tuple_size_v<decay_t<_Tuple>>>{});
  1460. }
  1461. #endif // C++17
  1462. /// @}
  1463. _GLIBCXX_END_NAMESPACE_VERSION
  1464. } // namespace std
  1465. #endif // C++11
  1466. #endif // _GLIBCXX_TUPLE