3 // Copyright (C) 2007-2019 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/tuple
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
40 #include <bits/uses_allocator.h>
41 #include <bits/invoke.h>
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 * @addtogroup utilities
52 template<typename... _Elements>
55 template<typename _Tp>
56 struct __is_empty_non_tuple : is_empty<_Tp> { };
58 // Using EBO for elements that are tuples causes ambiguous base errors.
59 template<typename _El0, typename... _El>
60 struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
62 // Use the Empty Base-class Optimization for empty, non-final types.
63 template<typename _Tp>
64 using __empty_not_final
65 = typename conditional<__is_final(_Tp), false_type,
66 __is_empty_non_tuple<_Tp>>::type;
68 template<std::size_t _Idx, typename _Head,
69 bool = __empty_not_final<_Head>::value>
72 template<std::size_t _Idx, typename _Head>
73 struct _Head_base<_Idx, _Head, true>
76 constexpr _Head_base()
79 constexpr _Head_base(const _Head& __h)
82 constexpr _Head_base(const _Head_base&) = default;
83 constexpr _Head_base(_Head_base&&) = default;
85 template<typename _UHead>
86 constexpr _Head_base(_UHead&& __h)
87 : _Head(std::forward<_UHead>(__h)) { }
89 _Head_base(allocator_arg_t, __uses_alloc0)
92 template<typename _Alloc>
93 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
94 : _Head(allocator_arg, *__a._M_a) { }
96 template<typename _Alloc>
97 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
98 : _Head(*__a._M_a) { }
100 template<typename _UHead>
101 _Head_base(__uses_alloc0, _UHead&& __uhead)
102 : _Head(std::forward<_UHead>(__uhead)) { }
104 template<typename _Alloc, typename _UHead>
105 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
106 : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
108 template<typename _Alloc, typename _UHead>
109 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
110 : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
112 static constexpr _Head&
113 _M_head(_Head_base& __b) noexcept { return __b; }
115 static constexpr const _Head&
116 _M_head(const _Head_base& __b) noexcept { return __b; }
119 template<std::size_t _Idx, typename _Head>
120 struct _Head_base<_Idx, _Head, false>
122 constexpr _Head_base()
125 constexpr _Head_base(const _Head& __h)
126 : _M_head_impl(__h) { }
128 constexpr _Head_base(const _Head_base&) = default;
129 constexpr _Head_base(_Head_base&&) = default;
131 template<typename _UHead>
132 constexpr _Head_base(_UHead&& __h)
133 : _M_head_impl(std::forward<_UHead>(__h)) { }
135 _Head_base(allocator_arg_t, __uses_alloc0)
138 template<typename _Alloc>
139 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
140 : _M_head_impl(allocator_arg, *__a._M_a) { }
142 template<typename _Alloc>
143 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
144 : _M_head_impl(*__a._M_a) { }
146 template<typename _UHead>
147 _Head_base(__uses_alloc0, _UHead&& __uhead)
148 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
150 template<typename _Alloc, typename _UHead>
151 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
152 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
155 template<typename _Alloc, typename _UHead>
156 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
157 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
159 static constexpr _Head&
160 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
162 static constexpr const _Head&
163 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
169 * Contains the actual implementation of the @c tuple template, stored
170 * as a recursive inheritance hierarchy from the first element (most
171 * derived class) to the last (least derived class). The @c Idx
172 * parameter gives the 0-based index of the element stored at this
173 * point in the hierarchy; we use it to implement a constant-time
176 template<std::size_t _Idx, typename... _Elements>
180 * Recursive tuple implementation. Here we store the @c Head element
181 * and derive from a @c Tuple_impl containing the remaining elements
182 * (which contains the @c Tail).
184 template<std::size_t _Idx, typename _Head, typename... _Tail>
185 struct _Tuple_impl<_Idx, _Head, _Tail...>
186 : public _Tuple_impl<_Idx + 1, _Tail...>,
187 private _Head_base<_Idx, _Head>
189 template<std::size_t, typename...> friend class _Tuple_impl;
191 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
192 typedef _Head_base<_Idx, _Head> _Base;
194 static constexpr _Head&
195 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
197 static constexpr const _Head&
198 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
200 static constexpr _Inherited&
201 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
203 static constexpr const _Inherited&
204 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
206 constexpr _Tuple_impl()
207 : _Inherited(), _Base() { }
210 constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
211 : _Inherited(__tail...), _Base(__head) { }
213 template<typename _UHead, typename... _UTail, typename = typename
214 enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
216 constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
217 : _Inherited(std::forward<_UTail>(__tail)...),
218 _Base(std::forward<_UHead>(__head)) { }
220 constexpr _Tuple_impl(const _Tuple_impl&) = default;
222 // _GLIBCXX_RESOLVE_LIB_DEFECTS
223 // 2729. Missing SFINAE on std::pair::operator=
224 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
227 _Tuple_impl(_Tuple_impl&& __in)
228 noexcept(__and_<is_nothrow_move_constructible<_Head>,
229 is_nothrow_move_constructible<_Inherited>>::value)
230 : _Inherited(std::move(_M_tail(__in))),
231 _Base(std::forward<_Head>(_M_head(__in))) { }
233 template<typename... _UElements>
234 constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
235 : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
236 _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
238 template<typename _UHead, typename... _UTails>
239 constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
240 : _Inherited(std::move
241 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
242 _Base(std::forward<_UHead>
243 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
245 template<typename _Alloc>
246 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
247 : _Inherited(__tag, __a),
248 _Base(__tag, __use_alloc<_Head>(__a)) { }
250 template<typename _Alloc>
251 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
252 const _Head& __head, const _Tail&... __tail)
253 : _Inherited(__tag, __a, __tail...),
254 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
256 template<typename _Alloc, typename _UHead, typename... _UTail,
257 typename = typename enable_if<sizeof...(_Tail)
258 == sizeof...(_UTail)>::type>
259 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
260 _UHead&& __head, _UTail&&... __tail)
261 : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
262 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
263 std::forward<_UHead>(__head)) { }
265 template<typename _Alloc>
266 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
267 const _Tuple_impl& __in)
268 : _Inherited(__tag, __a, _M_tail(__in)),
269 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
271 template<typename _Alloc>
272 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
274 : _Inherited(__tag, __a, std::move(_M_tail(__in))),
275 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
276 std::forward<_Head>(_M_head(__in))) { }
278 template<typename _Alloc, typename... _UElements>
279 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
280 const _Tuple_impl<_Idx, _UElements...>& __in)
281 : _Inherited(__tag, __a,
282 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
283 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
284 _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
286 template<typename _Alloc, typename _UHead, typename... _UTails>
287 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
288 _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
289 : _Inherited(__tag, __a, std::move
290 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
291 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
293 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
295 template<typename... _UElements>
297 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
299 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
300 _M_tail(*this)._M_assign(
301 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
304 template<typename _UHead, typename... _UTails>
306 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
308 _M_head(*this) = std::forward<_UHead>
309 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
310 _M_tail(*this)._M_assign(
311 std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
316 _M_swap(_Tuple_impl& __in)
319 swap(_M_head(*this), _M_head(__in));
320 _Inherited::_M_swap(_M_tail(__in));
324 // Basis case of inheritance recursion.
325 template<std::size_t _Idx, typename _Head>
326 struct _Tuple_impl<_Idx, _Head>
327 : private _Head_base<_Idx, _Head>
329 template<std::size_t, typename...> friend class _Tuple_impl;
331 typedef _Head_base<_Idx, _Head> _Base;
333 static constexpr _Head&
334 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
336 static constexpr const _Head&
337 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
339 constexpr _Tuple_impl()
343 constexpr _Tuple_impl(const _Head& __head)
346 template<typename _UHead>
348 constexpr _Tuple_impl(_UHead&& __head)
349 : _Base(std::forward<_UHead>(__head)) { }
351 constexpr _Tuple_impl(const _Tuple_impl&) = default;
353 // _GLIBCXX_RESOLVE_LIB_DEFECTS
354 // 2729. Missing SFINAE on std::pair::operator=
355 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
358 _Tuple_impl(_Tuple_impl&& __in)
359 noexcept(is_nothrow_move_constructible<_Head>::value)
360 : _Base(std::forward<_Head>(_M_head(__in))) { }
362 template<typename _UHead>
363 constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
364 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
366 template<typename _UHead>
367 constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
368 : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
371 template<typename _Alloc>
372 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
373 : _Base(__tag, __use_alloc<_Head>(__a)) { }
375 template<typename _Alloc>
376 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
378 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
380 template<typename _Alloc, typename _UHead>
381 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
383 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
384 std::forward<_UHead>(__head)) { }
386 template<typename _Alloc>
387 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
388 const _Tuple_impl& __in)
389 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
391 template<typename _Alloc>
392 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
394 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
395 std::forward<_Head>(_M_head(__in))) { }
397 template<typename _Alloc, typename _UHead>
398 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
399 const _Tuple_impl<_Idx, _UHead>& __in)
400 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
401 _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
403 template<typename _Alloc, typename _UHead>
404 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
405 _Tuple_impl<_Idx, _UHead>&& __in)
406 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
407 std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
410 template<typename _UHead>
412 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
414 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
417 template<typename _UHead>
419 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
422 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
427 _M_swap(_Tuple_impl& __in)
430 swap(_M_head(*this), _M_head(__in));
434 // Concept utility functions, reused in conditionally-explicit
436 template<bool, typename... _Elements>
439 template<typename... _UElements>
440 static constexpr bool _ConstructibleTuple()
442 return __and_<is_constructible<_Elements, const _UElements&>...>::value;
445 template<typename... _UElements>
446 static constexpr bool _ImplicitlyConvertibleTuple()
448 return __and_<is_convertible<const _UElements&, _Elements>...>::value;
451 template<typename... _UElements>
452 static constexpr bool _MoveConstructibleTuple()
454 return __and_<is_constructible<_Elements, _UElements&&>...>::value;
457 template<typename... _UElements>
458 static constexpr bool _ImplicitlyMoveConvertibleTuple()
460 return __and_<is_convertible<_UElements&&, _Elements>...>::value;
463 template<typename _SrcTuple>
464 static constexpr bool _NonNestedTuple()
466 return __and_<__not_<is_same<tuple<_Elements...>,
467 __remove_cvref_t<_SrcTuple>>>,
468 __not_<is_convertible<_SrcTuple, _Elements...>>,
469 __not_<is_constructible<_Elements..., _SrcTuple>>
473 template<typename... _UElements>
474 static constexpr bool _NotSameTuple()
476 return __not_<is_same<tuple<_Elements...>,
477 __remove_cvref_t<_UElements>...>>::value;
481 template<typename... _Elements>
482 struct _TC<false, _Elements...>
484 template<typename... _UElements>
485 static constexpr bool _ConstructibleTuple()
490 template<typename... _UElements>
491 static constexpr bool _ImplicitlyConvertibleTuple()
496 template<typename... _UElements>
497 static constexpr bool _MoveConstructibleTuple()
502 template<typename... _UElements>
503 static constexpr bool _ImplicitlyMoveConvertibleTuple()
508 template<typename... _UElements>
509 static constexpr bool _NonNestedTuple()
514 template<typename... _UElements>
515 static constexpr bool _NotSameTuple()
521 /// Primary class template, tuple
522 template<typename... _Elements>
523 class tuple : public _Tuple_impl<0, _Elements...>
525 typedef _Tuple_impl<0, _Elements...> _Inherited;
527 // Used for constraining the default constructor so
528 // that it becomes dependent on the constraints.
529 template<typename _Dummy>
532 static constexpr bool _DefaultConstructibleTuple()
534 return __and_<is_default_constructible<_Elements>...>::value;
536 static constexpr bool _ImplicitlyDefaultConstructibleTuple()
538 return __and_<__is_implicitly_default_constructible<_Elements>...>
543 template<typename... _UElements>
545 __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
547 { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
549 template<typename... _UElements>
550 static constexpr bool __nothrow_assignable()
553 __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
557 template<typename _Dummy = void,
558 typename enable_if<_TC2<_Dummy>::
559 _ImplicitlyDefaultConstructibleTuple(),
564 template<typename _Dummy = void,
565 typename enable_if<_TC2<_Dummy>::
566 _DefaultConstructibleTuple()
569 _ImplicitlyDefaultConstructibleTuple(),
571 explicit constexpr tuple()
574 // Shortcut for the cases where constructors taking _Elements...
575 // need to be constrained.
576 template<typename _Dummy> using _TCC =
577 _TC<is_same<_Dummy, void>::value,
580 template<typename _Dummy = void,
582 _TCC<_Dummy>::template
583 _ConstructibleTuple<_Elements...>()
584 && _TCC<_Dummy>::template
585 _ImplicitlyConvertibleTuple<_Elements...>()
586 && (sizeof...(_Elements) >= 1),
588 constexpr tuple(const _Elements&... __elements)
589 : _Inherited(__elements...) { }
591 template<typename _Dummy = void,
593 _TCC<_Dummy>::template
594 _ConstructibleTuple<_Elements...>()
595 && !_TCC<_Dummy>::template
596 _ImplicitlyConvertibleTuple<_Elements...>()
597 && (sizeof...(_Elements) >= 1),
599 explicit constexpr tuple(const _Elements&... __elements)
600 : _Inherited(__elements...) { }
602 // Shortcut for the cases where constructors taking _UElements...
603 // need to be constrained.
604 template<typename... _UElements> using _TMC =
605 _TC<(sizeof...(_Elements) == sizeof...(_UElements))
606 && (_TC<(sizeof...(_UElements)==1), _Elements...>::
607 template _NotSameTuple<_UElements...>()),
610 // Shortcut for the cases where constructors taking tuple<_UElements...>
611 // need to be constrained.
612 template<typename... _UElements> using _TMCT =
613 _TC<(sizeof...(_Elements) == sizeof...(_UElements))
614 && !is_same<tuple<_Elements...>,
615 tuple<_UElements...>>::value,
618 template<typename... _UElements, typename
620 _TMC<_UElements...>::template
621 _MoveConstructibleTuple<_UElements...>()
622 && _TMC<_UElements...>::template
623 _ImplicitlyMoveConvertibleTuple<_UElements...>()
624 && (sizeof...(_Elements) >= 1),
626 constexpr tuple(_UElements&&... __elements)
627 : _Inherited(std::forward<_UElements>(__elements)...) { }
629 template<typename... _UElements, typename
631 _TMC<_UElements...>::template
632 _MoveConstructibleTuple<_UElements...>()
633 && !_TMC<_UElements...>::template
634 _ImplicitlyMoveConvertibleTuple<_UElements...>()
635 && (sizeof...(_Elements) >= 1),
637 explicit constexpr tuple(_UElements&&... __elements)
638 : _Inherited(std::forward<_UElements>(__elements)...) { }
640 constexpr tuple(const tuple&) = default;
642 constexpr tuple(tuple&&) = default;
644 // Shortcut for the cases where constructors taking tuples
645 // must avoid creating temporaries.
646 template<typename _Dummy> using _TNTC =
647 _TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1,
650 template<typename... _UElements, typename _Dummy = void, typename
651 enable_if<_TMCT<_UElements...>::template
652 _ConstructibleTuple<_UElements...>()
653 && _TMCT<_UElements...>::template
654 _ImplicitlyConvertibleTuple<_UElements...>()
655 && _TNTC<_Dummy>::template
656 _NonNestedTuple<const tuple<_UElements...>&>(),
658 constexpr tuple(const tuple<_UElements...>& __in)
659 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
662 template<typename... _UElements, typename _Dummy = void, typename
663 enable_if<_TMCT<_UElements...>::template
664 _ConstructibleTuple<_UElements...>()
665 && !_TMCT<_UElements...>::template
666 _ImplicitlyConvertibleTuple<_UElements...>()
667 && _TNTC<_Dummy>::template
668 _NonNestedTuple<const tuple<_UElements...>&>(),
670 explicit constexpr tuple(const tuple<_UElements...>& __in)
671 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
674 template<typename... _UElements, typename _Dummy = void, typename
675 enable_if<_TMCT<_UElements...>::template
676 _MoveConstructibleTuple<_UElements...>()
677 && _TMCT<_UElements...>::template
678 _ImplicitlyMoveConvertibleTuple<_UElements...>()
679 && _TNTC<_Dummy>::template
680 _NonNestedTuple<tuple<_UElements...>&&>(),
682 constexpr tuple(tuple<_UElements...>&& __in)
683 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
685 template<typename... _UElements, typename _Dummy = void, typename
686 enable_if<_TMCT<_UElements...>::template
687 _MoveConstructibleTuple<_UElements...>()
688 && !_TMCT<_UElements...>::template
689 _ImplicitlyMoveConvertibleTuple<_UElements...>()
690 && _TNTC<_Dummy>::template
691 _NonNestedTuple<tuple<_UElements...>&&>(),
693 explicit constexpr tuple(tuple<_UElements...>&& __in)
694 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
696 // Allocator-extended constructors.
698 template<typename _Alloc>
699 tuple(allocator_arg_t __tag, const _Alloc& __a)
700 : _Inherited(__tag, __a) { }
702 template<typename _Alloc, typename _Dummy = void,
704 _TCC<_Dummy>::template
705 _ConstructibleTuple<_Elements...>()
706 && _TCC<_Dummy>::template
707 _ImplicitlyConvertibleTuple<_Elements...>(),
709 tuple(allocator_arg_t __tag, const _Alloc& __a,
710 const _Elements&... __elements)
711 : _Inherited(__tag, __a, __elements...) { }
713 template<typename _Alloc, typename _Dummy = void,
715 _TCC<_Dummy>::template
716 _ConstructibleTuple<_Elements...>()
717 && !_TCC<_Dummy>::template
718 _ImplicitlyConvertibleTuple<_Elements...>(),
720 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
721 const _Elements&... __elements)
722 : _Inherited(__tag, __a, __elements...) { }
724 template<typename _Alloc, typename... _UElements, typename
725 enable_if<_TMC<_UElements...>::template
726 _MoveConstructibleTuple<_UElements...>()
727 && _TMC<_UElements...>::template
728 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
730 tuple(allocator_arg_t __tag, const _Alloc& __a,
731 _UElements&&... __elements)
732 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
735 template<typename _Alloc, typename... _UElements, typename
736 enable_if<_TMC<_UElements...>::template
737 _MoveConstructibleTuple<_UElements...>()
738 && !_TMC<_UElements...>::template
739 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
741 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
742 _UElements&&... __elements)
743 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
746 template<typename _Alloc>
747 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
748 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
750 template<typename _Alloc>
751 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
752 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
754 template<typename _Alloc, typename _Dummy = void,
755 typename... _UElements, typename
756 enable_if<_TMCT<_UElements...>::template
757 _ConstructibleTuple<_UElements...>()
758 && _TMCT<_UElements...>::template
759 _ImplicitlyConvertibleTuple<_UElements...>()
760 && _TNTC<_Dummy>::template
761 _NonNestedTuple<const tuple<_UElements...>&>(),
763 tuple(allocator_arg_t __tag, const _Alloc& __a,
764 const tuple<_UElements...>& __in)
765 : _Inherited(__tag, __a,
766 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
769 template<typename _Alloc, typename _Dummy = void,
770 typename... _UElements, typename
771 enable_if<_TMCT<_UElements...>::template
772 _ConstructibleTuple<_UElements...>()
773 && !_TMCT<_UElements...>::template
774 _ImplicitlyConvertibleTuple<_UElements...>()
775 && _TNTC<_Dummy>::template
776 _NonNestedTuple<const tuple<_UElements...>&>(),
778 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
779 const tuple<_UElements...>& __in)
780 : _Inherited(__tag, __a,
781 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
784 template<typename _Alloc, typename _Dummy = void,
785 typename... _UElements, typename
786 enable_if<_TMCT<_UElements...>::template
787 _MoveConstructibleTuple<_UElements...>()
788 && _TMCT<_UElements...>::template
789 _ImplicitlyMoveConvertibleTuple<_UElements...>()
790 && _TNTC<_Dummy>::template
791 _NonNestedTuple<tuple<_UElements...>&&>(),
793 tuple(allocator_arg_t __tag, const _Alloc& __a,
794 tuple<_UElements...>&& __in)
795 : _Inherited(__tag, __a,
796 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
799 template<typename _Alloc, typename _Dummy = void,
800 typename... _UElements, typename
801 enable_if<_TMCT<_UElements...>::template
802 _MoveConstructibleTuple<_UElements...>()
803 && !_TMCT<_UElements...>::template
804 _ImplicitlyMoveConvertibleTuple<_UElements...>()
805 && _TNTC<_Dummy>::template
806 _NonNestedTuple<tuple<_UElements...>&&>(),
808 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
809 tuple<_UElements...>&& __in)
810 : _Inherited(__tag, __a,
811 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
817 operator=(typename conditional<__assignable<const _Elements&...>(),
819 const __nonesuch_no_braces&>::type __in)
820 noexcept(__nothrow_assignable<const _Elements&...>())
822 this->_M_assign(__in);
827 operator=(typename conditional<__assignable<_Elements...>(),
829 __nonesuch_no_braces&&>::type __in)
830 noexcept(__nothrow_assignable<_Elements...>())
832 this->_M_assign(std::move(__in));
836 template<typename... _UElements>
837 __enable_if_t<__assignable<const _UElements&...>(), tuple&>
838 operator=(const tuple<_UElements...>& __in)
839 noexcept(__nothrow_assignable<const _UElements&...>())
841 this->_M_assign(__in);
845 template<typename... _UElements>
846 __enable_if_t<__assignable<_UElements...>(), tuple&>
847 operator=(tuple<_UElements...>&& __in)
848 noexcept(__nothrow_assignable<_UElements...>())
850 this->_M_assign(std::move(__in));
857 noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
858 { _Inherited::_M_swap(__in); }
861 #if __cpp_deduction_guides >= 201606
862 template<typename... _UTypes>
863 tuple(_UTypes...) -> tuple<_UTypes...>;
864 template<typename _T1, typename _T2>
865 tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
866 template<typename _Alloc, typename... _UTypes>
867 tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
868 template<typename _Alloc, typename _T1, typename _T2>
869 tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
870 template<typename _Alloc, typename... _UTypes>
871 tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
874 // Explicit specialization, zero-element tuple.
879 void swap(tuple&) noexcept { /* no-op */ }
880 // We need the default since we're going to define no-op
881 // allocator constructors.
883 // No-op allocator constructors.
884 template<typename _Alloc>
885 tuple(allocator_arg_t, const _Alloc&) { }
886 template<typename _Alloc>
887 tuple(allocator_arg_t, const _Alloc&, const tuple&) { }
890 /// Partial specialization, 2-element tuple.
891 /// Includes construction and assignment from a pair.
892 template<typename _T1, typename _T2>
893 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
895 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
897 template<typename _U1, typename _U2>
898 static constexpr bool __assignable()
900 return __and_<is_assignable<_T1&, _U1>,
901 is_assignable<_T2&, _U2>>::value;
904 template<typename _U1, typename _U2>
905 static constexpr bool __nothrow_assignable()
907 return __and_<is_nothrow_assignable<_T1&, _U1>,
908 is_nothrow_assignable<_T2&, _U2>>::value;
912 template <typename _U1 = _T1,
914 typename enable_if<__and_<
915 __is_implicitly_default_constructible<_U1>,
916 __is_implicitly_default_constructible<_U2>>
917 ::value, bool>::type = true>
921 template <typename _U1 = _T1,
925 is_default_constructible<_U1>,
926 is_default_constructible<_U2>,
928 __and_<__is_implicitly_default_constructible<_U1>,
929 __is_implicitly_default_constructible<_U2>>>>
930 ::value, bool>::type = false>
931 explicit constexpr tuple()
934 // Shortcut for the cases where constructors taking _T1, _T2
935 // need to be constrained.
936 template<typename _Dummy> using _TCC =
937 _TC<is_same<_Dummy, void>::value, _T1, _T2>;
939 template<typename _Dummy = void, typename
940 enable_if<_TCC<_Dummy>::template
941 _ConstructibleTuple<_T1, _T2>()
942 && _TCC<_Dummy>::template
943 _ImplicitlyConvertibleTuple<_T1, _T2>(),
945 constexpr tuple(const _T1& __a1, const _T2& __a2)
946 : _Inherited(__a1, __a2) { }
948 template<typename _Dummy = void, typename
949 enable_if<_TCC<_Dummy>::template
950 _ConstructibleTuple<_T1, _T2>()
951 && !_TCC<_Dummy>::template
952 _ImplicitlyConvertibleTuple<_T1, _T2>(),
954 explicit constexpr tuple(const _T1& __a1, const _T2& __a2)
955 : _Inherited(__a1, __a2) { }
957 // Shortcut for the cases where constructors taking _U1, _U2
958 // need to be constrained.
959 using _TMC = _TC<true, _T1, _T2>;
961 template<typename _U1, typename _U2, typename
962 enable_if<_TMC::template
963 _MoveConstructibleTuple<_U1, _U2>()
965 _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
966 && !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value,
968 constexpr tuple(_U1&& __a1, _U2&& __a2)
969 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
971 template<typename _U1, typename _U2, typename
972 enable_if<_TMC::template
973 _MoveConstructibleTuple<_U1, _U2>()
975 _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
976 && !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value,
978 explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
979 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
981 constexpr tuple(const tuple&) = default;
983 constexpr tuple(tuple&&) = default;
985 template<typename _U1, typename _U2, typename
986 enable_if<_TMC::template
987 _ConstructibleTuple<_U1, _U2>()
989 _ImplicitlyConvertibleTuple<_U1, _U2>(),
991 constexpr tuple(const tuple<_U1, _U2>& __in)
992 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
994 template<typename _U1, typename _U2, typename
995 enable_if<_TMC::template
996 _ConstructibleTuple<_U1, _U2>()
998 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1000 explicit constexpr tuple(const tuple<_U1, _U2>& __in)
1001 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
1003 template<typename _U1, typename _U2, typename
1004 enable_if<_TMC::template
1005 _MoveConstructibleTuple<_U1, _U2>()
1007 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1009 constexpr tuple(tuple<_U1, _U2>&& __in)
1010 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1012 template<typename _U1, typename _U2, typename
1013 enable_if<_TMC::template
1014 _MoveConstructibleTuple<_U1, _U2>()
1016 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1017 bool>::type = false>
1018 explicit constexpr tuple(tuple<_U1, _U2>&& __in)
1019 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1021 template<typename _U1, typename _U2, typename
1022 enable_if<_TMC::template
1023 _ConstructibleTuple<_U1, _U2>()
1025 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1027 constexpr tuple(const pair<_U1, _U2>& __in)
1028 : _Inherited(__in.first, __in.second) { }
1030 template<typename _U1, typename _U2, typename
1031 enable_if<_TMC::template
1032 _ConstructibleTuple<_U1, _U2>()
1034 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1035 bool>::type = false>
1036 explicit constexpr tuple(const pair<_U1, _U2>& __in)
1037 : _Inherited(__in.first, __in.second) { }
1039 template<typename _U1, typename _U2, typename
1040 enable_if<_TMC::template
1041 _MoveConstructibleTuple<_U1, _U2>()
1043 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1045 constexpr tuple(pair<_U1, _U2>&& __in)
1046 : _Inherited(std::forward<_U1>(__in.first),
1047 std::forward<_U2>(__in.second)) { }
1049 template<typename _U1, typename _U2, typename
1050 enable_if<_TMC::template
1051 _MoveConstructibleTuple<_U1, _U2>()
1053 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1054 bool>::type = false>
1055 explicit constexpr tuple(pair<_U1, _U2>&& __in)
1056 : _Inherited(std::forward<_U1>(__in.first),
1057 std::forward<_U2>(__in.second)) { }
1059 // Allocator-extended constructors.
1061 template<typename _Alloc>
1062 tuple(allocator_arg_t __tag, const _Alloc& __a)
1063 : _Inherited(__tag, __a) { }
1065 template<typename _Alloc, typename _Dummy = void,
1067 _TCC<_Dummy>::template
1068 _ConstructibleTuple<_T1, _T2>()
1069 && _TCC<_Dummy>::template
1070 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1073 tuple(allocator_arg_t __tag, const _Alloc& __a,
1074 const _T1& __a1, const _T2& __a2)
1075 : _Inherited(__tag, __a, __a1, __a2) { }
1077 template<typename _Alloc, typename _Dummy = void,
1079 _TCC<_Dummy>::template
1080 _ConstructibleTuple<_T1, _T2>()
1081 && !_TCC<_Dummy>::template
1082 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1085 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1086 const _T1& __a1, const _T2& __a2)
1087 : _Inherited(__tag, __a, __a1, __a2) { }
1089 template<typename _Alloc, typename _U1, typename _U2, typename
1090 enable_if<_TMC::template
1091 _MoveConstructibleTuple<_U1, _U2>()
1093 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1095 tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1096 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1097 std::forward<_U2>(__a2)) { }
1099 template<typename _Alloc, typename _U1, typename _U2, typename
1100 enable_if<_TMC::template
1101 _MoveConstructibleTuple<_U1, _U2>()
1103 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1104 bool>::type = false>
1105 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1106 _U1&& __a1, _U2&& __a2)
1107 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1108 std::forward<_U2>(__a2)) { }
1110 template<typename _Alloc>
1111 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1112 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1114 template<typename _Alloc>
1115 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1116 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1118 template<typename _Alloc, typename _U1, typename _U2, typename
1119 enable_if<_TMC::template
1120 _ConstructibleTuple<_U1, _U2>()
1122 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1124 tuple(allocator_arg_t __tag, const _Alloc& __a,
1125 const tuple<_U1, _U2>& __in)
1126 : _Inherited(__tag, __a,
1127 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1130 template<typename _Alloc, typename _U1, typename _U2, typename
1131 enable_if<_TMC::template
1132 _ConstructibleTuple<_U1, _U2>()
1134 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1135 bool>::type = false>
1136 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1137 const tuple<_U1, _U2>& __in)
1138 : _Inherited(__tag, __a,
1139 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1142 template<typename _Alloc, typename _U1, typename _U2, typename
1143 enable_if<_TMC::template
1144 _MoveConstructibleTuple<_U1, _U2>()
1146 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1148 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1149 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1152 template<typename _Alloc, typename _U1, typename _U2, typename
1153 enable_if<_TMC::template
1154 _MoveConstructibleTuple<_U1, _U2>()
1156 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1157 bool>::type = false>
1158 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1159 tuple<_U1, _U2>&& __in)
1160 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1163 template<typename _Alloc, typename _U1, typename _U2, typename
1164 enable_if<_TMC::template
1165 _ConstructibleTuple<_U1, _U2>()
1167 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1169 tuple(allocator_arg_t __tag, const _Alloc& __a,
1170 const pair<_U1, _U2>& __in)
1171 : _Inherited(__tag, __a, __in.first, __in.second) { }
1173 template<typename _Alloc, typename _U1, typename _U2, typename
1174 enable_if<_TMC::template
1175 _ConstructibleTuple<_U1, _U2>()
1177 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1178 bool>::type = false>
1179 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1180 const pair<_U1, _U2>& __in)
1181 : _Inherited(__tag, __a, __in.first, __in.second) { }
1183 template<typename _Alloc, typename _U1, typename _U2, typename
1184 enable_if<_TMC::template
1185 _MoveConstructibleTuple<_U1, _U2>()
1187 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1189 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1190 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1191 std::forward<_U2>(__in.second)) { }
1193 template<typename _Alloc, typename _U1, typename _U2, typename
1194 enable_if<_TMC::template
1195 _MoveConstructibleTuple<_U1, _U2>()
1197 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1198 bool>::type = false>
1199 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1200 pair<_U1, _U2>&& __in)
1201 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1202 std::forward<_U2>(__in.second)) { }
1205 operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
1207 const __nonesuch_no_braces&>::type __in)
1208 noexcept(__nothrow_assignable<const _T1&, const _T2&>())
1210 this->_M_assign(__in);
1215 operator=(typename conditional<__assignable<_T1, _T2>(),
1217 __nonesuch_no_braces&&>::type __in)
1218 noexcept(__nothrow_assignable<_T1, _T2>())
1220 this->_M_assign(std::move(__in));
1224 template<typename _U1, typename _U2>
1225 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1226 operator=(const tuple<_U1, _U2>& __in)
1227 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1229 this->_M_assign(__in);
1233 template<typename _U1, typename _U2>
1234 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1235 operator=(tuple<_U1, _U2>&& __in)
1236 noexcept(__nothrow_assignable<_U1, _U2>())
1238 this->_M_assign(std::move(__in));
1242 template<typename _U1, typename _U2>
1243 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1244 operator=(const pair<_U1, _U2>& __in)
1245 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1247 this->_M_head(*this) = __in.first;
1248 this->_M_tail(*this)._M_head(*this) = __in.second;
1252 template<typename _U1, typename _U2>
1253 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1254 operator=(pair<_U1, _U2>&& __in)
1255 noexcept(__nothrow_assignable<_U1, _U2>())
1257 this->_M_head(*this) = std::forward<_U1>(__in.first);
1258 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1264 noexcept(__and_<__is_nothrow_swappable<_T1>,
1265 __is_nothrow_swappable<_T2>>::value)
1266 { _Inherited::_M_swap(__in); }
1270 /// class tuple_size
1271 template<typename... _Elements>
1272 struct tuple_size<tuple<_Elements...>>
1273 : public integral_constant<std::size_t, sizeof...(_Elements)> { };
1275 #if __cplusplus > 201402L
1276 template <typename _Tp>
1277 inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1281 * Recursive case for tuple_element: strip off the first element in
1282 * the tuple and retrieve the (i-1)th element of the remaining tuple.
1284 template<std::size_t __i, typename _Head, typename... _Tail>
1285 struct tuple_element<__i, tuple<_Head, _Tail...> >
1286 : tuple_element<__i - 1, tuple<_Tail...> > { };
1289 * Basis case for tuple_element: The first element is the one we're seeking.
1291 template<typename _Head, typename... _Tail>
1292 struct tuple_element<0, tuple<_Head, _Tail...> >
1298 * Error case for tuple_element: invalid index.
1300 template<size_t __i>
1301 struct tuple_element<__i, tuple<>>
1303 static_assert(__i < tuple_size<tuple<>>::value,
1304 "tuple index is in range");
1307 template<std::size_t __i, typename _Head, typename... _Tail>
1309 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1310 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1312 template<std::size_t __i, typename _Head, typename... _Tail>
1313 constexpr const _Head&
1314 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1315 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1317 /// Return a reference to the ith element of a tuple.
1318 template<std::size_t __i, typename... _Elements>
1319 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1320 get(tuple<_Elements...>& __t) noexcept
1321 { return std::__get_helper<__i>(__t); }
1323 /// Return a const reference to the ith element of a const tuple.
1324 template<std::size_t __i, typename... _Elements>
1325 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
1326 get(const tuple<_Elements...>& __t) noexcept
1327 { return std::__get_helper<__i>(__t); }
1329 /// Return an rvalue reference to the ith element of a tuple rvalue.
1330 template<std::size_t __i, typename... _Elements>
1331 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1332 get(tuple<_Elements...>&& __t) noexcept
1334 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1335 return std::forward<__element_type&&>(std::get<__i>(__t));
1338 /// Return a const rvalue reference to the ith element of a const tuple rvalue.
1339 template<std::size_t __i, typename... _Elements>
1340 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
1341 get(const tuple<_Elements...>&& __t) noexcept
1343 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1344 return std::forward<const __element_type&&>(std::get<__i>(__t));
1347 #if __cplusplus >= 201402L
1349 #define __cpp_lib_tuples_by_type 201304
1351 template<typename _Head, size_t __i, typename... _Tail>
1353 __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1354 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1356 template<typename _Head, size_t __i, typename... _Tail>
1357 constexpr const _Head&
1358 __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1359 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1361 /// Return a reference to the unique element of type _Tp of a tuple.
1362 template <typename _Tp, typename... _Types>
1364 get(tuple<_Types...>& __t) noexcept
1365 { return std::__get_helper2<_Tp>(__t); }
1367 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1368 template <typename _Tp, typename... _Types>
1370 get(tuple<_Types...>&& __t) noexcept
1371 { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
1373 /// Return a const reference to the unique element of type _Tp of a tuple.
1374 template <typename _Tp, typename... _Types>
1375 constexpr const _Tp&
1376 get(const tuple<_Types...>& __t) noexcept
1377 { return std::__get_helper2<_Tp>(__t); }
1379 /// Return a const reference to the unique element of type _Tp of
1380 /// a const tuple rvalue.
1381 template <typename _Tp, typename... _Types>
1382 constexpr const _Tp&&
1383 get(const tuple<_Types...>&& __t) noexcept
1384 { return std::forward<const _Tp&&>(std::__get_helper2<_Tp>(__t)); }
1387 // This class performs the comparison operations on tuples
1388 template<typename _Tp, typename _Up, size_t __i, size_t __size>
1389 struct __tuple_compare
1391 static constexpr bool
1392 __eq(const _Tp& __t, const _Up& __u)
1394 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1395 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1398 static constexpr bool
1399 __less(const _Tp& __t, const _Up& __u)
1401 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1402 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1403 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1407 template<typename _Tp, typename _Up, size_t __size>
1408 struct __tuple_compare<_Tp, _Up, __size, __size>
1410 static constexpr bool
1411 __eq(const _Tp&, const _Up&) { return true; }
1413 static constexpr bool
1414 __less(const _Tp&, const _Up&) { return false; }
1417 template<typename... _TElements, typename... _UElements>
1419 operator==(const tuple<_TElements...>& __t,
1420 const tuple<_UElements...>& __u)
1422 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1423 "tuple objects can only be compared if they have equal sizes.");
1424 using __compare = __tuple_compare<tuple<_TElements...>,
1425 tuple<_UElements...>,
1426 0, sizeof...(_TElements)>;
1427 return __compare::__eq(__t, __u);
1430 template<typename... _TElements, typename... _UElements>
1432 operator<(const tuple<_TElements...>& __t,
1433 const tuple<_UElements...>& __u)
1435 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1436 "tuple objects can only be compared if they have equal sizes.");
1437 using __compare = __tuple_compare<tuple<_TElements...>,
1438 tuple<_UElements...>,
1439 0, sizeof...(_TElements)>;
1440 return __compare::__less(__t, __u);
1443 template<typename... _TElements, typename... _UElements>
1445 operator!=(const tuple<_TElements...>& __t,
1446 const tuple<_UElements...>& __u)
1447 { return !(__t == __u); }
1449 template<typename... _TElements, typename... _UElements>
1451 operator>(const tuple<_TElements...>& __t,
1452 const tuple<_UElements...>& __u)
1453 { return __u < __t; }
1455 template<typename... _TElements, typename... _UElements>
1457 operator<=(const tuple<_TElements...>& __t,
1458 const tuple<_UElements...>& __u)
1459 { return !(__u < __t); }
1461 template<typename... _TElements, typename... _UElements>
1463 operator>=(const tuple<_TElements...>& __t,
1464 const tuple<_UElements...>& __u)
1465 { return !(__t < __u); }
1468 template<typename... _Elements>
1469 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1470 make_tuple(_Elements&&... __args)
1472 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1474 return __result_type(std::forward<_Elements>(__args)...);
1477 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1478 // 2275. Why is forward_as_tuple not constexpr?
1479 /// std::forward_as_tuple
1480 template<typename... _Elements>
1481 constexpr tuple<_Elements&&...>
1482 forward_as_tuple(_Elements&&... __args) noexcept
1483 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
1485 template<size_t, typename, typename, size_t>
1486 struct __make_tuple_impl;
1488 template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
1489 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
1490 : __make_tuple_impl<_Idx + 1,
1491 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
1495 template<std::size_t _Nm, typename _Tuple, typename... _Tp>
1496 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
1498 typedef tuple<_Tp...> __type;
1501 template<typename _Tuple>
1502 struct __do_make_tuple
1503 : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
1506 // Returns the std::tuple equivalent of a tuple-like type.
1507 template<typename _Tuple>
1509 : public __do_make_tuple<__remove_cvref_t<_Tuple>>
1512 // Combines several std::tuple's into a single one.
1513 template<typename...>
1514 struct __combine_tuples;
1517 struct __combine_tuples<>
1519 typedef tuple<> __type;
1522 template<typename... _Ts>
1523 struct __combine_tuples<tuple<_Ts...>>
1525 typedef tuple<_Ts...> __type;
1528 template<typename... _T1s, typename... _T2s, typename... _Rem>
1529 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
1531 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
1532 _Rem...>::__type __type;
1535 // Computes the result type of tuple_cat given a set of tuple-like types.
1536 template<typename... _Tpls>
1537 struct __tuple_cat_result
1539 typedef typename __combine_tuples
1540 <typename __make_tuple<_Tpls>::__type...>::__type __type;
1543 // Helper to determine the index set for the first tuple-like
1544 // type of a given set.
1545 template<typename...>
1546 struct __make_1st_indices;
1549 struct __make_1st_indices<>
1551 typedef std::_Index_tuple<> __type;
1554 template<typename _Tp, typename... _Tpls>
1555 struct __make_1st_indices<_Tp, _Tpls...>
1557 typedef typename std::_Build_index_tuple<std::tuple_size<
1558 typename std::remove_reference<_Tp>::type>::value>::__type __type;
1561 // Performs the actual concatenation by step-wise expanding tuple-like
1562 // objects into the elements, which are finally forwarded into the
1564 template<typename _Ret, typename _Indices, typename... _Tpls>
1565 struct __tuple_concater;
1567 template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
1568 struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
1570 template<typename... _Us>
1571 static constexpr _Ret
1572 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1574 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1575 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
1576 return __next::_S_do(std::forward<_Tpls>(__tps)...,
1577 std::forward<_Us>(__us)...,
1578 std::get<_Is>(std::forward<_Tp>(__tp))...);
1582 template<typename _Ret>
1583 struct __tuple_concater<_Ret, std::_Index_tuple<>>
1585 template<typename... _Us>
1586 static constexpr _Ret
1587 _S_do(_Us&&... __us)
1589 return _Ret(std::forward<_Us>(__us)...);
1594 template<typename... _Tpls, typename = typename
1595 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1597 tuple_cat(_Tpls&&... __tpls)
1598 -> typename __tuple_cat_result<_Tpls...>::__type
1600 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1601 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1602 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1603 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1606 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1607 // 2301. Why is tie not constexpr?
1609 template<typename... _Elements>
1610 constexpr tuple<_Elements&...>
1611 tie(_Elements&... __args) noexcept
1612 { return tuple<_Elements&...>(__args...); }
1615 template<typename... _Elements>
1617 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
1618 // Constrained free swap overload, see p0185r1
1619 typename enable_if<__and_<__is_swappable<_Elements>...>::value
1624 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1625 noexcept(noexcept(__x.swap(__y)))
1628 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
1629 template<typename... _Elements>
1630 typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
1631 swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
1634 // A class (and instance) which can be used in 'tie' when an element
1635 // of a tuple is not required.
1636 // _GLIBCXX14_CONSTEXPR
1637 // 2933. PR for LWG 2773 could be clearer
1638 struct _Swallow_assign
1641 _GLIBCXX14_CONSTEXPR const _Swallow_assign&
1642 operator=(const _Tp&) const
1646 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1647 // 2773. Making std::ignore constexpr
1648 _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
1650 /// Partial specialization for tuples
1651 template<typename... _Types, typename _Alloc>
1652 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
1654 // See stl_pair.h...
1655 template<class _T1, class _T2>
1656 template<typename... _Args1, typename... _Args2>
1659 pair(piecewise_construct_t,
1660 tuple<_Args1...> __first, tuple<_Args2...> __second)
1661 : pair(__first, __second,
1662 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
1663 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
1666 template<class _T1, class _T2>
1667 template<typename... _Args1, std::size_t... _Indexes1,
1668 typename... _Args2, std::size_t... _Indexes2>
1671 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1672 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1673 : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1674 second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1677 #if __cplusplus >= 201703L
1678 # define __cpp_lib_apply 201603
1680 template <typename _Fn, typename _Tuple, size_t... _Idx>
1681 constexpr decltype(auto)
1682 __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
1684 return std::__invoke(std::forward<_Fn>(__f),
1685 std::get<_Idx>(std::forward<_Tuple>(__t))...);
1688 template <typename _Fn, typename _Tuple>
1689 constexpr decltype(auto)
1690 apply(_Fn&& __f, _Tuple&& __t)
1693 = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>;
1694 return std::__apply_impl(std::forward<_Fn>(__f),
1695 std::forward<_Tuple>(__t),
1699 #define __cpp_lib_make_from_tuple 201606
1701 template <typename _Tp, typename _Tuple, size_t... _Idx>
1703 __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
1704 { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
1706 template <typename _Tp, typename _Tuple>
1708 make_from_tuple(_Tuple&& __t)
1710 return __make_from_tuple_impl<_Tp>(
1711 std::forward<_Tuple>(__t),
1712 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{});
1718 _GLIBCXX_END_NAMESPACE_VERSION
1723 #endif // _GLIBCXX_TUPLE