Zero-element tuple implementation. This is the basis case for the inheritance recursion.
Recursive tuple implementation. Here we store the Head
element and derive from a Tuple_impl
containing the remaining elements (which contains the Tail
).
Gives the type of the ith element of a given tuple type.
Recursive case for tuple_element: strip off the first element in the tuple and retrieve the (i-1)th element of the remaining tuple.
Basis case for tuple_element: The first element is the one we're seeking.
Finds the size of a given tuple type.
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 template<
typename _Tp>
48 {
typedef const _Tp& type; };
50 template<
typename _Tp>
51 struct __add_c_ref<_Tp&>
52 {
typedef _Tp& type; };
55 template<
typename _Tp>
57 {
typedef _Tp& type; };
59 template<
typename _Tp>
60 struct __add_ref<_Tp&>
61 {
typedef _Tp& type; };
71 template<
int _Idx,
typename... _Elements>
79 struct _Tuple_impl<_Idx> { };
86 template<
int _Idx,
typename _Head,
typename... _Tail>
87 struct _Tuple_impl<_Idx, _Head, _Tail...>
88 :
public _Tuple_impl<_Idx + 1, _Tail...>
90 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
94 _Inherited& _M_tail() {
return *
this; }
95 const _Inherited& _M_tail()
const {
return *
this; }
97 _Tuple_impl() : _Inherited(), _M_head() { }
100 _Tuple_impl(
typename __add_c_ref<_Head>::type __head,
101 typename __add_c_ref<_Tail>::type... __tail)
102 : _Inherited(__tail...), _M_head(__head) { }
104 template<
typename... _UElements>
105 _Tuple_impl(
const _Tuple_impl<_Idx, _UElements...>& __in)
106 : _Inherited(__in._M_tail()), _M_head(__in._M_head) { }
108 _Tuple_impl(
const _Tuple_impl& __in)
109 : _Inherited(__in._M_tail()), _M_head(__in._M_head) { }
111 template<
typename... _UElements>
113 operator=(
const _Tuple_impl<_Idx, _UElements...>& __in)
115 _M_head = __in._M_head;
116 _M_tail() = __in._M_tail();
121 operator=(
const _Tuple_impl& __in)
123 _M_head = __in._M_head;
124 _M_tail() = __in._M_tail();
129 template<
typename... _Elements>
130 class tuple :
public _Tuple_impl<0, _Elements...>
132 typedef _Tuple_impl<0, _Elements...> _Inherited;
135 tuple() : _Inherited() { }
138 tuple(
typename __add_c_ref<_Elements>::type... __elements)
139 : _Inherited(__elements...) { }
141 template<
typename... _UElements>
142 tuple(
const tuple<_UElements...>& __in)
143 : _Inherited(__in) { }
145 tuple(
const tuple& __in)
146 : _Inherited(__in) { }
148 template<
typename... _UElements>
150 operator=(
const tuple<_UElements...>& __in)
152 static_cast<_Inherited&
>(*this) = __in;
157 operator=(
const tuple& __in)
159 static_cast<_Inherited&
>(*this) = __in;
164 template<>
class tuple<> { };
167 template<
typename _T1,
typename _T2>
168 class tuple<_T1, _T2> :
public _Tuple_impl<0, _T1, _T2>
170 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
173 tuple() : _Inherited() { }
176 tuple(
typename __add_c_ref<_T1>::type __a1,
177 typename __add_c_ref<_T2>::type __a2)
178 : _Inherited(__a1, __a2) { }
180 template<
typename _U1,
typename _U2>
181 tuple(
const tuple<_U1, _U2>& __in)
182 : _Inherited(__in) { }
184 tuple(
const tuple& __in)
185 : _Inherited(__in) { }
187 template<
typename _U1,
typename _U2>
188 tuple(
const pair<_U1, _U2>& __in)
189 : _Inherited(_Tuple_impl<0,
190 typename __add_c_ref<_U1>::type,
191 typename __add_c_ref<_U2>::type>(__in.first,
195 template<
typename _U1,
typename _U2>
197 operator=(
const tuple<_U1, _U2>& __in)
199 static_cast<_Inherited&
>(*this) = __in;
204 operator=(
const tuple& __in)
206 static_cast<_Inherited&
>(*this) = __in;
210 template<
typename _U1,
typename _U2>
212 operator=(
const pair<_U1, _U2>& __in)
214 this->_M_head = __in.first;
215 this->_M_tail()._M_head = __in.second;
222 template<
int __i,
typename _Tp>
223 struct tuple_element;
229 template<
int __i,
typename _Head,
typename... _Tail>
230 struct tuple_element<__i, tuple<_Head, _Tail...> >
231 : tuple_element<__i - 1, tuple<_Tail...> > { };
236 template<
typename _Head,
typename... _Tail>
237 struct tuple_element<0, tuple<_Head, _Tail...> >
243 template<
typename _Tp>
247 template<
typename... _Elements>
248 struct tuple_size<tuple<_Elements...> >
250 static const int value =
sizeof...(_Elements);
253 template<
typename... _Elements>
254 const int tuple_size<tuple<_Elements...> >::value;
256 template<
int __i,
typename _Head,
typename... _Tail>
257 inline typename __add_ref<_Head>::type
258 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t)
263 template<
int __i,
typename _Head,
typename... _Tail>
264 inline typename __add_c_ref<_Head>::type
265 __get_helper(
const _Tuple_impl<__i, _Head, _Tail...>& __t)
272 template<
int __i,
typename... _Elements>
273 inline typename __add_ref<
274 typename tuple_element<__i, tuple<_Elements...> >::type
276 get(tuple<_Elements...>& __t)
278 return __get_helper<__i>(__t);
281 template<
int __i,
typename... _Elements>
282 inline typename __add_c_ref<
283 typename tuple_element<__i, tuple<_Elements...> >::type
285 get(
const tuple<_Elements...>& __t)
287 return __get_helper<__i>(__t);
291 template<
int __check_equal_size,
int __i,
int __j,
292 typename _Tp,
typename _Up>
293 struct __tuple_compare;
295 template<
int __i,
int __j,
typename _Tp,
typename _Up>
296 struct __tuple_compare<0, __i, __j, _Tp, _Up>
298 static bool __eq(
const _Tp& __t,
const _Up& __u)
300 return (get<__i>(__t) == get<__i>(__u) &&
301 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u));
304 static bool __less(
const _Tp& __t,
const _Up& __u)
306 return ((get<__i>(__t) < get<__i>(__u))
307 || !(get<__i>(__u) < get<__i>(__t)) &&
308 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u));
312 template<
int __i,
typename _Tp,
typename _Up>
313 struct __tuple_compare<0, __i, __i, _Tp, _Up>
315 static bool __eq(
const _Tp&,
const _Up&)
318 static bool __less(
const _Tp&,
const _Up&)
322 template<
typename... _TElements,
typename... _UElements>
325 const tuple<_UElements...>& __u)
327 typedef tuple<_TElements...> _Tp;
328 typedef tuple<_UElements...> _Up;
329 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
330 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
333 template<
typename... _TElements,
typename... _UElements>
335 operator<(
const tuple<_TElements...>& __t,
336 const tuple<_UElements...>& __u)
338 typedef tuple<_TElements...> _Tp;
339 typedef tuple<_UElements...> _Up;
340 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
341 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
344 template<
typename... _TElements,
typename... _UElements>
347 const tuple<_UElements...>& __u)
348 {
return !(__t == __u); }
350 template<
typename... _TElements,
typename... _UElements>
352 operator>(
const tuple<_TElements...>& __t,
353 const tuple<_UElements...>& __u)
354 {
return __u < __t; }
356 template<
typename... _TElements,
typename... _UElements>
359 const tuple<_UElements...>& __u)
360 {
return !(__u < __t); }
362 template<
typename... _TElements,
typename... _UElements>
365 const tuple<_UElements...>& __u)
366 {
return !(__t < __u); }
368 template<
typename _Tp>
369 class reference_wrapper;
372 template<
typename _Tp>
373 struct __strip_reference_wrapper
378 template<
typename _Tp>
379 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
384 template<
typename _Tp>
385 struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
390 template<
typename... _Elements>
391 inline tuple<typename __strip_reference_wrapper<_Elements>::__type...>
392 make_tuple(_Elements... __args)
394 typedef tuple<typename __strip_reference_wrapper<_Elements>::__type...>
396 return __result_type(__args...);
399 template<
typename... _Elements>
400 inline tuple<_Elements&...>
401 tie(_Elements&... __args)
403 return tuple<_Elements&...>(__args...);
408 struct _Swallow_assign
412 operator=(
const _Tp&)
419 _Swallow_assign ignore;
422 _GLIBCXX_END_NAMESPACE_VERSION
bool operator>=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:644
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
bool operator<=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:580
bool operator<(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:548
bool operator>(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:612
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))