29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
43 template<
typename _Tp>
45 {
typedef const _Tp& type; };
47 template<
typename _Tp>
48 struct __add_c_ref<_Tp&>
49 {
typedef _Tp& type; };
52 template<
typename _Tp>
54 {
typedef _Tp& type; };
56 template<
typename _Tp>
57 struct __add_ref<_Tp&>
58 {
typedef _Tp& type; };
60 template<std::
size_t _Idx,
typename _Head,
bool _IsEmpty>
63 template<std::
size_t _Idx,
typename _Head>
64 struct _Head_base<_Idx, _Head, true>
70 _Head_base(
const _Head& __h)
73 template<
typename _UHead>
74 _Head_base(_UHead&& __h)
75 : _Head(std::forward<_UHead>(__h)) { }
77 _Head& _M_head() {
return *
this; }
78 const _Head& _M_head()
const {
return *
this; }
80 void _M_swap_impl(_Head&&) { }
83 template<std::
size_t _Idx,
typename _Head>
84 struct _Head_base<_Idx, _Head, false>
89 _Head_base(
const _Head& __h)
90 : _M_head_impl(__h) { }
92 template<
typename _UHead>
93 _Head_base(_UHead&& __h)
94 : _M_head_impl(std::forward<_UHead>(__h)) { }
96 _Head& _M_head() {
return _M_head_impl; }
97 const _Head& _M_head()
const {
return _M_head_impl; }
100 _M_swap_impl(_Head&& __h)
103 swap(__h, _M_head_impl);
117 template<std::size_t _Idx,
typename... _Elements>
124 template<std::
size_t _Idx>
136 template<std::size_t _Idx,
typename _Head,
typename... _Tail>
139 private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
142 typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
144 _Head& _M_head() {
return _Base::_M_head(); }
145 const _Head& _M_head()
const {
return _Base::_M_head(); }
148 const _Inherited& _M_tail()
const {
return *
this; }
154 _Tuple_impl(
const _Head& __head,
const _Tail&... __tail)
157 template<
typename _UHead,
typename... _UTail>
160 :
_Inherited(std::forward<_UTail>(__tail)...),
161 _Base(std::forward<_UHead>(__head)) { }
163 _Tuple_impl(
const _Tuple_impl& __in)
164 :
_Inherited(__in._M_tail()), _Base(__in._M_head()) { }
166 _Tuple_impl(_Tuple_impl&& __in)
167 :
_Inherited(std::move<_Inherited&&>(__in._M_tail())),
168 _Base(std::forward<_Head>(__in._M_head())) { }
170 template<
typename... _UElements>
172 :
_Inherited(__in._M_tail()), _Base(__in._M_head()) { }
174 template<
typename... _UElements>
179 _Base>(__in._M_head())) { }
182 operator=(
const _Tuple_impl& __in)
184 _M_head() = __in._M_head();
185 _M_tail() = __in._M_tail();
190 operator=(_Tuple_impl&& __in)
197 template<
typename... _UElements>
201 _M_head() = __in._M_head();
202 _M_tail() = __in._M_tail();
206 template<
typename... _UElements>
217 _M_swap_impl(_Tuple_impl&& __in)
219 _Base::_M_swap_impl(__in._M_head());
220 _Inherited::_M_swap_impl(__in._M_tail());
225 template<
typename... _Elements>
235 tuple(
const _Elements&... __elements)
238 template<
typename... _UElements>
240 tuple(_UElements&&... __elements)
241 :
_Inherited(std::forward<_UElements>(__elements)...) { }
243 tuple(
const tuple& __in)
244 :
_Inherited(static_cast<const _Inherited&>(__in)) { }
249 template<
typename... _UElements>
254 template<
typename... _UElements>
259 template<
typename... _UElements>
265 operator=(
const tuple& __in)
272 operator=(tuple&& __in)
278 template<
typename... _UElements>
286 template<
typename... _UElements>
296 { _Inherited::_M_swap_impl(__in); }
304 void swap(
tuple&&) { }
308 template<
typename _T1,
typename _T2>
318 tuple(
const _T1& __a1,
const _T2& __a2)
321 template<
typename _U1,
typename _U2>
323 tuple(_U1&& __a1, _U2&& __a2)
324 :
_Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
327 :
_Inherited(static_cast<const _Inherited&>(__in)) { }
332 template<
typename _U1,
typename _U2>
336 template<
typename _U1,
typename _U2>
340 template<
typename _U1,
typename _U2>
344 template<
typename _U1,
typename _U2>
349 operator=(
const tuple& __in)
356 operator=(
tuple&& __in)
362 template<
typename _U1,
typename _U2>
370 template<
typename _U1,
typename _U2>
378 template<
typename _U1,
typename _U2>
382 this->_M_head() = __in.
first;
383 this->_M_tail()._M_head() = __in.
second;
387 template<
typename _U1,
typename _U2>
400 swap(this->_M_head(), __in._M_head());
401 swap(this->_M_tail()._M_head(), __in._M_tail()._M_head());
407 template<std::
size_t __i,
typename _Tp>
414 template<std::size_t __i,
typename _Head,
typename... _Tail>
421 template<
typename _Head,
typename... _Tail>
428 template<
typename _Tp>
432 template<
typename... _Elements>
435 static const std::size_t value =
sizeof...(_Elements);
438 template<
typename... _Elements>
441 template<std::size_t __i,
typename _Head,
typename... _Tail>
442 inline typename __add_ref<_Head>::type
444 {
return __t._M_head(); }
446 template<std::size_t __i,
typename _Head,
typename... _Tail>
447 inline typename __add_c_ref<_Head>::type
448 __get_helper(
const _Tuple_impl<__i, _Head, _Tail...>& __t)
449 {
return __t._M_head(); }
453 template<std::size_t __i,
typename... _Elements>
454 inline typename __add_ref<
455 typename tuple_element<__i, tuple<_Elements...> >::type
457 get(tuple<_Elements...>& __t)
458 {
return __get_helper<__i>(__t); }
460 template<std::size_t __i,
typename... _Elements>
461 inline typename __add_c_ref<
462 typename tuple_element<__i, tuple<_Elements...> >::type
464 get(
const tuple<_Elements...>& __t)
465 {
return __get_helper<__i>(__t); }
468 template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
469 typename _Tp,
typename _Up>
470 struct __tuple_compare;
472 template<std::
size_t __i, std::
size_t __j,
typename _Tp,
typename _Up>
473 struct __tuple_compare<0, __i, __j, _Tp, _Up>
475 static bool __eq(
const _Tp& __t,
const _Up& __u)
477 return (get<__i>(__t) == get<__i>(__u) &&
478 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
481 static bool __less(
const _Tp& __t,
const _Up& __u)
483 return ((get<__i>(__t) < get<__i>(__u))
484 || !(get<__i>(__u) < get<__i>(__t)) &&
485 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
489 template<std::
size_t __i,
typename _Tp,
typename _Up>
490 struct __tuple_compare<0, __i, __i, _Tp, _Up>
492 static bool __eq(
const _Tp&,
const _Up&)
495 static bool __less(
const _Tp&,
const _Up&)
499 template<
typename... _TElements,
typename... _UElements>
502 const tuple<_UElements...>& __u)
504 typedef tuple<_TElements...> _Tp;
505 typedef tuple<_UElements...> _Up;
506 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
507 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
510 template<
typename... _TElements,
typename... _UElements>
512 operator<(
const tuple<_TElements...>& __t,
513 const tuple<_UElements...>& __u)
515 typedef tuple<_TElements...> _Tp;
516 typedef tuple<_UElements...> _Up;
517 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
518 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
521 template<
typename... _TElements,
typename... _UElements>
524 const tuple<_UElements...>& __u)
525 {
return !(__t == __u); }
527 template<
typename... _TElements,
typename... _UElements>
529 operator>(
const tuple<_TElements...>& __t,
530 const tuple<_UElements...>& __u)
531 {
return __u < __t; }
533 template<
typename... _TElements,
typename... _UElements>
535 operator<=(
const tuple<_TElements...>& __t,
536 const tuple<_UElements...>& __u)
537 {
return !(__u < __t); }
539 template<
typename... _TElements,
typename... _UElements>
541 operator>=(
const tuple<_TElements...>& __t,
542 const tuple<_UElements...>& __u)
543 {
return !(__t < __u); }
546 template<
typename... _Elements>
547 inline tuple<typename __decay_and_strip<_Elements>::__type...>
548 make_tuple(_Elements&&... __args)
550 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
552 return __result_type(std::forward<_Elements>(__args)...);
555 template<std::size_t...>
struct __index_holder { };
557 template<std::size_t __i,
typename _IdxHolder,
typename... _Elements>
558 struct __index_holder_impl;
560 template<std::size_t __i, std::size_t... _Indexes,
typename _IdxHolder,
561 typename... _Elements>
562 struct __index_holder_impl<__i, __index_holder<_Indexes...>,
563 _IdxHolder, _Elements...>
565 typedef typename __index_holder_impl<__i + 1,
566 __index_holder<_Indexes..., __i>,
567 _Elements...>::type type;
570 template<std::size_t __i, std::size_t... _Indexes>
571 struct __index_holder_impl<__i, __index_holder<_Indexes...> >
572 {
typedef __index_holder<_Indexes...> type; };
574 template<
typename... _Elements>
575 struct __make_index_holder
576 : __index_holder_impl<0, __index_holder<>, _Elements...> { };
578 template<
typename... _TElements, std::size_t... _TIdx,
579 typename... _UElements, std::size_t... _UIdx>
580 inline tuple<_TElements..., _UElements...>
581 __tuple_cat_helper(
const tuple<_TElements...>& __t,
582 const __index_holder<_TIdx...>&,
583 const tuple<_UElements...>& __u,
584 const __index_holder<_UIdx...>&)
585 {
return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)...,
586 get<_UIdx>(__u)...); }
588 template<
typename... _TElements, std::size_t... _TIdx,
589 typename... _UElements, std::size_t... _UIdx>
590 inline tuple<_TElements..., _UElements...>
591 __tuple_cat_helper(tuple<_TElements...>&& __t,
592 const __index_holder<_TIdx...>&,
593 const tuple<_UElements...>& __u,
594 const __index_holder<_UIdx...>&)
595 {
return tuple<_TElements..., _UElements...>
596 (
std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
598 template<
typename... _TElements, std::size_t... _TIdx,
599 typename... _UElements, std::size_t... _UIdx>
600 inline tuple<_TElements..., _UElements...>
601 __tuple_cat_helper(
const tuple<_TElements...>& __t,
602 const __index_holder<_TIdx...>&,
603 tuple<_UElements...>&& __u,
604 const __index_holder<_UIdx...>&)
605 {
return tuple<_TElements..., _UElements...>
606 (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
608 template<
typename... _TElements, std::size_t... _TIdx,
609 typename... _UElements, std::size_t... _UIdx>
610 inline tuple<_TElements..., _UElements...>
611 __tuple_cat_helper(tuple<_TElements...>&& __t,
612 const __index_holder<_TIdx...>&,
613 tuple<_UElements...>&& __u,
614 const __index_holder<_UIdx...>&)
615 {
return tuple<_TElements..., _UElements...>
618 template<
typename... _TElements,
typename... _UElements>
619 inline tuple<_TElements..., _UElements...>
620 tuple_cat(
const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
622 return __tuple_cat_helper(__t,
typename
623 __make_index_holder<_TElements...>::type(),
625 __make_index_holder<_UElements...>::type());
628 template<
typename... _TElements,
typename... _UElements>
629 inline tuple<_TElements..., _UElements...>
630 tuple_cat(tuple<_TElements...>&& __t,
const tuple<_UElements...>& __u)
632 return __tuple_cat_helper(std::move(__t),
typename
633 __make_index_holder<_TElements...>::type(),
635 __make_index_holder<_UElements...>::type());
638 template<
typename... _TElements,
typename... _UElements>
639 inline tuple<_TElements..., _UElements...>
640 tuple_cat(
const tuple<_TElements...>& __t, tuple<_UElements...>&& __u)
642 return __tuple_cat_helper(__t,
typename
643 __make_index_holder<_TElements...>::type(),
644 std::move(__u),
typename
645 __make_index_holder<_UElements...>::type());
648 template<
typename... _TElements,
typename... _UElements>
649 inline tuple<_TElements..., _UElements...>
650 tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u)
652 return __tuple_cat_helper(std::move(__t),
typename
653 __make_index_holder<_TElements...>::type(),
654 std::move(__u),
typename
655 __make_index_holder<_UElements...>::type());
658 template<
typename... _Elements>
659 inline tuple<_Elements&...>
660 tie(_Elements&... __args)
661 {
return tuple<_Elements&...>(__args...); }
663 template<
typename... _Elements>
665 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
668 template<
typename... _Elements>
670 swap(tuple<_Elements...>&& __x, tuple<_Elements...>& __y)
673 template<
typename... _Elements>
675 swap(tuple<_Elements...>& __x, tuple<_Elements...>&& __y)
680 struct _Swallow_assign
684 operator=(
const _Tp&)
691 _Swallow_assign ignore;
695 #endif // __GXX_EXPERIMENTAL_CXX0X__
697 #endif // _GLIBCXX_TUPLE