tuple 59 KB

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