29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 template<
typename _Tp>
47 {
typedef const _Tp& type; };
49 template<
typename _Tp>
50 struct __add_c_ref<_Tp&>
51 {
typedef _Tp& type; };
54 template<
typename _Tp>
56 {
typedef _Tp& type; };
58 template<
typename _Tp>
59 struct __add_ref<_Tp&>
60 {
typedef _Tp& type; };
62 template<std::
size_t _Idx,
typename _Head,
bool _IsEmpty>
65 template<std::
size_t _Idx,
typename _Head>
66 struct _Head_base<_Idx, _Head, true>
69 constexpr _Head_base()
72 constexpr _Head_base(
const _Head& __h)
75 template<
typename _UHead>
76 _Head_base(_UHead&& __h)
77 : _Head(std::
forward<_UHead>(__h)) { }
79 _Head& _M_head() {
return *
this; }
80 const _Head& _M_head()
const {
return *
this; }
83 _M_swap_impl(_Head& __h)
90 template<std::
size_t _Idx,
typename _Head>
91 struct _Head_base<_Idx, _Head, false>
93 constexpr _Head_base()
96 constexpr _Head_base(
const _Head& __h)
97 : _M_head_impl(__h) { }
99 template<
typename _UHead>
100 _Head_base(_UHead&& __h)
101 : _M_head_impl(std::
forward<_UHead>(__h)) { }
103 _Head& _M_head() {
return _M_head_impl; }
104 const _Head& _M_head()
const {
return _M_head_impl; }
107 _M_swap_impl(_Head& __h)
110 swap(__h, _M_head());
124 template<std::size_t _Idx,
typename... _Elements>
131 template<std::
size_t _Idx>
143 template<std::size_t _Idx,
typename _Head,
typename... _Tail>
146 private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
149 typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
151 _Head& _M_head() {
return _Base::_M_head(); }
152 const _Head& _M_head()
const {
return _Base::_M_head(); }
155 const _Inherited& _M_tail()
const {
return *
this; }
161 constexpr _Tuple_impl(
const _Head& __head,
const _Tail&... __tail)
164 template<
typename _UHead,
typename... _UTail>
166 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
167 :
_Inherited(std::forward<_UTail>(__tail)...),
168 _Base(std::forward<_UHead>(__head)) { }
170 constexpr _Tuple_impl(
const _Tuple_impl&) =
default;
172 _Tuple_impl(_Tuple_impl&& __in)
174 _Base(std::forward<_Head>(__in._M_head())) { }
176 template<
typename... _UElements>
178 :
_Inherited(__in._M_tail()), _Base(__in._M_head()) { }
180 template<
typename _UHead,
typename... _UTails>
183 _Base(std::forward<_UHead>(__in._M_head())) { }
186 operator=(
const _Tuple_impl& __in)
188 _M_head() = __in._M_head();
189 _M_tail() = __in._M_tail();
194 operator=(_Tuple_impl&& __in)
196 _M_head() = std::forward<_Head>(__in._M_head());
197 _M_tail() = std::move(__in._M_tail());
201 template<
typename... _UElements>
205 _M_head() = __in._M_head();
206 _M_tail() = __in._M_tail();
210 template<
typename _UHead,
typename... _UTails>
214 _M_head() = std::forward<_UHead>(__in._M_head());
215 _M_tail() = std::move(__in._M_tail());
221 _M_swap_impl(_Tuple_impl& __in)
223 _Base::_M_swap_impl(__in._M_head());
224 _Inherited::_M_swap_impl(__in._M_tail());
229 template<
typename... _Elements>
239 constexpr tuple(
const _Elements&... __elements)
242 template<
typename... _UElements,
typename =
typename
244 ==
sizeof...(_Elements)>::type>
246 tuple(_UElements&&... __elements)
247 :
_Inherited(std::forward<_UElements>(__elements)...) { }
249 constexpr tuple(
const tuple&) =
default;
252 :
_Inherited(static_cast<_Inherited&&>(__in)) { }
254 template<
typename... _UElements,
typename =
typename
256 ==
sizeof...(_Elements)>::type>
261 template<
typename... _UElements,
typename =
typename
263 ==
sizeof...(_Elements)>::type>
268 operator=(
const tuple& __in)
275 operator=(tuple&& __in)
277 static_cast<_Inherited&
>(*this) = std::move(__in);
281 template<
typename... _UElements,
typename =
typename
283 ==
sizeof...(_Elements)>::type>
291 template<
typename... _UElements,
typename =
typename
293 ==
sizeof...(_Elements)>::type>
297 static_cast<_Inherited&
>(*this) = std::move(__in);
303 { _Inherited::_M_swap_impl(__in); }
310 void swap(
tuple&) { }
314 template<
typename _T1,
typename _T2>
324 constexpr tuple(
const _T1& __a1,
const _T2& __a2)
327 template<
typename _U1,
typename _U2>
329 tuple(_U1&& __a1, _U2&& __a2)
330 :
_Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
332 constexpr tuple(
const tuple&) =
default;
335 :
_Inherited(static_cast<_Inherited&&>(__in)) { }
337 template<
typename _U1,
typename _U2>
341 template<
typename _U1,
typename _U2>
345 template<
typename _U1,
typename _U2>
349 template<
typename _U1,
typename _U2>
352 std::forward<_U2>(__in.
second)) { }
355 operator=(
const tuple& __in)
362 operator=(tuple&& __in)
364 static_cast<_Inherited&
>(*this) = std::move(__in);
368 template<
typename _U1,
typename _U2>
376 template<
typename _U1,
typename _U2>
380 static_cast<_Inherited&
>(*this) = std::move(__in);
384 template<
typename _U1,
typename _U2>
388 this->_M_head() = __in.
first;
389 this->_M_tail()._M_head() = __in.
second;
393 template<
typename _U1,
typename _U2>
397 this->_M_head() = std::forward<_U1>(__in.
first);
398 this->_M_tail()._M_head() = std::forward<_U2>(__in.
second);
406 swap(this->_M_head(), __in._M_head());
407 swap(this->_M_tail()._M_head(), __in._M_tail()._M_head());
412 template<
typename _T1>
422 constexpr tuple(
const _T1& __a1)
425 template<
typename _U1,
typename =
typename
431 constexpr tuple(
const tuple&) =
default;
434 :
_Inherited(static_cast<_Inherited&&>(__in)) { }
436 template<
typename _U1>
440 template<
typename _U1>
445 operator=(
const tuple& __in)
452 operator=(tuple&& __in)
454 static_cast<_Inherited&
>(*this) = std::move(__in);
458 template<
typename _U1>
466 template<
typename _U1>
470 static_cast<_Inherited&
>(*this) = std::move(__in);
476 { _Inherited::_M_swap_impl(__in); }
481 template<std::
size_t __i,
typename _Tp>
488 template<std::size_t __i,
typename _Head,
typename... _Tail>
495 template<
typename _Head,
typename... _Tail>
502 template<
typename _Tp>
506 template<
typename... _Elements>
509 static const std::size_t value =
sizeof...(_Elements);
512 template<
typename... _Elements>
515 template<std::size_t __i,
typename _Head,
typename... _Tail>
516 inline typename __add_ref<_Head>::type
518 {
return __t._M_head(); }
520 template<std::size_t __i,
typename _Head,
typename... _Tail>
521 inline typename __add_c_ref<_Head>::type
522 __get_helper(
const _Tuple_impl<__i, _Head, _Tail...>& __t)
523 {
return __t._M_head(); }
527 template<std::size_t __i,
typename... _Elements>
528 inline typename __add_ref<
529 typename tuple_element<__i, tuple<_Elements...> >::type
531 get(tuple<_Elements...>& __t)
532 {
return __get_helper<__i>(__t); }
534 template<std::size_t __i,
typename... _Elements>
535 inline typename __add_c_ref<
536 typename tuple_element<__i, tuple<_Elements...> >::type
538 get(
const tuple<_Elements...>& __t)
539 {
return __get_helper<__i>(__t); }
542 template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
543 typename _Tp,
typename _Up>
544 struct __tuple_compare;
546 template<std::
size_t __i, std::
size_t __j,
typename _Tp,
typename _Up>
547 struct __tuple_compare<0, __i, __j, _Tp, _Up>
549 static bool __eq(
const _Tp& __t,
const _Up& __u)
551 return (get<__i>(__t) == get<__i>(__u) &&
552 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
555 static bool __less(
const _Tp& __t,
const _Up& __u)
557 return ((get<__i>(__t) < get<__i>(__u))
558 || !(get<__i>(__u) < get<__i>(__t)) &&
559 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
563 template<std::
size_t __i,
typename _Tp,
typename _Up>
564 struct __tuple_compare<0, __i, __i, _Tp, _Up>
566 static bool __eq(
const _Tp&,
const _Up&)
569 static bool __less(
const _Tp&,
const _Up&)
573 template<
typename... _TElements,
typename... _UElements>
575 operator==(
const tuple<_TElements...>& __t,
576 const tuple<_UElements...>& __u)
578 typedef tuple<_TElements...> _Tp;
579 typedef tuple<_UElements...> _Up;
580 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
581 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
584 template<
typename... _TElements,
typename... _UElements>
586 operator<(
const tuple<_TElements...>& __t,
587 const tuple<_UElements...>& __u)
589 typedef tuple<_TElements...> _Tp;
590 typedef tuple<_UElements...> _Up;
591 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
592 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
595 template<
typename... _TElements,
typename... _UElements>
597 operator!=(
const tuple<_TElements...>& __t,
598 const tuple<_UElements...>& __u)
599 {
return !(__t == __u); }
601 template<
typename... _TElements,
typename... _UElements>
603 operator>(
const tuple<_TElements...>& __t,
604 const tuple<_UElements...>& __u)
605 {
return __u < __t; }
607 template<
typename... _TElements,
typename... _UElements>
609 operator<=(
const tuple<_TElements...>& __t,
610 const tuple<_UElements...>& __u)
611 {
return !(__u < __t); }
613 template<
typename... _TElements,
typename... _UElements>
615 operator>=(
const tuple<_TElements...>& __t,
616 const tuple<_UElements...>& __u)
617 {
return !(__t < __u); }
620 template<
typename... _Elements>
621 inline tuple<typename __decay_and_strip<_Elements>::__type...>
622 make_tuple(_Elements&&... __args)
624 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
626 return __result_type(std::forward<_Elements>(__args)...);
629 template<
typename... _Elements>
630 inline tuple<_Elements&&...>
631 forward_as_tuple(_Elements&&... __args)
632 {
return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
634 template<std::size_t...>
struct __index_holder { };
636 template<std::size_t __i,
typename _IdxHolder,
typename... _Elements>
637 struct __index_holder_impl;
639 template<std::size_t __i, std::size_t... _Indexes,
typename _IdxHolder,
640 typename... _Elements>
641 struct __index_holder_impl<__i, __index_holder<_Indexes...>,
642 _IdxHolder, _Elements...>
644 typedef typename __index_holder_impl<__i + 1,
645 __index_holder<_Indexes..., __i>,
646 _Elements...>::type type;
649 template<std::size_t __i, std::size_t... _Indexes>
650 struct __index_holder_impl<__i, __index_holder<_Indexes...> >
651 {
typedef __index_holder<_Indexes...> type; };
653 template<
typename... _Elements>
654 struct __make_index_holder
655 : __index_holder_impl<0, __index_holder<>, _Elements...> { };
657 template<
typename... _TElements, std::size_t... _TIdx,
658 typename... _UElements, std::size_t... _UIdx>
659 inline tuple<_TElements..., _UElements...>
660 __tuple_cat_helper(
const tuple<_TElements...>& __t,
661 const __index_holder<_TIdx...>&,
662 const tuple<_UElements...>& __u,
663 const __index_holder<_UIdx...>&)
664 {
return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)...,
665 get<_UIdx>(__u)...); }
667 template<
typename... _TElements, std::size_t... _TIdx,
668 typename... _UElements, std::size_t... _UIdx>
669 inline tuple<_TElements..., _UElements...>
670 __tuple_cat_helper(tuple<_TElements...>&& __t,
671 const __index_holder<_TIdx...>&,
672 const tuple<_UElements...>& __u,
673 const __index_holder<_UIdx...>&)
674 {
return tuple<_TElements..., _UElements...>
675 (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
677 template<
typename... _TElements, std::size_t... _TIdx,
678 typename... _UElements, std::size_t... _UIdx>
679 inline tuple<_TElements..., _UElements...>
680 __tuple_cat_helper(
const tuple<_TElements...>& __t,
681 const __index_holder<_TIdx...>&,
682 tuple<_UElements...>&& __u,
683 const __index_holder<_UIdx...>&)
684 {
return tuple<_TElements..., _UElements...>
685 (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
687 template<
typename... _TElements, std::size_t... _TIdx,
688 typename... _UElements, std::size_t... _UIdx>
689 inline tuple<_TElements..., _UElements...>
690 __tuple_cat_helper(tuple<_TElements...>&& __t,
691 const __index_holder<_TIdx...>&,
692 tuple<_UElements...>&& __u,
693 const __index_holder<_UIdx...>&)
694 {
return tuple<_TElements..., _UElements...>
695 (std::forward<_TElements>(get<_TIdx>(__t))...,
696 std::forward<_UElements>(get<_UIdx>(__u))...); }
698 template<
typename... _TElements,
typename... _UElements>
699 inline tuple<_TElements..., _UElements...>
700 tuple_cat(
const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
702 return __tuple_cat_helper(__t,
typename
703 __make_index_holder<_TElements...>::type(),
705 __make_index_holder<_UElements...>::type());
708 template<
typename... _TElements,
typename... _UElements>
709 inline tuple<_TElements..., _UElements...>
710 tuple_cat(tuple<_TElements...>&& __t,
const tuple<_UElements...>& __u)
712 return __tuple_cat_helper(std::move(__t),
typename
713 __make_index_holder<_TElements...>::type(),
715 __make_index_holder<_UElements...>::type());
718 template<
typename... _TElements,
typename... _UElements>
719 inline tuple<_TElements..., _UElements...>
720 tuple_cat(
const tuple<_TElements...>& __t, tuple<_UElements...>&& __u)
722 return __tuple_cat_helper(__t,
typename
723 __make_index_holder<_TElements...>::type(),
724 std::move(__u),
typename
725 __make_index_holder<_UElements...>::type());
728 template<
typename... _TElements,
typename... _UElements>
729 inline tuple<_TElements..., _UElements...>
730 tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u)
732 return __tuple_cat_helper(std::move(__t),
typename
733 __make_index_holder<_TElements...>::type(),
734 std::move(__u),
typename
735 __make_index_holder<_UElements...>::type());
738 template<
typename... _Elements>
739 inline tuple<_Elements&...>
740 tie(_Elements&... __args)
741 {
return tuple<_Elements&...>(__args...); }
743 template<
typename... _Elements>
745 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
750 struct _Swallow_assign
753 const _Swallow_assign&
754 operator=(
const _Tp&)
const
758 const _Swallow_assign ignore{};
764 template<
int... _Indexes>
771 template<std::
size_t _Num>
784 template<
class _T1,
class _T2>
785 template<
typename _Tp,
typename... _Args>
788 __cons(tuple<_Args...>&& __tuple)
790 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
792 return __do_cons<_Tp>(std::move(__tuple), _Indexes());
795 template<
class _T1,
class _T2>
796 template<
typename _Tp,
typename... _Args,
int... _Indexes>
799 __do_cons(tuple<_Args...>&& __tuple,
800 const _Index_tuple<_Indexes...>&)
801 {
return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
803 _GLIBCXX_END_NAMESPACE_VERSION
806 #endif // __GXX_EXPERIMENTAL_CXX0X__
808 #endif // _GLIBCXX_TUPLE