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