3// Copyright (C) 2007-2022 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.
30#define _GLIBCXX_TUPLE 1
32#pragma GCC system_header
34#if __cplusplus < 201103L
35# include <bits/c++0x_warning.h>
38#include <bits/stl_pair.h> // for std::pair
39#include <bits/uses_allocator.h> // for std::allocator_arg_t
40#include <bits/utility.h> // for std::get, std::tuple_size etc.
41#include <bits/invoke.h> // for std::__invoke
42#if __cplusplus > 201703L
44# define __cpp_lib_constexpr_tuple 201811L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
52 * @addtogroup utilities
56 template<typename... _Elements>
59 template<typename _Tp>
60 struct __is_empty_non_tuple : is_empty<_Tp> { };
62 // Using EBO for elements that are tuples causes ambiguous base errors.
63 template<typename _El0, typename... _El>
64 struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
66 // Use the Empty Base-class Optimization for empty, non-final types.
67 template<typename _Tp>
68 using __empty_not_final
69 = __conditional_t<__is_final(_Tp), false_type,
70 __is_empty_non_tuple<_Tp>>;
72 template<size_t _Idx, typename _Head,
73 bool = __empty_not_final<_Head>::value>
76#if __has_cpp_attribute(__no_unique_address__)
77 template<size_t _Idx, typename _Head>
78 struct _Head_base<_Idx, _Head, true>
80 constexpr _Head_base()
83 constexpr _Head_base(const _Head& __h)
84 : _M_head_impl(__h) { }
86 constexpr _Head_base(const _Head_base&) = default;
87 constexpr _Head_base(_Head_base&&) = default;
89 template<typename _UHead>
90 constexpr _Head_base(_UHead&& __h)
91 : _M_head_impl(std::forward<_UHead>(__h)) { }
94 _Head_base(allocator_arg_t, __uses_alloc0)
97 template<typename _Alloc>
99 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
100 : _M_head_impl(allocator_arg, *__a._M_a) { }
102 template<typename _Alloc>
104 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
105 : _M_head_impl(*__a._M_a) { }
107 template<typename _UHead>
109 _Head_base(__uses_alloc0, _UHead&& __uhead)
110 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
112 template<typename _Alloc, typename _UHead>
114 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
115 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
118 template<typename _Alloc, typename _UHead>
120 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
121 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
123 static constexpr _Head&
124 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
126 static constexpr const _Head&
127 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
129 [[__no_unique_address__]] _Head _M_head_impl;
132 template<size_t _Idx, typename _Head>
133 struct _Head_base<_Idx, _Head, true>
136 constexpr _Head_base()
139 constexpr _Head_base(const _Head& __h)
142 constexpr _Head_base(const _Head_base&) = default;
143 constexpr _Head_base(_Head_base&&) = default;
145 template<typename _UHead>
146 constexpr _Head_base(_UHead&& __h)
147 : _Head(std::forward<_UHead>(__h)) { }
150 _Head_base(allocator_arg_t, __uses_alloc0)
153 template<typename _Alloc>
155 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
156 : _Head(allocator_arg, *__a._M_a) { }
158 template<typename _Alloc>
160 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
161 : _Head(*__a._M_a) { }
163 template<typename _UHead>
165 _Head_base(__uses_alloc0, _UHead&& __uhead)
166 : _Head(std::forward<_UHead>(__uhead)) { }
168 template<typename _Alloc, typename _UHead>
170 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
171 : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
173 template<typename _Alloc, typename _UHead>
175 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
176 : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
178 static constexpr _Head&
179 _M_head(_Head_base& __b) noexcept { return __b; }
181 static constexpr const _Head&
182 _M_head(const _Head_base& __b) noexcept { return __b; }
186 template<size_t _Idx, typename _Head>
187 struct _Head_base<_Idx, _Head, false>
189 constexpr _Head_base()
192 constexpr _Head_base(const _Head& __h)
193 : _M_head_impl(__h) { }
195 constexpr _Head_base(const _Head_base&) = default;
196 constexpr _Head_base(_Head_base&&) = default;
198 template<typename _UHead>
199 constexpr _Head_base(_UHead&& __h)
200 : _M_head_impl(std::forward<_UHead>(__h)) { }
203 _Head_base(allocator_arg_t, __uses_alloc0)
206 template<typename _Alloc>
208 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
209 : _M_head_impl(allocator_arg, *__a._M_a) { }
211 template<typename _Alloc>
213 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
214 : _M_head_impl(*__a._M_a) { }
216 template<typename _UHead>
218 _Head_base(__uses_alloc0, _UHead&& __uhead)
219 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
221 template<typename _Alloc, typename _UHead>
223 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
224 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
227 template<typename _Alloc, typename _UHead>
229 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
230 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
232 static constexpr _Head&
233 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
235 static constexpr const _Head&
236 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
242 * Contains the actual implementation of the @c tuple template, stored
243 * as a recursive inheritance hierarchy from the first element (most
244 * derived class) to the last (least derived class). The @c Idx
245 * parameter gives the 0-based index of the element stored at this
246 * point in the hierarchy; we use it to implement a constant-time
249 template<size_t _Idx, typename... _Elements>
253 * Recursive tuple implementation. Here we store the @c Head element
254 * and derive from a @c Tuple_impl containing the remaining elements
255 * (which contains the @c Tail).
257 template<size_t _Idx, typename _Head, typename... _Tail>
258 struct _Tuple_impl<_Idx, _Head, _Tail...>
259 : public _Tuple_impl<_Idx + 1, _Tail...>,
260 private _Head_base<_Idx, _Head>
262 template<size_t, typename...> friend struct _Tuple_impl;
264 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
265 typedef _Head_base<_Idx, _Head> _Base;
267 static constexpr _Head&
268 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
270 static constexpr const _Head&
271 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
273 static constexpr _Inherited&
274 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
276 static constexpr const _Inherited&
277 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
279 constexpr _Tuple_impl()
280 : _Inherited(), _Base() { }
283 _Tuple_impl(const _Head& __head, const _Tail&... __tail)
284 : _Inherited(__tail...), _Base(__head)
287 template<typename _UHead, typename... _UTail,
288 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
290 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
291 : _Inherited(std::forward<_UTail>(__tail)...),
292 _Base(std::forward<_UHead>(__head))
295 constexpr _Tuple_impl(const _Tuple_impl&) = default;
297 // _GLIBCXX_RESOLVE_LIB_DEFECTS
298 // 2729. Missing SFINAE on std::pair::operator=
299 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
301 _Tuple_impl(_Tuple_impl&&) = default;
303 template<typename... _UElements>
305 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
306 : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
307 _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
310 template<typename _UHead, typename... _UTails>
312 _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
313 : _Inherited(std::move
314 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
315 _Base(std::forward<_UHead>
316 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
319#if __cplusplus > 202002L
320 template<typename... _UElements>
322 _Tuple_impl(_Tuple_impl<_Idx, _UElements...>& __in)
323 : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
324 _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
327 template<typename _UHead, typename... _UTails>
329 _Tuple_impl(const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
330 : _Inherited(std::move
331 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
332 _Base(std::forward<const _UHead>
333 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
337 template<typename _Alloc>
339 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
340 : _Inherited(__tag, __a),
341 _Base(__tag, __use_alloc<_Head>(__a))
344 template<typename _Alloc>
346 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
347 const _Head& __head, const _Tail&... __tail)
348 : _Inherited(__tag, __a, __tail...),
349 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head)
352 template<typename _Alloc, typename _UHead, typename... _UTail,
353 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
355 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
356 _UHead&& __head, _UTail&&... __tail)
357 : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
358 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
359 std::forward<_UHead>(__head))
362 template<typename _Alloc>
364 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
365 const _Tuple_impl& __in)
366 : _Inherited(__tag, __a, _M_tail(__in)),
367 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in))
370 template<typename _Alloc>
372 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
374 : _Inherited(__tag, __a, std::move(_M_tail(__in))),
375 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
376 std::forward<_Head>(_M_head(__in)))
379 template<typename _Alloc, typename _UHead, typename... _UTails>
381 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
382 const _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
383 : _Inherited(__tag, __a,
384 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
385 _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
386 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
389 template<typename _Alloc, typename _UHead, typename... _UTails>
391 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
392 _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
393 : _Inherited(__tag, __a, std::move
394 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
395 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
397 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
400#if __cplusplus > 202002L
401 template<typename _Alloc, typename _UHead, typename... _UTails>
403 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
404 _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
405 : _Inherited(__tag, __a,
406 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
407 _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a),
408 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
411 template<typename _Alloc, typename _UHead, typename... _UTails>
413 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
414 const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
415 : _Inherited(__tag, __a, std::move
416 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
417 _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a),
418 std::forward<const _UHead>
419 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
423 template<typename... _UElements>
426 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
428 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
429 _M_tail(*this)._M_assign(
430 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
433 template<typename _UHead, typename... _UTails>
436 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
438 _M_head(*this) = std::forward<_UHead>
439 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
440 _M_tail(*this)._M_assign(
441 std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
444#if __cplusplus > 202002L
445 template<typename... _UElements>
447 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in) const
449 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
450 _M_tail(*this)._M_assign(
451 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
454 template<typename _UHead, typename... _UTails>
456 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) const
458 _M_head(*this) = std::forward<_UHead>
459 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
460 _M_tail(*this)._M_assign(
461 std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
468 _M_swap(_Tuple_impl& __in)
471 swap(_M_head(*this), _M_head(__in));
472 _Inherited::_M_swap(_M_tail(__in));
475#if __cplusplus > 202002L
477 _M_swap(const _Tuple_impl& __in) const
480 swap(_M_head(*this), _M_head(__in));
481 _Inherited::_M_swap(_M_tail(__in));
486 // Basis case of inheritance recursion.
487 template<size_t _Idx, typename _Head>
488 struct _Tuple_impl<_Idx, _Head>
489 : private _Head_base<_Idx, _Head>
491 template<size_t, typename...> friend struct _Tuple_impl;
493 typedef _Head_base<_Idx, _Head> _Base;
495 static constexpr _Head&
496 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
498 static constexpr const _Head&
499 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
506 _Tuple_impl(const _Head& __head)
510 template<typename _UHead>
512 _Tuple_impl(_UHead&& __head)
513 : _Base(std::forward<_UHead>(__head))
516 constexpr _Tuple_impl(const _Tuple_impl&) = default;
518 // _GLIBCXX_RESOLVE_LIB_DEFECTS
519 // 2729. Missing SFINAE on std::pair::operator=
520 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
522#if _GLIBCXX_INLINE_VERSION
523 _Tuple_impl(_Tuple_impl&&) = default;
526 _Tuple_impl(_Tuple_impl&& __in)
527 noexcept(is_nothrow_move_constructible<_Head>::value)
528 : _Base(static_cast<_Base&&>(__in))
532 template<typename _UHead>
534 _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
535 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
538 template<typename _UHead>
540 _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
541 : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
544#if __cplusplus > 202002L
545 template<typename _UHead>
547 _Tuple_impl(_Tuple_impl<_Idx, _UHead>& __in)
548 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
551 template<typename _UHead>
553 _Tuple_impl(const _Tuple_impl<_Idx, _UHead>&& __in)
554 : _Base(std::forward<const _UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
558 template<typename _Alloc>
560 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
561 : _Base(__tag, __use_alloc<_Head>(__a))
564 template<typename _Alloc>
566 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
568 : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
571 template<typename _Alloc, typename _UHead>
573 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
575 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
576 std::forward<_UHead>(__head))
579 template<typename _Alloc>
581 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
582 const _Tuple_impl& __in)
583 : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), _M_head(__in))
586 template<typename _Alloc>
588 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
590 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
591 std::forward<_Head>(_M_head(__in)))
594 template<typename _Alloc, typename _UHead>
596 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
597 const _Tuple_impl<_Idx, _UHead>& __in)
598 : _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
599 _Tuple_impl<_Idx, _UHead>::_M_head(__in))
602 template<typename _Alloc, typename _UHead>
604 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
605 _Tuple_impl<_Idx, _UHead>&& __in)
606 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
607 std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
610#if __cplusplus > 202002L
611 template<typename _Alloc, typename _UHead>
613 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
614 _Tuple_impl<_Idx, _UHead>& __in)
615 : _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a),
616 _Tuple_impl<_Idx, _UHead>::_M_head(__in))
619 template<typename _Alloc, typename _UHead>
621 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
622 const _Tuple_impl<_Idx, _UHead>&& __in)
623 : _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a),
624 std::forward<const _UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
628 template<typename _UHead>
631 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
633 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
636 template<typename _UHead>
639 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
642 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
645#if __cplusplus > 202002L
646 template<typename _UHead>
648 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in) const
650 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
653 template<typename _UHead>
655 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in) const
658 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
665 _M_swap(_Tuple_impl& __in)
668 swap(_M_head(*this), _M_head(__in));
671#if __cplusplus > 202002L
673 _M_swap(const _Tuple_impl& __in) const
676 swap(_M_head(*this), _M_head(__in));
681 // Concept utility functions, reused in conditionally-explicit
683 template<bool, typename... _Types>
684 struct _TupleConstraints
686 template<typename... _UTypes>
687 using __constructible = __and_<is_constructible<_Types, _UTypes>...>;
689 template<typename... _UTypes>
690 using __convertible = __and_<is_convertible<_UTypes, _Types>...>;
692 // Constraint for a non-explicit constructor.
693 // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
694 // and every Ui is implicitly convertible to Ti.
695 template<typename... _UTypes>
696 static constexpr bool __is_implicitly_constructible()
698 return __and_<__constructible<_UTypes...>,
699 __convertible<_UTypes...>
703 // Constraint for a non-explicit constructor.
704 // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
705 // but not every Ui is implicitly convertible to Ti.
706 template<typename... _UTypes>
707 static constexpr bool __is_explicitly_constructible()
709 return __and_<__constructible<_UTypes...>,
710 __not_<__convertible<_UTypes...>>
714 static constexpr bool __is_implicitly_default_constructible()
716 return __and_<std::__is_implicitly_default_constructible<_Types>...
720 static constexpr bool __is_explicitly_default_constructible()
722 return __and_<is_default_constructible<_Types>...,
724 std::__is_implicitly_default_constructible<_Types>...>
729 // Partial specialization used when a required precondition isn't met,
730 // e.g. when sizeof...(_Types) != sizeof...(_UTypes).
731 template<typename... _Types>
732 struct _TupleConstraints<false, _Types...>
734 template<typename... _UTypes>
735 static constexpr bool __is_implicitly_constructible()
738 template<typename... _UTypes>
739 static constexpr bool __is_explicitly_constructible()
743 /// Primary class template, tuple
744 template<typename... _Elements>
745 class tuple : public _Tuple_impl<0, _Elements...>
747 typedef _Tuple_impl<0, _Elements...> _Inherited;
750 using _TCC = _TupleConstraints<_Cond, _Elements...>;
752 // Constraint for non-explicit default constructor
753 template<bool _Dummy>
754 using _ImplicitDefaultCtor = __enable_if_t<
755 _TCC<_Dummy>::__is_implicitly_default_constructible(),
758 // Constraint for explicit default constructor
759 template<bool _Dummy>
760 using _ExplicitDefaultCtor = __enable_if_t<
761 _TCC<_Dummy>::__is_explicitly_default_constructible(),
764 // Constraint for non-explicit constructors
765 template<bool _Cond, typename... _Args>
766 using _ImplicitCtor = __enable_if_t<
767 _TCC<_Cond>::template __is_implicitly_constructible<_Args...>(),
770 // Constraint for non-explicit constructors
771 template<bool _Cond, typename... _Args>
772 using _ExplicitCtor = __enable_if_t<
773 _TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
776 template<typename... _UElements>
778 __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
780 { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
782 // Condition for noexcept-specifier of an assignment operator.
783 template<typename... _UElements>
784 static constexpr bool __nothrow_assignable()
787 __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
790 // Condition for noexcept-specifier of a constructor.
791 template<typename... _UElements>
792 static constexpr bool __nothrow_constructible()
795 __and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
798 // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
799 template<typename _Up>
800 static constexpr bool __valid_args()
802 return sizeof...(_Elements) == 1
803 && !is_same<tuple, __remove_cvref_t<_Up>>::value;
806 // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) > 1.
807 template<typename, typename, typename... _Tail>
808 static constexpr bool __valid_args()
809 { return (sizeof...(_Tail) + 2) == sizeof...(_Elements); }
811 /* Constraint for constructors with a tuple<UTypes...> parameter ensures
812 * that the constructor is only viable when it would not interfere with
813 * tuple(UTypes&&...) or tuple(const tuple&) or tuple(tuple&&).
814 * Such constructors are only viable if:
815 * either sizeof...(Types) != 1,
816 * or (when Types... expands to T and UTypes... expands to U)
817 * is_convertible_v<TUPLE, T>, is_constructible_v<T, TUPLE>,
818 * and is_same_v<T, U> are all false.
820 template<typename _Tuple, typename = tuple,
821 typename = __remove_cvref_t<_Tuple>>
825 // If TUPLE is convertible to the single element in *this,
826 // then TUPLE should match tuple(UTypes&&...) instead.
827 template<typename _Tuple, typename _Tp, typename _Up>
828 struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Up>>
829 : __or_<is_convertible<_Tuple, _Tp>, is_constructible<_Tp, _Tuple>>::type
831 // If TUPLE and *this each have a single element of the same type,
832 // then TUPLE should match a copy/move constructor instead.
833 template<typename _Tuple, typename _Tp>
834 struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Tp>>
838 // Return true iff sizeof...(Types) == 1 && tuple_size_v<TUPLE> == 1
839 // and the single element in Types can be initialized from TUPLE,
840 // or is the same type as tuple_element_t<0, TUPLE>.
841 template<typename _Tuple>
842 static constexpr bool __use_other_ctor()
843 { return _UseOtherCtor<_Tuple>::value; }
845#if __cplusplus > 202002L
846 template<typename... _Args>
847 static constexpr bool __constructible
848 = _TCC<true>::template __constructible<_Args...>::value;
850 template<typename... _Args>
851 static constexpr bool __convertible
852 = _TCC<true>::template __convertible<_Args...>::value;
856 template<typename _Dummy = void,
857 _ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
860 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
863 template<typename _Dummy = void,
864 _ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
867 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
870 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
871 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
873 tuple(const _Elements&... __elements)
874 noexcept(__nothrow_constructible<const _Elements&...>())
875 : _Inherited(__elements...) { }
877 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
878 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
880 tuple(const _Elements&... __elements)
881 noexcept(__nothrow_constructible<const _Elements&...>())
882 : _Inherited(__elements...) { }
884 template<typename... _UElements,
885 bool _Valid = __valid_args<_UElements...>(),
886 _ImplicitCtor<_Valid, _UElements...> = true>
888 tuple(_UElements&&... __elements)
889 noexcept(__nothrow_constructible<_UElements...>())
890 : _Inherited(std::forward<_UElements>(__elements)...) { }
892 template<typename... _UElements,
893 bool _Valid = __valid_args<_UElements...>(),
894 _ExplicitCtor<_Valid, _UElements...> = false>
896 tuple(_UElements&&... __elements)
897 noexcept(__nothrow_constructible<_UElements...>())
898 : _Inherited(std::forward<_UElements>(__elements)...) { }
900 constexpr tuple(const tuple&) = default;
902 constexpr tuple(tuple&&) = default;
904 template<typename... _UElements,
905 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
906 && !__use_other_ctor<const tuple<_UElements...>&>(),
907 _ImplicitCtor<_Valid, const _UElements&...> = true>
909 tuple(const tuple<_UElements...>& __in)
910 noexcept(__nothrow_constructible<const _UElements&...>())
911 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
914 template<typename... _UElements,
915 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
916 && !__use_other_ctor<const tuple<_UElements...>&>(),
917 _ExplicitCtor<_Valid, const _UElements&...> = false>
919 tuple(const tuple<_UElements...>& __in)
920 noexcept(__nothrow_constructible<const _UElements&...>())
921 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
924 template<typename... _UElements,
925 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
926 && !__use_other_ctor<tuple<_UElements...>&&>(),
927 _ImplicitCtor<_Valid, _UElements...> = true>
929 tuple(tuple<_UElements...>&& __in)
930 noexcept(__nothrow_constructible<_UElements...>())
931 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
933 template<typename... _UElements,
934 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
935 && !__use_other_ctor<tuple<_UElements...>&&>(),
936 _ExplicitCtor<_Valid, _UElements...> = false>
938 tuple(tuple<_UElements...>&& __in)
939 noexcept(__nothrow_constructible<_UElements...>())
940 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
942#if __cplusplus > 202002L
943 template<typename... _UElements>
944 requires (sizeof...(_Elements) == sizeof...(_UElements))
945 && (!__use_other_ctor<tuple<_UElements...>&>())
946 && __constructible<_UElements&...>
947 explicit(!__convertible<_UElements&...>)
949 tuple(tuple<_UElements...>& __in)
950 noexcept(__nothrow_constructible<_UElements&...>())
951 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&>(__in))
954 template<typename... _UElements>
955 requires (sizeof...(_Elements) == sizeof...(_UElements))
956 && (!__use_other_ctor<const tuple<_UElements...>&&>())
957 && __constructible<const _UElements...>
958 explicit(!__convertible<const _UElements...>)
960 tuple(const tuple<_UElements...>&& __in)
961 noexcept(__nothrow_constructible<const _UElements...>())
962 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&&>(__in)) { }
965 // Allocator-extended constructors.
967 template<typename _Alloc,
968 _ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
970 tuple(allocator_arg_t __tag, const _Alloc& __a)
971 : _Inherited(__tag, __a) { }
973 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
974 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
976 tuple(allocator_arg_t __tag, const _Alloc& __a,
977 const _Elements&... __elements)
978 : _Inherited(__tag, __a, __elements...) { }
980 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
981 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
984 tuple(allocator_arg_t __tag, const _Alloc& __a,
985 const _Elements&... __elements)
986 : _Inherited(__tag, __a, __elements...) { }
988 template<typename _Alloc, typename... _UElements,
989 bool _Valid = __valid_args<_UElements...>(),
990 _ImplicitCtor<_Valid, _UElements...> = true>
992 tuple(allocator_arg_t __tag, const _Alloc& __a,
993 _UElements&&... __elements)
994 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
997 template<typename _Alloc, typename... _UElements,
998 bool _Valid = __valid_args<_UElements...>(),
999 _ExplicitCtor<_Valid, _UElements...> = false>
1000 _GLIBCXX20_CONSTEXPR
1002 tuple(allocator_arg_t __tag, const _Alloc& __a,
1003 _UElements&&... __elements)
1004 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
1007 template<typename _Alloc>
1008 _GLIBCXX20_CONSTEXPR
1009 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1010 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1012 template<typename _Alloc>
1013 _GLIBCXX20_CONSTEXPR
1014 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1015 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1017 template<typename _Alloc, typename... _UElements,
1018 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
1019 && !__use_other_ctor<const tuple<_UElements...>&>(),
1020 _ImplicitCtor<_Valid, const _UElements&...> = true>
1021 _GLIBCXX20_CONSTEXPR
1022 tuple(allocator_arg_t __tag, const _Alloc& __a,
1023 const tuple<_UElements...>& __in)
1024 : _Inherited(__tag, __a,
1025 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
1028 template<typename _Alloc, typename... _UElements,
1029 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
1030 && !__use_other_ctor<const tuple<_UElements...>&>(),
1031 _ExplicitCtor<_Valid, const _UElements&...> = false>
1032 _GLIBCXX20_CONSTEXPR
1034 tuple(allocator_arg_t __tag, const _Alloc& __a,
1035 const tuple<_UElements...>& __in)
1036 : _Inherited(__tag, __a,
1037 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
1040 template<typename _Alloc, typename... _UElements,
1041 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
1042 && !__use_other_ctor<tuple<_UElements...>&&>(),
1043 _ImplicitCtor<_Valid, _UElements...> = true>
1044 _GLIBCXX20_CONSTEXPR
1045 tuple(allocator_arg_t __tag, const _Alloc& __a,
1046 tuple<_UElements...>&& __in)
1047 : _Inherited(__tag, __a,
1048 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
1051 template<typename _Alloc, typename... _UElements,
1052 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
1053 && !__use_other_ctor<tuple<_UElements...>&&>(),
1054 _ExplicitCtor<_Valid, _UElements...> = false>
1055 _GLIBCXX20_CONSTEXPR
1057 tuple(allocator_arg_t __tag, const _Alloc& __a,
1058 tuple<_UElements...>&& __in)
1059 : _Inherited(__tag, __a,
1060 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
1063#if __cplusplus > 202002L
1064 template<typename _Alloc, typename... _UElements>
1065 requires (sizeof...(_Elements) == sizeof...(_UElements))
1066 && (!__use_other_ctor<tuple<_UElements...>&>())
1067 && __constructible<_UElements&...>
1068 explicit(!__convertible<_UElements&...>)
1070 tuple(allocator_arg_t __tag, const _Alloc& __a,
1071 tuple<_UElements...>& __in)
1072 : _Inherited(__tag, __a,
1073 static_cast<_Tuple_impl<0, _UElements...>&>(__in))
1076 template<typename _Alloc, typename... _UElements>
1077 requires (sizeof...(_Elements) == sizeof...(_UElements))
1078 && (!__use_other_ctor<const tuple<_UElements...>>())
1079 && __constructible<const _UElements...>
1080 explicit(!__convertible<const _UElements...>)
1082 tuple(allocator_arg_t __tag, const _Alloc& __a,
1083 const tuple<_UElements...>&& __in)
1084 : _Inherited(__tag, __a,
1085 static_cast<const _Tuple_impl<0, _UElements...>&&>(__in))
1091 _GLIBCXX20_CONSTEXPR
1093 operator=(__conditional_t<__assignable<const _Elements&...>(),
1095 const __nonesuch&> __in)
1096 noexcept(__nothrow_assignable<const _Elements&...>())
1098 this->_M_assign(__in);
1102 _GLIBCXX20_CONSTEXPR
1104 operator=(__conditional_t<__assignable<_Elements...>(),
1107 noexcept(__nothrow_assignable<_Elements...>())
1109 this->_M_assign(std::move(__in));
1113 template<typename... _UElements>
1114 _GLIBCXX20_CONSTEXPR
1115 __enable_if_t<__assignable<const _UElements&...>(), tuple&>
1116 operator=(const tuple<_UElements...>& __in)
1117 noexcept(__nothrow_assignable<const _UElements&...>())
1119 this->_M_assign(__in);
1123 template<typename... _UElements>
1124 _GLIBCXX20_CONSTEXPR
1125 __enable_if_t<__assignable<_UElements...>(), tuple&>
1126 operator=(tuple<_UElements...>&& __in)
1127 noexcept(__nothrow_assignable<_UElements...>())
1129 this->_M_assign(std::move(__in));
1133#if __cplusplus > 202002L
1134 constexpr const tuple&
1135 operator=(const tuple& __in) const
1136 requires (is_copy_assignable_v<const _Elements> && ...)
1138 this->_M_assign(__in);
1142 constexpr const tuple&
1143 operator=(tuple&& __in) const
1144 requires (is_assignable_v<const _Elements&, _Elements> && ...)
1146 this->_M_assign(std::move(__in));
1150 template<typename... _UElements>
1151 constexpr const tuple&
1152 operator=(const tuple<_UElements...>& __in) const
1153 requires (sizeof...(_Elements) == sizeof...(_UElements))
1154 && (is_assignable_v<const _Elements&, const _UElements&> && ...)
1156 this->_M_assign(__in);
1160 template<typename... _UElements>
1161 constexpr const tuple&
1162 operator=(tuple<_UElements...>&& __in) const
1163 requires (sizeof...(_Elements) == sizeof...(_UElements))
1164 && (is_assignable_v<const _Elements&, _UElements> && ...)
1166 this->_M_assign(std::move(__in));
1172 _GLIBCXX20_CONSTEXPR
1175 noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
1176 { _Inherited::_M_swap(__in); }
1178#if __cplusplus > 202002L
1179 // As an extension, we constrain the const swap member function in order
1180 // to continue accepting explicit instantiation of tuples whose elements
1181 // are not all const swappable. Without this constraint, such an
1182 // explicit instantiation would also instantiate the ill-formed body of
1183 // this function and yield a hard error. This constraint shouldn't
1184 // affect the behavior of valid programs.
1186 swap(const tuple& __in) const
1187 noexcept(__and_v<__is_nothrow_swappable<const _Elements>...>)
1188 requires (is_swappable_v<const _Elements> && ...)
1189 { _Inherited::_M_swap(__in); }
1193#if __cpp_deduction_guides >= 201606
1194 template<typename... _UTypes>
1195 tuple(_UTypes...) -> tuple<_UTypes...>;
1196 template<typename _T1, typename _T2>
1197 tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
1198 template<typename _Alloc, typename... _UTypes>
1199 tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
1200 template<typename _Alloc, typename _T1, typename _T2>
1201 tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
1202 template<typename _Alloc, typename... _UTypes>
1203 tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
1206 // Explicit specialization, zero-element tuple.
1211 _GLIBCXX20_CONSTEXPR
1212 void swap(tuple&) noexcept { /* no-op */ }
1213#if __cplusplus > 202002L
1214 constexpr void swap(const tuple&) const noexcept { /* no-op */ }
1216 // We need the default since we're going to define no-op
1217 // allocator constructors.
1219 // No-op allocator constructors.
1220 template<typename _Alloc>
1221 _GLIBCXX20_CONSTEXPR
1222 tuple(allocator_arg_t, const _Alloc&) noexcept { }
1223 template<typename _Alloc>
1224 _GLIBCXX20_CONSTEXPR
1225 tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept { }
1228 /// Partial specialization, 2-element tuple.
1229 /// Includes construction and assignment from a pair.
1230 template<typename _T1, typename _T2>
1231 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
1233 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
1235 // Constraint for non-explicit default constructor
1236 template<bool _Dummy, typename _U1, typename _U2>
1237 using _ImplicitDefaultCtor = __enable_if_t<
1238 _TupleConstraints<_Dummy, _U1, _U2>::
1239 __is_implicitly_default_constructible(),
1242 // Constraint for explicit default constructor
1243 template<bool _Dummy, typename _U1, typename _U2>
1244 using _ExplicitDefaultCtor = __enable_if_t<
1245 _TupleConstraints<_Dummy, _U1, _U2>::
1246 __is_explicitly_default_constructible(),
1249 template<bool _Dummy>
1250 using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
1252 // Constraint for non-explicit constructors
1253 template<bool _Cond, typename _U1, typename _U2>
1254 using _ImplicitCtor = __enable_if_t<
1255 _TCC<_Cond>::template __is_implicitly_constructible<_U1, _U2>(),
1258 // Constraint for non-explicit constructors
1259 template<bool _Cond, typename _U1, typename _U2>
1260 using _ExplicitCtor = __enable_if_t<
1261 _TCC<_Cond>::template __is_explicitly_constructible<_U1, _U2>(),
1264 template<typename _U1, typename _U2>
1265 static constexpr bool __assignable()
1267 return __and_<is_assignable<_T1&, _U1>,
1268 is_assignable<_T2&, _U2>>::value;
1271 template<typename _U1, typename _U2>
1272 static constexpr bool __nothrow_assignable()
1274 return __and_<is_nothrow_assignable<_T1&, _U1>,
1275 is_nothrow_assignable<_T2&, _U2>>::value;
1278 template<typename _U1, typename _U2>
1279 static constexpr bool __nothrow_constructible()
1281 return __and_<is_nothrow_constructible<_T1, _U1>,
1282 is_nothrow_constructible<_T2, _U2>>::value;
1285 static constexpr bool __nothrow_default_constructible()
1287 return __and_<is_nothrow_default_constructible<_T1>,
1288 is_nothrow_default_constructible<_T2>>::value;
1291 template<typename _U1>
1292 static constexpr bool __is_alloc_arg()
1293 { return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; }
1295#if __cplusplus > 202002L
1296 template<typename _U1, typename _U2>
1297 static constexpr bool __constructible
1298 = _TCC<true>::template __constructible<_U1, _U2>::value;
1300 template<typename _U1, typename _U2>
1301 static constexpr bool __convertible
1302 = _TCC<true>::template __convertible<_U1, _U2>::value;
1306 template<bool _Dummy = true,
1307 _ImplicitDefaultCtor<_Dummy, _T1, _T2> = true>
1310 noexcept(__nothrow_default_constructible())
1313 template<bool _Dummy = true,
1314 _ExplicitDefaultCtor<_Dummy, _T1, _T2> = false>
1317 noexcept(__nothrow_default_constructible())
1320 template<bool _Dummy = true,
1321 _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
1323 tuple(const _T1& __a1, const _T2& __a2)
1324 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1325 : _Inherited(__a1, __a2) { }
1327 template<bool _Dummy = true,
1328 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1330 tuple(const _T1& __a1, const _T2& __a2)
1331 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1332 : _Inherited(__a1, __a2) { }
1334 template<typename _U1, typename _U2,
1335 _ImplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = true>
1337 tuple(_U1&& __a1, _U2&& __a2)
1338 noexcept(__nothrow_constructible<_U1, _U2>())
1339 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1341 template<typename _U1, typename _U2,
1342 _ExplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = false>
1344 tuple(_U1&& __a1, _U2&& __a2)
1345 noexcept(__nothrow_constructible<_U1, _U2>())
1346 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1348 constexpr tuple(const tuple&) = default;
1350 constexpr tuple(tuple&&) = default;
1352 template<typename _U1, typename _U2,
1353 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1355 tuple(const tuple<_U1, _U2>& __in)
1356 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1357 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
1359 template<typename _U1, typename _U2,
1360 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1362 tuple(const tuple<_U1, _U2>& __in)
1363 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1364 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
1366 template<typename _U1, typename _U2,
1367 _ImplicitCtor<true, _U1, _U2> = true>
1369 tuple(tuple<_U1, _U2>&& __in)
1370 noexcept(__nothrow_constructible<_U1, _U2>())
1371 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1373 template<typename _U1, typename _U2,
1374 _ExplicitCtor<true, _U1, _U2> = false>
1376 tuple(tuple<_U1, _U2>&& __in)
1377 noexcept(__nothrow_constructible<_U1, _U2>())
1378 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1380#if __cplusplus > 202002L
1381 template<typename _U1, typename _U2>
1382 requires __constructible<_U1&, _U2&>
1383 explicit(!__convertible<_U1&, _U2&>)
1385 tuple(tuple<_U1, _U2>& __in)
1386 noexcept(__nothrow_constructible<_U1&, _U2&>())
1387 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&>(__in)) { }
1389 template<typename _U1, typename _U2>
1390 requires __constructible<const _U1, const _U2>
1391 explicit(!__convertible<const _U1, const _U2>)
1393 tuple(const tuple<_U1, _U2>&& __in)
1394 noexcept(__nothrow_constructible<const _U1, const _U2>())
1395 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1398 template<typename _U1, typename _U2,
1399 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1401 tuple(const pair<_U1, _U2>& __in)
1402 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1403 : _Inherited(__in.first, __in.second) { }
1405 template<typename _U1, typename _U2,
1406 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1408 tuple(const pair<_U1, _U2>& __in)
1409 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1410 : _Inherited(__in.first, __in.second) { }
1412 template<typename _U1, typename _U2,
1413 _ImplicitCtor<true, _U1, _U2> = true>
1415 tuple(pair<_U1, _U2>&& __in)
1416 noexcept(__nothrow_constructible<_U1, _U2>())
1417 : _Inherited(std::forward<_U1>(__in.first),
1418 std::forward<_U2>(__in.second)) { }
1420 template<typename _U1, typename _U2,
1421 _ExplicitCtor<true, _U1, _U2> = false>
1423 tuple(pair<_U1, _U2>&& __in)
1424 noexcept(__nothrow_constructible<_U1, _U2>())
1425 : _Inherited(std::forward<_U1>(__in.first),
1426 std::forward<_U2>(__in.second)) { }
1428#if __cplusplus > 202002L
1429 template<typename _U1, typename _U2>
1430 requires __constructible<_U1&, _U2&>
1431 explicit(!__convertible<_U1&, _U2&>)
1433 tuple(pair<_U1, _U2>& __in)
1434 noexcept(__nothrow_constructible<_U1&, _U2&>())
1435 : _Inherited(__in.first, __in.second) { }
1437 template<typename _U1, typename _U2>
1438 requires __constructible<const _U1, const _U2>
1439 explicit(!__convertible<const _U1, const _U2>)
1441 tuple(const pair<_U1, _U2>&& __in)
1442 noexcept(__nothrow_constructible<const _U1, const _U2>())
1443 : _Inherited(std::forward<const _U1>(__in.first),
1444 std::forward<const _U2>(__in.second)) { }
1447 // Allocator-extended constructors.
1449 template<typename _Alloc,
1450 _ImplicitDefaultCtor<is_object<_Alloc>::value, _T1, _T2> = true>
1451 _GLIBCXX20_CONSTEXPR
1452 tuple(allocator_arg_t __tag, const _Alloc& __a)
1453 : _Inherited(__tag, __a) { }
1455 template<typename _Alloc, bool _Dummy = true,
1456 _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
1457 _GLIBCXX20_CONSTEXPR
1458 tuple(allocator_arg_t __tag, const _Alloc& __a,
1459 const _T1& __a1, const _T2& __a2)
1460 : _Inherited(__tag, __a, __a1, __a2) { }
1462 template<typename _Alloc, bool _Dummy = true,
1463 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1465 _GLIBCXX20_CONSTEXPR
1466 tuple(allocator_arg_t __tag, const _Alloc& __a,
1467 const _T1& __a1, const _T2& __a2)
1468 : _Inherited(__tag, __a, __a1, __a2) { }
1470 template<typename _Alloc, typename _U1, typename _U2,
1471 _ImplicitCtor<true, _U1, _U2> = true>
1472 _GLIBCXX20_CONSTEXPR
1473 tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1474 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1475 std::forward<_U2>(__a2)) { }
1477 template<typename _Alloc, typename _U1, typename _U2,
1478 _ExplicitCtor<true, _U1, _U2> = false>
1480 _GLIBCXX20_CONSTEXPR
1481 tuple(allocator_arg_t __tag, const _Alloc& __a,
1482 _U1&& __a1, _U2&& __a2)
1483 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1484 std::forward<_U2>(__a2)) { }
1486 template<typename _Alloc>
1487 _GLIBCXX20_CONSTEXPR
1488 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1489 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1491 template<typename _Alloc>
1492 _GLIBCXX20_CONSTEXPR
1493 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1494 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1496 template<typename _Alloc, typename _U1, typename _U2,
1497 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1498 _GLIBCXX20_CONSTEXPR
1499 tuple(allocator_arg_t __tag, const _Alloc& __a,
1500 const tuple<_U1, _U2>& __in)
1501 : _Inherited(__tag, __a,
1502 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1505 template<typename _Alloc, typename _U1, typename _U2,
1506 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1508 _GLIBCXX20_CONSTEXPR
1509 tuple(allocator_arg_t __tag, const _Alloc& __a,
1510 const tuple<_U1, _U2>& __in)
1511 : _Inherited(__tag, __a,
1512 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1515 template<typename _Alloc, typename _U1, typename _U2,
1516 _ImplicitCtor<true, _U1, _U2> = true>
1517 _GLIBCXX20_CONSTEXPR
1518 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1519 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1522 template<typename _Alloc, typename _U1, typename _U2,
1523 _ExplicitCtor<true, _U1, _U2> = false>
1525 _GLIBCXX20_CONSTEXPR
1526 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1527 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1530#if __cplusplus > 202002L
1531 template<typename _Alloc, typename _U1, typename _U2>
1532 requires __constructible<_U1&, _U2&>
1533 explicit(!__convertible<_U1&, _U2&>)
1535 tuple(allocator_arg_t __tag, const _Alloc& __a,
1536 tuple<_U1, _U2>& __in)
1537 : _Inherited(__tag, __a,
1538 static_cast<_Tuple_impl<0, _U1, _U2>&>(__in))
1541 template<typename _Alloc, typename _U1, typename _U2>
1542 requires __constructible<const _U1, const _U2>
1543 explicit(!__convertible<const _U1, const _U2>)
1545 tuple(allocator_arg_t __tag, const _Alloc& __a,
1546 const tuple<_U1, _U2>&& __in)
1547 : _Inherited(__tag, __a,
1548 static_cast<const _Tuple_impl<0, _U1, _U2>&&>(__in))
1552 template<typename _Alloc, typename _U1, typename _U2,
1553 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1554 _GLIBCXX20_CONSTEXPR
1555 tuple(allocator_arg_t __tag, const _Alloc& __a,
1556 const pair<_U1, _U2>& __in)
1557 : _Inherited(__tag, __a, __in.first, __in.second) { }
1559 template<typename _Alloc, typename _U1, typename _U2,
1560 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1562 _GLIBCXX20_CONSTEXPR
1563 tuple(allocator_arg_t __tag, const _Alloc& __a,
1564 const pair<_U1, _U2>& __in)
1565 : _Inherited(__tag, __a, __in.first, __in.second) { }
1567 template<typename _Alloc, typename _U1, typename _U2,
1568 _ImplicitCtor<true, _U1, _U2> = true>
1569 _GLIBCXX20_CONSTEXPR
1570 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1571 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1572 std::forward<_U2>(__in.second)) { }
1574 template<typename _Alloc, typename _U1, typename _U2,
1575 _ExplicitCtor<true, _U1, _U2> = false>
1577 _GLIBCXX20_CONSTEXPR
1578 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1579 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1580 std::forward<_U2>(__in.second)) { }
1582#if __cplusplus > 202002L
1583 template<typename _Alloc, typename _U1, typename _U2>
1584 requires __constructible<_U1&, _U2&>
1585 explicit(!__convertible<_U1&, _U2&>)
1587 tuple(allocator_arg_t __tag, const _Alloc& __a,
1588 pair<_U1, _U2>& __in)
1589 : _Inherited(__tag, __a, __in.first, __in.second) { }
1591 template<typename _Alloc, typename _U1, typename _U2>
1592 requires __constructible<const _U1, const _U2>
1593 explicit(!__convertible<const _U1, const _U2>)
1595 tuple(allocator_arg_t __tag, const _Alloc& __a, const pair<_U1, _U2>&& __in)
1596 : _Inherited(__tag, __a, std::forward<const _U1>(__in.first),
1597 std::forward<const _U2>(__in.second)) { }
1600 // Tuple assignment.
1602 _GLIBCXX20_CONSTEXPR
1604 operator=(__conditional_t<__assignable<const _T1&, const _T2&>(),
1606 const __nonesuch&> __in)
1607 noexcept(__nothrow_assignable<const _T1&, const _T2&>())
1609 this->_M_assign(__in);
1613 _GLIBCXX20_CONSTEXPR
1615 operator=(__conditional_t<__assignable<_T1, _T2>(),
1618 noexcept(__nothrow_assignable<_T1, _T2>())
1620 this->_M_assign(std::move(__in));
1624 template<typename _U1, typename _U2>
1625 _GLIBCXX20_CONSTEXPR
1626 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1627 operator=(const tuple<_U1, _U2>& __in)
1628 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1630 this->_M_assign(__in);
1634 template<typename _U1, typename _U2>
1635 _GLIBCXX20_CONSTEXPR
1636 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1637 operator=(tuple<_U1, _U2>&& __in)
1638 noexcept(__nothrow_assignable<_U1, _U2>())
1640 this->_M_assign(std::move(__in));
1644#if __cplusplus > 202002L
1645 constexpr const tuple&
1646 operator=(const tuple& __in) const
1647 requires is_copy_assignable_v<const _T1> && is_copy_assignable_v<const _T2>
1649 this->_M_assign(__in);
1653 constexpr const tuple&
1654 operator=(tuple&& __in) const
1655 requires is_assignable_v<const _T1&, _T1> && is_assignable_v<const _T2, _T2>
1657 this->_M_assign(std::move(__in));
1661 template<typename _U1, typename _U2>
1662 constexpr const tuple&
1663 operator=(const tuple<_U1, _U2>& __in) const
1664 requires is_assignable_v<const _T1&, const _U1&>
1665 && is_assignable_v<const _T2&, const _U2&>
1667 this->_M_assign(__in);
1671 template<typename _U1, typename _U2>
1672 constexpr const tuple&
1673 operator=(tuple<_U1, _U2>&& __in) const
1674 requires is_assignable_v<const _T1&, _U1>
1675 && is_assignable_v<const _T2&, _U2>
1677 this->_M_assign(std::move(__in));
1682 template<typename _U1, typename _U2>
1683 _GLIBCXX20_CONSTEXPR
1684 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1685 operator=(const pair<_U1, _U2>& __in)
1686 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1688 this->_M_head(*this) = __in.first;
1689 this->_M_tail(*this)._M_head(*this) = __in.second;
1693 template<typename _U1, typename _U2>
1694 _GLIBCXX20_CONSTEXPR
1695 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1696 operator=(pair<_U1, _U2>&& __in)
1697 noexcept(__nothrow_assignable<_U1, _U2>())
1699 this->_M_head(*this) = std::forward<_U1>(__in.first);
1700 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1704#if __cplusplus > 202002L
1705 template<typename _U1, typename _U2>
1706 constexpr const tuple&
1707 operator=(const pair<_U1, _U2>& __in) const
1708 requires is_assignable_v<const _T1&, const _U1&>
1709 && is_assignable_v<const _T2&, const _U2&>
1711 this->_M_head(*this) = __in.first;
1712 this->_M_tail(*this)._M_head(*this) = __in.second;
1716 template<typename _U1, typename _U2>
1717 constexpr const tuple&
1718 operator=(pair<_U1, _U2>&& __in) const
1719 requires is_assignable_v<const _T1&, _U1>
1720 && is_assignable_v<const _T2&, _U2>
1722 this->_M_head(*this) = std::forward<_U1>(__in.first);
1723 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1728 _GLIBCXX20_CONSTEXPR
1731 noexcept(__and_<__is_nothrow_swappable<_T1>,
1732 __is_nothrow_swappable<_T2>>::value)
1733 { _Inherited::_M_swap(__in); }
1735#if __cplusplus > 202002L
1737 swap(const tuple& __in) const
1738 noexcept(__and_v<__is_nothrow_swappable<const _T1>,
1739 __is_nothrow_swappable<const _T2>>)
1740 requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
1741 { _Inherited::_M_swap(__in); }
1746 /// class tuple_size
1747 template<typename... _Elements>
1748 struct tuple_size<tuple<_Elements...>>
1749 : public integral_constant<size_t, sizeof...(_Elements)> { };
1751#if __cplusplus >= 201703L
1752 template<typename... _Types>
1753 inline constexpr size_t tuple_size_v<tuple<_Types...>>
1754 = sizeof...(_Types);
1756 template<typename... _Types>
1757 inline constexpr size_t tuple_size_v<const tuple<_Types...>>
1758 = sizeof...(_Types);
1761 /// Trait to get the Ith element type from a tuple.
1762 template<size_t __i, typename... _Types>
1763 struct tuple_element<__i, tuple<_Types...>>
1765 static_assert(__i < sizeof...(_Types), "tuple index must be in range");
1767 using type = typename _Nth_type<__i, _Types...>::type;
1770 template<size_t __i, typename _Head, typename... _Tail>
1772 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1773 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1775 template<size_t __i, typename _Head, typename... _Tail>
1776 constexpr const _Head&
1777 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1778 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1780 // Deleted overload to improve diagnostics for invalid indices
1781 template<size_t __i, typename... _Types>
1782 __enable_if_t<(__i >= sizeof...(_Types))>
1783 __get_helper(const tuple<_Types...>&) = delete;
1785 /// Return a reference to the ith element of a tuple.
1786 template<size_t __i, typename... _Elements>
1787 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1788 get(tuple<_Elements...>& __t) noexcept
1789 { return std::__get_helper<__i>(__t); }
1791 /// Return a const reference to the ith element of a const tuple.
1792 template<size_t __i, typename... _Elements>
1793 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
1794 get(const tuple<_Elements...>& __t) noexcept
1795 { return std::__get_helper<__i>(__t); }
1797 /// Return an rvalue reference to the ith element of a tuple rvalue.
1798 template<size_t __i, typename... _Elements>
1799 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1800 get(tuple<_Elements...>&& __t) noexcept
1802 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1803 return std::forward<__element_type>(std::__get_helper<__i>(__t));
1806 /// Return a const rvalue reference to the ith element of a const tuple rvalue.
1807 template<size_t __i, typename... _Elements>
1808 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
1809 get(const tuple<_Elements...>&& __t) noexcept
1811 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1812 return std::forward<const __element_type>(std::__get_helper<__i>(__t));
1815 /// @cond undocumented
1816 // Deleted overload chosen for invalid indices.
1817 template<size_t __i, typename... _Elements>
1818 constexpr __enable_if_t<(__i >= sizeof...(_Elements))>
1819 get(const tuple<_Elements...>&) = delete;
1822#if __cplusplus >= 201402L
1824#define __cpp_lib_tuples_by_type 201304L
1826 /// Return a reference to the unique element of type _Tp of a tuple.
1827 template <typename _Tp, typename... _Types>
1829 get(tuple<_Types...>& __t) noexcept
1831 constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
1832 static_assert(__idx < sizeof...(_Types),
1833 "the type T in std::get<T> must occur exactly once in the tuple");
1834 return std::__get_helper<__idx>(__t);
1837 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1838 template <typename _Tp, typename... _Types>
1840 get(tuple<_Types...>&& __t) noexcept
1842 constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
1843 static_assert(__idx < sizeof...(_Types),
1844 "the type T in std::get<T> must occur exactly once in the tuple");
1845 return std::forward<_Tp>(std::__get_helper<__idx>(__t));
1848 /// Return a const reference to the unique element of type _Tp of a tuple.
1849 template <typename _Tp, typename... _Types>
1850 constexpr const _Tp&
1851 get(const tuple<_Types...>& __t) noexcept
1853 constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
1854 static_assert(__idx < sizeof...(_Types),
1855 "the type T in std::get<T> must occur exactly once in the tuple");
1856 return std::__get_helper<__idx>(__t);
1859 /// Return a const reference to the unique element of type _Tp of
1860 /// a const tuple rvalue.
1861 template <typename _Tp, typename... _Types>
1862 constexpr const _Tp&&
1863 get(const tuple<_Types...>&& __t) noexcept
1865 constexpr size_t __idx = __find_uniq_type_in_pack<_Tp, _Types...>();
1866 static_assert(__idx < sizeof...(_Types),
1867 "the type T in std::get<T> must occur exactly once in the tuple");
1868 return std::forward<const _Tp>(std::__get_helper<__idx>(__t));
1872 // This class performs the comparison operations on tuples
1873 template<typename _Tp, typename _Up, size_t __i, size_t __size>
1874 struct __tuple_compare
1876 static constexpr bool
1877 __eq(const _Tp& __t, const _Up& __u)
1879 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1880 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1883 static constexpr bool
1884 __less(const _Tp& __t, const _Up& __u)
1886 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1887 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1888 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1892 template<typename _Tp, typename _Up, size_t __size>
1893 struct __tuple_compare<_Tp, _Up, __size, __size>
1895 static constexpr bool
1896 __eq(const _Tp&, const _Up&) { return true; }
1898 static constexpr bool
1899 __less(const _Tp&, const _Up&) { return false; }
1902 template<typename... _TElements, typename... _UElements>
1904 operator==(const tuple<_TElements...>& __t,
1905 const tuple<_UElements...>& __u)
1907 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1908 "tuple objects can only be compared if they have equal sizes.");
1909 using __compare = __tuple_compare<tuple<_TElements...>,
1910 tuple<_UElements...>,
1911 0, sizeof...(_TElements)>;
1912 return __compare::__eq(__t, __u);
1915#if __cpp_lib_three_way_comparison
1916 template<typename _Cat, typename _Tp, typename _Up>
1918 __tuple_cmp(const _Tp&, const _Up&, index_sequence<>)
1919 { return _Cat::equivalent; }
1921 template<typename _Cat, typename _Tp, typename _Up,
1922 size_t _Idx0, size_t... _Idxs>
1924 __tuple_cmp(const _Tp& __t, const _Up& __u,
1925 index_sequence<_Idx0, _Idxs...>)
1928 = __detail::__synth3way(std::get<_Idx0>(__t), std::get<_Idx0>(__u));
1931 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence<_Idxs...>());
1934 template<typename... _Tps, typename... _Ups>
1936 common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>
1937 operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)
1940 = common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>;
1941 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence_for<_Tps...>());
1944 template<typename... _TElements, typename... _UElements>
1946 operator<(const tuple<_TElements...>& __t,
1947 const tuple<_UElements...>& __u)
1949 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1950 "tuple objects can only be compared if they have equal sizes.");
1951 using __compare = __tuple_compare<tuple<_TElements...>,
1952 tuple<_UElements...>,
1953 0, sizeof...(_TElements)>;
1954 return __compare::__less(__t, __u);
1957 template<typename... _TElements, typename... _UElements>
1959 operator!=(const tuple<_TElements...>& __t,
1960 const tuple<_UElements...>& __u)
1961 { return !(__t == __u); }
1963 template<typename... _TElements, typename... _UElements>
1965 operator>(const tuple<_TElements...>& __t,
1966 const tuple<_UElements...>& __u)
1967 { return __u < __t; }
1969 template<typename... _TElements, typename... _UElements>
1971 operator<=(const tuple<_TElements...>& __t,
1972 const tuple<_UElements...>& __u)
1973 { return !(__u < __t); }
1975 template<typename... _TElements, typename... _UElements>
1977 operator>=(const tuple<_TElements...>& __t,
1978 const tuple<_UElements...>& __u)
1979 { return !(__t < __u); }
1980#endif // three_way_comparison
1983 /// Create a tuple containing copies of the arguments
1984 template<typename... _Elements>
1985 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1986 make_tuple(_Elements&&... __args)
1988 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1990 return __result_type(std::forward<_Elements>(__args)...);
1993 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1994 // 2275. Why is forward_as_tuple not constexpr?
1995 /// Create a tuple of lvalue or rvalue references to the arguments
1996 template<typename... _Elements>
1997 constexpr tuple<_Elements&&...>
1998 forward_as_tuple(_Elements&&... __args) noexcept
1999 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
2001 // Declarations of std::array and its std::get overloads, so that
2002 // std::tuple_cat can use them if <tuple> is included before <array>.
2004 template<typename _Tp, size_t _Nm> struct array;
2006 template<size_t _Int, typename _Tp, size_t _Nm>
2008 get(array<_Tp, _Nm>&) noexcept;
2010 template<size_t _Int, typename _Tp, size_t _Nm>
2012 get(array<_Tp, _Nm>&&) noexcept;
2014 template<size_t _Int, typename _Tp, size_t _Nm>
2015 constexpr const _Tp&
2016 get(const array<_Tp, _Nm>&) noexcept;
2018 template<size_t _Int, typename _Tp, size_t _Nm>
2019 constexpr const _Tp&&
2020 get(const array<_Tp, _Nm>&&) noexcept;
2022 /// @cond undocumented
2023 template<size_t, typename, typename, size_t>
2024 struct __make_tuple_impl;
2026 template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
2027 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
2028 : __make_tuple_impl<_Idx + 1,
2029 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
2033 template<size_t _Nm, typename _Tuple, typename... _Tp>
2034 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
2036 typedef tuple<_Tp...> __type;
2039 template<typename _Tuple>
2040 struct __do_make_tuple
2041 : __make_tuple_impl<0, tuple<>, _Tuple, tuple_size<_Tuple>::value>
2044 // Returns the std::tuple equivalent of a tuple-like type.
2045 template<typename _Tuple>
2047 : public __do_make_tuple<__remove_cvref_t<_Tuple>>
2050 // Combines several std::tuple's into a single one.
2051 template<typename...>
2052 struct __combine_tuples;
2055 struct __combine_tuples<>
2057 typedef tuple<> __type;
2060 template<typename... _Ts>
2061 struct __combine_tuples<tuple<_Ts...>>
2063 typedef tuple<_Ts...> __type;
2066 template<typename... _T1s, typename... _T2s, typename... _Rem>
2067 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
2069 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
2070 _Rem...>::__type __type;
2073 // Computes the result type of tuple_cat given a set of tuple-like types.
2074 template<typename... _Tpls>
2075 struct __tuple_cat_result
2077 typedef typename __combine_tuples
2078 <typename __make_tuple<_Tpls>::__type...>::__type __type;
2081 // Helper to determine the index set for the first tuple-like
2082 // type of a given set.
2083 template<typename...>
2084 struct __make_1st_indices;
2087 struct __make_1st_indices<>
2089 typedef _Index_tuple<> __type;
2092 template<typename _Tp, typename... _Tpls>
2093 struct __make_1st_indices<_Tp, _Tpls...>
2095 typedef typename _Build_index_tuple<tuple_size<
2096 typename remove_reference<_Tp>::type>::value>::__type __type;
2099 // Performs the actual concatenation by step-wise expanding tuple-like
2100 // objects into the elements, which are finally forwarded into the
2102 template<typename _Ret, typename _Indices, typename... _Tpls>
2103 struct __tuple_concater;
2105 template<typename _Ret, size_t... _Is, typename _Tp, typename... _Tpls>
2106 struct __tuple_concater<_Ret, _Index_tuple<_Is...>, _Tp, _Tpls...>
2108 template<typename... _Us>
2109 static constexpr _Ret
2110 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
2112 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
2113 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
2114 return __next::_S_do(std::forward<_Tpls>(__tps)...,
2115 std::forward<_Us>(__us)...,
2116 std::get<_Is>(std::forward<_Tp>(__tp))...);
2120 template<typename _Ret>
2121 struct __tuple_concater<_Ret, _Index_tuple<>>
2123 template<typename... _Us>
2124 static constexpr _Ret
2125 _S_do(_Us&&... __us)
2127 return _Ret(std::forward<_Us>(__us)...);
2131 template<typename... _Tps>
2132 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
2136 /// Create a `tuple` containing all elements from multiple tuple-like objects
2137 template<typename... _Tpls, typename = typename
2138 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
2140 tuple_cat(_Tpls&&... __tpls)
2141 -> typename __tuple_cat_result<_Tpls...>::__type
2143 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
2144 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
2145 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
2146 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
2149 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2150 // 2301. Why is tie not constexpr?
2151 /// Return a tuple of lvalue references bound to the arguments
2152 template<typename... _Elements>
2153 constexpr tuple<_Elements&...>
2154 tie(_Elements&... __args) noexcept
2155 { return tuple<_Elements&...>(__args...); }
2157 /// Exchange the values of two tuples
2158 template<typename... _Elements>
2159 _GLIBCXX20_CONSTEXPR
2161#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2162 // Constrained free swap overload, see p0185r1
2163 typename enable_if<__and_<__is_swappable<_Elements>...>::value
2168 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
2169 noexcept(noexcept(__x.swap(__y)))
2172#if __cplusplus > 202002L
2173 template<typename... _Elements>
2174 requires (is_swappable_v<const _Elements> && ...)
2176 swap(const tuple<_Elements...>& __x, const tuple<_Elements...>& __y)
2177 noexcept(noexcept(__x.swap(__y)))
2181#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2182 /// Exchange the values of two const tuples (if const elements can be swapped)
2183 template<typename... _Elements>
2184 _GLIBCXX20_CONSTEXPR
2185 typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
2186 swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
2189 // A class (and instance) which can be used in 'tie' when an element
2190 // of a tuple is not required.
2191 // _GLIBCXX14_CONSTEXPR
2192 // 2933. PR for LWG 2773 could be clearer
2193 struct _Swallow_assign
2196 _GLIBCXX14_CONSTEXPR const _Swallow_assign&
2197 operator=(const _Tp&) const
2201 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2202 // 2773. Making std::ignore constexpr
2203 /** Used with `std::tie` to ignore an element of a tuple
2205 * When using `std::tie` to assign the elements of a tuple to variables,
2206 * unwanted elements can be ignored by using `std::ignore`. For example:
2210 * std::tie(x, std::ignore, y) = std::make_tuple(1, 2, 3);
2213 * This assignment will perform `x=1; std::ignore=2; y=3;` which results
2214 * in the second element being ignored.
2218 _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
2220 /// Partial specialization for tuples
2221 template<typename... _Types, typename _Alloc>
2222 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
2224 // See stl_pair.h...
2225 /** "piecewise construction" using a tuple of arguments for each member.
2227 * @param __first Arguments for the first member of the pair.
2228 * @param __second Arguments for the second member of the pair.
2230 * The elements of each tuple will be used as the constructor arguments
2231 * for the data members of the pair.
2233 template<class _T1, class _T2>
2234 template<typename... _Args1, typename... _Args2>
2235 _GLIBCXX20_CONSTEXPR
2238 pair(piecewise_construct_t,
2239 tuple<_Args1...> __first, tuple<_Args2...> __second)
2240 : pair(__first, __second,
2241 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
2242 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
2245 template<class _T1, class _T2>
2246 template<typename... _Args1, size_t... _Indexes1,
2247 typename... _Args2, size_t... _Indexes2>
2248 _GLIBCXX20_CONSTEXPR inline
2250 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
2251 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
2252 : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
2253 second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
2256#if __cplusplus >= 201703L
2258 // Unpack a std::tuple into a type trait and use its value.
2259 // For cv std::tuple<_Up> the result is _Trait<_Tp, cv _Up...>::value.
2260 // For cv std::tuple<_Up>& the result is _Trait<_Tp, cv _Up&...>::value.
2261 // Otherwise the result is false (because we don't know if std::get throws).
2262 template<template<typename...> class _Trait, typename _Tp, typename _Tuple>
2263 inline constexpr bool __unpack_std_tuple = false;
2265 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
2266 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>>
2267 = _Trait<_Tp, _Up...>::value;
2269 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
2270 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>&>
2271 = _Trait<_Tp, _Up&...>::value;
2273 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
2274 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>>
2275 = _Trait<_Tp, const _Up...>::value;
2277 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
2278 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>&>
2279 = _Trait<_Tp, const _Up&...>::value;
2281# define __cpp_lib_apply 201603L
2283 template <typename _Fn, typename _Tuple, size_t... _Idx>
2284 constexpr decltype(auto)
2285 __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
2287 return std::__invoke(std::forward<_Fn>(__f),
2288 std::get<_Idx>(std::forward<_Tuple>(__t))...);
2291 template <typename _Fn, typename _Tuple>
2292 constexpr decltype(auto)
2293 apply(_Fn&& __f, _Tuple&& __t)
2294 noexcept(__unpack_std_tuple<is_nothrow_invocable, _Fn, _Tuple>)
2297 = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>;
2298 return std::__apply_impl(std::forward<_Fn>(__f),
2299 std::forward<_Tuple>(__t),
2303#define __cpp_lib_make_from_tuple 201606L
2305 template <typename _Tp, typename _Tuple, size_t... _Idx>
2307 __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
2308 { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
2310 template <typename _Tp, typename _Tuple>
2312 make_from_tuple(_Tuple&& __t)
2313 noexcept(__unpack_std_tuple<is_nothrow_constructible, _Tp, _Tuple>)
2315 return __make_from_tuple_impl<_Tp>(
2316 std::forward<_Tuple>(__t),
2317 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{});
2321#if __cplusplus > 202002L
2322 template<typename... _TTypes, typename... _UTypes,
2323 template<typename> class TQual, template<typename> class UQual>
2324 requires requires { typename tuple<common_reference_t<TQual<_TTypes>, UQual<_UTypes>>...>; }
2325 struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, TQual, UQual>
2326 { using type = tuple<common_reference_t<TQual<_TTypes>, UQual<_UTypes>>...>; };
2328 template<typename... _TTypes, typename... _UTypes>
2329 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
2330 struct common_type<tuple<_TTypes...>, tuple<_UTypes...>>
2331 { using type = tuple<common_type_t<_TTypes, _UTypes>...>; };
2336_GLIBCXX_END_NAMESPACE_VERSION
2341#endif // _GLIBCXX_TUPLE