]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/std/tuple
libstdc++: Add workaround for weird std::tuple error [PR 96592]
[thirdparty/gcc.git] / libstdc++-v3 / include / std / tuple
1 // <tuple> -*- C++ -*-
2
3 // Copyright (C) 2007-2020 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 <utility>
39 #include <array>
40 #include <bits/uses_allocator.h>
41 #include <bits/invoke.h>
42 #if __cplusplus > 201703L
43 # include <compare>
44 # define __cpp_lib_constexpr_tuple 201811L
45 #endif
46
47 namespace 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 = typename conditional<__is_final(_Tp), false_type,
70 __is_empty_non_tuple<_Tp>>::type;
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 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
99 : _M_head_impl(allocator_arg, *__a._M_a) { }
100
101 template<typename _Alloc>
102 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
103 : _M_head_impl(*__a._M_a) { }
104
105 template<typename _UHead>
106 _GLIBCXX20_CONSTEXPR
107 _Head_base(__uses_alloc0, _UHead&& __uhead)
108 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
109
110 template<typename _Alloc, typename _UHead>
111 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
112 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
113 { }
114
115 template<typename _Alloc, typename _UHead>
116 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
117 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
118
119 static constexpr _Head&
120 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
121
122 static constexpr const _Head&
123 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
124
125 [[no_unique_address]] _Head _M_head_impl;
126 };
127 #else
128 template<size_t _Idx, typename _Head>
129 struct _Head_base<_Idx, _Head, true>
130 : public _Head
131 {
132 constexpr _Head_base()
133 : _Head() { }
134
135 constexpr _Head_base(const _Head& __h)
136 : _Head(__h) { }
137
138 constexpr _Head_base(const _Head_base&) = default;
139 constexpr _Head_base(_Head_base&&) = default;
140
141 template<typename _UHead>
142 constexpr _Head_base(_UHead&& __h)
143 : _Head(std::forward<_UHead>(__h)) { }
144
145 _Head_base(allocator_arg_t, __uses_alloc0)
146 : _Head() { }
147
148 template<typename _Alloc>
149 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
150 : _Head(allocator_arg, *__a._M_a) { }
151
152 template<typename _Alloc>
153 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
154 : _Head(*__a._M_a) { }
155
156 template<typename _UHead>
157 _Head_base(__uses_alloc0, _UHead&& __uhead)
158 : _Head(std::forward<_UHead>(__uhead)) { }
159
160 template<typename _Alloc, typename _UHead>
161 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
162 : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
163
164 template<typename _Alloc, typename _UHead>
165 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
166 : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
167
168 static constexpr _Head&
169 _M_head(_Head_base& __b) noexcept { return __b; }
170
171 static constexpr const _Head&
172 _M_head(const _Head_base& __b) noexcept { return __b; }
173 };
174 #endif
175
176 template<size_t _Idx, typename _Head>
177 struct _Head_base<_Idx, _Head, false>
178 {
179 constexpr _Head_base()
180 : _M_head_impl() { }
181
182 constexpr _Head_base(const _Head& __h)
183 : _M_head_impl(__h) { }
184
185 constexpr _Head_base(const _Head_base&) = default;
186 constexpr _Head_base(_Head_base&&) = default;
187
188 template<typename _UHead>
189 constexpr _Head_base(_UHead&& __h)
190 : _M_head_impl(std::forward<_UHead>(__h)) { }
191
192 _GLIBCXX20_CONSTEXPR
193 _Head_base(allocator_arg_t, __uses_alloc0)
194 : _M_head_impl() { }
195
196 template<typename _Alloc>
197 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
198 : _M_head_impl(allocator_arg, *__a._M_a) { }
199
200 template<typename _Alloc>
201 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
202 : _M_head_impl(*__a._M_a) { }
203
204 template<typename _UHead>
205 _GLIBCXX20_CONSTEXPR
206 _Head_base(__uses_alloc0, _UHead&& __uhead)
207 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
208
209 template<typename _Alloc, typename _UHead>
210 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
211 : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
212 { }
213
214 template<typename _Alloc, typename _UHead>
215 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
216 : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
217
218 static constexpr _Head&
219 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
220
221 static constexpr const _Head&
222 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
223
224 _Head _M_head_impl;
225 };
226
227 /**
228 * Contains the actual implementation of the @c tuple template, stored
229 * as a recursive inheritance hierarchy from the first element (most
230 * derived class) to the last (least derived class). The @c Idx
231 * parameter gives the 0-based index of the element stored at this
232 * point in the hierarchy; we use it to implement a constant-time
233 * get() operation.
234 */
235 template<size_t _Idx, typename... _Elements>
236 struct _Tuple_impl;
237
238 /**
239 * Recursive tuple implementation. Here we store the @c Head element
240 * and derive from a @c Tuple_impl containing the remaining elements
241 * (which contains the @c Tail).
242 */
243 template<size_t _Idx, typename _Head, typename... _Tail>
244 struct _Tuple_impl<_Idx, _Head, _Tail...>
245 : public _Tuple_impl<_Idx + 1, _Tail...>,
246 private _Head_base<_Idx, _Head>
247 {
248 template<size_t, typename...> friend struct _Tuple_impl;
249
250 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
251 typedef _Head_base<_Idx, _Head> _Base;
252
253 static constexpr _Head&
254 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
255
256 static constexpr const _Head&
257 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
258
259 static constexpr _Inherited&
260 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
261
262 static constexpr const _Inherited&
263 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
264
265 constexpr _Tuple_impl()
266 : _Inherited(), _Base() { }
267
268 explicit constexpr
269 _Tuple_impl(const _Head& __head, const _Tail&... __tail)
270 : _Inherited(__tail...), _Base(__head)
271 { }
272
273 template<typename _UHead, typename... _UTail,
274 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
275 explicit constexpr
276 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
277 : _Inherited(std::forward<_UTail>(__tail)...),
278 _Base(std::forward<_UHead>(__head))
279 { }
280
281 constexpr _Tuple_impl(const _Tuple_impl&) = default;
282
283 // _GLIBCXX_RESOLVE_LIB_DEFECTS
284 // 2729. Missing SFINAE on std::pair::operator=
285 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
286
287 constexpr
288 _Tuple_impl(_Tuple_impl&& __in)
289 noexcept(__and_<is_nothrow_move_constructible<_Head>,
290 is_nothrow_move_constructible<_Inherited>>::value)
291 : _Inherited(std::move(_M_tail(__in))),
292 _Base(std::forward<_Head>(_M_head(__in)))
293 { }
294
295 template<typename... _UElements>
296 constexpr
297 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
298 : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
299 _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
300 { }
301
302 template<typename _UHead, typename... _UTails>
303 constexpr
304 _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
305 : _Inherited(std::move
306 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
307 _Base(std::forward<_UHead>
308 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
309 { }
310
311 template<typename _Alloc>
312 _GLIBCXX20_CONSTEXPR
313 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
314 : _Inherited(__tag, __a),
315 _Base(__tag, __use_alloc<_Head>(__a))
316 { }
317
318 template<typename _Alloc>
319 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
320 const _Head& __head, const _Tail&... __tail)
321 : _Inherited(__tag, __a, __tail...),
322 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head)
323 { }
324
325 template<typename _Alloc, typename _UHead, typename... _UTail,
326 typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
327 _GLIBCXX20_CONSTEXPR
328 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
329 _UHead&& __head, _UTail&&... __tail)
330 : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
331 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
332 std::forward<_UHead>(__head))
333 { }
334
335 template<typename _Alloc>
336 _GLIBCXX20_CONSTEXPR
337 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
338 const _Tuple_impl& __in)
339 : _Inherited(__tag, __a, _M_tail(__in)),
340 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in))
341 { }
342
343 template<typename _Alloc>
344 _GLIBCXX20_CONSTEXPR
345 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
346 _Tuple_impl&& __in)
347 : _Inherited(__tag, __a, std::move(_M_tail(__in))),
348 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
349 std::forward<_Head>(_M_head(__in)))
350 { }
351
352 template<typename _Alloc, typename _UHead, typename... _UTails>
353 _GLIBCXX20_CONSTEXPR
354 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
355 const _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
356 : _Inherited(__tag, __a,
357 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
358 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
359 _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
360 { }
361
362 template<typename _Alloc, typename _UHead, typename... _UTails>
363 _GLIBCXX20_CONSTEXPR
364 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
365 _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
366 : _Inherited(__tag, __a, std::move
367 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
368 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
369 std::forward<_UHead>
370 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
371 { }
372
373 template<typename... _UElements>
374 _GLIBCXX20_CONSTEXPR
375 void
376 _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
377 {
378 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
379 _M_tail(*this)._M_assign(
380 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
381 }
382
383 template<typename _UHead, typename... _UTails>
384 _GLIBCXX20_CONSTEXPR
385 void
386 _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
387 {
388 _M_head(*this) = std::forward<_UHead>
389 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
390 _M_tail(*this)._M_assign(
391 std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)));
392 }
393
394 protected:
395 _GLIBCXX20_CONSTEXPR
396 void
397 _M_swap(_Tuple_impl& __in)
398 {
399 using std::swap;
400 swap(_M_head(*this), _M_head(__in));
401 _Inherited::_M_swap(_M_tail(__in));
402 }
403 };
404
405 // Basis case of inheritance recursion.
406 template<size_t _Idx, typename _Head>
407 struct _Tuple_impl<_Idx, _Head>
408 : private _Head_base<_Idx, _Head>
409 {
410 template<size_t, typename...> friend struct _Tuple_impl;
411
412 typedef _Head_base<_Idx, _Head> _Base;
413
414 static constexpr _Head&
415 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
416
417 static constexpr const _Head&
418 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
419
420 constexpr
421 _Tuple_impl()
422 : _Base() { }
423
424 explicit constexpr
425 _Tuple_impl(const _Head& __head)
426 : _Base(__head)
427 { }
428
429 template<typename _UHead>
430 explicit constexpr
431 _Tuple_impl(_UHead&& __head)
432 : _Base(std::forward<_UHead>(__head))
433 { }
434
435 constexpr _Tuple_impl(const _Tuple_impl&) = default;
436
437 // _GLIBCXX_RESOLVE_LIB_DEFECTS
438 // 2729. Missing SFINAE on std::pair::operator=
439 _Tuple_impl& operator=(const _Tuple_impl&) = delete;
440
441 constexpr
442 _Tuple_impl(_Tuple_impl&& __in)
443 noexcept(is_nothrow_move_constructible<_Head>::value)
444 : _Base(std::forward<_Head>(_M_head(__in)))
445 { }
446
447 template<typename _UHead>
448 constexpr
449 _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
450 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
451 { }
452
453 template<typename _UHead>
454 constexpr
455 _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
456 : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
457 { }
458
459 template<typename _Alloc>
460 _GLIBCXX20_CONSTEXPR
461 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
462 : _Base(__tag, __use_alloc<_Head>(__a))
463 { }
464
465 template<typename _Alloc>
466 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
467 const _Head& __head)
468 : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
469 { }
470
471 template<typename _Alloc, typename _UHead>
472 _GLIBCXX20_CONSTEXPR
473 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
474 _UHead&& __head)
475 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
476 std::forward<_UHead>(__head))
477 { }
478
479 template<typename _Alloc>
480 _GLIBCXX20_CONSTEXPR
481 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
482 const _Tuple_impl& __in)
483 : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), _M_head(__in))
484 { }
485
486 template<typename _Alloc>
487 _GLIBCXX20_CONSTEXPR
488 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
489 _Tuple_impl&& __in)
490 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
491 std::forward<_Head>(_M_head(__in)))
492 { }
493
494 template<typename _Alloc, typename _UHead>
495 _GLIBCXX20_CONSTEXPR
496 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
497 const _Tuple_impl<_Idx, _UHead>& __in)
498 : _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
499 _Tuple_impl<_Idx, _UHead>::_M_head(__in))
500 { }
501
502 template<typename _Alloc, typename _UHead>
503 _GLIBCXX20_CONSTEXPR
504 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
505 _Tuple_impl<_Idx, _UHead>&& __in)
506 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
507 std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
508 { }
509
510 template<typename _UHead>
511 _GLIBCXX20_CONSTEXPR
512 void
513 _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
514 {
515 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
516 }
517
518 template<typename _UHead>
519 _GLIBCXX20_CONSTEXPR
520 void
521 _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
522 {
523 _M_head(*this)
524 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
525 }
526
527 protected:
528 _GLIBCXX20_CONSTEXPR
529 void
530 _M_swap(_Tuple_impl& __in)
531 {
532 using std::swap;
533 swap(_M_head(*this), _M_head(__in));
534 }
535 };
536
537 // Concept utility functions, reused in conditionally-explicit
538 // constructors.
539 template<bool, typename... _Types>
540 struct _TupleConstraints
541 {
542 template<typename _Tp, typename _Up> // Workaround for PR 96592
543 using is_constructible
544 = __bool_constant<__is_constructible(_Tp, _Up)>;
545
546 // Constraint for a non-explicit constructor.
547 // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
548 // and every Ui is implicitly convertible to Ti.
549 template<typename... _UTypes>
550 static constexpr bool __is_implicitly_constructible()
551 {
552 return __and_<is_constructible<_Types, _UTypes>...,
553 is_convertible<_UTypes, _Types>...
554 >::value;
555 }
556
557 // Constraint for a non-explicit constructor.
558 // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
559 // but not every Ui is implicitly convertible to Ti.
560 template<typename... _UTypes>
561 static constexpr bool __is_explicitly_constructible()
562 {
563 return __and_<is_constructible<_Types, _UTypes>...,
564 __not_<__and_<is_convertible<_UTypes, _Types>...>>
565 >::value;
566 }
567
568 static constexpr bool __is_implicitly_default_constructible()
569 {
570 return __and_<std::__is_implicitly_default_constructible<_Types>...
571 >::value;
572 }
573
574 static constexpr bool __is_explicitly_default_constructible()
575 {
576 return __and_<is_default_constructible<_Types>...,
577 __not_<__and_<
578 std::__is_implicitly_default_constructible<_Types>...>
579 >>::value;
580 }
581 };
582
583 // Partial specialization used when a required precondition isn't met,
584 // e.g. when sizeof...(_Types) != sizeof...(_UTypes).
585 template<typename... _Types>
586 struct _TupleConstraints<false, _Types...>
587 {
588 template<typename... _UTypes>
589 static constexpr bool __is_implicitly_constructible()
590 { return false; }
591
592 template<typename... _UTypes>
593 static constexpr bool __is_explicitly_constructible()
594 { return false; }
595 };
596
597 /// Primary class template, tuple
598 template<typename... _Elements>
599 class tuple : public _Tuple_impl<0, _Elements...>
600 {
601 typedef _Tuple_impl<0, _Elements...> _Inherited;
602
603 template<bool _Cond>
604 using _TCC = _TupleConstraints<_Cond, _Elements...>;
605
606 // Constraint for non-explicit default constructor
607 template<bool _Dummy>
608 using _ImplicitDefaultCtor = __enable_if_t<
609 _TCC<_Dummy>::__is_implicitly_default_constructible(),
610 bool>;
611
612 // Constraint for explicit default constructor
613 template<bool _Dummy>
614 using _ExplicitDefaultCtor = __enable_if_t<
615 _TCC<_Dummy>::__is_explicitly_default_constructible(),
616 bool>;
617
618 // Constraint for non-explicit constructors
619 template<bool _Cond, typename... _Args>
620 using _ImplicitCtor = __enable_if_t<
621 _TCC<_Cond>::template __is_implicitly_constructible<_Args...>(),
622 bool>;
623
624 // Constraint for non-explicit constructors
625 template<bool _Cond, typename... _Args>
626 using _ExplicitCtor = __enable_if_t<
627 _TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
628 bool>;
629
630 template<typename... _UElements>
631 static constexpr
632 __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
633 __assignable()
634 { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
635
636 // Condition for noexcept-specifier of an assignment operator.
637 template<typename... _UElements>
638 static constexpr bool __nothrow_assignable()
639 {
640 return
641 __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
642 }
643
644 // Condition for noexcept-specifier of a constructor.
645 template<typename... _UElements>
646 static constexpr bool __nothrow_constructible()
647 {
648 return
649 __and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
650 }
651
652 // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
653 template<typename _Up>
654 static constexpr bool __valid_args()
655 {
656 return sizeof...(_Elements) == 1
657 && !is_same<tuple, __remove_cvref_t<_Up>>::value;
658 }
659
660 // Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) > 1.
661 template<typename, typename, typename... _Tail>
662 static constexpr bool __valid_args()
663 { return (sizeof...(_Tail) + 2) == sizeof...(_Elements); }
664
665 /* Constraint for constructors with a tuple<UTypes...> parameter ensures
666 * that the constructor is only viable when it would not interfere with
667 * tuple(UTypes&&...) or tuple(const tuple&) or tuple(tuple&&).
668 * Such constructors are only viable if:
669 * either sizeof...(Types) != 1,
670 * or (when Types... expands to T and UTypes... expands to U)
671 * is_convertible_v<TUPLE, T>, is_constructible_v<T, TUPLE>,
672 * and is_same_v<T, U> are all false.
673 */
674 template<typename _Tuple, typename = tuple,
675 typename = __remove_cvref_t<_Tuple>>
676 struct _UseOtherCtor
677 : false_type
678 { };
679 // If TUPLE is convertible to the single element in *this,
680 // then TUPLE should match tuple(UTypes&&...) instead.
681 template<typename _Tuple, typename _Tp, typename _Up>
682 struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Up>>
683 : __or_<is_convertible<_Tuple, _Tp>, is_constructible<_Tp, _Tuple>>
684 { };
685 // If TUPLE and *this each have a single element of the same type,
686 // then TUPLE should match a copy/move constructor instead.
687 template<typename _Tuple, typename _Tp>
688 struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Tp>>
689 : true_type
690 { };
691
692 // Return true iff sizeof...(Types) == 1 && tuple_size_v<TUPLE> == 1
693 // and the single element in Types can be initialized from TUPLE,
694 // or is the same type as tuple_element_t<0, TUPLE>.
695 template<typename _Tuple>
696 static constexpr bool __use_other_ctor()
697 { return _UseOtherCtor<_Tuple>::value; }
698
699 public:
700 template<typename _Dummy = void,
701 _ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
702 constexpr
703 tuple()
704 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
705 : _Inherited() { }
706
707 template<typename _Dummy = void,
708 _ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
709 explicit constexpr
710 tuple()
711 noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
712 : _Inherited() { }
713
714 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
715 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
716 constexpr
717 tuple(const _Elements&... __elements)
718 noexcept(__nothrow_constructible<const _Elements&...>())
719 : _Inherited(__elements...) { }
720
721 template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
722 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
723 explicit constexpr
724 tuple(const _Elements&... __elements)
725 noexcept(__nothrow_constructible<const _Elements&...>())
726 : _Inherited(__elements...) { }
727
728 template<typename... _UElements,
729 bool _Valid = __valid_args<_UElements...>(),
730 _ImplicitCtor<_Valid, _UElements...> = true>
731 constexpr
732 tuple(_UElements&&... __elements)
733 noexcept(__nothrow_constructible<_UElements...>())
734 : _Inherited(std::forward<_UElements>(__elements)...) { }
735
736 template<typename... _UElements,
737 bool _Valid = __valid_args<_UElements...>(),
738 _ExplicitCtor<_Valid, _UElements...> = false>
739 explicit constexpr
740 tuple(_UElements&&... __elements)
741 noexcept(__nothrow_constructible<_UElements...>())
742 : _Inherited(std::forward<_UElements>(__elements)...) { }
743
744 constexpr tuple(const tuple&) = default;
745
746 constexpr tuple(tuple&&) = default;
747
748 template<typename... _UElements,
749 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
750 && !__use_other_ctor<const tuple<_UElements...>&>(),
751 _ImplicitCtor<_Valid, const _UElements&...> = true>
752 constexpr
753 tuple(const tuple<_UElements...>& __in)
754 noexcept(__nothrow_constructible<const _UElements&...>())
755 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
756 { }
757
758 template<typename... _UElements,
759 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
760 && !__use_other_ctor<const tuple<_UElements...>&>(),
761 _ExplicitCtor<_Valid, const _UElements&...> = false>
762 explicit constexpr
763 tuple(const tuple<_UElements...>& __in)
764 noexcept(__nothrow_constructible<const _UElements&...>())
765 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
766 { }
767
768 template<typename... _UElements,
769 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
770 && !__use_other_ctor<tuple<_UElements...>&&>(),
771 _ImplicitCtor<_Valid, _UElements...> = true>
772 constexpr
773 tuple(tuple<_UElements...>&& __in)
774 noexcept(__nothrow_constructible<_UElements...>())
775 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
776
777 template<typename... _UElements,
778 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
779 && !__use_other_ctor<tuple<_UElements...>&&>(),
780 _ExplicitCtor<_Valid, _UElements...> = false>
781 explicit constexpr
782 tuple(tuple<_UElements...>&& __in)
783 noexcept(__nothrow_constructible<_UElements...>())
784 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
785
786 // Allocator-extended constructors.
787
788 template<typename _Alloc,
789 _ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
790 _GLIBCXX20_CONSTEXPR
791 tuple(allocator_arg_t __tag, const _Alloc& __a)
792 : _Inherited(__tag, __a) { }
793
794 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
795 _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
796 _GLIBCXX20_CONSTEXPR
797 tuple(allocator_arg_t __tag, const _Alloc& __a,
798 const _Elements&... __elements)
799 : _Inherited(__tag, __a, __elements...) { }
800
801 template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
802 _ExplicitCtor<_NotEmpty, const _Elements&...> = false>
803 _GLIBCXX20_CONSTEXPR
804 explicit
805 tuple(allocator_arg_t __tag, const _Alloc& __a,
806 const _Elements&... __elements)
807 : _Inherited(__tag, __a, __elements...) { }
808
809 template<typename _Alloc, typename... _UElements,
810 bool _Valid = __valid_args<_UElements...>(),
811 _ImplicitCtor<_Valid, _UElements...> = true>
812 _GLIBCXX20_CONSTEXPR
813 tuple(allocator_arg_t __tag, const _Alloc& __a,
814 _UElements&&... __elements)
815 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
816 { }
817
818 template<typename _Alloc, typename... _UElements,
819 bool _Valid = __valid_args<_UElements...>(),
820 _ExplicitCtor<_Valid, _UElements...> = false>
821 _GLIBCXX20_CONSTEXPR
822 explicit
823 tuple(allocator_arg_t __tag, const _Alloc& __a,
824 _UElements&&... __elements)
825 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
826 { }
827
828 template<typename _Alloc>
829 _GLIBCXX20_CONSTEXPR
830 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
831 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
832
833 template<typename _Alloc>
834 _GLIBCXX20_CONSTEXPR
835 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
836 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
837
838 template<typename _Alloc, typename... _UElements,
839 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
840 && !__use_other_ctor<const tuple<_UElements...>&>(),
841 _ImplicitCtor<_Valid, const _UElements&...> = true>
842 _GLIBCXX20_CONSTEXPR
843 tuple(allocator_arg_t __tag, const _Alloc& __a,
844 const tuple<_UElements...>& __in)
845 : _Inherited(__tag, __a,
846 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
847 { }
848
849 template<typename _Alloc, typename... _UElements,
850 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
851 && !__use_other_ctor<const tuple<_UElements...>&>(),
852 _ExplicitCtor<_Valid, const _UElements&...> = false>
853 _GLIBCXX20_CONSTEXPR
854 explicit
855 tuple(allocator_arg_t __tag, const _Alloc& __a,
856 const tuple<_UElements...>& __in)
857 : _Inherited(__tag, __a,
858 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
859 { }
860
861 template<typename _Alloc, typename... _UElements,
862 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
863 && !__use_other_ctor<tuple<_UElements...>&&>(),
864 _ImplicitCtor<_Valid, _UElements...> = true>
865 _GLIBCXX20_CONSTEXPR
866 tuple(allocator_arg_t __tag, const _Alloc& __a,
867 tuple<_UElements...>&& __in)
868 : _Inherited(__tag, __a,
869 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
870 { }
871
872 template<typename _Alloc, typename... _UElements,
873 bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
874 && !__use_other_ctor<tuple<_UElements...>&&>(),
875 _ExplicitCtor<_Valid, _UElements...> = false>
876 _GLIBCXX20_CONSTEXPR
877 explicit
878 tuple(allocator_arg_t __tag, const _Alloc& __a,
879 tuple<_UElements...>&& __in)
880 : _Inherited(__tag, __a,
881 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
882 { }
883
884 // tuple assignment
885
886 _GLIBCXX20_CONSTEXPR
887 tuple&
888 operator=(typename conditional<__assignable<const _Elements&...>(),
889 const tuple&,
890 const __nonesuch&>::type __in)
891 noexcept(__nothrow_assignable<const _Elements&...>())
892 {
893 this->_M_assign(__in);
894 return *this;
895 }
896
897 _GLIBCXX20_CONSTEXPR
898 tuple&
899 operator=(typename conditional<__assignable<_Elements...>(),
900 tuple&&,
901 __nonesuch&&>::type __in)
902 noexcept(__nothrow_assignable<_Elements...>())
903 {
904 this->_M_assign(std::move(__in));
905 return *this;
906 }
907
908 template<typename... _UElements>
909 _GLIBCXX20_CONSTEXPR
910 __enable_if_t<__assignable<const _UElements&...>(), tuple&>
911 operator=(const tuple<_UElements...>& __in)
912 noexcept(__nothrow_assignable<const _UElements&...>())
913 {
914 this->_M_assign(__in);
915 return *this;
916 }
917
918 template<typename... _UElements>
919 _GLIBCXX20_CONSTEXPR
920 __enable_if_t<__assignable<_UElements...>(), tuple&>
921 operator=(tuple<_UElements...>&& __in)
922 noexcept(__nothrow_assignable<_UElements...>())
923 {
924 this->_M_assign(std::move(__in));
925 return *this;
926 }
927
928 // tuple swap
929 _GLIBCXX20_CONSTEXPR
930 void
931 swap(tuple& __in)
932 noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value)
933 { _Inherited::_M_swap(__in); }
934 };
935
936 #if __cpp_deduction_guides >= 201606
937 template<typename... _UTypes>
938 tuple(_UTypes...) -> tuple<_UTypes...>;
939 template<typename _T1, typename _T2>
940 tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
941 template<typename _Alloc, typename... _UTypes>
942 tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
943 template<typename _Alloc, typename _T1, typename _T2>
944 tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
945 template<typename _Alloc, typename... _UTypes>
946 tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
947 #endif
948
949 // Explicit specialization, zero-element tuple.
950 template<>
951 class tuple<>
952 {
953 public:
954 void swap(tuple&) noexcept { /* no-op */ }
955 // We need the default since we're going to define no-op
956 // allocator constructors.
957 tuple() = default;
958 // No-op allocator constructors.
959 template<typename _Alloc>
960 _GLIBCXX20_CONSTEXPR
961 tuple(allocator_arg_t, const _Alloc&) noexcept { }
962 template<typename _Alloc>
963 _GLIBCXX20_CONSTEXPR
964 tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept { }
965 };
966
967 /// Partial specialization, 2-element tuple.
968 /// Includes construction and assignment from a pair.
969 template<typename _T1, typename _T2>
970 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
971 {
972 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
973
974 // Constraint for non-explicit default constructor
975 template<bool _Dummy, typename _U1, typename _U2>
976 using _ImplicitDefaultCtor = __enable_if_t<
977 _TupleConstraints<_Dummy, _U1, _U2>::
978 __is_implicitly_default_constructible(),
979 bool>;
980
981 // Constraint for explicit default constructor
982 template<bool _Dummy, typename _U1, typename _U2>
983 using _ExplicitDefaultCtor = __enable_if_t<
984 _TupleConstraints<_Dummy, _U1, _U2>::
985 __is_explicitly_default_constructible(),
986 bool>;
987
988 template<bool _Dummy>
989 using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
990
991 // Constraint for non-explicit constructors
992 template<bool _Cond, typename _U1, typename _U2>
993 using _ImplicitCtor = __enable_if_t<
994 _TCC<_Cond>::template __is_implicitly_constructible<_U1, _U2>(),
995 bool>;
996
997 // Constraint for non-explicit constructors
998 template<bool _Cond, typename _U1, typename _U2>
999 using _ExplicitCtor = __enable_if_t<
1000 _TCC<_Cond>::template __is_explicitly_constructible<_U1, _U2>(),
1001 bool>;
1002
1003 template<typename _U1, typename _U2>
1004 static constexpr bool __assignable()
1005 {
1006 return __and_<is_assignable<_T1&, _U1>,
1007 is_assignable<_T2&, _U2>>::value;
1008 }
1009
1010 template<typename _U1, typename _U2>
1011 static constexpr bool __nothrow_assignable()
1012 {
1013 return __and_<is_nothrow_assignable<_T1&, _U1>,
1014 is_nothrow_assignable<_T2&, _U2>>::value;
1015 }
1016
1017 template<typename _U1, typename _U2>
1018 static constexpr bool __nothrow_constructible()
1019 {
1020 return __and_<is_nothrow_constructible<_T1, _U1>,
1021 is_nothrow_constructible<_T2, _U2>>::value;
1022 }
1023
1024 static constexpr bool __nothrow_default_constructible()
1025 {
1026 return __and_<is_nothrow_default_constructible<_T1>,
1027 is_nothrow_default_constructible<_T2>>::value;
1028 }
1029
1030 template<typename _U1>
1031 static constexpr bool __is_alloc_arg()
1032 { return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; }
1033
1034 public:
1035 template<bool _Dummy = true,
1036 _ImplicitDefaultCtor<_Dummy, _T1, _T2> = true>
1037 constexpr
1038 tuple()
1039 noexcept(__nothrow_default_constructible())
1040 : _Inherited() { }
1041
1042 template<bool _Dummy = true,
1043 _ExplicitDefaultCtor<_Dummy, _T1, _T2> = false>
1044 explicit constexpr
1045 tuple()
1046 noexcept(__nothrow_default_constructible())
1047 : _Inherited() { }
1048
1049 template<bool _Dummy = true,
1050 _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
1051 constexpr
1052 tuple(const _T1& __a1, const _T2& __a2)
1053 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1054 : _Inherited(__a1, __a2) { }
1055
1056 template<bool _Dummy = true,
1057 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1058 explicit constexpr
1059 tuple(const _T1& __a1, const _T2& __a2)
1060 noexcept(__nothrow_constructible<const _T1&, const _T2&>())
1061 : _Inherited(__a1, __a2) { }
1062
1063 template<typename _U1, typename _U2,
1064 _ImplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = true>
1065 constexpr
1066 tuple(_U1&& __a1, _U2&& __a2)
1067 noexcept(__nothrow_constructible<_U1, _U2>())
1068 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1069
1070 template<typename _U1, typename _U2,
1071 _ExplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = false>
1072 explicit constexpr
1073 tuple(_U1&& __a1, _U2&& __a2)
1074 noexcept(__nothrow_constructible<_U1, _U2>())
1075 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
1076
1077 constexpr tuple(const tuple&) = default;
1078
1079 constexpr tuple(tuple&&) = default;
1080
1081 template<typename _U1, typename _U2,
1082 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1083 constexpr
1084 tuple(const tuple<_U1, _U2>& __in)
1085 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1086 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
1087
1088 template<typename _U1, typename _U2,
1089 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1090 explicit constexpr
1091 tuple(const tuple<_U1, _U2>& __in)
1092 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1093 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
1094
1095 template<typename _U1, typename _U2,
1096 _ImplicitCtor<true, _U1, _U2> = true>
1097 constexpr
1098 tuple(tuple<_U1, _U2>&& __in)
1099 noexcept(__nothrow_constructible<_U1, _U2>())
1100 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1101
1102 template<typename _U1, typename _U2,
1103 _ExplicitCtor<true, _U1, _U2> = false>
1104 explicit constexpr
1105 tuple(tuple<_U1, _U2>&& __in)
1106 noexcept(__nothrow_constructible<_U1, _U2>())
1107 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1108
1109 template<typename _U1, typename _U2,
1110 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1111 constexpr
1112 tuple(const pair<_U1, _U2>& __in)
1113 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1114 : _Inherited(__in.first, __in.second) { }
1115
1116 template<typename _U1, typename _U2,
1117 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1118 explicit constexpr
1119 tuple(const pair<_U1, _U2>& __in)
1120 noexcept(__nothrow_constructible<const _U1&, const _U2&>())
1121 : _Inherited(__in.first, __in.second) { }
1122
1123 template<typename _U1, typename _U2,
1124 _ImplicitCtor<true, _U1, _U2> = true>
1125 constexpr
1126 tuple(pair<_U1, _U2>&& __in)
1127 noexcept(__nothrow_constructible<_U1, _U2>())
1128 : _Inherited(std::forward<_U1>(__in.first),
1129 std::forward<_U2>(__in.second)) { }
1130
1131 template<typename _U1, typename _U2,
1132 _ExplicitCtor<true, _U1, _U2> = false>
1133 explicit constexpr
1134 tuple(pair<_U1, _U2>&& __in)
1135 noexcept(__nothrow_constructible<_U1, _U2>())
1136 : _Inherited(std::forward<_U1>(__in.first),
1137 std::forward<_U2>(__in.second)) { }
1138
1139 // Allocator-extended constructors.
1140
1141 template<typename _Alloc,
1142 _ImplicitDefaultCtor<is_object<_Alloc>::value, _T1, _T2> = true>
1143 _GLIBCXX20_CONSTEXPR
1144 tuple(allocator_arg_t __tag, const _Alloc& __a)
1145 : _Inherited(__tag, __a) { }
1146
1147 template<typename _Alloc, bool _Dummy = true,
1148 _ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
1149 _GLIBCXX20_CONSTEXPR
1150 tuple(allocator_arg_t __tag, const _Alloc& __a,
1151 const _T1& __a1, const _T2& __a2)
1152 : _Inherited(__tag, __a, __a1, __a2) { }
1153
1154 template<typename _Alloc, bool _Dummy = true,
1155 _ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
1156 explicit
1157 _GLIBCXX20_CONSTEXPR
1158 tuple(allocator_arg_t __tag, const _Alloc& __a,
1159 const _T1& __a1, const _T2& __a2)
1160 : _Inherited(__tag, __a, __a1, __a2) { }
1161
1162 template<typename _Alloc, typename _U1, typename _U2,
1163 _ImplicitCtor<true, _U1, _U2> = true>
1164 _GLIBCXX20_CONSTEXPR
1165 tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1166 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1167 std::forward<_U2>(__a2)) { }
1168
1169 template<typename _Alloc, typename _U1, typename _U2,
1170 _ExplicitCtor<true, _U1, _U2> = false>
1171 explicit
1172 _GLIBCXX20_CONSTEXPR
1173 tuple(allocator_arg_t __tag, const _Alloc& __a,
1174 _U1&& __a1, _U2&& __a2)
1175 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1176 std::forward<_U2>(__a2)) { }
1177
1178 template<typename _Alloc>
1179 _GLIBCXX20_CONSTEXPR
1180 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1181 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1182
1183 template<typename _Alloc>
1184 _GLIBCXX20_CONSTEXPR
1185 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1186 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1187
1188 template<typename _Alloc, typename _U1, typename _U2,
1189 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1190 _GLIBCXX20_CONSTEXPR
1191 tuple(allocator_arg_t __tag, const _Alloc& __a,
1192 const tuple<_U1, _U2>& __in)
1193 : _Inherited(__tag, __a,
1194 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1195 { }
1196
1197 template<typename _Alloc, typename _U1, typename _U2,
1198 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1199 explicit
1200 _GLIBCXX20_CONSTEXPR
1201 tuple(allocator_arg_t __tag, const _Alloc& __a,
1202 const tuple<_U1, _U2>& __in)
1203 : _Inherited(__tag, __a,
1204 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1205 { }
1206
1207 template<typename _Alloc, typename _U1, typename _U2,
1208 _ImplicitCtor<true, _U1, _U2> = true>
1209 _GLIBCXX20_CONSTEXPR
1210 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1211 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1212 { }
1213
1214 template<typename _Alloc, typename _U1, typename _U2,
1215 _ExplicitCtor<true, _U1, _U2> = false>
1216 explicit
1217 _GLIBCXX20_CONSTEXPR
1218 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1219 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1220 { }
1221
1222 template<typename _Alloc, typename _U1, typename _U2,
1223 _ImplicitCtor<true, const _U1&, const _U2&> = true>
1224 _GLIBCXX20_CONSTEXPR
1225 tuple(allocator_arg_t __tag, const _Alloc& __a,
1226 const pair<_U1, _U2>& __in)
1227 : _Inherited(__tag, __a, __in.first, __in.second) { }
1228
1229 template<typename _Alloc, typename _U1, typename _U2,
1230 _ExplicitCtor<true, const _U1&, const _U2&> = false>
1231 explicit
1232 _GLIBCXX20_CONSTEXPR
1233 tuple(allocator_arg_t __tag, const _Alloc& __a,
1234 const pair<_U1, _U2>& __in)
1235 : _Inherited(__tag, __a, __in.first, __in.second) { }
1236
1237 template<typename _Alloc, typename _U1, typename _U2,
1238 _ImplicitCtor<true, _U1, _U2> = true>
1239 _GLIBCXX20_CONSTEXPR
1240 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1241 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1242 std::forward<_U2>(__in.second)) { }
1243
1244 template<typename _Alloc, typename _U1, typename _U2,
1245 _ExplicitCtor<true, _U1, _U2> = false>
1246 explicit
1247 _GLIBCXX20_CONSTEXPR
1248 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1249 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1250 std::forward<_U2>(__in.second)) { }
1251
1252 // Tuple assignment.
1253
1254 _GLIBCXX20_CONSTEXPR
1255 tuple&
1256 operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
1257 const tuple&,
1258 const __nonesuch&>::type __in)
1259 noexcept(__nothrow_assignable<const _T1&, const _T2&>())
1260 {
1261 this->_M_assign(__in);
1262 return *this;
1263 }
1264
1265 _GLIBCXX20_CONSTEXPR
1266 tuple&
1267 operator=(typename conditional<__assignable<_T1, _T2>(),
1268 tuple&&,
1269 __nonesuch&&>::type __in)
1270 noexcept(__nothrow_assignable<_T1, _T2>())
1271 {
1272 this->_M_assign(std::move(__in));
1273 return *this;
1274 }
1275
1276 template<typename _U1, typename _U2>
1277 _GLIBCXX20_CONSTEXPR
1278 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1279 operator=(const tuple<_U1, _U2>& __in)
1280 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1281 {
1282 this->_M_assign(__in);
1283 return *this;
1284 }
1285
1286 template<typename _U1, typename _U2>
1287 _GLIBCXX20_CONSTEXPR
1288 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1289 operator=(tuple<_U1, _U2>&& __in)
1290 noexcept(__nothrow_assignable<_U1, _U2>())
1291 {
1292 this->_M_assign(std::move(__in));
1293 return *this;
1294 }
1295
1296 template<typename _U1, typename _U2>
1297 _GLIBCXX20_CONSTEXPR
1298 __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&>
1299 operator=(const pair<_U1, _U2>& __in)
1300 noexcept(__nothrow_assignable<const _U1&, const _U2&>())
1301 {
1302 this->_M_head(*this) = __in.first;
1303 this->_M_tail(*this)._M_head(*this) = __in.second;
1304 return *this;
1305 }
1306
1307 template<typename _U1, typename _U2>
1308 _GLIBCXX20_CONSTEXPR
1309 __enable_if_t<__assignable<_U1, _U2>(), tuple&>
1310 operator=(pair<_U1, _U2>&& __in)
1311 noexcept(__nothrow_assignable<_U1, _U2>())
1312 {
1313 this->_M_head(*this) = std::forward<_U1>(__in.first);
1314 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1315 return *this;
1316 }
1317
1318 _GLIBCXX20_CONSTEXPR
1319 void
1320 swap(tuple& __in)
1321 noexcept(__and_<__is_nothrow_swappable<_T1>,
1322 __is_nothrow_swappable<_T2>>::value)
1323 { _Inherited::_M_swap(__in); }
1324 };
1325
1326
1327 /// class tuple_size
1328 template<typename... _Elements>
1329 struct tuple_size<tuple<_Elements...>>
1330 : public integral_constant<size_t, sizeof...(_Elements)> { };
1331
1332 #if __cplusplus > 201402L
1333 template <typename _Tp>
1334 inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1335 #endif
1336
1337 /**
1338 * Recursive case for tuple_element: strip off the first element in
1339 * the tuple and retrieve the (i-1)th element of the remaining tuple.
1340 */
1341 template<size_t __i, typename _Head, typename... _Tail>
1342 struct tuple_element<__i, tuple<_Head, _Tail...> >
1343 : tuple_element<__i - 1, tuple<_Tail...> > { };
1344
1345 /**
1346 * Basis case for tuple_element: The first element is the one we're seeking.
1347 */
1348 template<typename _Head, typename... _Tail>
1349 struct tuple_element<0, tuple<_Head, _Tail...> >
1350 {
1351 typedef _Head type;
1352 };
1353
1354 /**
1355 * Error case for tuple_element: invalid index.
1356 */
1357 template<size_t __i>
1358 struct tuple_element<__i, tuple<>>
1359 {
1360 static_assert(__i < tuple_size<tuple<>>::value,
1361 "tuple index is in range");
1362 };
1363
1364 template<size_t __i, typename _Head, typename... _Tail>
1365 constexpr _Head&
1366 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1367 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1368
1369 template<size_t __i, typename _Head, typename... _Tail>
1370 constexpr const _Head&
1371 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1372 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1373
1374 /// Return a reference to the ith element of a tuple.
1375 template<size_t __i, typename... _Elements>
1376 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1377 get(tuple<_Elements...>& __t) noexcept
1378 { return std::__get_helper<__i>(__t); }
1379
1380 /// Return a const reference to the ith element of a const tuple.
1381 template<size_t __i, typename... _Elements>
1382 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
1383 get(const tuple<_Elements...>& __t) noexcept
1384 { return std::__get_helper<__i>(__t); }
1385
1386 /// Return an rvalue reference to the ith element of a tuple rvalue.
1387 template<size_t __i, typename... _Elements>
1388 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1389 get(tuple<_Elements...>&& __t) noexcept
1390 {
1391 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1392 return std::forward<__element_type&&>(std::get<__i>(__t));
1393 }
1394
1395 /// Return a const rvalue reference to the ith element of a const tuple rvalue.
1396 template<size_t __i, typename... _Elements>
1397 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
1398 get(const tuple<_Elements...>&& __t) noexcept
1399 {
1400 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1401 return std::forward<const __element_type&&>(std::get<__i>(__t));
1402 }
1403
1404 #if __cplusplus >= 201402L
1405
1406 #define __cpp_lib_tuples_by_type 201304
1407
1408 template<typename _Head, size_t __i, typename... _Tail>
1409 constexpr _Head&
1410 __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1411 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1412
1413 template<typename _Head, size_t __i, typename... _Tail>
1414 constexpr const _Head&
1415 __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1416 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1417
1418 /// Return a reference to the unique element of type _Tp of a tuple.
1419 template <typename _Tp, typename... _Types>
1420 constexpr _Tp&
1421 get(tuple<_Types...>& __t) noexcept
1422 { return std::__get_helper2<_Tp>(__t); }
1423
1424 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1425 template <typename _Tp, typename... _Types>
1426 constexpr _Tp&&
1427 get(tuple<_Types...>&& __t) noexcept
1428 { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
1429
1430 /// Return a const reference to the unique element of type _Tp of a tuple.
1431 template <typename _Tp, typename... _Types>
1432 constexpr const _Tp&
1433 get(const tuple<_Types...>& __t) noexcept
1434 { return std::__get_helper2<_Tp>(__t); }
1435
1436 /// Return a const reference to the unique element of type _Tp of
1437 /// a const tuple rvalue.
1438 template <typename _Tp, typename... _Types>
1439 constexpr const _Tp&&
1440 get(const tuple<_Types...>&& __t) noexcept
1441 { return std::forward<const _Tp&&>(std::__get_helper2<_Tp>(__t)); }
1442 #endif
1443
1444 // This class performs the comparison operations on tuples
1445 template<typename _Tp, typename _Up, size_t __i, size_t __size>
1446 struct __tuple_compare
1447 {
1448 static constexpr bool
1449 __eq(const _Tp& __t, const _Up& __u)
1450 {
1451 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1452 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1453 }
1454
1455 static constexpr bool
1456 __less(const _Tp& __t, const _Up& __u)
1457 {
1458 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1459 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1460 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1461 }
1462 };
1463
1464 template<typename _Tp, typename _Up, size_t __size>
1465 struct __tuple_compare<_Tp, _Up, __size, __size>
1466 {
1467 static constexpr bool
1468 __eq(const _Tp&, const _Up&) { return true; }
1469
1470 static constexpr bool
1471 __less(const _Tp&, const _Up&) { return false; }
1472 };
1473
1474 template<typename... _TElements, typename... _UElements>
1475 constexpr bool
1476 operator==(const tuple<_TElements...>& __t,
1477 const tuple<_UElements...>& __u)
1478 {
1479 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1480 "tuple objects can only be compared if they have equal sizes.");
1481 using __compare = __tuple_compare<tuple<_TElements...>,
1482 tuple<_UElements...>,
1483 0, sizeof...(_TElements)>;
1484 return __compare::__eq(__t, __u);
1485 }
1486
1487 #if __cpp_lib_three_way_comparison
1488 template<typename _Cat, typename _Tp, typename _Up>
1489 constexpr _Cat
1490 __tuple_cmp(const _Tp&, const _Up&, index_sequence<>)
1491 { return _Cat::equivalent; }
1492
1493 template<typename _Cat, typename _Tp, typename _Up,
1494 size_t _Idx0, size_t... _Idxs>
1495 constexpr _Cat
1496 __tuple_cmp(const _Tp& __t, const _Up& __u,
1497 index_sequence<_Idx0, _Idxs...>)
1498 {
1499 auto __c
1500 = __detail::__synth3way(std::get<_Idx0>(__t), std::get<_Idx0>(__u));
1501 if (__c != 0)
1502 return __c;
1503 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence<_Idxs...>());
1504 }
1505
1506 template<typename... _Tps, typename... _Ups>
1507 constexpr
1508 common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>
1509 operator<=>(const tuple<_Tps...>& __t, const tuple<_Ups...>& __u)
1510 {
1511 using _Cat
1512 = common_comparison_category_t<__detail::__synth3way_t<_Tps, _Ups>...>;
1513 return std::__tuple_cmp<_Cat>(__t, __u, index_sequence_for<_Tps...>());
1514 }
1515 #else
1516 template<typename... _TElements, typename... _UElements>
1517 constexpr bool
1518 operator<(const tuple<_TElements...>& __t,
1519 const tuple<_UElements...>& __u)
1520 {
1521 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1522 "tuple objects can only be compared if they have equal sizes.");
1523 using __compare = __tuple_compare<tuple<_TElements...>,
1524 tuple<_UElements...>,
1525 0, sizeof...(_TElements)>;
1526 return __compare::__less(__t, __u);
1527 }
1528
1529 template<typename... _TElements, typename... _UElements>
1530 constexpr bool
1531 operator!=(const tuple<_TElements...>& __t,
1532 const tuple<_UElements...>& __u)
1533 { return !(__t == __u); }
1534
1535 template<typename... _TElements, typename... _UElements>
1536 constexpr bool
1537 operator>(const tuple<_TElements...>& __t,
1538 const tuple<_UElements...>& __u)
1539 { return __u < __t; }
1540
1541 template<typename... _TElements, typename... _UElements>
1542 constexpr bool
1543 operator<=(const tuple<_TElements...>& __t,
1544 const tuple<_UElements...>& __u)
1545 { return !(__u < __t); }
1546
1547 template<typename... _TElements, typename... _UElements>
1548 constexpr bool
1549 operator>=(const tuple<_TElements...>& __t,
1550 const tuple<_UElements...>& __u)
1551 { return !(__t < __u); }
1552 #endif // three_way_comparison
1553
1554 // NB: DR 705.
1555 template<typename... _Elements>
1556 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1557 make_tuple(_Elements&&... __args)
1558 {
1559 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1560 __result_type;
1561 return __result_type(std::forward<_Elements>(__args)...);
1562 }
1563
1564 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1565 // 2275. Why is forward_as_tuple not constexpr?
1566 /// std::forward_as_tuple
1567 template<typename... _Elements>
1568 constexpr tuple<_Elements&&...>
1569 forward_as_tuple(_Elements&&... __args) noexcept
1570 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
1571
1572 template<size_t, typename, typename, size_t>
1573 struct __make_tuple_impl;
1574
1575 template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
1576 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
1577 : __make_tuple_impl<_Idx + 1,
1578 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
1579 _Tuple, _Nm>
1580 { };
1581
1582 template<size_t _Nm, typename _Tuple, typename... _Tp>
1583 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
1584 {
1585 typedef tuple<_Tp...> __type;
1586 };
1587
1588 template<typename _Tuple>
1589 struct __do_make_tuple
1590 : __make_tuple_impl<0, tuple<>, _Tuple, tuple_size<_Tuple>::value>
1591 { };
1592
1593 // Returns the std::tuple equivalent of a tuple-like type.
1594 template<typename _Tuple>
1595 struct __make_tuple
1596 : public __do_make_tuple<__remove_cvref_t<_Tuple>>
1597 { };
1598
1599 // Combines several std::tuple's into a single one.
1600 template<typename...>
1601 struct __combine_tuples;
1602
1603 template<>
1604 struct __combine_tuples<>
1605 {
1606 typedef tuple<> __type;
1607 };
1608
1609 template<typename... _Ts>
1610 struct __combine_tuples<tuple<_Ts...>>
1611 {
1612 typedef tuple<_Ts...> __type;
1613 };
1614
1615 template<typename... _T1s, typename... _T2s, typename... _Rem>
1616 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
1617 {
1618 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
1619 _Rem...>::__type __type;
1620 };
1621
1622 // Computes the result type of tuple_cat given a set of tuple-like types.
1623 template<typename... _Tpls>
1624 struct __tuple_cat_result
1625 {
1626 typedef typename __combine_tuples
1627 <typename __make_tuple<_Tpls>::__type...>::__type __type;
1628 };
1629
1630 // Helper to determine the index set for the first tuple-like
1631 // type of a given set.
1632 template<typename...>
1633 struct __make_1st_indices;
1634
1635 template<>
1636 struct __make_1st_indices<>
1637 {
1638 typedef _Index_tuple<> __type;
1639 };
1640
1641 template<typename _Tp, typename... _Tpls>
1642 struct __make_1st_indices<_Tp, _Tpls...>
1643 {
1644 typedef typename _Build_index_tuple<tuple_size<
1645 typename remove_reference<_Tp>::type>::value>::__type __type;
1646 };
1647
1648 // Performs the actual concatenation by step-wise expanding tuple-like
1649 // objects into the elements, which are finally forwarded into the
1650 // result tuple.
1651 template<typename _Ret, typename _Indices, typename... _Tpls>
1652 struct __tuple_concater;
1653
1654 template<typename _Ret, size_t... _Is, typename _Tp, typename... _Tpls>
1655 struct __tuple_concater<_Ret, _Index_tuple<_Is...>, _Tp, _Tpls...>
1656 {
1657 template<typename... _Us>
1658 static constexpr _Ret
1659 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1660 {
1661 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1662 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
1663 return __next::_S_do(std::forward<_Tpls>(__tps)...,
1664 std::forward<_Us>(__us)...,
1665 std::get<_Is>(std::forward<_Tp>(__tp))...);
1666 }
1667 };
1668
1669 template<typename _Ret>
1670 struct __tuple_concater<_Ret, _Index_tuple<>>
1671 {
1672 template<typename... _Us>
1673 static constexpr _Ret
1674 _S_do(_Us&&... __us)
1675 {
1676 return _Ret(std::forward<_Us>(__us)...);
1677 }
1678 };
1679
1680 /// tuple_cat
1681 template<typename... _Tpls, typename = typename
1682 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1683 constexpr auto
1684 tuple_cat(_Tpls&&... __tpls)
1685 -> typename __tuple_cat_result<_Tpls...>::__type
1686 {
1687 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1688 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1689 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1690 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1691 }
1692
1693 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1694 // 2301. Why is tie not constexpr?
1695 /// tie
1696 template<typename... _Elements>
1697 constexpr tuple<_Elements&...>
1698 tie(_Elements&... __args) noexcept
1699 { return tuple<_Elements&...>(__args...); }
1700
1701 /// swap
1702 template<typename... _Elements>
1703 _GLIBCXX20_CONSTEXPR
1704 inline
1705 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
1706 // Constrained free swap overload, see p0185r1
1707 typename enable_if<__and_<__is_swappable<_Elements>...>::value
1708 >::type
1709 #else
1710 void
1711 #endif
1712 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1713 noexcept(noexcept(__x.swap(__y)))
1714 { __x.swap(__y); }
1715
1716 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
1717 template<typename... _Elements>
1718 _GLIBCXX20_CONSTEXPR
1719 typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
1720 swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
1721 #endif
1722
1723 // A class (and instance) which can be used in 'tie' when an element
1724 // of a tuple is not required.
1725 // _GLIBCXX14_CONSTEXPR
1726 // 2933. PR for LWG 2773 could be clearer
1727 struct _Swallow_assign
1728 {
1729 template<class _Tp>
1730 _GLIBCXX14_CONSTEXPR const _Swallow_assign&
1731 operator=(const _Tp&) const
1732 { return *this; }
1733 };
1734
1735 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1736 // 2773. Making std::ignore constexpr
1737 _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
1738
1739 /// Partial specialization for tuples
1740 template<typename... _Types, typename _Alloc>
1741 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
1742
1743 // See stl_pair.h...
1744 /** "piecewise construction" using a tuple of arguments for each member.
1745 *
1746 * @param __first Arguments for the first member of the pair.
1747 * @param __second Arguments for the second member of the pair.
1748 *
1749 * The elements of each tuple will be used as the constructor arguments
1750 * for the data members of the pair.
1751 */
1752 template<class _T1, class _T2>
1753 template<typename... _Args1, typename... _Args2>
1754 _GLIBCXX20_CONSTEXPR
1755 inline
1756 pair<_T1, _T2>::
1757 pair(piecewise_construct_t,
1758 tuple<_Args1...> __first, tuple<_Args2...> __second)
1759 : pair(__first, __second,
1760 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
1761 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
1762 { }
1763
1764 template<class _T1, class _T2>
1765 template<typename... _Args1, size_t... _Indexes1,
1766 typename... _Args2, size_t... _Indexes2>
1767 _GLIBCXX20_CONSTEXPR inline
1768 pair<_T1, _T2>::
1769 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1770 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1771 : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1772 second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1773 { }
1774
1775 #if __cplusplus >= 201703L
1776
1777 // Unpack a std::tuple into a type trait and use its value.
1778 // For cv std::tuple<_Up> the result is _Trait<_Tp, cv _Up...>::value.
1779 // For cv std::tuple<_Up>& the result is _Trait<_Tp, cv _Up&...>::value.
1780 // Otherwise the result is false (because we don't know if std::get throws).
1781 template<template<typename...> class _Trait, typename _Tp, typename _Tuple>
1782 inline constexpr bool __unpack_std_tuple = false;
1783
1784 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
1785 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>>
1786 = _Trait<_Tp, _Up...>::value;
1787
1788 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
1789 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, tuple<_Up...>&>
1790 = _Trait<_Tp, _Up&...>::value;
1791
1792 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
1793 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>>
1794 = _Trait<_Tp, const _Up...>::value;
1795
1796 template<template<typename...> class _Trait, typename _Tp, typename... _Up>
1797 inline constexpr bool __unpack_std_tuple<_Trait, _Tp, const tuple<_Up...>&>
1798 = _Trait<_Tp, const _Up&...>::value;
1799
1800 # define __cpp_lib_apply 201603
1801
1802 template <typename _Fn, typename _Tuple, size_t... _Idx>
1803 constexpr decltype(auto)
1804 __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>)
1805 {
1806 return std::__invoke(std::forward<_Fn>(__f),
1807 std::get<_Idx>(std::forward<_Tuple>(__t))...);
1808 }
1809
1810 template <typename _Fn, typename _Tuple>
1811 constexpr decltype(auto)
1812 apply(_Fn&& __f, _Tuple&& __t)
1813 noexcept(__unpack_std_tuple<is_nothrow_invocable, _Fn, _Tuple>)
1814 {
1815 using _Indices
1816 = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>;
1817 return std::__apply_impl(std::forward<_Fn>(__f),
1818 std::forward<_Tuple>(__t),
1819 _Indices{});
1820 }
1821
1822 #define __cpp_lib_make_from_tuple 201606
1823
1824 template <typename _Tp, typename _Tuple, size_t... _Idx>
1825 constexpr _Tp
1826 __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>)
1827 { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); }
1828
1829 template <typename _Tp, typename _Tuple>
1830 constexpr _Tp
1831 make_from_tuple(_Tuple&& __t)
1832 noexcept(__unpack_std_tuple<is_nothrow_constructible, _Tp, _Tuple>)
1833 {
1834 return __make_from_tuple_impl<_Tp>(
1835 std::forward<_Tuple>(__t),
1836 make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{});
1837 }
1838 #endif // C++17
1839
1840 /// @}
1841
1842 _GLIBCXX_END_NAMESPACE_VERSION
1843 } // namespace std
1844
1845 #endif // C++11
1846
1847 #endif // _GLIBCXX_TUPLE