libstdc++
tuple
Go to the documentation of this file.
1// <tuple> -*- C++ -*-
2
3// Copyright (C) 2007-2023 Free Software Foundation, Inc.
4//
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)
9// any later version.
10
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.
15
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.
19
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/>.
24
25/** @file include/tuple
26 * This is a Standard C++ Library header.
27 */
28
29#ifndef _GLIBCXX_TUPLE
30#define _GLIBCXX_TUPLE 1
31
32#pragma GCC system_header
33
34#if __cplusplus < 201103L
35# include <bits/c++0x_warning.h>
36#else
37
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
43# include <compare>
44# define __cpp_lib_constexpr_tuple 201811L
45#endif
46
47namespace std _GLIBCXX_VISIBILITY(default)
48{
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
50
51 /**
52 * @addtogroup utilities
53 * @{
54 */
55
56 template<typename... _Elements>
57 class tuple;
58
59 template<typename _Tp>
60 struct __is_empty_non_tuple : is_empty<_Tp> { };
61
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 { };
65
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>>;
71
72 template<size_t _Idx, typename _Head,
73 bool = __empty_not_final<_Head>::value>
74 struct _Head_base;
75
76#if __has_cpp_attribute(__no_unique_address__)
77 template<size_t _Idx, typename _Head>
78 struct _Head_base<_Idx, _Head, true>
79 {
80 constexpr _Head_base()
81 : _M_head_impl() { }
82
83 constexpr _Head_base(const _Head& __h)
84 : _M_head_impl(__h) { }
85
86 constexpr _Head_base(const _Head_base&) = default;
87 constexpr _Head_base(_Head_base&&) = default;
88
89 template<typename _UHead>
90 constexpr _Head_base(_UHead&& __h)
91 : _M_head_impl(std::forward<_UHead>(__h)) { }
92
93 _GLIBCXX20_CONSTEXPR
94 _Head_base(allocator_arg_t, __uses_alloc0)
95 : _M_head_impl() { }
96
97 template<typename _Alloc>
98 _GLIBCXX20_CONSTEXPR
99 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
100 : _M_head_impl(allocator_arg, *__a._M_a) { }
101
102 template<typename _Alloc>
103 _GLIBCXX20_CONSTEXPR
104 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
105 : _M_head_impl(*__a._M_a) { }
106
107 template<typename _UHead>
108 _GLIBCXX20_CONSTEXPR
109 _Head_base(__uses_alloc0, _UHead&& __uhead)
110 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
111
112 template<typename _Alloc, typename _UHead>
113 _GLIBCXX20_CONSTEXPR
114 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
115 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
116 { }
117
118 template<typename _Alloc, typename _UHead>
119 _GLIBCXX20_CONSTEXPR
120 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
121 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
122
123 static constexpr _Head&
124 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
125
126 static constexpr const _Head&
127 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
128
129 [[__no_unique_address__]] _Head _M_head_impl;
130 };
131#else
132 template<size_t _Idx, typename _Head>
133 struct _Head_base<_Idx, _Head, true>
134 : public _Head
135 {
136 constexpr _Head_base()
137 : _Head() { }
138
139 constexpr _Head_base(const _Head& __h)
140 : _Head(__h) { }
141
142 constexpr _Head_base(const _Head_base&) = default;
143 constexpr _Head_base(_Head_base&&) = default;
144
145 template<typename _UHead>
146 constexpr _Head_base(_UHead&& __h)
147 : _Head(std::forward<_UHead>(__h)) { }
148
149 _GLIBCXX20_CONSTEXPR
150 _Head_base(allocator_arg_t, __uses_alloc0)
151 : _Head() { }
152
153 template<typename _Alloc>
154 _GLIBCXX20_CONSTEXPR
155 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
156 : _Head(allocator_arg, *__a._M_a) { }
157
158 template<typename _Alloc>
159 _GLIBCXX20_CONSTEXPR
160 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
161 : _Head(*__a._M_a) { }
162
163 template<typename _UHead>
164 _GLIBCXX20_CONSTEXPR
165 _Head_base(__uses_alloc0, _UHead&& __uhead)
166 : _Head(std::forward<_UHead>(__uhead)) { }
167
168 template<typename _Alloc, typename _UHead>
169 _GLIBCXX20_CONSTEXPR
170 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
171 : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
172
173 template<typename _Alloc, typename _UHead>
174 _GLIBCXX20_CONSTEXPR
175 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
176 : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
177
178 static constexpr _Head&
179 _M_head(_Head_base& __b) noexcept { return __b; }
180
181 static constexpr const _Head&
182 _M_head(const _Head_base& __b) noexcept { return __b; }
183 };
184#endif
185
186 template<size_t _Idx, typename _Head>
187 struct _Head_base<_Idx, _Head, false>
188 {
189 constexpr _Head_base()
190 : _M_head_impl() { }
191
192 constexpr _Head_base(const _Head& __h)
193 : _M_head_impl(__h) { }
194
195 constexpr _Head_base(const _Head_base&) = default;
196 constexpr _Head_base(_Head_base&&) = default;
197
198 template<typename _UHead>
199 constexpr _Head_base(_UHead&& __h)
200 : _M_head_impl(std::forward<_UHead>(__h)) { }
201
202 _GLIBCXX20_CONSTEXPR
203 _Head_base(allocator_arg_t, __uses_alloc0)
204 : _M_head_impl() { }
205
206 template<typename _Alloc>
207 _GLIBCXX20_CONSTEXPR
208 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
209 : _M_head_impl(allocator_arg, *__a._M_a) { }
210
211 template<typename _Alloc>
212 _GLIBCXX20_CONSTEXPR
213 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
214 : _M_head_impl(*__a._M_a) { }
215
216 template<typename _UHead>
217 _GLIBCXX20_CONSTEXPR
218 _Head_base(__uses_alloc0, _UHead&& __uhead)
219 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
220
221 template<typename _Alloc, typename _UHead>
222 _GLIBCXX20_CONSTEXPR
223 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
224 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
225 { }
226
227 template<typename _Alloc, typename _UHead>
228 _GLIBCXX20_CONSTEXPR
229 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
230 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
231
232 static constexpr _Head&
233 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
234
235 static constexpr const _Head&
236 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
237
238 _Head _M_head_impl;
239 };
240
241 /**
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
247 * get() operation.
248 */
249 template<size_t _Idx, typename... _Elements>
250 struct _Tuple_impl;
251
252 /**
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).
256 */
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>
261 {
262 template<size_t, typename...> friend struct _Tuple_impl;
263
264 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
265 typedef _Head_base<_Idx, _Head> _Base;
266
267 static constexpr _Head&
268 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
269
270 static constexpr const _Head&
271 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
272
273 static constexpr _Inherited&
274 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
275
276 static constexpr const _Inherited&
277 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
278
279 constexpr _Tuple_impl()
280 : _Inherited(), _Base() { }
281
282 explicit constexpr
283 _Tuple_impl(const _Head& __head, const _Tail&... __tail)
284 : _Inherited(__tail...), _Base(__head)
285 { }
286
287 template<typename _UHead, typename... _UTail,
288 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
289 explicit constexpr
290 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
291 : _Inherited(std::forward<_UTail>(__tail)...),
292 _Base(std::forward<_UHead>(__head))
293 { }
294
295 constexpr _Tuple_impl(const _Tuple_impl&) = default;
296
297 // _GLIBCXX_RESOLVE_LIB_DEFECTS
298 // 2729. Missing SFINAE on std::pair::operator=
299 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
300
301 _Tuple_impl(_Tuple_impl&&) = default;
302
303 template<typename... _UElements>
304 constexpr
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))
308 { }
309
310 template<typename _UHead, typename... _UTails>
311 constexpr
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)))
317 { }
318
319#if __cplusplus > 202002L
320 template<typename... _UElements>
321 constexpr
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))
325 { }
326
327 template<typename _UHead, typename... _UTails>
328 constexpr
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)))
334 { }
335#endif // C++23
336
337 template<typename _Alloc>
338 _GLIBCXX20_CONSTEXPR
339 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
340 : _Inherited(__tag, __a),
341 _Base(__tag, __use_alloc<_Head>(__a))
342 { }
343
344 template<typename _Alloc>
345 _GLIBCXX20_CONSTEXPR
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)
350 { }
351
352 template<typename _Alloc, typename _UHead, typename... _UTail,
353 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
354 _GLIBCXX20_CONSTEXPR
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))
360 { }
361
362 template<typename _Alloc>
363 _GLIBCXX20_CONSTEXPR
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))
368 { }
369
370 template<typename _Alloc>
371 _GLIBCXX20_CONSTEXPR
372 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
373 _Tuple_impl&& __in)
374 : _Inherited(__tag, __a, std::move(_M_tail(__in))),
375 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
376 std::forward<_Head>(_M_head(__in)))
377 { }
378
379 template<typename _Alloc, typename _UHead, typename... _UTails>
380 _GLIBCXX20_CONSTEXPR
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))
387 { }
388
389 template<typename _Alloc, typename _UHead, typename... _UTails>
390 _GLIBCXX20_CONSTEXPR
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),
396 std::forward<_UHead>
397 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
398 { }
399
400#if __cplusplus > 202002L
401 template<typename _Alloc, typename _UHead, typename... _UTails>
402 constexpr
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))
409 { }
410
411 template<typename _Alloc, typename _UHead, typename... _UTails>
412 constexpr
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)))
420 { }
421#endif // C++23
422
423 template<typename... _UElements>
424 _GLIBCXX20_CONSTEXPR
425 void
426 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
427 {
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));
431 }
432
433 template<typename _UHead, typename... _UTails>
434 _GLIBCXX20_CONSTEXPR
435 void
436 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
437 {
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)));
442 }
443
444#if __cplusplus > 202002L
445 template<typename... _UElements>
446 constexpr void
447 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in) const
448 {
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));
452 }
453
454 template<typename _UHead, typename... _UTails>
455 constexpr void
456 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) const
457 {
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)));
462 }
463#endif // C++23
464
465 protected:
466 _GLIBCXX20_CONSTEXPR
467 void
468 _M_swap(_Tuple_impl& __in)
469 {
470 using std::swap;
471 swap(_M_head(*this), _M_head(__in));
472 _Inherited::_M_swap(_M_tail(__in));
473 }
474
475#if __cplusplus > 202002L
476 constexpr void
477 _M_swap(const _Tuple_impl& __in) const
478 {
479 using std::swap;
480 swap(_M_head(*this), _M_head(__in));
481 _Inherited::_M_swap(_M_tail(__in));
482 }
483#endif // C++23
484 };
485
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>
490 {
491 template<size_t, typename...> friend struct _Tuple_impl;
492
493 typedef _Head_base<_Idx, _Head> _Base;
494
495 static constexpr _Head&
496 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
497
498 static constexpr const _Head&
499 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
500
501 constexpr
502 _Tuple_impl()
503 : _Base() { }
504
505 explicit constexpr
506 _Tuple_impl(const _Head& __head)
507 : _Base(__head)
508 { }
509
510 template<typename _UHead>
511 explicit constexpr
512 _Tuple_impl(_UHead&& __head)
513 : _Base(std::forward<_UHead>(__head))
514 { }
515
516 constexpr _Tuple_impl(const _Tuple_impl&) = default;
517
518 // _GLIBCXX_RESOLVE_LIB_DEFECTS
519 // 2729. Missing SFINAE on std::pair::operator=
520 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
521
522#if _GLIBCXX_INLINE_VERSION
523 _Tuple_impl(_Tuple_impl&&) = default;
524#else
525 constexpr
526 _Tuple_impl(_Tuple_impl&& __in)
527 noexcept(is_nothrow_move_constructible<_Head>::value)
528 : _Base(static_cast<_Base&&>(__in))
529 { }
530#endif
531
532 template<typename _UHead>
533 constexpr
534 _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
535 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
536 { }
537
538 template<typename _UHead>
539 constexpr
540 _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
541 : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
542 { }
543
544#if __cplusplus > 202002L
545 template<typename _UHead>
546 constexpr
547 _Tuple_impl(_Tuple_impl<_Idx, _UHead>& __in)
548 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
549 { }
550
551 template<typename _UHead>
552 constexpr
553 _Tuple_impl(const _Tuple_impl<_Idx, _UHead>&& __in)
554 : _Base(std::forward<const _UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
555 { }
556#endif // C++23
557
558 template<typename _Alloc>
559 _GLIBCXX20_CONSTEXPR
560 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
561 : _Base(__tag, __use_alloc<_Head>(__a))
562 { }
563
564 template<typename _Alloc>
565 _GLIBCXX20_CONSTEXPR
566 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
567 const _Head& __head)
568 : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
569 { }
570
571 template<typename _Alloc, typename _UHead>
572 _GLIBCXX20_CONSTEXPR
573 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
574 _UHead&& __head)
575 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
576 std::forward<_UHead>(__head))
577 { }
578
579 template<typename _Alloc>
580 _GLIBCXX20_CONSTEXPR
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))
584 { }
585
586 template<typename _Alloc>
587 _GLIBCXX20_CONSTEXPR
588 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
589 _Tuple_impl&& __in)
590 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
591 std::forward<_Head>(_M_head(__in)))
592 { }
593
594 template<typename _Alloc, typename _UHead>
595 _GLIBCXX20_CONSTEXPR
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))
600 { }
601
602 template<typename _Alloc, typename _UHead>
603 _GLIBCXX20_CONSTEXPR
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)))
608 { }
609
610#if __cplusplus > 202002L
611 template<typename _Alloc, typename _UHead>
612 constexpr
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))
617 { }
618
619 template<typename _Alloc, typename _UHead>
620 constexpr
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)))
625 { }
626#endif // C++23
627
628 template<typename _UHead>
629 _GLIBCXX20_CONSTEXPR
630 void
631 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
632 {
633 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
634 }
635
636 template<typename _UHead>
637 _GLIBCXX20_CONSTEXPR
638 void
639 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
640 {
641 _M_head(*this)
642 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
643 }
644
645#if __cplusplus > 202002L
646 template<typename _UHead>
647 constexpr void
648 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in) const
649 {
650 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
651 }
652
653 template<typename _UHead>
654 constexpr void
655 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in) const
656 {
657 _M_head(*this)
658 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
659 }
660#endif // C++23
661
662 protected:
663 _GLIBCXX20_CONSTEXPR
664 void
665 _M_swap(_Tuple_impl& __in)
666 {
667 using std::swap;
668 swap(_M_head(*this), _M_head(__in));
669 }
670
671#if __cplusplus > 202002L
672 constexpr void
673 _M_swap(const _Tuple_impl& __in) const
674 {
675 using std::swap;
676 swap(_M_head(*this), _M_head(__in));
677 }
678#endif // C++23
679 };
680
681 // Concept utility functions, reused in conditionally-explicit
682 // constructors.
683 template<bool, typename... _Types>
684 struct _TupleConstraints
685 {
686 template<typename... _UTypes>
687 using __constructible = __and_<is_constructible<_Types, _UTypes>...>;
688
689 template<typename... _UTypes>
690 using __convertible = __and_<is_convertible<_UTypes, _Types>...>;
691
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()
697 {
698 return __and_<__constructible<_UTypes...>,
699 __convertible<_UTypes...>
700 >::value;
701 }
702
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()
708 {
709 return __and_<__constructible<_UTypes...>,
710 __not_<__convertible<_UTypes...>>
711 >::value;
712 }
713
714 static constexpr bool __is_implicitly_default_constructible()
715 {
716 return __and_<std::__is_implicitly_default_constructible<_Types>...
717 >::value;
718 }
719
720 static constexpr bool __is_explicitly_default_constructible()
721 {
722 return __and_<is_default_constructible<_Types>...,
723 __not_<__and_<
724 std::__is_implicitly_default_constructible<_Types>...>
725 >>::value;
726 }
727 };
728
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...>
733 {
734 template<typename... _UTypes>
735 static constexpr bool __is_implicitly_constructible()
736 { return false; }
737
738 template<typename... _UTypes>
739 static constexpr bool __is_explicitly_constructible()
740 { return false; }
741 };
742
743 /// Primary class template, tuple
744 template<typename... _Elements>
745 class tuple : public _Tuple_impl<0, _Elements...>
746 {
747 typedef _Tuple_impl<0, _Elements...> _Inherited;
748
749 template<bool _Cond>
750 using _TCC = _TupleConstraints<_Cond, _Elements...>;
751
752 // Constraint for non-explicit default constructor
753 template<bool _Dummy>
754 using _ImplicitDefaultCtor = __enable_if_t<
755 _TCC<_Dummy>::__is_implicitly_default_constructible(),
756 bool>;
757
758 // Constraint for explicit default constructor
759 template<bool _Dummy>
760 using _ExplicitDefaultCtor = __enable_if_t<
761 _TCC<_Dummy>::__is_explicitly_default_constructible(),
762 bool>;
763
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...>(),
768 bool>;
769
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...>(),
774 bool>;
775
776 template<typename... _UElements>
777 static constexpr
778 __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
779 __assignable()
780 { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
781
782 // Condition for noexcept-specifier of an assignment operator.
783 template<typename... _UElements>
784 static constexpr bool __nothrow_assignable()
785 {
786 return
787 __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
788 }
789
790 // Condition for noexcept-specifier of a constructor.
791 template<typename... _UElements>
792 static constexpr bool __nothrow_constructible()
793 {
794 return
795 __and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
796 }
797
798 // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
799 template<typename _Up>
800 static constexpr bool __valid_args()
801 {
802 return sizeof...(_Elements) == 1
803 && !is_same<tuple, __remove_cvref_t<_Up>>::value;
804 }
805
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); }
810
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.
819 */
820 template<typename _Tuple, typename = tuple,
821 typename = __remove_cvref_t<_Tuple>>
822 struct _UseOtherCtor
823 : false_type
824 { };
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
830 { };
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>>
835 : true_type
836 { };
837
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; }
844
845#if __cplusplus > 202002L
846 template<typename... _Args>
847 static constexpr bool __constructible
848 = _TCC<true>::template __constructible<_Args...>::value;
849
850 template<typename... _Args>
851 static constexpr bool __convertible
852 = _TCC<true>::template __convertible<_Args...>::value;
853#endif // C++23
854
855 public:
856 template<typename _Dummy = void,
857 _ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
858 constexpr
859 tuple()
860 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
861 : _Inherited() { }
862
863 template<typename _Dummy = void,
864 _ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
865 explicit constexpr
866 tuple()
867 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
868 : _Inherited() { }
869
870 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
871 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
872 constexpr
873 tuple(const _Elements&... __elements)
874 noexcept(__nothrow_constructible<const _Elements&...>())
875 : _Inherited(__elements...) { }
876
877 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
878 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
879 explicit constexpr
880 tuple(const _Elements&... __elements)
881 noexcept(__nothrow_constructible<const _Elements&...>())
882 : _Inherited(__elements...) { }
883
884 template<typename... _UElements,
885 bool _Valid = __valid_args<_UElements...>(),
886 _ImplicitCtor<_Valid, _UElements...> = true>
887 constexpr
888 tuple(_UElements&&... __elements)
889 noexcept(__nothrow_constructible<_UElements...>())
890 : _Inherited(std::forward<_UElements>(__elements)...) { }
891
892 template<typename... _UElements,
893 bool _Valid = __valid_args<_UElements...>(),
894 _ExplicitCtor<_Valid, _UElements...> = false>
895 explicit constexpr
896 tuple(_UElements&&... __elements)
897 noexcept(__nothrow_constructible<_UElements...>())
898 : _Inherited(std::forward<_UElements>(__elements)...) { }
899
900 constexpr tuple(const tuple&) = default;
901
902 constexpr tuple(tuple&&) = default;
903
904 template<typename... _UElements,
905 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
906 && !__use_other_ctor<const tuple<_UElements...>&>(),
907 _ImplicitCtor<_Valid, const _UElements&...> = true>
908 constexpr
909 tuple(const tuple<_UElements...>& __in)
910 noexcept(__nothrow_constructible<const _UElements&...>())
911 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
912 { }
913
914 template<typename... _UElements,
915 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
916 && !__use_other_ctor<const tuple<_UElements...>&>(),
917 _ExplicitCtor<_Valid, const _UElements&...> = false>
918 explicit constexpr
919 tuple(const tuple<_UElements...>& __in)
920 noexcept(__nothrow_constructible<const _UElements&...>())
921 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
922 { }
923
924 template<typename... _UElements,
925 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
926 && !__use_other_ctor<tuple<_UElements...>&&>(),
927 _ImplicitCtor<_Valid, _UElements...> = true>
928 constexpr
929 tuple(tuple<_UElements...>&& __in)
930 noexcept(__nothrow_constructible<_UElements...>())
931 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
932
933 template<typename... _UElements,
934 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
935 && !__use_other_ctor<tuple<_UElements...>&&>(),
936 _ExplicitCtor<_Valid, _UElements...> = false>
937 explicit constexpr
938 tuple(tuple<_UElements...>&& __in)
939 noexcept(__nothrow_constructible<_UElements...>())
940 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
941
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&...>)
948 constexpr
949 tuple(tuple<_UElements...>& __in)
950 noexcept(__nothrow_constructible<_UElements&...>())
951 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&>(__in))
952 { }
953
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...>)
959 constexpr
960 tuple(const tuple<_UElements...>&& __in)
961 noexcept(__nothrow_constructible<const _UElements...>())
962 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&&>(__in)) { }
963#endif // C++23
964
965 // Allocator-extended constructors.
966
967 template<typename _Alloc,
968 _ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
969 _GLIBCXX20_CONSTEXPR
970 tuple(allocator_arg_t __tag, const _Alloc& __a)
971 : _Inherited(__tag, __a) { }
972
973 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
974 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
975 _GLIBCXX20_CONSTEXPR
976 tuple(allocator_arg_t __tag, const _Alloc& __a,
977 const _Elements&... __elements)
978 : _Inherited(__tag, __a, __elements...) { }
979
980 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
981 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
982 _GLIBCXX20_CONSTEXPR
983 explicit
984 tuple(allocator_arg_t __tag, const _Alloc& __a,
985 const _Elements&... __elements)
986 : _Inherited(__tag, __a, __elements...) { }
987
988 template<typename _Alloc, typename... _UElements,
989 bool _Valid = __valid_args<_UElements...>(),
990 _ImplicitCtor<_Valid, _UElements...> = true>
991 _GLIBCXX20_CONSTEXPR
992 tuple(allocator_arg_t __tag, const _Alloc& __a,
993 _UElements&&... __elements)
994 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
995 { }
996
997 template<typename _Alloc, typename... _UElements,
998 bool _Valid = __valid_args<_UElements...>(),
999 _ExplicitCtor<_Valid, _UElements...> = false>
1000 _GLIBCXX20_CONSTEXPR
1001 explicit
1002 tuple(allocator_arg_t __tag, const _Alloc& __a,
1003 _UElements&&... __elements)
1004 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
1005 { }
1006
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)) { }
1011
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)) { }
1016
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))
1026 { }
1027
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
1033 explicit
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))
1038 { }
1039
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))
1049 { }
1050
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
1056 explicit
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))
1061 { }
1062
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&...>)
1069 constexpr
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))
1074 { }
1075
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...>)
1081 constexpr
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))
1086 { }
1087#endif // C++23
1088
1089 // tuple assignment
1090
1091 _GLIBCXX20_CONSTEXPR
1092 tuple&
1093 operator=(__conditional_t<__assignable<const _Elements&...>(),
1094 const tuple&,
1095 const __nonesuch&> __in)
1096 noexcept(__nothrow_assignable<const _Elements&...>())
1097 {
1098 this->_M_assign(__in);
1099 return *this;
1100 }
1101
1102 _GLIBCXX20_CONSTEXPR
1103 tuple&
1104 operator=(__conditional_t<__assignable<_Elements...>(),
1105 tuple&&,
1106 __nonesuch&&> __in)
1107 noexcept(__nothrow_assignable<_Elements...>())
1108 {
1109 this->_M_assign(std::move(__in));
1110 return *this;
1111 }
1112
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&...>())
1118 {
1119 this->_M_assign(__in);
1120 return *this;
1121 }
1122
1123 template<typename... _UElements>
1124 _GLIBCXX20_CONSTEXPR
1125 __enable_if_t<__assignable<_UElements...>(), tuple&>
1126 operator=(tuple<_UElements...>&& __in)
1127 noexcept(__nothrow_assignable<_UElements...>())
1128 {
1129 this->_M_assign(std::move(__in));
1130 return *this;
1131 }
1132
1133#if __cplusplus > 202002L
1134 constexpr const tuple&
1135 operator=(const tuple& __in) const
1136 requires (is_copy_assignable_v<const _Elements> && ...)
1137 {
1138 this->_M_assign(__in);
1139 return *this;
1140 }
1141
1142 constexpr const tuple&
1143 operator=(tuple&& __in) const
1144 requires (is_assignable_v<const _Elements&, _Elements> && ...)
1145 {
1146 this->_M_assign(std::move(__in));
1147 return *this;
1148 }
1149
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&> && ...)
1155 {
1156 this->_M_assign(__in);
1157 return *this;
1158 }
1159
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> && ...)
1165 {
1166 this->_M_assign(std::move(__in));
1167 return *this;
1168 }
1169#endif // C++23
1170
1171 // tuple swap
1172 _GLIBCXX20_CONSTEXPR
1173 void
1174 swap(tuple& __in)
1175 noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
1176 { _Inherited::_M_swap(__in); }
1177
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.
1185 constexpr void
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); }
1190#endif // C++23
1191 };
1192
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...>;
1204#endif
1205
1206 // Explicit specialization, zero-element tuple.
1207 template<>
1208 class tuple<>
1209 {
1210 public:
1211 _GLIBCXX20_CONSTEXPR
1212 void swap(tuple&) noexcept { /* no-op */ }
1213#if __cplusplus > 202002L
1214 constexpr void swap(const tuple&) const noexcept { /* no-op */ }
1215#endif
1216 // We need the default since we're going to define no-op
1217 // allocator constructors.
1218 tuple() = default;
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 { }
1226 };
1227
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>
1232 {
1233 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
1234
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(),
1240 bool>;
1241
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(),
1247 bool>;
1248
1249 template<bool _Dummy>
1250 using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
1251
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>(),
1256 bool>;
1257
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>(),
1262 bool>;
1263
1264 template<typename _U1, typename _U2>
1265 static constexpr bool __assignable()
1266 {
1267 return __and_<is_assignable<_T1&, _U1>,
1268 is_assignable<_T2&, _U2>>::value;
1269 }
1270
1271 template<typename _U1, typename _U2>
1272 static constexpr bool __nothrow_assignable()
1273 {
1274 return __and_<is_nothrow_assignable<_T1&, _U1>,
1275 is_nothrow_assignable<_T2&, _U2>>::value;
1276 }
1277
1278 template<typename _U1, typename _U2>
1279 static constexpr bool __nothrow_constructible()
1280 {
1281 return __and_<is_nothrow_constructible<_T1, _U1>,
1282 is_nothrow_constructible<_T2, _U2>>::value;
1283 }
1284
1285 static constexpr bool __nothrow_default_constructible()
1286 {
1287 return __and_<is_nothrow_default_constructible<_T1>,
1288 is_nothrow_default_constructible<_T2>>::value;
1289 }
1290
1291 template<typename _U1>
1292 static constexpr bool __is_alloc_arg()
1293 { return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; }
1294
1295#if __cplusplus > 202002L
1296 template<typename _U1, typename _U2>
1297 static constexpr bool __constructible
1298 = _TCC<true>::template __constructible<_U1, _U2>::value;
1299
1300 template<typename _U1, typename _U2>
1301 static constexpr bool __convertible
1302 = _TCC<true>::template __convertible<_U1, _U2>::value;
1303#endif // C++23
1304
1305 public:
1306 template<bool _Dummy = true,
1307 _ImplicitDefaultCtor<_Dummy, _T1, _T2> = true>
1308 constexpr
1309 tuple()
1310 noexcept(__nothrow_default_constructible())
1311 : _Inherited() { }
1312
1313 template<bool _Dummy = true,
1314 _ExplicitDefaultCtor<_Dummy, _T1, _T2> = false>
1315 explicit constexpr
1316 tuple()
1317 noexcept(__nothrow_default_constructible())
1318 : _Inherited() { }
1319
1320 template<bool _Dummy = true,
1321 _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
1322 constexpr
1323 tuple(const _T1& __a1, const _T2& __a2)
1324 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1325 : _Inherited(__a1, __a2) { }
1326
1327 template<bool _Dummy = true,
1328 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1329 explicit constexpr
1330 tuple(const _T1& __a1, const _T2& __a2)
1331 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1332 : _Inherited(__a1, __a2) { }
1333
1334 template<typename _U1, typename _U2,
1335 _ImplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = true>
1336 constexpr
1337 tuple(_U1&& __a1, _U2&& __a2)
1338 noexcept(__nothrow_constructible<_U1, _U2>())
1339 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1340
1341 template<typename _U1, typename _U2,
1342 _ExplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = false>
1343 explicit constexpr
1344 tuple(_U1&& __a1, _U2&& __a2)
1345 noexcept(__nothrow_constructible<_U1, _U2>())
1346 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1347
1348 constexpr tuple(const tuple&) = default;
1349
1350 constexpr tuple(tuple&&) = default;
1351
1352 template<typename _U1, typename _U2,
1353 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1354 constexpr
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)) { }
1358
1359 template<typename _U1, typename _U2,
1360 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1361 explicit constexpr
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)) { }
1365
1366 template<typename _U1, typename _U2,
1367 _ImplicitCtor<true, _U1, _U2> = true>
1368 constexpr
1369 tuple(tuple<_U1, _U2>&& __in)
1370 noexcept(__nothrow_constructible<_U1, _U2>())
1371 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1372
1373 template<typename _U1, typename _U2,
1374 _ExplicitCtor<true, _U1, _U2> = false>
1375 explicit constexpr
1376 tuple(tuple<_U1, _U2>&& __in)
1377 noexcept(__nothrow_constructible<_U1, _U2>())
1378 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1379
1380#if __cplusplus > 202002L
1381 template<typename _U1, typename _U2>
1382 requires __constructible<_U1&, _U2&>
1383 explicit(!__convertible<_U1&, _U2&>)
1384 constexpr
1385 tuple(tuple<_U1, _U2>& __in)
1386 noexcept(__nothrow_constructible<_U1&, _U2&>())
1387 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&>(__in)) { }
1388
1389 template<typename _U1, typename _U2>
1390 requires __constructible<const _U1, const _U2>
1391 explicit(!__convertible<const _U1, const _U2>)
1392 constexpr
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)) { }
1396#endif // C++23
1397
1398 template<typename _U1, typename _U2,
1399 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1400 constexpr
1401 tuple(const pair<_U1, _U2>& __in)
1402 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1403 : _Inherited(__in.first, __in.second) { }
1404
1405 template<typename _U1, typename _U2,
1406 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1407 explicit constexpr
1408 tuple(const pair<_U1, _U2>& __in)
1409 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1410 : _Inherited(__in.first, __in.second) { }
1411
1412 template<typename _U1, typename _U2,
1413 _ImplicitCtor<true, _U1, _U2> = true>
1414 constexpr
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)) { }
1419
1420 template<typename _U1, typename _U2,
1421 _ExplicitCtor<true, _U1, _U2> = false>
1422 explicit constexpr
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)) { }
1427
1428#if __cplusplus > 202002L
1429 template<typename _U1, typename _U2>
1430 requires __constructible<_U1&, _U2&>
1431 explicit(!__convertible<_U1&, _U2&>)
1432 constexpr
1433 tuple(pair<_U1, _U2>& __in)
1434 noexcept(__nothrow_constructible<_U1&, _U2&>())
1435 : _Inherited(__in.first, __in.second) { }
1436
1437 template<typename _U1, typename _U2>
1438 requires __constructible<const _U1, const _U2>
1439 explicit(!__convertible<const _U1, const _U2>)
1440 constexpr
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)) { }
1445#endif // C++23
1446
1447 // Allocator-extended constructors.
1448
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) { }
1454
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) { }
1461
1462 template<typename _Alloc, bool _Dummy = true,
1463 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1464 explicit
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) { }
1469
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)) { }
1476
1477 template<typename _Alloc, typename _U1, typename _U2,
1478 _ExplicitCtor<true, _U1, _U2> = false>
1479 explicit
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)) { }
1485
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)) { }
1490
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)) { }
1495
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))
1503 { }
1504
1505 template<typename _Alloc, typename _U1, typename _U2,
1506 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1507 explicit
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))
1513 { }
1514
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))
1520 { }
1521
1522 template<typename _Alloc, typename _U1, typename _U2,
1523 _ExplicitCtor<true, _U1, _U2> = false>
1524 explicit
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))
1528 { }
1529
1530#if __cplusplus > 202002L
1531 template<typename _Alloc, typename _U1, typename _U2>
1532 requires __constructible<_U1&, _U2&>
1533 explicit(!__convertible<_U1&, _U2&>)
1534 constexpr
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))
1539 { }
1540
1541 template<typename _Alloc, typename _U1, typename _U2>
1542 requires __constructible<const _U1, const _U2>
1543 explicit(!__convertible<const _U1, const _U2>)
1544 constexpr
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))
1549 { }
1550#endif // C++23
1551
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) { }
1558
1559 template<typename _Alloc, typename _U1, typename _U2,
1560 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1561 explicit
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) { }
1566
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)) { }
1573
1574 template<typename _Alloc, typename _U1, typename _U2,
1575 _ExplicitCtor<true, _U1, _U2> = false>
1576 explicit
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)) { }
1581
1582#if __cplusplus > 202002L
1583 template<typename _Alloc, typename _U1, typename _U2>
1584 requires __constructible<_U1&, _U2&>
1585 explicit(!__convertible<_U1&, _U2&>)
1586 constexpr
1587 tuple(allocator_arg_t __tag, const _Alloc& __a,
1588 pair<_U1, _U2>& __in)
1589 : _Inherited(__tag, __a, __in.first, __in.second) { }
1590
1591 template<typename _Alloc, typename _U1, typename _U2>
1592 requires __constructible<const _U1, const _U2>
1593 explicit(!__convertible<const _U1, const _U2>)
1594 constexpr
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)) { }
1598#endif // C++23
1599
1600 // Tuple assignment.
1601
1602 _GLIBCXX20_CONSTEXPR
1603 tuple&
1604 operator=(__conditional_t<__assignable<const _T1&, const _T2&>(),
1605 const tuple&,
1606 const __nonesuch&> __in)
1607 noexcept(__nothrow_assignable<const _T1&, const _T2&>())
1608 {
1609 this->_M_assign(__in);
1610 return *this;
1611 }
1612
1613 _GLIBCXX20_CONSTEXPR
1614 tuple&
1615 operator=(__conditional_t<__assignable<_T1, _T2>(),
1616 tuple&&,
1617 __nonesuch&&> __in)
1618 noexcept(__nothrow_assignable<_T1, _T2>())
1619 {
1620 this->_M_assign(std::move(__in));
1621 return *this;
1622 }
1623
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&>())
1629 {
1630 this->_M_assign(__in);
1631 return *this;
1632 }
1633
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>())
1639 {
1640 this->_M_assign(std::move(__in));
1641 return *this;
1642 }
1643
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>
1648 {
1649 this->_M_assign(__in);
1650 return *this;
1651 }
1652
1653 constexpr const tuple&
1654 operator=(tuple&& __in) const
1655 requires is_assignable_v<const _T1&, _T1> && is_assignable_v<const _T2, _T2>
1656 {
1657 this->_M_assign(std::move(__in));
1658 return *this;
1659 }
1660
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&>
1666 {
1667 this->_M_assign(__in);
1668 return *this;
1669 }
1670
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>
1676 {
1677 this->_M_assign(std::move(__in));
1678 return *this;
1679 }
1680#endif // C++23
1681
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&>())
1687 {
1688 this->_M_head(*this) = __in.first;
1689 this->_M_tail(*this)._M_head(*this) = __in.second;
1690 return *this;
1691 }
1692
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>())
1698 {
1699 this->_M_head(*this) = std::forward<_U1>(__in.first);
1700 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1701 return *this;
1702 }
1703
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&>
1710 {
1711 this->_M_head(*this) = __in.first;
1712 this->_M_tail(*this)._M_head(*this) = __in.second;
1713 return *this;
1714 }
1715
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>
1721 {
1722 this->_M_head(*this) = std::forward<_U1>(__in.first);
1723 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1724 return *this;
1725 }
1726#endif // C++23
1727
1728 _GLIBCXX20_CONSTEXPR
1729 void
1730 swap(tuple& __in)
1731 noexcept(__and_<__is_nothrow_swappable<_T1>,
1732 __is_nothrow_swappable<_T2>>::value)
1733 { _Inherited::_M_swap(__in); }
1734
1735#if __cplusplus > 202002L
1736 constexpr void
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); }
1742#endif // C++23
1743 };
1744
1745
1746 /// class tuple_size
1747 template<typename... _Elements>
1748 struct tuple_size<tuple<_Elements...>>
1749 : public integral_constant<size_t, sizeof...(_Elements)> { };
1750
1751#if __cplusplus >= 201703L
1752 template<typename... _Types>
1753 inline constexpr size_t tuple_size_v<tuple<_Types...>>
1754 = sizeof...(_Types);
1755
1756 template<typename... _Types>
1757 inline constexpr size_t tuple_size_v<const tuple<_Types...>>
1758 = sizeof...(_Types);
1759#endif
1760
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...>>
1764 {
1765 static_assert(__i < sizeof...(_Types), "tuple index must be in range");
1766
1767 using type = typename _Nth_type<__i, _Types...>::type;
1768 };
1769
1770 template<size_t __i, typename _Head, typename... _Tail>
1771 constexpr _Head&
1772 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1773 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1774
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); }
1779
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;
1784
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); }
1790
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); }
1796
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
1801 {
1802 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1803 return std::forward<__element_type>(std::__get_helper<__i>(__t));
1804 }
1805
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
1810 {
1811 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1812 return std::forward<const __element_type>(std::__get_helper<__i>(__t));
1813 }
1814
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;
1820 /// @endcond
1821
1822#if __cplusplus >= 201402L
1823
1824#define __cpp_lib_tuples_by_type 201304L
1825
1826 /// Return a reference to the unique element of type _Tp of a tuple.
1827 template <typename _Tp, typename... _Types>
1828 constexpr _Tp&
1829 get(tuple<_Types...>& __t) noexcept
1830 {
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);
1835 }
1836
1837 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1838 template <typename _Tp, typename... _Types>
1839 constexpr _Tp&&
1840 get(tuple<_Types...>&& __t) noexcept
1841 {
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));
1846 }
1847
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
1852 {
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);
1857 }
1858
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
1864 {
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));
1869 }
1870#endif
1871
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
1875 {
1876 static constexpr bool
1877 __eq(const _Tp& __t, const _Up& __u)
1878 {
1879 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1880 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1881 }
1882
1883 static constexpr bool
1884 __less(const _Tp& __t, const _Up& __u)
1885 {
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));
1889 }
1890 };
1891
1892 template<typename _Tp, typename _Up, size_t __size>
1893 struct __tuple_compare<_Tp, _Up, __size, __size>
1894 {
1895 static constexpr bool
1896 __eq(const _Tp&, const _Up&) { return true; }
1897
1898 static constexpr bool
1899 __less(const _Tp&, const _Up&) { return false; }
1900 };
1901
1902 template<typename... _TElements, typename... _UElements>
1903 constexpr bool
1904 operator==(const tuple<_TElements...>& __t,
1905 const tuple<_UElements...>& __u)
1906 {
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);
1913 }
1914
1915#if __cpp_lib_three_way_comparison
1916 template<typename _Cat, typename _Tp, typename _Up>
1917 constexpr _Cat
1918 __tuple_cmp(const _Tp&, const _Up&, index_sequence<>)
1919 { return _Cat::equivalent; }
1920
1921 template<typename _Cat, typename _Tp, typename _Up,
1922 size_t _Idx0, size_t... _Idxs>
1923 constexpr _Cat
1924 __tuple_cmp(const _Tp& __t, const _Up& __u,
1925 index_sequence<_Idx0, _Idxs...>)
1926 {
1927 auto __c
1928 = __detail::__synth3way(std::get<_Idx0>(__t), std::get<_Idx0>(__u));
1929 if (__c != 0)
1930 return __c;
1931 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence<_Idxs...>());
1932 }
1933
1934 template<typename... _Tps, typename... _Ups>
1935 constexpr
1936 common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>
1937 operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)
1938 {
1939 using _Cat
1940 = common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>;
1941 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence_for<_Tps...>());
1942 }
1943#else
1944 template<typename... _TElements, typename... _UElements>
1945 constexpr bool
1946 operator<(const tuple<_TElements...>& __t,
1947 const tuple<_UElements...>& __u)
1948 {
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);
1955 }
1956
1957 template<typename... _TElements, typename... _UElements>
1958 constexpr bool
1959 operator!=(const tuple<_TElements...>& __t,
1960 const tuple<_UElements...>& __u)
1961 { return !(__t == __u); }
1962
1963 template<typename... _TElements, typename... _UElements>
1964 constexpr bool
1965 operator>(const tuple<_TElements...>& __t,
1966 const tuple<_UElements...>& __u)
1967 { return __u < __t; }
1968
1969 template<typename... _TElements, typename... _UElements>
1970 constexpr bool
1971 operator<=(const tuple<_TElements...>& __t,
1972 const tuple<_UElements...>& __u)
1973 { return !(__u < __t); }
1974
1975 template<typename... _TElements, typename... _UElements>
1976 constexpr bool
1977 operator>=(const tuple<_TElements...>& __t,
1978 const tuple<_UElements...>& __u)
1979 { return !(__t < __u); }
1980#endif // three_way_comparison
1981
1982 // NB: DR 705.
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)
1987 {
1988 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1989 __result_type;
1990 return __result_type(std::forward<_Elements>(__args)...);
1991 }
1992
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)...); }
2000
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>.
2003
2004 template<typename _Tp, size_t _Nm> struct array;
2005
2006 template<size_t _Int, typename _Tp, size_t _Nm>
2007 constexpr _Tp&
2008 get(array<_Tp, _Nm>&) noexcept;
2009
2010 template<size_t _Int, typename _Tp, size_t _Nm>
2011 constexpr _Tp&&
2012 get(array<_Tp, _Nm>&&) noexcept;
2013
2014 template<size_t _Int, typename _Tp, size_t _Nm>
2015 constexpr const _Tp&
2016 get(const array<_Tp, _Nm>&) noexcept;
2017
2018 template<size_t _Int, typename _Tp, size_t _Nm>
2019 constexpr const _Tp&&
2020 get(const array<_Tp, _Nm>&&) noexcept;
2021
2022 /// @cond undocumented
2023 template<size_t, typename, typename, size_t>
2024 struct __make_tuple_impl;
2025
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>>,
2030 _Tuple, _Nm>
2031 { };
2032
2033 template<size_t _Nm, typename _Tuple, typename... _Tp>
2034 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
2035 {
2036 typedef tuple<_Tp...> __type;
2037 };
2038
2039 template<typename _Tuple>
2040 struct __do_make_tuple
2041 : __make_tuple_impl<0, tuple<>, _Tuple, tuple_size<_Tuple>::value>
2042 { };
2043
2044 // Returns the std::tuple equivalent of a tuple-like type.
2045 template<typename _Tuple>
2046 struct __make_tuple
2047 : public __do_make_tuple<__remove_cvref_t<_Tuple>>
2048 { };
2049
2050 // Combines several std::tuple's into a single one.
2051 template<typename...>
2052 struct __combine_tuples;
2053
2054 template<>
2055 struct __combine_tuples<>
2056 {
2057 typedef tuple<> __type;
2058 };
2059
2060 template<typename... _Ts>
2061 struct __combine_tuples<tuple<_Ts...>>
2062 {
2063 typedef tuple<_Ts...> __type;
2064 };
2065
2066 template<typename... _T1s, typename... _T2s, typename... _Rem>
2067 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
2068 {
2069 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
2070 _Rem...>::__type __type;
2071 };
2072
2073 // Computes the result type of tuple_cat given a set of tuple-like types.
2074 template<typename... _Tpls>
2075 struct __tuple_cat_result
2076 {
2077 typedef typename __combine_tuples
2078 <typename __make_tuple<_Tpls>::__type...>::__type __type;
2079 };
2080
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;
2085
2086 template<>
2087 struct __make_1st_indices<>
2088 {
2089 typedef _Index_tuple<> __type;
2090 };
2091
2092 template<typename _Tp, typename... _Tpls>
2093 struct __make_1st_indices<_Tp, _Tpls...>
2094 {
2095 typedef typename _Build_index_tuple<tuple_size<
2096 typename remove_reference<_Tp>::type>::value>::__type __type;
2097 };
2098
2099 // Performs the actual concatenation by step-wise expanding tuple-like
2100 // objects into the elements, which are finally forwarded into the
2101 // result tuple.
2102 template<typename _Ret, typename _Indices, typename... _Tpls>
2103 struct __tuple_concater;
2104
2105 template<typename _Ret, size_t... _Is, typename _Tp, typename... _Tpls>
2106 struct __tuple_concater<_Ret, _Index_tuple<_Is...>, _Tp, _Tpls...>
2107 {
2108 template<typename... _Us>
2109 static constexpr _Ret
2110 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
2111 {
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))...);
2117 }
2118 };
2119
2120 template<typename _Ret>
2121 struct __tuple_concater<_Ret, _Index_tuple<>>
2122 {
2123 template<typename... _Us>
2124 static constexpr _Ret
2125 _S_do(_Us&&... __us)
2126 {
2127 return _Ret(std::forward<_Us>(__us)...);
2128 }
2129 };
2130
2131 template<typename... _Tps>
2132 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
2133 { };
2134 /// @endcond
2135
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>
2139 constexpr auto
2140 tuple_cat(_Tpls&&... __tpls)
2141 -> typename __tuple_cat_result<_Tpls...>::__type
2142 {
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)...);
2147 }
2148
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...); }
2156
2157 /// Exchange the values of two tuples
2158 template<typename... _Elements>
2159 _GLIBCXX20_CONSTEXPR
2160 inline
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
2164 >::type
2165#else
2166 void
2167#endif
2168 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
2169 noexcept(noexcept(__x.swap(__y)))
2170 { __x.swap(__y); }
2171
2172#if __cplusplus > 202002L
2173 template<typename... _Elements>
2174 requires (is_swappable_v<const _Elements> && ...)
2175 constexpr void
2176 swap(const tuple<_Elements...>& __x, const tuple<_Elements...>& __y)
2177 noexcept(noexcept(__x.swap(__y)))
2178 { __x.swap(__y); }
2179#endif // C++23
2180
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;
2187#endif
2188
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
2194 {
2195 template<class _Tp>
2196 _GLIBCXX14_CONSTEXPR const _Swallow_assign&
2197 operator=(const _Tp&) const
2198 { return *this; }
2199 };
2200
2201 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2202 // 2773. Making std::ignore constexpr
2203 /** Used with `std::tie` to ignore an element of a tuple
2204 *
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:
2207 *
2208 * ```
2209 * int x, y;
2210 * std::tie(x, std::ignore, y) = std::make_tuple(1, 2, 3);
2211 * ```
2212 *
2213 * This assignment will perform `x=1; std::ignore=2; y=3;` which results
2214 * in the second element being ignored.
2215 *
2216 * @since C++11
2217 */
2218 _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
2219
2220 /// Partial specialization for tuples
2221 template<typename... _Types, typename _Alloc>
2222 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
2223
2224 // See stl_pair.h...
2225 /** "piecewise construction" using a tuple of arguments for each member.
2226 *
2227 * @param __first Arguments for the first member of the pair.
2228 * @param __second Arguments for the second member of the pair.
2229 *
2230 * The elements of each tuple will be used as the constructor arguments
2231 * for the data members of the pair.
2232 */
2233 template<class _T1, class _T2>
2234 template<typename... _Args1, typename... _Args2>
2235 _GLIBCXX20_CONSTEXPR
2236 inline
2237 pair<_T1, _T2>::
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())
2243 { }
2244
2245 template<class _T1, class _T2>
2246 template<typename... _Args1, size_t... _Indexes1,
2247 typename... _Args2, size_t... _Indexes2>
2248 _GLIBCXX20_CONSTEXPR inline
2249 pair<_T1, _T2>::
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))...)
2254 { }
2255
2256#if __cplusplus >= 201703L
2257
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;
2264
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;
2268
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;
2272
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;
2276
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;
2280
2281# define __cpp_lib_apply 201603L
2282
2283 template <typename _Fn, typename _Tuple, size_t... _Idx>
2284 constexpr decltype(auto)
2285 __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
2286 {
2287 return std::__invoke(std::forward<_Fn>(__f),
2288 std::get<_Idx>(std::forward<_Tuple>(__t))...);
2289 }
2290
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>)
2295 {
2296 using _Indices
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),
2300 _Indices{});
2301 }
2302
2303#define __cpp_lib_make_from_tuple 201606L
2304
2305 template <typename _Tp, typename _Tuple, size_t... _Idx>
2306 constexpr _Tp
2307 __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
2308 { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
2309
2310 template <typename _Tp, typename _Tuple>
2311 constexpr _Tp
2312 make_from_tuple(_Tuple&& __t)
2313 noexcept(__unpack_std_tuple<is_nothrow_constructible, _Tp, _Tuple>)
2314 {
2315 return __make_from_tuple_impl<_Tp>(
2316 std::forward<_Tuple>(__t),
2317 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{});
2318 }
2319#endif // C++17
2320
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>>...>; };
2327
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>...>; };
2332#endif // C++23
2333
2334 /// @}
2335
2336_GLIBCXX_END_NAMESPACE_VERSION
2337} // namespace std
2338
2339#endif // C++11
2340
2341#endif // _GLIBCXX_TUPLE