tuple 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. // <tuple> -*- C++ -*-
  2. // Copyright (C) 2007-2015 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. namespace std _GLIBCXX_VISIBILITY(default)
  33. {
  34. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  35. /**
  36. * @addtogroup utilities
  37. * @{
  38. */
  39. template<std::size_t _Idx, typename _Head, bool _IsEmptyNotFinal>
  40. struct _Head_base;
  41. template<std::size_t _Idx, typename _Head>
  42. struct _Head_base<_Idx, _Head, true>
  43. : public _Head
  44. {
  45. constexpr _Head_base()
  46. : _Head() { }
  47. constexpr _Head_base(const _Head& __h)
  48. : _Head(__h) { }
  49. constexpr _Head_base(const _Head_base&) = default;
  50. constexpr _Head_base(_Head_base&&) = default;
  51. template<typename _UHead>
  52. constexpr _Head_base(_UHead&& __h)
  53. : _Head(std::forward<_UHead>(__h)) { }
  54. _Head_base(allocator_arg_t, __uses_alloc0)
  55. : _Head() { }
  56. template<typename _Alloc>
  57. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  58. : _Head(allocator_arg, *__a._M_a) { }
  59. template<typename _Alloc>
  60. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  61. : _Head(*__a._M_a) { }
  62. template<typename _UHead>
  63. _Head_base(__uses_alloc0, _UHead&& __uhead)
  64. : _Head(std::forward<_UHead>(__uhead)) { }
  65. template<typename _Alloc, typename _UHead>
  66. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  67. : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
  68. template<typename _Alloc, typename _UHead>
  69. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  70. : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
  71. static constexpr _Head&
  72. _M_head(_Head_base& __b) noexcept { return __b; }
  73. static constexpr const _Head&
  74. _M_head(const _Head_base& __b) noexcept { return __b; }
  75. };
  76. template<std::size_t _Idx, typename _Head>
  77. struct _Head_base<_Idx, _Head, false>
  78. {
  79. constexpr _Head_base()
  80. : _M_head_impl() { }
  81. constexpr _Head_base(const _Head& __h)
  82. : _M_head_impl(__h) { }
  83. constexpr _Head_base(const _Head_base&) = default;
  84. constexpr _Head_base(_Head_base&&) = default;
  85. template<typename _UHead>
  86. constexpr _Head_base(_UHead&& __h)
  87. : _M_head_impl(std::forward<_UHead>(__h)) { }
  88. _Head_base(allocator_arg_t, __uses_alloc0)
  89. : _M_head_impl() { }
  90. template<typename _Alloc>
  91. _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
  92. : _M_head_impl(allocator_arg, *__a._M_a) { }
  93. template<typename _Alloc>
  94. _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
  95. : _M_head_impl(*__a._M_a) { }
  96. template<typename _UHead>
  97. _Head_base(__uses_alloc0, _UHead&& __uhead)
  98. : _M_head_impl(std::forward<_UHead>(__uhead)) { }
  99. template<typename _Alloc, typename _UHead>
  100. _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
  101. : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
  102. { }
  103. template<typename _Alloc, typename _UHead>
  104. _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
  105. : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
  106. static constexpr _Head&
  107. _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
  108. static constexpr const _Head&
  109. _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
  110. _Head _M_head_impl;
  111. };
  112. /**
  113. * Contains the actual implementation of the @c tuple template, stored
  114. * as a recursive inheritance hierarchy from the first element (most
  115. * derived class) to the last (least derived class). The @c Idx
  116. * parameter gives the 0-based index of the element stored at this
  117. * point in the hierarchy; we use it to implement a constant-time
  118. * get() operation.
  119. */
  120. template<std::size_t _Idx, typename... _Elements>
  121. struct _Tuple_impl;
  122. template<typename _Tp>
  123. struct __is_empty_non_tuple : is_empty<_Tp> { };
  124. // Using EBO for elements that are tuples causes ambiguous base errors.
  125. template<typename _El0, typename... _El>
  126. struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
  127. // Use the Empty Base-class Optimization for empty, non-final types.
  128. template<typename _Tp>
  129. using __empty_not_final
  130. = typename conditional<__is_final(_Tp), false_type,
  131. __is_empty_non_tuple<_Tp>>::type;
  132. /**
  133. * Recursive tuple implementation. Here we store the @c Head element
  134. * and derive from a @c Tuple_impl containing the remaining elements
  135. * (which contains the @c Tail).
  136. */
  137. template<std::size_t _Idx, typename _Head, typename... _Tail>
  138. struct _Tuple_impl<_Idx, _Head, _Tail...>
  139. : public _Tuple_impl<_Idx + 1, _Tail...>,
  140. private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
  141. {
  142. template<std::size_t, typename...> friend class _Tuple_impl;
  143. typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
  144. typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
  145. static constexpr _Head&
  146. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  147. static constexpr const _Head&
  148. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  149. static constexpr _Inherited&
  150. _M_tail(_Tuple_impl& __t) noexcept { return __t; }
  151. static constexpr const _Inherited&
  152. _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
  153. constexpr _Tuple_impl()
  154. : _Inherited(), _Base() { }
  155. explicit
  156. constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
  157. : _Inherited(__tail...), _Base(__head) { }
  158. template<typename _UHead, typename... _UTail, typename = typename
  159. enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
  160. explicit
  161. constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
  162. : _Inherited(std::forward<_UTail>(__tail)...),
  163. _Base(std::forward<_UHead>(__head)) { }
  164. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  165. constexpr
  166. _Tuple_impl(_Tuple_impl&& __in)
  167. noexcept(__and_<is_nothrow_move_constructible<_Head>,
  168. is_nothrow_move_constructible<_Inherited>>::value)
  169. : _Inherited(std::move(_M_tail(__in))),
  170. _Base(std::forward<_Head>(_M_head(__in))) { }
  171. template<typename... _UElements>
  172. constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
  173. : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  174. _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
  175. template<typename _UHead, typename... _UTails>
  176. constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  177. : _Inherited(std::move
  178. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  179. _Base(std::forward<_UHead>
  180. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
  181. template<typename _Alloc>
  182. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  183. : _Inherited(__tag, __a),
  184. _Base(__tag, __use_alloc<_Head>(__a)) { }
  185. template<typename _Alloc>
  186. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  187. const _Head& __head, const _Tail&... __tail)
  188. : _Inherited(__tag, __a, __tail...),
  189. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
  190. template<typename _Alloc, typename _UHead, typename... _UTail,
  191. typename = typename enable_if<sizeof...(_Tail)
  192. == sizeof...(_UTail)>::type>
  193. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  194. _UHead&& __head, _UTail&&... __tail)
  195. : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
  196. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  197. std::forward<_UHead>(__head)) { }
  198. template<typename _Alloc>
  199. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  200. const _Tuple_impl& __in)
  201. : _Inherited(__tag, __a, _M_tail(__in)),
  202. _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
  203. template<typename _Alloc>
  204. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  205. _Tuple_impl&& __in)
  206. : _Inherited(__tag, __a, std::move(_M_tail(__in))),
  207. _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  208. std::forward<_Head>(_M_head(__in))) { }
  209. template<typename _Alloc, typename... _UElements>
  210. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  211. const _Tuple_impl<_Idx, _UElements...>& __in)
  212. : _Inherited(__tag, __a,
  213. _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  214. _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  215. _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
  216. template<typename _Alloc, typename _UHead, typename... _UTails>
  217. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  218. _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  219. : _Inherited(__tag, __a, std::move
  220. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  221. _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  222. std::forward<_UHead>
  223. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
  224. _Tuple_impl&
  225. operator=(const _Tuple_impl& __in)
  226. {
  227. _M_head(*this) = _M_head(__in);
  228. _M_tail(*this) = _M_tail(__in);
  229. return *this;
  230. }
  231. _Tuple_impl&
  232. operator=(_Tuple_impl&& __in)
  233. noexcept(__and_<is_nothrow_move_assignable<_Head>,
  234. is_nothrow_move_assignable<_Inherited>>::value)
  235. {
  236. _M_head(*this) = std::forward<_Head>(_M_head(__in));
  237. _M_tail(*this) = std::move(_M_tail(__in));
  238. return *this;
  239. }
  240. template<typename... _UElements>
  241. _Tuple_impl&
  242. operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
  243. {
  244. _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
  245. _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
  246. return *this;
  247. }
  248. template<typename _UHead, typename... _UTails>
  249. _Tuple_impl&
  250. operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  251. {
  252. _M_head(*this) = std::forward<_UHead>
  253. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
  254. _M_tail(*this) = std::move
  255. (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in));
  256. return *this;
  257. }
  258. protected:
  259. void
  260. _M_swap(_Tuple_impl& __in)
  261. noexcept(noexcept(swap(std::declval<_Head&>(),
  262. std::declval<_Head&>()))
  263. && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
  264. {
  265. using std::swap;
  266. swap(_M_head(*this), _M_head(__in));
  267. _Inherited::_M_swap(_M_tail(__in));
  268. }
  269. };
  270. // Basis case of inheritance recursion.
  271. template<std::size_t _Idx, typename _Head>
  272. struct _Tuple_impl<_Idx, _Head>
  273. : private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
  274. {
  275. template<std::size_t, typename...> friend class _Tuple_impl;
  276. typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
  277. static constexpr _Head&
  278. _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  279. static constexpr const _Head&
  280. _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
  281. constexpr _Tuple_impl()
  282. : _Base() { }
  283. explicit
  284. constexpr _Tuple_impl(const _Head& __head)
  285. : _Base(__head) { }
  286. template<typename _UHead>
  287. explicit
  288. constexpr _Tuple_impl(_UHead&& __head)
  289. : _Base(std::forward<_UHead>(__head)) { }
  290. constexpr _Tuple_impl(const _Tuple_impl&) = default;
  291. constexpr
  292. _Tuple_impl(_Tuple_impl&& __in)
  293. noexcept(is_nothrow_move_constructible<_Head>::value)
  294. : _Base(std::forward<_Head>(_M_head(__in))) { }
  295. template<typename _UHead>
  296. constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
  297. : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
  298. template<typename _UHead>
  299. constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
  300. : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  301. { }
  302. template<typename _Alloc>
  303. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  304. : _Base(__tag, __use_alloc<_Head>(__a)) { }
  305. template<typename _Alloc>
  306. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  307. const _Head& __head)
  308. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
  309. template<typename _Alloc, typename _UHead>
  310. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  311. _UHead&& __head)
  312. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  313. std::forward<_UHead>(__head)) { }
  314. template<typename _Alloc>
  315. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  316. const _Tuple_impl& __in)
  317. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
  318. template<typename _Alloc>
  319. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  320. _Tuple_impl&& __in)
  321. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  322. std::forward<_Head>(_M_head(__in))) { }
  323. template<typename _Alloc, typename _UHead>
  324. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  325. const _Tuple_impl<_Idx, _UHead>& __in)
  326. : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  327. _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
  328. template<typename _Alloc, typename _UHead>
  329. _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  330. _Tuple_impl<_Idx, _UHead>&& __in)
  331. : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  332. std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
  333. { }
  334. _Tuple_impl&
  335. operator=(const _Tuple_impl& __in)
  336. {
  337. _M_head(*this) = _M_head(__in);
  338. return *this;
  339. }
  340. _Tuple_impl&
  341. operator=(_Tuple_impl&& __in)
  342. noexcept(is_nothrow_move_assignable<_Head>::value)
  343. {
  344. _M_head(*this) = std::forward<_Head>(_M_head(__in));
  345. return *this;
  346. }
  347. template<typename _UHead>
  348. _Tuple_impl&
  349. operator=(const _Tuple_impl<_Idx, _UHead>& __in)
  350. {
  351. _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
  352. return *this;
  353. }
  354. template<typename _UHead>
  355. _Tuple_impl&
  356. operator=(_Tuple_impl<_Idx, _UHead>&& __in)
  357. {
  358. _M_head(*this)
  359. = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
  360. return *this;
  361. }
  362. protected:
  363. void
  364. _M_swap(_Tuple_impl& __in)
  365. noexcept(noexcept(swap(std::declval<_Head&>(), std::declval<_Head&>())))
  366. {
  367. using std::swap;
  368. swap(_M_head(*this), _M_head(__in));
  369. }
  370. };
  371. /// Primary class template, tuple
  372. template<typename... _Elements>
  373. class tuple : public _Tuple_impl<0, _Elements...>
  374. {
  375. typedef _Tuple_impl<0, _Elements...> _Inherited;
  376. public:
  377. constexpr tuple()
  378. : _Inherited() { }
  379. explicit
  380. constexpr tuple(const _Elements&... __elements)
  381. : _Inherited(__elements...) { }
  382. template<typename... _UElements, typename = typename
  383. enable_if<__and_<is_convertible<_UElements,
  384. _Elements>...>::value>::type>
  385. explicit
  386. constexpr tuple(_UElements&&... __elements)
  387. : _Inherited(std::forward<_UElements>(__elements)...) { }
  388. constexpr tuple(const tuple&) = default;
  389. constexpr tuple(tuple&&) = default;
  390. template<typename... _UElements, typename = typename
  391. enable_if<__and_<is_convertible<const _UElements&,
  392. _Elements>...>::value>::type>
  393. constexpr tuple(const tuple<_UElements...>& __in)
  394. : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  395. { }
  396. template<typename... _UElements, typename = typename
  397. enable_if<__and_<is_convertible<_UElements,
  398. _Elements>...>::value>::type>
  399. constexpr tuple(tuple<_UElements...>&& __in)
  400. : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
  401. // Allocator-extended constructors.
  402. template<typename _Alloc>
  403. tuple(allocator_arg_t __tag, const _Alloc& __a)
  404. : _Inherited(__tag, __a) { }
  405. template<typename _Alloc>
  406. tuple(allocator_arg_t __tag, const _Alloc& __a,
  407. const _Elements&... __elements)
  408. : _Inherited(__tag, __a, __elements...) { }
  409. template<typename _Alloc, typename... _UElements, typename = typename
  410. enable_if<sizeof...(_UElements)
  411. == sizeof...(_Elements)>::type>
  412. tuple(allocator_arg_t __tag, const _Alloc& __a,
  413. _UElements&&... __elements)
  414. : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
  415. { }
  416. template<typename _Alloc>
  417. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  418. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  419. template<typename _Alloc>
  420. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  421. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  422. template<typename _Alloc, typename... _UElements, typename = typename
  423. enable_if<sizeof...(_UElements)
  424. == sizeof...(_Elements)>::type>
  425. tuple(allocator_arg_t __tag, const _Alloc& __a,
  426. const tuple<_UElements...>& __in)
  427. : _Inherited(__tag, __a,
  428. static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
  429. { }
  430. template<typename _Alloc, typename... _UElements, typename = typename
  431. enable_if<sizeof...(_UElements)
  432. == sizeof...(_Elements)>::type>
  433. tuple(allocator_arg_t __tag, const _Alloc& __a,
  434. tuple<_UElements...>&& __in)
  435. : _Inherited(__tag, __a,
  436. static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
  437. { }
  438. tuple&
  439. operator=(const tuple& __in)
  440. {
  441. static_cast<_Inherited&>(*this) = __in;
  442. return *this;
  443. }
  444. tuple&
  445. operator=(tuple&& __in)
  446. noexcept(is_nothrow_move_assignable<_Inherited>::value)
  447. {
  448. static_cast<_Inherited&>(*this) = std::move(__in);
  449. return *this;
  450. }
  451. template<typename... _UElements, typename = typename
  452. enable_if<sizeof...(_UElements)
  453. == sizeof...(_Elements)>::type>
  454. tuple&
  455. operator=(const tuple<_UElements...>& __in)
  456. {
  457. static_cast<_Inherited&>(*this) = __in;
  458. return *this;
  459. }
  460. template<typename... _UElements, typename = typename
  461. enable_if<sizeof...(_UElements)
  462. == sizeof...(_Elements)>::type>
  463. tuple&
  464. operator=(tuple<_UElements...>&& __in)
  465. {
  466. static_cast<_Inherited&>(*this) = std::move(__in);
  467. return *this;
  468. }
  469. void
  470. swap(tuple& __in)
  471. noexcept(noexcept(__in._M_swap(__in)))
  472. { _Inherited::_M_swap(__in); }
  473. };
  474. // Explicit specialization, zero-element tuple.
  475. template<>
  476. class tuple<>
  477. {
  478. public:
  479. void swap(tuple&) noexcept { /* no-op */ }
  480. };
  481. /// Partial specialization, 2-element tuple.
  482. /// Includes construction and assignment from a pair.
  483. template<typename _T1, typename _T2>
  484. class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
  485. {
  486. typedef _Tuple_impl<0, _T1, _T2> _Inherited;
  487. public:
  488. constexpr tuple()
  489. : _Inherited() { }
  490. explicit
  491. constexpr tuple(const _T1& __a1, const _T2& __a2)
  492. : _Inherited(__a1, __a2) { }
  493. template<typename _U1, typename _U2, typename = typename
  494. enable_if<__and_<is_convertible<_U1, _T1>,
  495. is_convertible<_U2, _T2>>::value>::type>
  496. explicit
  497. constexpr tuple(_U1&& __a1, _U2&& __a2)
  498. : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
  499. constexpr tuple(const tuple&) = default;
  500. constexpr tuple(tuple&&) = default;
  501. template<typename _U1, typename _U2, typename = typename
  502. enable_if<__and_<is_convertible<const _U1&, _T1>,
  503. is_convertible<const _U2&, _T2>>::value>::type>
  504. constexpr tuple(const tuple<_U1, _U2>& __in)
  505. : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
  506. template<typename _U1, typename _U2, typename = typename
  507. enable_if<__and_<is_convertible<_U1, _T1>,
  508. is_convertible<_U2, _T2>>::value>::type>
  509. constexpr tuple(tuple<_U1, _U2>&& __in)
  510. : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
  511. template<typename _U1, typename _U2, typename = typename
  512. enable_if<__and_<is_convertible<const _U1&, _T1>,
  513. is_convertible<const _U2&, _T2>>::value>::type>
  514. constexpr tuple(const pair<_U1, _U2>& __in)
  515. : _Inherited(__in.first, __in.second) { }
  516. template<typename _U1, typename _U2, typename = typename
  517. enable_if<__and_<is_convertible<_U1, _T1>,
  518. is_convertible<_U2, _T2>>::value>::type>
  519. constexpr tuple(pair<_U1, _U2>&& __in)
  520. : _Inherited(std::forward<_U1>(__in.first),
  521. std::forward<_U2>(__in.second)) { }
  522. // Allocator-extended constructors.
  523. template<typename _Alloc>
  524. tuple(allocator_arg_t __tag, const _Alloc& __a)
  525. : _Inherited(__tag, __a) { }
  526. template<typename _Alloc>
  527. tuple(allocator_arg_t __tag, const _Alloc& __a,
  528. const _T1& __a1, const _T2& __a2)
  529. : _Inherited(__tag, __a, __a1, __a2) { }
  530. template<typename _Alloc, typename _U1, typename _U2>
  531. tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
  532. : _Inherited(__tag, __a, std::forward<_U1>(__a1),
  533. std::forward<_U2>(__a2)) { }
  534. template<typename _Alloc>
  535. tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
  536. : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
  537. template<typename _Alloc>
  538. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
  539. : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
  540. template<typename _Alloc, typename _U1, typename _U2>
  541. tuple(allocator_arg_t __tag, const _Alloc& __a,
  542. const tuple<_U1, _U2>& __in)
  543. : _Inherited(__tag, __a,
  544. static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
  545. { }
  546. template<typename _Alloc, typename _U1, typename _U2>
  547. tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
  548. : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
  549. { }
  550. template<typename _Alloc, typename _U1, typename _U2>
  551. tuple(allocator_arg_t __tag, const _Alloc& __a,
  552. const pair<_U1, _U2>& __in)
  553. : _Inherited(__tag, __a, __in.first, __in.second) { }
  554. template<typename _Alloc, typename _U1, typename _U2>
  555. tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
  556. : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
  557. std::forward<_U2>(__in.second)) { }
  558. tuple&
  559. operator=(const tuple& __in)
  560. {
  561. static_cast<_Inherited&>(*this) = __in;
  562. return *this;
  563. }
  564. tuple&
  565. operator=(tuple&& __in)
  566. noexcept(is_nothrow_move_assignable<_Inherited>::value)
  567. {
  568. static_cast<_Inherited&>(*this) = std::move(__in);
  569. return *this;
  570. }
  571. template<typename _U1, typename _U2>
  572. tuple&
  573. operator=(const tuple<_U1, _U2>& __in)
  574. {
  575. static_cast<_Inherited&>(*this) = __in;
  576. return *this;
  577. }
  578. template<typename _U1, typename _U2>
  579. tuple&
  580. operator=(tuple<_U1, _U2>&& __in)
  581. {
  582. static_cast<_Inherited&>(*this) = std::move(__in);
  583. return *this;
  584. }
  585. template<typename _U1, typename _U2>
  586. tuple&
  587. operator=(const pair<_U1, _U2>& __in)
  588. {
  589. this->_M_head(*this) = __in.first;
  590. this->_M_tail(*this)._M_head(*this) = __in.second;
  591. return *this;
  592. }
  593. template<typename _U1, typename _U2>
  594. tuple&
  595. operator=(pair<_U1, _U2>&& __in)
  596. {
  597. this->_M_head(*this) = std::forward<_U1>(__in.first);
  598. this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
  599. return *this;
  600. }
  601. void
  602. swap(tuple& __in)
  603. noexcept(noexcept(__in._M_swap(__in)))
  604. { _Inherited::_M_swap(__in); }
  605. };
  606. /// Gives the type of the ith element of a given tuple type.
  607. template<std::size_t __i, typename _Tp>
  608. struct tuple_element;
  609. /**
  610. * Recursive case for tuple_element: strip off the first element in
  611. * the tuple and retrieve the (i-1)th element of the remaining tuple.
  612. */
  613. template<std::size_t __i, typename _Head, typename... _Tail>
  614. struct tuple_element<__i, tuple<_Head, _Tail...> >
  615. : tuple_element<__i - 1, tuple<_Tail...> > { };
  616. /**
  617. * Basis case for tuple_element: The first element is the one we're seeking.
  618. */
  619. template<typename _Head, typename... _Tail>
  620. struct tuple_element<0, tuple<_Head, _Tail...> >
  621. {
  622. typedef _Head type;
  623. };
  624. // Duplicate of C++14's tuple_element_t for internal use in C++11 mode
  625. template<std::size_t __i, typename _Tp>
  626. using __tuple_element_t = typename tuple_element<__i, _Tp>::type;
  627. template<std::size_t __i, typename _Tp>
  628. struct tuple_element<__i, const _Tp>
  629. {
  630. typedef typename add_const<__tuple_element_t<__i, _Tp>>::type type;
  631. };
  632. template<std::size_t __i, typename _Tp>
  633. struct tuple_element<__i, volatile _Tp>
  634. {
  635. typedef typename add_volatile<__tuple_element_t<__i, _Tp>>::type type;
  636. };
  637. template<std::size_t __i, typename _Tp>
  638. struct tuple_element<__i, const volatile _Tp>
  639. {
  640. typedef typename add_cv<__tuple_element_t<__i, _Tp>>::type type;
  641. };
  642. #if __cplusplus > 201103L
  643. #define __cpp_lib_tuple_element_t 201402
  644. template<std::size_t __i, typename _Tp>
  645. using tuple_element_t = typename tuple_element<__i, _Tp>::type;
  646. #endif
  647. /// Finds the size of a given tuple type.
  648. template<typename _Tp>
  649. struct tuple_size;
  650. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  651. // 2313. tuple_size should always derive from integral_constant<size_t, N>
  652. template<typename _Tp>
  653. struct tuple_size<const _Tp>
  654. : integral_constant<size_t, tuple_size<_Tp>::value> { };
  655. template<typename _Tp>
  656. struct tuple_size<volatile _Tp>
  657. : integral_constant<size_t, tuple_size<_Tp>::value> { };
  658. template<typename _Tp>
  659. struct tuple_size<const volatile _Tp>
  660. : integral_constant<size_t, tuple_size<_Tp>::value> { };
  661. /// class tuple_size
  662. template<typename... _Elements>
  663. struct tuple_size<tuple<_Elements...>>
  664. : public integral_constant<std::size_t, sizeof...(_Elements)> { };
  665. template<std::size_t __i, typename _Head, typename... _Tail>
  666. constexpr _Head&
  667. __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  668. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  669. template<std::size_t __i, typename _Head, typename... _Tail>
  670. constexpr const _Head&
  671. __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  672. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  673. /// Return a reference to the ith element of a tuple.
  674. template<std::size_t __i, typename... _Elements>
  675. constexpr __tuple_element_t<__i, tuple<_Elements...>>&
  676. get(tuple<_Elements...>& __t) noexcept
  677. { return std::__get_helper<__i>(__t); }
  678. /// Return a const reference to the ith element of a const tuple.
  679. template<std::size_t __i, typename... _Elements>
  680. constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
  681. get(const tuple<_Elements...>& __t) noexcept
  682. { return std::__get_helper<__i>(__t); }
  683. /// Return an rvalue reference to the ith element of a tuple rvalue.
  684. template<std::size_t __i, typename... _Elements>
  685. constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
  686. get(tuple<_Elements...>&& __t) noexcept
  687. {
  688. typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
  689. return std::forward<__element_type&&>(std::get<__i>(__t));
  690. }
  691. #if __cplusplus > 201103L
  692. #define __cpp_lib_tuples_by_type 201304
  693. template<typename _Head, size_t __i, typename... _Tail>
  694. constexpr _Head&
  695. __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  696. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  697. template<typename _Head, size_t __i, typename... _Tail>
  698. constexpr const _Head&
  699. __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
  700. { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
  701. /// Return a reference to the unique element of type _Tp of a tuple.
  702. template <typename _Tp, typename... _Types>
  703. constexpr _Tp&
  704. get(tuple<_Types...>& __t) noexcept
  705. { return std::__get_helper2<_Tp>(__t); }
  706. /// Return a reference to the unique element of type _Tp of a tuple rvalue.
  707. template <typename _Tp, typename... _Types>
  708. constexpr _Tp&&
  709. get(tuple<_Types...>&& __t) noexcept
  710. { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
  711. /// Return a const reference to the unique element of type _Tp of a tuple.
  712. template <typename _Tp, typename... _Types>
  713. constexpr const _Tp&
  714. get(const tuple<_Types...>& __t) noexcept
  715. { return std::__get_helper2<_Tp>(__t); }
  716. #endif
  717. // This class performs the comparison operations on tuples
  718. template<typename _Tp, typename _Up, size_t __i, size_t __size>
  719. struct __tuple_compare
  720. {
  721. static constexpr bool
  722. __eq(const _Tp& __t, const _Up& __u)
  723. {
  724. return bool(std::get<__i>(__t) == std::get<__i>(__u))
  725. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
  726. }
  727. static constexpr bool
  728. __less(const _Tp& __t, const _Up& __u)
  729. {
  730. return bool(std::get<__i>(__t) < std::get<__i>(__u))
  731. || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
  732. && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
  733. }
  734. };
  735. template<typename _Tp, typename _Up, size_t __size>
  736. struct __tuple_compare<_Tp, _Up, __size, __size>
  737. {
  738. static constexpr bool
  739. __eq(const _Tp&, const _Up&) { return true; }
  740. static constexpr bool
  741. __less(const _Tp&, const _Up&) { return false; }
  742. };
  743. template<typename... _TElements, typename... _UElements>
  744. constexpr bool
  745. operator==(const tuple<_TElements...>& __t,
  746. const tuple<_UElements...>& __u)
  747. {
  748. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  749. "tuple objects can only be compared if they have equal sizes.");
  750. using __compare = __tuple_compare<tuple<_TElements...>,
  751. tuple<_UElements...>,
  752. 0, sizeof...(_TElements)>;
  753. return __compare::__eq(__t, __u);
  754. }
  755. template<typename... _TElements, typename... _UElements>
  756. constexpr bool
  757. operator<(const tuple<_TElements...>& __t,
  758. const tuple<_UElements...>& __u)
  759. {
  760. static_assert(sizeof...(_TElements) == sizeof...(_UElements),
  761. "tuple objects can only be compared if they have equal sizes.");
  762. using __compare = __tuple_compare<tuple<_TElements...>,
  763. tuple<_UElements...>,
  764. 0, sizeof...(_TElements)>;
  765. return __compare::__less(__t, __u);
  766. }
  767. template<typename... _TElements, typename... _UElements>
  768. constexpr bool
  769. operator!=(const tuple<_TElements...>& __t,
  770. const tuple<_UElements...>& __u)
  771. { return !(__t == __u); }
  772. template<typename... _TElements, typename... _UElements>
  773. constexpr bool
  774. operator>(const tuple<_TElements...>& __t,
  775. const tuple<_UElements...>& __u)
  776. { return __u < __t; }
  777. template<typename... _TElements, typename... _UElements>
  778. constexpr bool
  779. operator<=(const tuple<_TElements...>& __t,
  780. const tuple<_UElements...>& __u)
  781. { return !(__u < __t); }
  782. template<typename... _TElements, typename... _UElements>
  783. constexpr bool
  784. operator>=(const tuple<_TElements...>& __t,
  785. const tuple<_UElements...>& __u)
  786. { return !(__t < __u); }
  787. // NB: DR 705.
  788. template<typename... _Elements>
  789. constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
  790. make_tuple(_Elements&&... __args)
  791. {
  792. typedef tuple<typename __decay_and_strip<_Elements>::__type...>
  793. __result_type;
  794. return __result_type(std::forward<_Elements>(__args)...);
  795. }
  796. template<typename... _Elements>
  797. tuple<_Elements&&...>
  798. forward_as_tuple(_Elements&&... __args) noexcept
  799. { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
  800. template<typename>
  801. struct __is_tuple_like_impl : false_type
  802. { };
  803. template<typename... _Tps>
  804. struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
  805. { };
  806. template<typename _T1, typename _T2>
  807. struct __is_tuple_like_impl<pair<_T1, _T2>> : true_type
  808. { };
  809. template<typename _Tp, std::size_t _Nm>
  810. struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type
  811. { };
  812. // Internal type trait that allows us to sfinae-protect tuple_cat.
  813. template<typename _Tp>
  814. struct __is_tuple_like
  815. : public __is_tuple_like_impl<typename std::remove_cv
  816. <typename std::remove_reference<_Tp>::type>::type>::type
  817. { };
  818. template<size_t, typename, typename, size_t>
  819. struct __make_tuple_impl;
  820. template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
  821. struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
  822. : __make_tuple_impl<_Idx + 1,
  823. tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
  824. _Tuple, _Nm>
  825. { };
  826. template<std::size_t _Nm, typename _Tuple, typename... _Tp>
  827. struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
  828. {
  829. typedef tuple<_Tp...> __type;
  830. };
  831. template<typename _Tuple>
  832. struct __do_make_tuple
  833. : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
  834. { };
  835. // Returns the std::tuple equivalent of a tuple-like type.
  836. template<typename _Tuple>
  837. struct __make_tuple
  838. : public __do_make_tuple<typename std::remove_cv
  839. <typename std::remove_reference<_Tuple>::type>::type>
  840. { };
  841. // Combines several std::tuple's into a single one.
  842. template<typename...>
  843. struct __combine_tuples;
  844. template<>
  845. struct __combine_tuples<>
  846. {
  847. typedef tuple<> __type;
  848. };
  849. template<typename... _Ts>
  850. struct __combine_tuples<tuple<_Ts...>>
  851. {
  852. typedef tuple<_Ts...> __type;
  853. };
  854. template<typename... _T1s, typename... _T2s, typename... _Rem>
  855. struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
  856. {
  857. typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
  858. _Rem...>::__type __type;
  859. };
  860. // Computes the result type of tuple_cat given a set of tuple-like types.
  861. template<typename... _Tpls>
  862. struct __tuple_cat_result
  863. {
  864. typedef typename __combine_tuples
  865. <typename __make_tuple<_Tpls>::__type...>::__type __type;
  866. };
  867. // Helper to determine the index set for the first tuple-like
  868. // type of a given set.
  869. template<typename...>
  870. struct __make_1st_indices;
  871. template<>
  872. struct __make_1st_indices<>
  873. {
  874. typedef std::_Index_tuple<> __type;
  875. };
  876. template<typename _Tp, typename... _Tpls>
  877. struct __make_1st_indices<_Tp, _Tpls...>
  878. {
  879. typedef typename std::_Build_index_tuple<std::tuple_size<
  880. typename std::remove_reference<_Tp>::type>::value>::__type __type;
  881. };
  882. // Performs the actual concatenation by step-wise expanding tuple-like
  883. // objects into the elements, which are finally forwarded into the
  884. // result tuple.
  885. template<typename _Ret, typename _Indices, typename... _Tpls>
  886. struct __tuple_concater;
  887. template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
  888. struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
  889. {
  890. template<typename... _Us>
  891. static constexpr _Ret
  892. _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
  893. {
  894. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  895. typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
  896. return __next::_S_do(std::forward<_Tpls>(__tps)...,
  897. std::forward<_Us>(__us)...,
  898. std::get<_Is>(std::forward<_Tp>(__tp))...);
  899. }
  900. };
  901. template<typename _Ret>
  902. struct __tuple_concater<_Ret, std::_Index_tuple<>>
  903. {
  904. template<typename... _Us>
  905. static constexpr _Ret
  906. _S_do(_Us&&... __us)
  907. {
  908. return _Ret(std::forward<_Us>(__us)...);
  909. }
  910. };
  911. /// tuple_cat
  912. template<typename... _Tpls, typename = typename
  913. enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
  914. constexpr auto
  915. tuple_cat(_Tpls&&... __tpls)
  916. -> typename __tuple_cat_result<_Tpls...>::__type
  917. {
  918. typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
  919. typedef typename __make_1st_indices<_Tpls...>::__type __idx;
  920. typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
  921. return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
  922. }
  923. /// tie
  924. template<typename... _Elements>
  925. inline tuple<_Elements&...>
  926. tie(_Elements&... __args) noexcept
  927. { return tuple<_Elements&...>(__args...); }
  928. /// swap
  929. template<typename... _Elements>
  930. inline void
  931. swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
  932. noexcept(noexcept(__x.swap(__y)))
  933. { __x.swap(__y); }
  934. // A class (and instance) which can be used in 'tie' when an element
  935. // of a tuple is not required
  936. struct _Swallow_assign
  937. {
  938. template<class _Tp>
  939. const _Swallow_assign&
  940. operator=(const _Tp&) const
  941. { return *this; }
  942. };
  943. const _Swallow_assign ignore{};
  944. /// Partial specialization for tuples
  945. template<typename... _Types, typename _Alloc>
  946. struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
  947. // See stl_pair.h...
  948. template<class _T1, class _T2>
  949. template<typename... _Args1, typename... _Args2>
  950. inline
  951. pair<_T1, _T2>::
  952. pair(piecewise_construct_t,
  953. tuple<_Args1...> __first, tuple<_Args2...> __second)
  954. : pair(__first, __second,
  955. typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
  956. typename _Build_index_tuple<sizeof...(_Args2)>::__type())
  957. { }
  958. template<class _T1, class _T2>
  959. template<typename... _Args1, std::size_t... _Indexes1,
  960. typename... _Args2, std::size_t... _Indexes2>
  961. inline
  962. pair<_T1, _T2>::
  963. pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
  964. _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
  965. : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
  966. second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
  967. { }
  968. /// @}
  969. _GLIBCXX_END_NAMESPACE_VERSION
  970. } // namespace std
  971. #endif // C++11
  972. #endif // _GLIBCXX_TUPLE