29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
40 #include <bits/uses_allocator.h>
42 namespace std _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 template<std::
size_t _Idx,
typename _Head,
bool _IsEmptyNotFinal>
54 template<std::
size_t _Idx,
typename _Head>
55 struct _Head_base<_Idx, _Head, true>
58 constexpr _Head_base()
61 constexpr _Head_base(
const _Head& __h)
64 constexpr _Head_base(
const _Head_base&) =
default;
65 constexpr _Head_base(_Head_base&&) =
default;
67 template<
typename _UHead>
68 constexpr _Head_base(_UHead&& __h)
69 : _Head(std::
forward<_UHead>(__h)) { }
71 _Head_base(allocator_arg_t, __uses_alloc0)
74 template<
typename _Alloc>
75 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
76 : _Head(allocator_arg, *__a._M_a) { }
78 template<
typename _Alloc>
79 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
80 : _Head(*__a._M_a) { }
82 template<
typename _UHead>
83 _Head_base(__uses_alloc0, _UHead&& __uhead)
84 : _Head(std::
forward<_UHead>(__uhead)) { }
86 template<
typename _Alloc,
typename _UHead>
87 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
88 : _Head(allocator_arg, *__a._M_a, std::
forward<_UHead>(__uhead)) { }
90 template<
typename _Alloc,
typename _UHead>
91 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
92 : _Head(std::
forward<_UHead>(__uhead), *__a._M_a) { }
94 static constexpr _Head&
95 _M_head(_Head_base& __b) noexcept {
return __b; }
97 static constexpr
const _Head&
98 _M_head(
const _Head_base& __b) noexcept {
return __b; }
101 template<std::
size_t _Idx,
typename _Head>
102 struct _Head_base<_Idx, _Head, false>
104 constexpr _Head_base()
107 constexpr _Head_base(
const _Head& __h)
108 : _M_head_impl(__h) { }
110 constexpr _Head_base(
const _Head_base&) =
default;
111 constexpr _Head_base(_Head_base&&) =
default;
113 template<
typename _UHead>
114 constexpr _Head_base(_UHead&& __h)
115 : _M_head_impl(std::
forward<_UHead>(__h)) { }
117 _Head_base(allocator_arg_t, __uses_alloc0)
120 template<
typename _Alloc>
121 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
122 : _M_head_impl(allocator_arg, *__a._M_a) { }
124 template<
typename _Alloc>
125 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
126 : _M_head_impl(*__a._M_a) { }
128 template<
typename _UHead>
129 _Head_base(__uses_alloc0, _UHead&& __uhead)
130 : _M_head_impl(std::
forward<_UHead>(__uhead)) { }
132 template<
typename _Alloc,
typename _UHead>
133 _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
134 : _M_head_impl(allocator_arg, *__a._M_a, std::
forward<_UHead>(__uhead))
137 template<
typename _Alloc,
typename _UHead>
138 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
139 : _M_head_impl(std::
forward<_UHead>(__uhead), *__a._M_a) { }
141 static constexpr _Head&
142 _M_head(_Head_base& __b) noexcept {
return __b._M_head_impl; }
144 static constexpr
const _Head&
145 _M_head(
const _Head_base& __b) noexcept {
return __b._M_head_impl; }
158 template<std::size_t _Idx,
typename... _Elements>
161 template<
typename _Tp>
162 struct __is_empty_non_tuple :
is_empty<_Tp> { };
165 template<
typename _El0,
typename... _El>
169 template<
typename _Tp>
170 using __empty_not_final
171 =
typename conditional<__is_final(_Tp),
false_type,
172 __is_empty_non_tuple<_Tp>>::type;
179 template<std::size_t _Idx,
typename _Head,
typename... _Tail>
182 private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
184 template<std::size_t,
typename...>
friend class _Tuple_impl;
187 typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
189 static constexpr _Head&
190 _M_head(
_Tuple_impl& __t) noexcept {
return _Base::_M_head(__t); }
192 static constexpr
const _Head&
193 _M_head(
const _Tuple_impl& __t) noexcept {
return _Base::_M_head(__t); }
199 _M_tail(
const _Tuple_impl& __t) noexcept {
return __t; }
205 constexpr _Tuple_impl(
const _Head& __head,
const _Tail&... __tail)
208 template<
typename _UHead,
typename... _UTail,
typename =
typename
209 enable_if<
sizeof...(_Tail) ==
sizeof...(_UTail)>::type>
211 constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
212 :
_Inherited(std::forward<_UTail>(__tail)...),
213 _Base(std::forward<_UHead>(__head)) { }
215 constexpr _Tuple_impl(
const _Tuple_impl&) =
default;
218 _Tuple_impl(_Tuple_impl&& __in)
219 noexcept(__and_<is_nothrow_move_constructible<_Head>,
220 is_nothrow_move_constructible<_Inherited>>::value)
222 _Base(std::forward<_Head>(_M_head(__in))) { }
224 template<
typename... _UElements>
229 template<
typename _UHead,
typename... _UTails>
233 _Base(std::forward<_UHead>
236 template<
typename _Alloc>
239 _Base(__tag, __use_alloc<_Head>(__a)) { }
241 template<
typename _Alloc>
243 const _Head& __head,
const _Tail&... __tail)
245 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
247 template<
typename _Alloc,
typename _UHead,
typename... _UTail,
248 typename =
typename enable_if<
sizeof...(_Tail)
249 ==
sizeof...(_UTail)>::type>
251 _UHead&& __head, _UTail&&... __tail)
252 :
_Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
253 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
254 std::forward<_UHead>(__head)) { }
256 template<
typename _Alloc>
258 const _Tuple_impl& __in)
260 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
262 template<
typename _Alloc>
265 :
_Inherited(__tag, __a, std::move(_M_tail(__in))),
266 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
267 std::forward<_Head>(_M_head(__in))) { }
269 template<
typename _Alloc,
typename... _UElements>
274 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
277 template<
typename _Alloc,
typename _UHead,
typename... _UTails>
282 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
287 operator=(
const _Tuple_impl& __in)
289 _M_head(*
this) = _M_head(__in);
290 _M_tail(*
this) = _M_tail(__in);
295 operator=(_Tuple_impl&& __in)
296 noexcept(__and_<is_nothrow_move_assignable<_Head>,
297 is_nothrow_move_assignable<_Inherited>>::value)
299 _M_head(*
this) = std::forward<_Head>(_M_head(__in));
300 _M_tail(*
this) = std::move(_M_tail(__in));
304 template<
typename... _UElements>
313 template<
typename _UHead,
typename... _UTails>
317 _M_head(*
this) = std::forward<_UHead>
319 _M_tail(*
this) = std::move
326 _M_swap(_Tuple_impl& __in)
327 noexcept(__is_nothrow_swappable<_Head>::value
328 && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
331 swap(_M_head(*
this), _M_head(__in));
332 _Inherited::_M_swap(_M_tail(__in));
337 template<std::
size_t _Idx,
typename _Head>
339 :
private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
341 template<std::size_t,
typename...>
friend class _Tuple_impl;
343 typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
345 static constexpr _Head&
346 _M_head(
_Tuple_impl& __t) noexcept {
return _Base::_M_head(__t); }
348 static constexpr
const _Head&
349 _M_head(
const _Tuple_impl& __t) noexcept {
return _Base::_M_head(__t); }
351 constexpr _Tuple_impl()
355 constexpr _Tuple_impl(
const _Head& __head)
358 template<
typename _UHead>
360 constexpr _Tuple_impl(_UHead&& __head)
361 : _Base(std::
forward<_UHead>(__head)) { }
363 constexpr _Tuple_impl(
const _Tuple_impl&) =
default;
366 _Tuple_impl(_Tuple_impl&& __in)
367 noexcept(is_nothrow_move_constructible<_Head>::value)
368 : _Base(std::
forward<_Head>(_M_head(__in))) { }
370 template<
typename _UHead>
371 constexpr _Tuple_impl(
const _Tuple_impl<_Idx, _UHead>& __in)
372 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
374 template<
typename _UHead>
375 constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
376 : _Base(std::
forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
379 template<
typename _Alloc>
380 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a)
381 : _Base(__tag, __use_alloc<_Head>(__a)) { }
383 template<
typename _Alloc>
384 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
386 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
388 template<
typename _Alloc,
typename _UHead>
389 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
391 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
392 std::
forward<_UHead>(__head)) { }
394 template<
typename _Alloc>
395 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
396 const _Tuple_impl& __in)
397 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
399 template<
typename _Alloc>
400 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
402 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
403 std::
forward<_Head>(_M_head(__in))) { }
405 template<
typename _Alloc,
typename _UHead>
406 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
407 const _Tuple_impl<_Idx, _UHead>& __in)
408 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
409 _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
411 template<
typename _Alloc,
typename _UHead>
412 _Tuple_impl(allocator_arg_t __tag,
const _Alloc& __a,
413 _Tuple_impl<_Idx, _UHead>&& __in)
414 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
415 std::
forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
419 operator=(
const _Tuple_impl& __in)
421 _M_head(*
this) = _M_head(__in);
426 operator=(_Tuple_impl&& __in)
427 noexcept(is_nothrow_move_assignable<_Head>::value)
429 _M_head(*
this) = std::forward<_Head>(_M_head(__in));
433 template<
typename _UHead>
435 operator=(
const _Tuple_impl<_Idx, _UHead>& __in)
437 _M_head(*
this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
441 template<
typename _UHead>
443 operator=(_Tuple_impl<_Idx, _UHead>&& __in)
446 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
452 _M_swap(_Tuple_impl& __in)
453 noexcept(__is_nothrow_swappable<_Head>::value)
456 swap(_M_head(*
this), _M_head(__in));
460 template<
typename... _Elements>
465 template<bool,
typename... _Elements>
468 template<
typename... _UElements>
469 static constexpr
bool _ConstructibleTuple()
471 return __and_<is_constructible<_Elements, const _UElements&>...>::value;
474 template<
typename... _UElements>
475 static constexpr
bool _ImplicitlyConvertibleTuple()
477 return __and_<is_convertible<const _UElements&, _Elements>...>::value;
480 template<
typename... _UElements>
481 static constexpr
bool _MoveConstructibleTuple()
483 return __and_<is_constructible<_Elements, _UElements&&>...>::value;
486 template<
typename... _UElements>
487 static constexpr
bool _ImplicitlyMoveConvertibleTuple()
489 return __and_<is_convertible<_UElements&&, _Elements>...>::value;
492 template<
typename _SrcTuple>
493 static constexpr
bool _NonNestedTuple()
495 return __and_<__not_<is_same<tuple<_Elements...>,
497 typename remove_reference<_SrcTuple>::type
499 __not_<is_convertible<_SrcTuple, _Elements...>>,
500 __not_<is_constructible<_Elements..., _SrcTuple>>
503 template<
typename... _UElements>
504 static constexpr
bool _NotSameTuple()
506 return __not_<is_same<tuple<_Elements...>,
507 typename remove_const<
508 typename remove_reference<_UElements...>::type
513 template<
typename... _Elements>
514 struct _TC<false, _Elements...>
516 template<
typename... _UElements>
517 static constexpr
bool _ConstructibleTuple()
522 template<
typename... _UElements>
523 static constexpr
bool _ImplicitlyConvertibleTuple()
528 template<
typename... _UElements>
529 static constexpr
bool _MoveConstructibleTuple()
534 template<
typename... _UElements>
535 static constexpr
bool _ImplicitlyMoveConvertibleTuple()
540 template<
typename... _UElements>
541 static constexpr
bool _NonNestedTuple()
545 template<
typename... _UElements>
546 static constexpr
bool _NotSameTuple()
553 template<
typename... _Elements>
554 class tuple :
public _Tuple_impl<0, _Elements...>
556 typedef _Tuple_impl<0, _Elements...> _Inherited;
560 template<
typename _Dummy>
563 static constexpr
bool _DefaultConstructibleTuple()
565 return __and_<is_default_constructible<_Elements>...>::value;
567 static constexpr
bool _ImplicitlyDefaultConstructibleTuple()
569 return __and_<__is_implicitly_default_constructible<_Elements>...>
575 template<
typename _Dummy = void,
576 typename enable_if<_TC2<_Dummy>::
577 _ImplicitlyDefaultConstructibleTuple(),
582 template<
typename _Dummy = void,
583 typename enable_if<_TC2<_Dummy>::
584 _DefaultConstructibleTuple()
587 _ImplicitlyDefaultConstructibleTuple(),
589 explicit constexpr tuple()
594 template<
typename _Dummy>
using _TCC =
595 _TC<is_same<_Dummy, void>::value,
598 template<
typename _Dummy = void,
600 _TCC<_Dummy>::template
601 _ConstructibleTuple<_Elements...>()
602 && _TCC<_Dummy>::template
603 _ImplicitlyConvertibleTuple<_Elements...>()
604 && (
sizeof...(_Elements) >= 1),
606 constexpr tuple(
const _Elements&... __elements)
607 : _Inherited(__elements...) { }
609 template<
typename _Dummy = void,
611 _TCC<_Dummy>::template
612 _ConstructibleTuple<_Elements...>()
613 && !_TCC<_Dummy>::template
614 _ImplicitlyConvertibleTuple<_Elements...>()
615 && (
sizeof...(_Elements) >= 1),
617 explicit constexpr tuple(
const _Elements&... __elements)
618 : _Inherited(__elements...) { }
622 template<
typename... _UElements>
using _TMC =
623 _TC<(
sizeof...(_Elements) ==
sizeof...(_UElements)),
626 template<
typename... _UElements,
typename
628 _TC<
sizeof...(_UElements) == 1, _Elements...>::template
629 _NotSameTuple<_UElements...>()
630 && _TMC<_UElements...>::template
631 _MoveConstructibleTuple<_UElements...>()
632 && _TMC<_UElements...>::template
633 _ImplicitlyMoveConvertibleTuple<_UElements...>()
634 && (
sizeof...(_Elements) >= 1),
636 constexpr tuple(_UElements&&... __elements)
637 : _Inherited(std::forward<_UElements>(__elements)...) { }
639 template<
typename... _UElements,
typename
641 _TC<
sizeof...(_UElements) == 1, _Elements...>::
template
642 _NotSameTuple<_UElements...>()
643 && _TMC<_UElements...>::template
644 _MoveConstructibleTuple<_UElements...>()
645 && !_TMC<_UElements...>::template
646 _ImplicitlyMoveConvertibleTuple<_UElements...>()
647 && (
sizeof...(_Elements) >= 1),
649 explicit constexpr tuple(_UElements&&... __elements)
650 : _Inherited(std::
forward<_UElements>(__elements)...) { }
652 constexpr tuple(
const tuple&) =
default;
654 constexpr tuple(tuple&&) =
default;
658 template<
typename _Dummy>
using _TNTC =
659 _TC<is_same<_Dummy, void>::value &&
sizeof...(_Elements) == 1,
662 template<
typename... _UElements,
typename _Dummy =
void,
typename
663 enable_if<_TMC<_UElements...>::template
664 _ConstructibleTuple<_UElements...>()
665 && _TMC<_UElements...>::template
666 _ImplicitlyConvertibleTuple<_UElements...>()
667 && _TNTC<_Dummy>::template
668 _NonNestedTuple<
const tuple<_UElements...>&>(),
670 constexpr tuple(
const tuple<_UElements...>& __in)
671 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
674 template<
typename... _UElements,
typename _Dummy = void,
typename
675 enable_if<_TMC<_UElements...>::template
676 _ConstructibleTuple<_UElements...>()
677 && !_TMC<_UElements...>::template
678 _ImplicitlyConvertibleTuple<_UElements...>()
679 && _TNTC<_Dummy>::template
680 _NonNestedTuple<
const tuple<_UElements...>&>(),
682 explicit constexpr tuple(
const tuple<_UElements...>& __in)
683 : _Inherited(
static_cast<const _Tuple_impl<0, _UElements...
>&>(__in))
686 template<
typename... _UElements,
typename _Dummy = void,
typename
687 enable_if<_TMC<_UElements...>::template
688 _MoveConstructibleTuple<_UElements...>()
689 && _TMC<_UElements...>::template
690 _ImplicitlyMoveConvertibleTuple<_UElements...>()
691 && _TNTC<_Dummy>::template
692 _NonNestedTuple<tuple<_UElements...>&&>(),
694 constexpr tuple(tuple<_UElements...>&& __in)
695 : _Inherited(
static_cast<_Tuple_impl<0, _UElements...
>&&>(__in)) { }
697 template<
typename... _UElements,
typename _Dummy = void,
typename
698 enable_if<_TMC<_UElements...>::template
699 _MoveConstructibleTuple<_UElements...>()
700 && !_TMC<_UElements...>::template
701 _ImplicitlyMoveConvertibleTuple<_UElements...>()
702 && _TNTC<_Dummy>::template
703 _NonNestedTuple<tuple<_UElements...>&&>(),
705 explicit constexpr tuple(tuple<_UElements...>&& __in)
706 : _Inherited(
static_cast<_Tuple_impl<0, _UElements...
>&&>(__in)) { }
710 template<
typename _Alloc>
711 tuple(allocator_arg_t __tag,
const _Alloc& __a)
712 : _Inherited(__tag, __a) { }
714 template<
typename _Alloc,
typename _Dummy = void,
716 _TCC<_Dummy>::template
717 _ConstructibleTuple<_Elements...>()
718 && _TCC<_Dummy>::template
719 _ImplicitlyConvertibleTuple<_Elements...>(),
721 tuple(allocator_arg_t __tag,
const _Alloc& __a,
722 const _Elements&... __elements)
723 : _Inherited(__tag, __a, __elements...) { }
725 template<
typename _Alloc,
typename _Dummy = void,
727 _TCC<_Dummy>::template
728 _ConstructibleTuple<_Elements...>()
729 && !_TCC<_Dummy>::template
730 _ImplicitlyConvertibleTuple<_Elements...>(),
732 explicit tuple(allocator_arg_t __tag,
const _Alloc& __a,
733 const _Elements&... __elements)
734 : _Inherited(__tag, __a, __elements...) { }
736 template<
typename _Alloc,
typename... _UElements,
typename
737 enable_if<_TMC<_UElements...>::template
738 _MoveConstructibleTuple<_UElements...>()
739 && _TMC<_UElements...>::template
740 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
742 tuple(allocator_arg_t __tag,
const _Alloc& __a,
743 _UElements&&... __elements)
744 : _Inherited(__tag, __a, std::
forward<_UElements>(__elements)...)
747 template<
typename _Alloc,
typename... _UElements,
typename
748 enable_if<_TMC<_UElements...>::template
749 _MoveConstructibleTuple<_UElements...>()
750 && !_TMC<_UElements...>::template
751 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
753 explicit tuple(allocator_arg_t __tag,
const _Alloc& __a,
754 _UElements&&... __elements)
755 : _Inherited(__tag, __a, std::
forward<_UElements>(__elements)...)
758 template<
typename _Alloc>
759 tuple(allocator_arg_t __tag,
const _Alloc& __a,
const tuple& __in)
760 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
762 template<
typename _Alloc>
763 tuple(allocator_arg_t __tag,
const _Alloc& __a, tuple&& __in)
764 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
766 template<
typename _Alloc,
typename... _UElements,
typename
767 enable_if<_TMC<_UElements...>::template
768 _ConstructibleTuple<_UElements...>()
769 && _TMC<_UElements...>::template
770 _ImplicitlyConvertibleTuple<_UElements...>(),
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))
778 template<
typename _Alloc,
typename... _UElements,
typename
779 enable_if<_TMC<_UElements...>::template
780 _ConstructibleTuple<_UElements...>()
781 && !_TMC<_UElements...>::template
782 _ImplicitlyConvertibleTuple<_UElements...>(),
784 explicit tuple(allocator_arg_t __tag,
const _Alloc& __a,
785 const tuple<_UElements...>& __in)
786 : _Inherited(__tag, __a,
787 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
790 template<
typename _Alloc,
typename... _UElements,
typename
791 enable_if<_TMC<_UElements...>::template
792 _MoveConstructibleTuple<_UElements...>()
793 && _TMC<_UElements...>::template
794 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
796 tuple(allocator_arg_t __tag,
const _Alloc& __a,
797 tuple<_UElements...>&& __in)
798 : _Inherited(__tag, __a,
799 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
802 template<
typename _Alloc,
typename... _UElements,
typename
803 enable_if<_TMC<_UElements...>::template
804 _MoveConstructibleTuple<_UElements...>()
805 && !_TMC<_UElements...>::template
806 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
808 explicit tuple(allocator_arg_t __tag,
const _Alloc& __a,
809 tuple<_UElements...>&& __in)
810 : _Inherited(__tag, __a,
811 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
815 operator=(
const tuple& __in)
817 static_cast<_Inherited&
>(*this) = __in;
822 operator=(tuple&& __in)
823 noexcept(is_nothrow_move_assignable<_Inherited>::value)
825 static_cast<_Inherited&
>(*this) = std::move(__in);
829 template<
typename... _UElements,
typename =
typename
830 enable_if<
sizeof...(_UElements)
831 ==
sizeof...(_Elements)>::type>
833 operator=(
const tuple<_UElements...>& __in)
835 static_cast<_Inherited&
>(*this) = __in;
839 template<
typename... _UElements,
typename =
typename
840 enable_if<
sizeof...(_UElements)
841 ==
sizeof...(_Elements)>::type>
843 operator=(tuple<_UElements...>&& __in)
845 static_cast<_Inherited&
>(*this) = std::move(__in);
851 noexcept(noexcept(__in._M_swap(__in)))
852 { _Inherited::_M_swap(__in); }
860 void swap(tuple&) noexcept { }
865 template<
typename _T1,
typename _T2>
871 template <
typename _U1 = _T1,
873 typename enable_if<__and_<
874 __is_implicitly_default_constructible<_U1>,
875 __is_implicitly_default_constructible<_U2>>
876 ::value,
bool>::type =
true>
881 template <
typename _U1 = _T1,
885 is_default_constructible<_U1>,
886 is_default_constructible<_U2>,
888 __and_<__is_implicitly_default_constructible<_U1>,
889 __is_implicitly_default_constructible<_U2>>>>
890 ::value,
bool>::type =
false>
892 explicit constexpr tuple()
897 template<
typename _Dummy>
using _TCC =
898 _TC<is_same<_Dummy, void>::value, _T1, _T2>;
900 template<
typename _Dummy = void,
typename
901 enable_if<_TCC<_Dummy>::template
902 _ConstructibleTuple<_T1, _T2>()
903 && _TCC<_Dummy>::template
904 _ImplicitlyConvertibleTuple<_T1, _T2>(),
906 constexpr tuple(
const _T1& __a1,
const _T2& __a2)
909 template<
typename _Dummy = void,
typename
910 enable_if<_TCC<_Dummy>::template
911 _ConstructibleTuple<_T1, _T2>()
912 && !_TCC<_Dummy>::template
913 _ImplicitlyConvertibleTuple<_T1, _T2>(),
915 explicit constexpr tuple(
const _T1& __a1,
const _T2& __a2)
920 using _TMC = _TC<true, _T1, _T2>;
922 template<
typename _U1,
typename _U2,
typename
923 enable_if<_TMC::template
924 _MoveConstructibleTuple<_U1, _U2>()
926 _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
927 && !is_same<typename decay<_U1>::type,
930 constexpr tuple(_U1&& __a1, _U2&& __a2)
931 :
_Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
933 template<
typename _U1,
typename _U2,
typename
934 enable_if<_TMC::template
935 _MoveConstructibleTuple<_U1, _U2>()
937 _ImplicitlyMoveConvertibleTuple<_U1, _U2>()
938 && !is_same<typename decay<_U1>::type,
941 explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
942 :
_Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
944 constexpr tuple(
const tuple&) =
default;
946 constexpr tuple(tuple&&) =
default;
948 template<
typename _U1,
typename _U2,
typename
949 enable_if<_TMC::template
950 _ConstructibleTuple<_U1, _U2>()
952 _ImplicitlyConvertibleTuple<_U1, _U2>(),
957 template<
typename _U1,
typename _U2,
typename
958 enable_if<_TMC::template
959 _ConstructibleTuple<_U1, _U2>()
961 _ImplicitlyConvertibleTuple<_U1, _U2>(),
966 template<
typename _U1,
typename _U2,
typename
967 enable_if<_TMC::template
968 _MoveConstructibleTuple<_U1, _U2>()
970 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
975 template<
typename _U1,
typename _U2,
typename
976 enable_if<_TMC::template
977 _MoveConstructibleTuple<_U1, _U2>()
979 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
984 template<
typename _U1,
typename _U2,
typename
985 enable_if<_TMC::template
986 _ConstructibleTuple<_U1, _U2>()
988 _ImplicitlyConvertibleTuple<_U1, _U2>(),
993 template<
typename _U1,
typename _U2,
typename
994 enable_if<_TMC::template
995 _ConstructibleTuple<_U1, _U2>()
997 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1002 template<
typename _U1,
typename _U2,
typename
1003 enable_if<_TMC::template
1004 _MoveConstructibleTuple<_U1, _U2>()
1006 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1010 std::forward<_U2>(__in.
second)) { }
1012 template<
typename _U1,
typename _U2,
typename
1013 enable_if<_TMC::template
1014 _MoveConstructibleTuple<_U1, _U2>()
1016 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1017 bool>::type =
false>
1020 std::forward<_U2>(__in.
second)) { }
1024 template<
typename _Alloc>
1028 template<
typename _Alloc,
typename _Dummy = void,
1030 _TCC<_Dummy>::template
1031 _ConstructibleTuple<_T1, _T2>()
1032 && _TCC<_Dummy>::template
1033 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1037 const _T1& __a1,
const _T2& __a2)
1040 template<
typename _Alloc,
typename _Dummy = void,
1042 _TCC<_Dummy>::template
1043 _ConstructibleTuple<_T1, _T2>()
1044 && !_TCC<_Dummy>::template
1045 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1049 const _T1& __a1,
const _T2& __a2)
1052 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1053 enable_if<_TMC::template
1054 _MoveConstructibleTuple<_U1, _U2>()
1056 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1058 tuple(
allocator_arg_t __tag,
const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1059 :
_Inherited(__tag, __a, std::forward<_U1>(__a1),
1060 std::forward<_U2>(__a2)) { }
1062 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1063 enable_if<_TMC::template
1064 _MoveConstructibleTuple<_U1, _U2>()
1066 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1067 bool>::type =
false>
1069 _U1&& __a1, _U2&& __a2)
1070 :
_Inherited(__tag, __a, std::forward<_U1>(__a1),
1071 std::forward<_U2>(__a2)) { }
1073 template<
typename _Alloc>
1075 :
_Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1077 template<
typename _Alloc>
1079 :
_Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1081 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1082 enable_if<_TMC::template
1083 _ConstructibleTuple<_U1, _U2>()
1085 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1093 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1094 enable_if<_TMC::template
1095 _ConstructibleTuple<_U1, _U2>()
1097 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1098 bool>::type =
false>
1105 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1106 enable_if<_TMC::template
1107 _MoveConstructibleTuple<_U1, _U2>()
1109 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1115 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1116 enable_if<_TMC::template
1117 _MoveConstructibleTuple<_U1, _U2>()
1119 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1120 bool>::type =
false>
1126 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1127 enable_if<_TMC::template
1128 _ConstructibleTuple<_U1, _U2>()
1130 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1136 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1137 enable_if<_TMC::template
1138 _ConstructibleTuple<_U1, _U2>()
1140 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1141 bool>::type =
false>
1146 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1147 enable_if<_TMC::template
1148 _MoveConstructibleTuple<_U1, _U2>()
1150 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1154 std::forward<_U2>(__in.
second)) { }
1156 template<
typename _Alloc,
typename _U1,
typename _U2,
typename
1157 enable_if<_TMC::template
1158 _MoveConstructibleTuple<_U1, _U2>()
1160 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1161 bool>::type =
false>
1165 std::forward<_U2>(__in.
second)) { }
1168 operator=(
const tuple& __in)
1175 operator=(tuple&& __in)
1176 noexcept(is_nothrow_move_assignable<_Inherited>::value)
1178 static_cast<_Inherited&
>(*this) = std::move(__in);
1182 template<
typename _U1,
typename _U2>
1190 template<
typename _U1,
typename _U2>
1194 static_cast<_Inherited&
>(*this) = std::move(__in);
1198 template<
typename _U1,
typename _U2>
1202 this->_M_head(*
this) = __in.
first;
1203 this->_M_tail(*this)._M_head(*
this) = __in.
second;
1207 template<
typename _U1,
typename _U2>
1211 this->_M_head(*
this) = std::forward<_U1>(__in.
first);
1212 this->_M_tail(*this)._M_head(*
this) = std::forward<_U2>(__in.
second);
1218 noexcept(noexcept(__in._M_swap(__in)))
1219 { _Inherited::_M_swap(__in); }
1227 template<std::size_t __i,
typename _Head,
typename... _Tail>
1234 template<
typename _Head,
typename... _Tail>
1241 template<
typename... _Elements>
1245 template<std::size_t __i,
typename _Head,
typename... _Tail>
1250 template<std::size_t __i,
typename _Head,
typename... _Tail>
1251 constexpr
const _Head&
1252 __get_helper(
const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1253 {
return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1256 template<std::size_t __i,
typename... _Elements>
1257 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1259 {
return std::__get_helper<__i>(__t); }
1262 template<std::size_t __i,
typename... _Elements>
1263 constexpr
const __tuple_element_t<__i, tuple<_Elements...>>&
1264 get(
const tuple<_Elements...>& __t) noexcept
1265 {
return std::__get_helper<__i>(__t); }
1268 template<std::size_t __i,
typename... _Elements>
1269 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1272 typedef __tuple_element_t<__i,
tuple<_Elements...>> __element_type;
1273 return std::forward<__element_type&&>(std::get<__i>(__t));
1276 #if __cplusplus > 201103L
1278 #define __cpp_lib_tuples_by_type 201304
1280 template<
typename _Head,
size_t __i,
typename... _Tail>
1282 __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1283 {
return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1285 template<
typename _Head,
size_t __i,
typename... _Tail>
1286 constexpr
const _Head&
1287 __get_helper2(
const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1288 {
return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1291 template <
typename _Tp,
typename... _Types>
1294 {
return std::__get_helper2<_Tp>(__t); }
1297 template <
typename _Tp,
typename... _Types>
1300 {
return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
1303 template <
typename _Tp,
typename... _Types>
1304 constexpr
const _Tp&
1305 get(
const tuple<_Types...>& __t) noexcept
1306 {
return std::__get_helper2<_Tp>(__t); }
1310 template<
typename _Tp,
typename _Up,
size_t __i,
size_t __size>
1311 struct __tuple_compare
1313 static constexpr
bool
1314 __eq(
const _Tp& __t,
const _Up& __u)
1316 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1317 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1320 static constexpr
bool
1321 __less(
const _Tp& __t,
const _Up& __u)
1323 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1324 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1325 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1329 template<
typename _Tp,
typename _Up,
size_t __size>
1330 struct __tuple_compare<_Tp, _Up, __size, __size>
1332 static constexpr
bool
1333 __eq(
const _Tp&,
const _Up&) {
return true; }
1335 static constexpr
bool
1336 __less(
const _Tp&,
const _Up&) {
return false; }
1339 template<
typename... _TElements,
typename... _UElements>
1341 operator==(
const tuple<_TElements...>& __t,
1342 const tuple<_UElements...>& __u)
1344 static_assert(
sizeof...(_TElements) ==
sizeof...(_UElements),
1345 "tuple objects can only be compared if they have equal sizes.");
1346 using __compare = __tuple_compare<tuple<_TElements...>,
1347 tuple<_UElements...>,
1348 0,
sizeof...(_TElements)>;
1349 return __compare::__eq(__t, __u);
1352 template<
typename... _TElements,
typename... _UElements>
1354 operator<(
const tuple<_TElements...>& __t,
1355 const tuple<_UElements...>& __u)
1357 static_assert(
sizeof...(_TElements) ==
sizeof...(_UElements),
1358 "tuple objects can only be compared if they have equal sizes.");
1359 using __compare = __tuple_compare<tuple<_TElements...>,
1360 tuple<_UElements...>,
1361 0,
sizeof...(_TElements)>;
1362 return __compare::__less(__t, __u);
1365 template<
typename... _TElements,
typename... _UElements>
1367 operator!=(
const tuple<_TElements...>& __t,
1368 const tuple<_UElements...>& __u)
1369 {
return !(__t == __u); }
1371 template<
typename... _TElements,
typename... _UElements>
1373 operator>(
const tuple<_TElements...>& __t,
1374 const tuple<_UElements...>& __u)
1375 {
return __u < __t; }
1377 template<
typename... _TElements,
typename... _UElements>
1379 operator<=(
const tuple<_TElements...>& __t,
1380 const tuple<_UElements...>& __u)
1381 {
return !(__u < __t); }
1383 template<
typename... _TElements,
typename... _UElements>
1385 operator>=(
const tuple<_TElements...>& __t,
1386 const tuple<_UElements...>& __u)
1387 {
return !(__t < __u); }
1390 template<
typename... _Elements>
1391 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1392 make_tuple(_Elements&&... __args)
1394 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1396 return __result_type(std::forward<_Elements>(__args)...);
1401 template<
typename... _Elements>
1402 constexpr tuple<_Elements&&...>
1403 forward_as_tuple(_Elements&&... __args) noexcept
1404 {
return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
1406 template<
typename... _Tps>
1407 struct __is_tuple_like_impl<tuple<_Tps...>> :
true_type
1411 template<
typename _Tp>
1412 struct __is_tuple_like
1413 :
public __is_tuple_like_impl<typename std::remove_cv
1414 <typename std::remove_reference<_Tp>::type>::type>::type
1417 template<
size_t,
typename,
typename,
size_t>
1418 struct __make_tuple_impl;
1420 template<
size_t _Idx,
typename _Tuple,
typename... _Tp,
size_t _Nm>
1421 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
1422 : __make_tuple_impl<_Idx + 1,
1423 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
1427 template<std::size_t _Nm,
typename _Tuple,
typename... _Tp>
1428 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
1430 typedef tuple<_Tp...> __type;
1433 template<
typename _Tuple>
1434 struct __do_make_tuple
1435 : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
1439 template<
typename _Tuple>
1441 :
public __do_make_tuple<typename std::remove_cv
1442 <typename std::remove_reference<_Tuple>::type>::type>
1446 template<
typename...>
1447 struct __combine_tuples;
1450 struct __combine_tuples<>
1452 typedef tuple<> __type;
1455 template<
typename... _Ts>
1456 struct __combine_tuples<tuple<_Ts...>>
1458 typedef tuple<_Ts...> __type;
1461 template<
typename... _T1s,
typename... _T2s,
typename... _Rem>
1462 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
1464 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
1465 _Rem...>::__type __type;
1469 template<
typename... _Tpls>
1470 struct __tuple_cat_result
1472 typedef typename __combine_tuples
1478 template<
typename...>
1479 struct __make_1st_indices;
1482 struct __make_1st_indices<>
1484 typedef std::_Index_tuple<> __type;
1487 template<
typename _Tp,
typename... _Tpls>
1488 struct __make_1st_indices<_Tp, _Tpls...>
1491 typename std::remove_reference<_Tp>::type>::value>::__type __type;
1497 template<
typename _Ret,
typename _Indices,
typename... _Tpls>
1498 struct __tuple_concater;
1500 template<
typename _Ret, std::size_t... _Is,
typename _Tp,
typename... _Tpls>
1501 struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
1503 template<
typename... _Us>
1504 static constexpr _Ret
1505 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1507 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1508 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
1509 return __next::_S_do(std::forward<_Tpls>(__tps)...,
1510 std::forward<_Us>(__us)...,
1511 std::get<_Is>(std::forward<_Tp>(__tp))...);
1515 template<
typename _Ret>
1516 struct __tuple_concater<_Ret, std::_Index_tuple<>>
1518 template<
typename... _Us>
1519 static constexpr _Ret
1520 _S_do(_Us&&... __us)
1522 return _Ret(std::forward<_Us>(__us)...);
1527 template<
typename... _Tpls,
typename =
typename
1528 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1530 tuple_cat(_Tpls&&... __tpls)
1531 ->
typename __tuple_cat_result<_Tpls...>::__type
1533 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1534 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1535 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1536 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1542 template<
typename... _Elements>
1543 constexpr tuple<_Elements&...>
1544 tie(_Elements&... __args) noexcept
1545 {
return tuple<_Elements&...>(__args...); }
1548 template<
typename... _Elements>
1550 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1556 struct _Swallow_assign
1559 const _Swallow_assign&
1560 operator=(
const _Tp&)
const
1564 const _Swallow_assign ignore{};
1567 template<
typename... _Types,
typename _Alloc>
1571 template<
class _T1,
class _T2>
1572 template<
typename... _Args1,
typename... _Args2>
1577 :
pair(__first, __second,
1578 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
1579 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
1582 template<
class _T1,
class _T2>
1583 template<
typename... _Args1, std::size_t... _Indexes1,
1584 typename... _Args2, std::size_t... _Indexes2>
1587 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1588 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1589 : first(std::
forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1590 second(std::
forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1595 _GLIBCXX_END_NAMESPACE_VERSION
1600 #endif // _GLIBCXX_TUPLE
constexpr pair()
second is a copy of the second object
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Declare uses_allocator so it can be specialized in <queue> etc.
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
Primary class template, tuple.
_T2 second
first is a copy of the first object
__combine_tuples< typename __make_tuple< _Tpls >::__type...>::__type __type
tuple_cat
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Struct holding two objects of arbitrary type.
_T1 first
second_type is the second bound type
constexpr tuple< _Elements &...> tie(_Elements &...__args) noexcept
tie
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.