3 // Copyright (C) 2007-2016 Free Software Foundation, Inc.
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)
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.
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.
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/>.
25 /** @file include/tuple
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
40 #include <bits/uses_allocator.h>
42 namespace std _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 * @addtogroup utilities
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; }
151 * Contains the actual implementation of the @c tuple template, stored
152 * as a recursive inheritance hierarchy from the first element (most
153 * derived class) to the last (least derived class). The @c Idx
154 * parameter gives the 0-based index of the element stored at this
155 * point in the hierarchy; we use it to implement a constant-time
158 template<std::size_t _Idx, typename... _Elements>
161 template<typename _Tp>
162 struct __is_empty_non_tuple : is_empty<_Tp> { };
164 // Using EBO for elements that are tuples causes ambiguous base errors.
165 template<typename _El0, typename... _El>
166 struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
168 // Use the Empty Base-class Optimization for empty, non-final types.
169 template<typename _Tp>
170 using __empty_not_final
171 = typename conditional<__is_final(_Tp), false_type,
172 __is_empty_non_tuple<_Tp>>::type;
175 * Recursive tuple implementation. Here we store the @c Head element
176 * and derive from a @c Tuple_impl containing the remaining elements
177 * (which contains the @c Tail).
179 template<std::size_t _Idx, typename _Head, typename... _Tail>
180 struct _Tuple_impl<_Idx, _Head, _Tail...>
181 : public _Tuple_impl<_Idx + 1, _Tail...>,
182 private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
184 template<std::size_t, typename...> friend class _Tuple_impl;
186 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
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); }
195 static constexpr _Inherited&
196 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
198 static constexpr const _Inherited&
199 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
201 constexpr _Tuple_impl()
202 : _Inherited(), _Base() { }
205 constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
206 : _Inherited(__tail...), _Base(__head) { }
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)
221 : _Inherited(std::move(_M_tail(__in))),
222 _Base(std::forward<_Head>(_M_head(__in))) { }
224 template<typename... _UElements>
225 constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
226 : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
227 _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
229 template<typename _UHead, typename... _UTails>
230 constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
231 : _Inherited(std::move
232 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
233 _Base(std::forward<_UHead>
234 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
236 template<typename _Alloc>
237 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
238 : _Inherited(__tag, __a),
239 _Base(__tag, __use_alloc<_Head>(__a)) { }
241 template<typename _Alloc>
242 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
243 const _Head& __head, const _Tail&... __tail)
244 : _Inherited(__tag, __a, __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>
250 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
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>
257 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
258 const _Tuple_impl& __in)
259 : _Inherited(__tag, __a, _M_tail(__in)),
260 _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
262 template<typename _Alloc>
263 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
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>
270 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
271 const _Tuple_impl<_Idx, _UElements...>& __in)
272 : _Inherited(__tag, __a,
273 _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
274 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
275 _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
277 template<typename _Alloc, typename _UHead, typename... _UTails>
278 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
279 _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
280 : _Inherited(__tag, __a, std::move
281 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
282 _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
284 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
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>
306 operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
308 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
309 _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
313 template<typename _UHead, typename... _UTails>
315 operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
317 _M_head(*this) = std::forward<_UHead>
318 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
319 _M_tail(*this) = std::move
320 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in));
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));
336 // Basis case of inheritance recursion.
337 template<std::size_t _Idx, typename _Head>
338 struct _Tuple_impl<_Idx, _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>
463 // Concept utility functions, reused in conditionally-explicit
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>>
505 template<typename... _Elements>
506 struct _TC<false, _Elements...>
508 template<typename... _UElements>
509 static constexpr bool _ConstructibleTuple()
514 template<typename... _UElements>
515 static constexpr bool _ImplicitlyConvertibleTuple()
520 template<typename... _UElements>
521 static constexpr bool _MoveConstructibleTuple()
526 template<typename... _UElements>
527 static constexpr bool _ImplicitlyMoveConvertibleTuple()
532 template<typename... _UElements>
533 static constexpr bool _NonNestedTuple()
539 /// Primary class template, tuple
540 template<typename... _Elements>
541 class tuple : public _Tuple_impl<0, _Elements...>
543 typedef _Tuple_impl<0, _Elements...> _Inherited;
545 // Used for constraining the default constructor so
546 // that it becomes dependent on the constraints.
547 template<typename _Dummy>
550 static constexpr bool _DefaultConstructibleTuple()
552 return __and_<is_default_constructible<_Elements>...>::value;
554 static constexpr bool _ImplicitlyDefaultConstructibleTuple()
556 return __and_<__is_implicitly_default_constructible<_Elements>...>
562 template<typename _Dummy = void,
563 typename enable_if<_TC2<_Dummy>::
564 _ImplicitlyDefaultConstructibleTuple(),
569 template<typename _Dummy = void,
570 typename enable_if<_TC2<_Dummy>::
571 _DefaultConstructibleTuple()
574 _ImplicitlyDefaultConstructibleTuple(),
576 explicit constexpr tuple()
579 // Shortcut for the cases where constructors taking _Elements...
580 // need to be constrained.
581 template<typename _Dummy> using _TCC =
582 _TC<is_same<_Dummy, void>::value,
585 template<typename _Dummy = void,
587 _TCC<_Dummy>::template
588 _ConstructibleTuple<_Elements...>()
589 && _TCC<_Dummy>::template
590 _ImplicitlyConvertibleTuple<_Elements...>()
591 && (sizeof...(_Elements) >= 1),
593 constexpr tuple(const _Elements&... __elements)
594 : _Inherited(__elements...) { }
596 template<typename _Dummy = void,
598 _TCC<_Dummy>::template
599 _ConstructibleTuple<_Elements...>()
600 && !_TCC<_Dummy>::template
601 _ImplicitlyConvertibleTuple<_Elements...>()
602 && (sizeof...(_Elements) >= 1),
604 explicit constexpr tuple(const _Elements&... __elements)
605 : _Inherited(__elements...) { }
607 // Shortcut for the cases where constructors taking _UElements...
608 // need to be constrained.
609 template<typename... _UElements> using _TMC =
610 _TC<(sizeof...(_Elements) == sizeof...(_UElements)),
613 template<typename... _UElements, typename
614 enable_if<_TMC<_UElements...>::template
615 _MoveConstructibleTuple<_UElements...>()
616 && _TMC<_UElements...>::template
617 _ImplicitlyMoveConvertibleTuple<_UElements...>()
618 && (sizeof...(_Elements) >= 1),
620 constexpr tuple(_UElements&&... __elements)
621 : _Inherited(std::forward<_UElements>(__elements)...) { }
623 template<typename... _UElements, typename
624 enable_if<_TMC<_UElements...>::template
625 _MoveConstructibleTuple<_UElements...>()
626 && !_TMC<_UElements...>::template
627 _ImplicitlyMoveConvertibleTuple<_UElements...>()
628 && (sizeof...(_Elements) >= 1),
630 explicit constexpr tuple(_UElements&&... __elements)
631 : _Inherited(std::forward<_UElements>(__elements)...) { }
633 constexpr tuple(const tuple&) = default;
635 constexpr tuple(tuple&&) = default;
637 // Shortcut for the cases where constructors taking tuples
638 // must avoid creating temporaries.
639 template<typename _Dummy> using _TNTC =
640 _TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1,
643 template<typename... _UElements, typename _Dummy = void, typename
644 enable_if<_TMC<_UElements...>::template
645 _ConstructibleTuple<_UElements...>()
646 && _TMC<_UElements...>::template
647 _ImplicitlyConvertibleTuple<_UElements...>()
648 && _TNTC<_Dummy>::template
649 _NonNestedTuple<const tuple<_UElements...>&>(),
651 constexpr tuple(const tuple<_UElements...>& __in)
652 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
655 template<typename... _UElements, typename _Dummy = void, typename
656 enable_if<_TMC<_UElements...>::template
657 _ConstructibleTuple<_UElements...>()
658 && !_TMC<_UElements...>::template
659 _ImplicitlyConvertibleTuple<_UElements...>()
660 && _TNTC<_Dummy>::template
661 _NonNestedTuple<const tuple<_UElements...>&>(),
663 explicit constexpr tuple(const tuple<_UElements...>& __in)
664 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
667 template<typename... _UElements, typename _Dummy = void, typename
668 enable_if<_TMC<_UElements...>::template
669 _MoveConstructibleTuple<_UElements...>()
670 && _TMC<_UElements...>::template
671 _ImplicitlyMoveConvertibleTuple<_UElements...>()
672 && _TNTC<_Dummy>::template
673 _NonNestedTuple<tuple<_UElements...>&&>(),
675 constexpr tuple(tuple<_UElements...>&& __in)
676 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
678 template<typename... _UElements, typename _Dummy = void, typename
679 enable_if<_TMC<_UElements...>::template
680 _MoveConstructibleTuple<_UElements...>()
681 && !_TMC<_UElements...>::template
682 _ImplicitlyMoveConvertibleTuple<_UElements...>()
683 && _TNTC<_Dummy>::template
684 _NonNestedTuple<tuple<_UElements...>&&>(),
686 explicit constexpr tuple(tuple<_UElements...>&& __in)
687 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
689 // Allocator-extended constructors.
691 template<typename _Alloc>
692 tuple(allocator_arg_t __tag, const _Alloc& __a)
693 : _Inherited(__tag, __a) { }
695 template<typename _Alloc, typename _Dummy = void,
697 _TCC<_Dummy>::template
698 _ConstructibleTuple<_Elements...>()
699 && _TCC<_Dummy>::template
700 _ImplicitlyConvertibleTuple<_Elements...>(),
702 tuple(allocator_arg_t __tag, const _Alloc& __a,
703 const _Elements&... __elements)
704 : _Inherited(__tag, __a, __elements...) { }
706 template<typename _Alloc, typename _Dummy = void,
708 _TCC<_Dummy>::template
709 _ConstructibleTuple<_Elements...>()
710 && !_TCC<_Dummy>::template
711 _ImplicitlyConvertibleTuple<_Elements...>(),
713 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
714 const _Elements&... __elements)
715 : _Inherited(__tag, __a, __elements...) { }
717 template<typename _Alloc, typename... _UElements, typename
718 enable_if<_TMC<_UElements...>::template
719 _MoveConstructibleTuple<_UElements...>()
720 && _TMC<_UElements...>::template
721 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
723 tuple(allocator_arg_t __tag, const _Alloc& __a,
724 _UElements&&... __elements)
725 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
728 template<typename _Alloc, typename... _UElements, typename
729 enable_if<_TMC<_UElements...>::template
730 _MoveConstructibleTuple<_UElements...>()
731 && !_TMC<_UElements...>::template
732 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
734 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
735 _UElements&&... __elements)
736 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
739 template<typename _Alloc>
740 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
741 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
743 template<typename _Alloc>
744 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
745 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
747 template<typename _Alloc, typename... _UElements, typename
748 enable_if<_TMC<_UElements...>::template
749 _ConstructibleTuple<_UElements...>()
750 && _TMC<_UElements...>::template
751 _ImplicitlyConvertibleTuple<_UElements...>(),
753 tuple(allocator_arg_t __tag, const _Alloc& __a,
754 const tuple<_UElements...>& __in)
755 : _Inherited(__tag, __a,
756 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
759 template<typename _Alloc, typename... _UElements, typename
760 enable_if<_TMC<_UElements...>::template
761 _ConstructibleTuple<_UElements...>()
762 && !_TMC<_UElements...>::template
763 _ImplicitlyConvertibleTuple<_UElements...>(),
765 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
766 const tuple<_UElements...>& __in)
767 : _Inherited(__tag, __a,
768 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
771 template<typename _Alloc, typename... _UElements, typename
772 enable_if<_TMC<_UElements...>::template
773 _MoveConstructibleTuple<_UElements...>()
774 && _TMC<_UElements...>::template
775 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
777 tuple(allocator_arg_t __tag, const _Alloc& __a,
778 tuple<_UElements...>&& __in)
779 : _Inherited(__tag, __a,
780 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
783 template<typename _Alloc, typename... _UElements, typename
784 enable_if<_TMC<_UElements...>::template
785 _MoveConstructibleTuple<_UElements...>()
786 && !_TMC<_UElements...>::template
787 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
789 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
790 tuple<_UElements...>&& __in)
791 : _Inherited(__tag, __a,
792 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
796 operator=(const tuple& __in)
798 static_cast<_Inherited&>(*this) = __in;
803 operator=(tuple&& __in)
804 noexcept(is_nothrow_move_assignable<_Inherited>::value)
806 static_cast<_Inherited&>(*this) = std::move(__in);
810 template<typename... _UElements, typename = typename
811 enable_if<sizeof...(_UElements)
812 == sizeof...(_Elements)>::type>
814 operator=(const tuple<_UElements...>& __in)
816 static_cast<_Inherited&>(*this) = __in;
820 template<typename... _UElements, typename = typename
821 enable_if<sizeof...(_UElements)
822 == sizeof...(_Elements)>::type>
824 operator=(tuple<_UElements...>&& __in)
826 static_cast<_Inherited&>(*this) = std::move(__in);
832 noexcept(noexcept(__in._M_swap(__in)))
833 { _Inherited::_M_swap(__in); }
836 // Explicit specialization, zero-element tuple.
841 void swap(tuple&) noexcept { /* no-op */ }
844 /// Partial specialization, 2-element tuple.
845 /// Includes construction and assignment from a pair.
846 template<typename _T1, typename _T2>
847 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
849 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
852 template <typename _U1 = _T1,
854 typename enable_if<__and_<
855 __is_implicitly_default_constructible<_U1>,
856 __is_implicitly_default_constructible<_U2>>
857 ::value, bool>::type = true>
862 template <typename _U1 = _T1,
866 is_default_constructible<_U1>,
867 is_default_constructible<_U2>,
869 __and_<__is_implicitly_default_constructible<_U1>,
870 __is_implicitly_default_constructible<_U2>>>>
871 ::value, bool>::type = false>
873 explicit constexpr tuple()
876 // Shortcut for the cases where constructors taking _T1, _T2
877 // need to be constrained.
878 template<typename _Dummy> using _TCC =
879 _TC<is_same<_Dummy, void>::value, _T1, _T2>;
881 template<typename _Dummy = void, typename
882 enable_if<_TCC<_Dummy>::template
883 _ConstructibleTuple<_T1, _T2>()
884 && _TCC<_Dummy>::template
885 _ImplicitlyConvertibleTuple<_T1, _T2>(),
887 constexpr tuple(const _T1& __a1, const _T2& __a2)
888 : _Inherited(__a1, __a2) { }
890 template<typename _Dummy = void, typename
891 enable_if<_TCC<_Dummy>::template
892 _ConstructibleTuple<_T1, _T2>()
893 && !_TCC<_Dummy>::template
894 _ImplicitlyConvertibleTuple<_T1, _T2>(),
896 explicit constexpr tuple(const _T1& __a1, const _T2& __a2)
897 : _Inherited(__a1, __a2) { }
899 // Shortcut for the cases where constructors taking _U1, _U2
900 // need to be constrained.
901 using _TMC = _TC<true, _T1, _T2>;
903 template<typename _U1, typename _U2, typename
904 enable_if<_TMC::template
905 _MoveConstructibleTuple<_U1, _U2>()
907 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
909 constexpr tuple(_U1&& __a1, _U2&& __a2)
910 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
912 template<typename _U1, typename _U2, typename
913 enable_if<_TMC::template
914 _MoveConstructibleTuple<_U1, _U2>()
916 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
918 explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
919 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
921 constexpr tuple(const tuple&) = default;
923 constexpr tuple(tuple&&) = default;
925 template<typename _U1, typename _U2, typename
926 enable_if<_TMC::template
927 _ConstructibleTuple<_U1, _U2>()
929 _ImplicitlyConvertibleTuple<_U1, _U2>(),
931 constexpr tuple(const tuple<_U1, _U2>& __in)
932 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
934 template<typename _U1, typename _U2, typename
935 enable_if<_TMC::template
936 _ConstructibleTuple<_U1, _U2>()
938 _ImplicitlyConvertibleTuple<_U1, _U2>(),
940 explicit constexpr tuple(const tuple<_U1, _U2>& __in)
941 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
943 template<typename _U1, typename _U2, typename
944 enable_if<_TMC::template
945 _MoveConstructibleTuple<_U1, _U2>()
947 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
949 constexpr tuple(tuple<_U1, _U2>&& __in)
950 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
952 template<typename _U1, typename _U2, typename
953 enable_if<_TMC::template
954 _MoveConstructibleTuple<_U1, _U2>()
956 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
958 explicit constexpr tuple(tuple<_U1, _U2>&& __in)
959 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
961 template<typename _U1, typename _U2, typename
962 enable_if<_TMC::template
963 _ConstructibleTuple<_U1, _U2>()
965 _ImplicitlyConvertibleTuple<_U1, _U2>(),
967 constexpr tuple(const pair<_U1, _U2>& __in)
968 : _Inherited(__in.first, __in.second) { }
970 template<typename _U1, typename _U2, typename
971 enable_if<_TMC::template
972 _ConstructibleTuple<_U1, _U2>()
974 _ImplicitlyConvertibleTuple<_U1, _U2>(),
976 explicit constexpr tuple(const pair<_U1, _U2>& __in)
977 : _Inherited(__in.first, __in.second) { }
979 template<typename _U1, typename _U2, typename
980 enable_if<_TMC::template
981 _MoveConstructibleTuple<_U1, _U2>()
983 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
985 constexpr tuple(pair<_U1, _U2>&& __in)
986 : _Inherited(std::forward<_U1>(__in.first),
987 std::forward<_U2>(__in.second)) { }
989 template<typename _U1, typename _U2, typename
990 enable_if<_TMC::template
991 _MoveConstructibleTuple<_U1, _U2>()
993 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
995 explicit constexpr tuple(pair<_U1, _U2>&& __in)
996 : _Inherited(std::forward<_U1>(__in.first),
997 std::forward<_U2>(__in.second)) { }
999 // Allocator-extended constructors.
1001 template<typename _Alloc>
1002 tuple(allocator_arg_t __tag, const _Alloc& __a)
1003 : _Inherited(__tag, __a) { }
1005 template<typename _Alloc, typename _Dummy = void,
1007 _TCC<_Dummy>::template
1008 _ConstructibleTuple<_T1, _T2>()
1009 && _TCC<_Dummy>::template
1010 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1013 tuple(allocator_arg_t __tag, const _Alloc& __a,
1014 const _T1& __a1, const _T2& __a2)
1015 : _Inherited(__tag, __a, __a1, __a2) { }
1017 template<typename _Alloc, typename _Dummy = void,
1019 _TCC<_Dummy>::template
1020 _ConstructibleTuple<_T1, _T2>()
1021 && !_TCC<_Dummy>::template
1022 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1025 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1026 const _T1& __a1, const _T2& __a2)
1027 : _Inherited(__tag, __a, __a1, __a2) { }
1029 template<typename _Alloc, typename _U1, typename _U2, typename
1030 enable_if<_TMC::template
1031 _MoveConstructibleTuple<_U1, _U2>()
1033 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1035 tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1036 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1037 std::forward<_U2>(__a2)) { }
1039 template<typename _Alloc, typename _U1, typename _U2, typename
1040 enable_if<_TMC::template
1041 _MoveConstructibleTuple<_U1, _U2>()
1043 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1044 bool>::type = false>
1045 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1046 _U1&& __a1, _U2&& __a2)
1047 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1048 std::forward<_U2>(__a2)) { }
1050 template<typename _Alloc>
1051 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1052 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1054 template<typename _Alloc>
1055 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1056 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1058 template<typename _Alloc, typename _U1, typename _U2, typename
1059 enable_if<_TMC::template
1060 _ConstructibleTuple<_U1, _U2>()
1062 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1064 tuple(allocator_arg_t __tag, const _Alloc& __a,
1065 const tuple<_U1, _U2>& __in)
1066 : _Inherited(__tag, __a,
1067 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1070 template<typename _Alloc, typename _U1, typename _U2, typename
1071 enable_if<_TMC::template
1072 _ConstructibleTuple<_U1, _U2>()
1074 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1075 bool>::type = false>
1076 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1077 const tuple<_U1, _U2>& __in)
1078 : _Inherited(__tag, __a,
1079 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1082 template<typename _Alloc, typename _U1, typename _U2, typename
1083 enable_if<_TMC::template
1084 _MoveConstructibleTuple<_U1, _U2>()
1086 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1088 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1089 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1092 template<typename _Alloc, typename _U1, typename _U2, typename
1093 enable_if<_TMC::template
1094 _MoveConstructibleTuple<_U1, _U2>()
1096 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1097 bool>::type = false>
1098 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1099 tuple<_U1, _U2>&& __in)
1100 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1103 template<typename _Alloc, typename _U1, typename _U2, typename
1104 enable_if<_TMC::template
1105 _ConstructibleTuple<_U1, _U2>()
1107 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1109 tuple(allocator_arg_t __tag, const _Alloc& __a,
1110 const pair<_U1, _U2>& __in)
1111 : _Inherited(__tag, __a, __in.first, __in.second) { }
1113 template<typename _Alloc, typename _U1, typename _U2, typename
1114 enable_if<_TMC::template
1115 _ConstructibleTuple<_U1, _U2>()
1117 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1118 bool>::type = false>
1119 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1120 const pair<_U1, _U2>& __in)
1121 : _Inherited(__tag, __a, __in.first, __in.second) { }
1123 template<typename _Alloc, typename _U1, typename _U2, typename
1124 enable_if<_TMC::template
1125 _MoveConstructibleTuple<_U1, _U2>()
1127 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1129 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1130 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1131 std::forward<_U2>(__in.second)) { }
1133 template<typename _Alloc, typename _U1, typename _U2, typename
1134 enable_if<_TMC::template
1135 _MoveConstructibleTuple<_U1, _U2>()
1137 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1138 bool>::type = false>
1139 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1140 pair<_U1, _U2>&& __in)
1141 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1142 std::forward<_U2>(__in.second)) { }
1145 operator=(const tuple& __in)
1147 static_cast<_Inherited&>(*this) = __in;
1152 operator=(tuple&& __in)
1153 noexcept(is_nothrow_move_assignable<_Inherited>::value)
1155 static_cast<_Inherited&>(*this) = std::move(__in);
1159 template<typename _U1, typename _U2>
1161 operator=(const tuple<_U1, _U2>& __in)
1163 static_cast<_Inherited&>(*this) = __in;
1167 template<typename _U1, typename _U2>
1169 operator=(tuple<_U1, _U2>&& __in)
1171 static_cast<_Inherited&>(*this) = std::move(__in);
1175 template<typename _U1, typename _U2>
1177 operator=(const pair<_U1, _U2>& __in)
1179 this->_M_head(*this) = __in.first;
1180 this->_M_tail(*this)._M_head(*this) = __in.second;
1184 template<typename _U1, typename _U2>
1186 operator=(pair<_U1, _U2>&& __in)
1188 this->_M_head(*this) = std::forward<_U1>(__in.first);
1189 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1195 noexcept(noexcept(__in._M_swap(__in)))
1196 { _Inherited::_M_swap(__in); }
1201 * Recursive case for tuple_element: strip off the first element in
1202 * the tuple and retrieve the (i-1)th element of the remaining tuple.
1204 template<std::size_t __i, typename _Head, typename... _Tail>
1205 struct tuple_element<__i, tuple<_Head, _Tail...> >
1206 : tuple_element<__i - 1, tuple<_Tail...> > { };
1209 * Basis case for tuple_element: The first element is the one we're seeking.
1211 template<typename _Head, typename... _Tail>
1212 struct tuple_element<0, tuple<_Head, _Tail...> >
1217 /// class tuple_size
1218 template<typename... _Elements>
1219 struct tuple_size<tuple<_Elements...>>
1220 : public integral_constant<std::size_t, sizeof...(_Elements)> { };
1222 template<std::size_t __i, typename _Head, typename... _Tail>
1224 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1225 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1227 template<std::size_t __i, typename _Head, typename... _Tail>
1228 constexpr const _Head&
1229 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1230 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1232 /// Return a reference to the ith element of a tuple.
1233 template<std::size_t __i, typename... _Elements>
1234 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1235 get(tuple<_Elements...>& __t) noexcept
1236 { return std::__get_helper<__i>(__t); }
1238 /// Return a const reference to the ith element of a const tuple.
1239 template<std::size_t __i, typename... _Elements>
1240 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
1241 get(const tuple<_Elements...>& __t) noexcept
1242 { return std::__get_helper<__i>(__t); }
1244 /// Return an rvalue reference to the ith element of a tuple rvalue.
1245 template<std::size_t __i, typename... _Elements>
1246 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1247 get(tuple<_Elements...>&& __t) noexcept
1249 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1250 return std::forward<__element_type&&>(std::get<__i>(__t));
1253 #if __cplusplus > 201103L
1255 #define __cpp_lib_tuples_by_type 201304
1257 template<typename _Head, size_t __i, typename... _Tail>
1259 __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1260 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1262 template<typename _Head, size_t __i, typename... _Tail>
1263 constexpr const _Head&
1264 __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1265 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1267 /// Return a reference to the unique element of type _Tp of a tuple.
1268 template <typename _Tp, typename... _Types>
1270 get(tuple<_Types...>& __t) noexcept
1271 { return std::__get_helper2<_Tp>(__t); }
1273 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1274 template <typename _Tp, typename... _Types>
1276 get(tuple<_Types...>&& __t) noexcept
1277 { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
1279 /// Return a const reference to the unique element of type _Tp of a tuple.
1280 template <typename _Tp, typename... _Types>
1281 constexpr const _Tp&
1282 get(const tuple<_Types...>& __t) noexcept
1283 { return std::__get_helper2<_Tp>(__t); }
1286 // This class performs the comparison operations on tuples
1287 template<typename _Tp, typename _Up, size_t __i, size_t __size>
1288 struct __tuple_compare
1290 static constexpr bool
1291 __eq(const _Tp& __t, const _Up& __u)
1293 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1294 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1297 static constexpr bool
1298 __less(const _Tp& __t, const _Up& __u)
1300 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1301 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1302 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1306 template<typename _Tp, typename _Up, size_t __size>
1307 struct __tuple_compare<_Tp, _Up, __size, __size>
1309 static constexpr bool
1310 __eq(const _Tp&, const _Up&) { return true; }
1312 static constexpr bool
1313 __less(const _Tp&, const _Up&) { return false; }
1316 template<typename... _TElements, typename... _UElements>
1318 operator==(const tuple<_TElements...>& __t,
1319 const tuple<_UElements...>& __u)
1321 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1322 "tuple objects can only be compared if they have equal sizes.");
1323 using __compare = __tuple_compare<tuple<_TElements...>,
1324 tuple<_UElements...>,
1325 0, sizeof...(_TElements)>;
1326 return __compare::__eq(__t, __u);
1329 template<typename... _TElements, typename... _UElements>
1331 operator<(const tuple<_TElements...>& __t,
1332 const tuple<_UElements...>& __u)
1334 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1335 "tuple objects can only be compared if they have equal sizes.");
1336 using __compare = __tuple_compare<tuple<_TElements...>,
1337 tuple<_UElements...>,
1338 0, sizeof...(_TElements)>;
1339 return __compare::__less(__t, __u);
1342 template<typename... _TElements, typename... _UElements>
1344 operator!=(const tuple<_TElements...>& __t,
1345 const tuple<_UElements...>& __u)
1346 { return !(__t == __u); }
1348 template<typename... _TElements, typename... _UElements>
1350 operator>(const tuple<_TElements...>& __t,
1351 const tuple<_UElements...>& __u)
1352 { return __u < __t; }
1354 template<typename... _TElements, typename... _UElements>
1356 operator<=(const tuple<_TElements...>& __t,
1357 const tuple<_UElements...>& __u)
1358 { return !(__u < __t); }
1360 template<typename... _TElements, typename... _UElements>
1362 operator>=(const tuple<_TElements...>& __t,
1363 const tuple<_UElements...>& __u)
1364 { return !(__t < __u); }
1367 template<typename... _Elements>
1368 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1369 make_tuple(_Elements&&... __args)
1371 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1373 return __result_type(std::forward<_Elements>(__args)...);
1376 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1377 // 2275. Why is forward_as_tuple not constexpr?
1378 template<typename... _Elements>
1379 constexpr tuple<_Elements&&...>
1380 forward_as_tuple(_Elements&&... __args) noexcept
1381 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
1383 template<typename... _Tps>
1384 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
1387 // Internal type trait that allows us to sfinae-protect tuple_cat.
1388 template<typename _Tp>
1389 struct __is_tuple_like
1390 : public __is_tuple_like_impl<typename std::remove_cv
1391 <typename std::remove_reference<_Tp>::type>::type>::type
1394 template<size_t, typename, typename, size_t>
1395 struct __make_tuple_impl;
1397 template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
1398 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
1399 : __make_tuple_impl<_Idx + 1,
1400 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
1404 template<std::size_t _Nm, typename _Tuple, typename... _Tp>
1405 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
1407 typedef tuple<_Tp...> __type;
1410 template<typename _Tuple>
1411 struct __do_make_tuple
1412 : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
1415 // Returns the std::tuple equivalent of a tuple-like type.
1416 template<typename _Tuple>
1418 : public __do_make_tuple<typename std::remove_cv
1419 <typename std::remove_reference<_Tuple>::type>::type>
1422 // Combines several std::tuple's into a single one.
1423 template<typename...>
1424 struct __combine_tuples;
1427 struct __combine_tuples<>
1429 typedef tuple<> __type;
1432 template<typename... _Ts>
1433 struct __combine_tuples<tuple<_Ts...>>
1435 typedef tuple<_Ts...> __type;
1438 template<typename... _T1s, typename... _T2s, typename... _Rem>
1439 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
1441 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
1442 _Rem...>::__type __type;
1445 // Computes the result type of tuple_cat given a set of tuple-like types.
1446 template<typename... _Tpls>
1447 struct __tuple_cat_result
1449 typedef typename __combine_tuples
1450 <typename __make_tuple<_Tpls>::__type...>::__type __type;
1453 // Helper to determine the index set for the first tuple-like
1454 // type of a given set.
1455 template<typename...>
1456 struct __make_1st_indices;
1459 struct __make_1st_indices<>
1461 typedef std::_Index_tuple<> __type;
1464 template<typename _Tp, typename... _Tpls>
1465 struct __make_1st_indices<_Tp, _Tpls...>
1467 typedef typename std::_Build_index_tuple<std::tuple_size<
1468 typename std::remove_reference<_Tp>::type>::value>::__type __type;
1471 // Performs the actual concatenation by step-wise expanding tuple-like
1472 // objects into the elements, which are finally forwarded into the
1474 template<typename _Ret, typename _Indices, typename... _Tpls>
1475 struct __tuple_concater;
1477 template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
1478 struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
1480 template<typename... _Us>
1481 static constexpr _Ret
1482 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1484 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1485 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
1486 return __next::_S_do(std::forward<_Tpls>(__tps)...,
1487 std::forward<_Us>(__us)...,
1488 std::get<_Is>(std::forward<_Tp>(__tp))...);
1492 template<typename _Ret>
1493 struct __tuple_concater<_Ret, std::_Index_tuple<>>
1495 template<typename... _Us>
1496 static constexpr _Ret
1497 _S_do(_Us&&... __us)
1499 return _Ret(std::forward<_Us>(__us)...);
1504 template<typename... _Tpls, typename = typename
1505 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1507 tuple_cat(_Tpls&&... __tpls)
1508 -> typename __tuple_cat_result<_Tpls...>::__type
1510 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1511 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1512 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1513 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1516 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1517 // 2301. Why is tie not constexpr?
1519 template<typename... _Elements>
1520 constexpr tuple<_Elements&...>
1521 tie(_Elements&... __args) noexcept
1522 { return tuple<_Elements&...>(__args...); }
1525 template<typename... _Elements>
1527 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1528 noexcept(noexcept(__x.swap(__y)))
1531 // A class (and instance) which can be used in 'tie' when an element
1532 // of a tuple is not required
1533 struct _Swallow_assign
1536 const _Swallow_assign&
1537 operator=(const _Tp&) const
1541 const _Swallow_assign ignore{};
1543 /// Partial specialization for tuples
1544 template<typename... _Types, typename _Alloc>
1545 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
1547 // See stl_pair.h...
1548 template<class _T1, class _T2>
1549 template<typename... _Args1, typename... _Args2>
1552 pair(piecewise_construct_t,
1553 tuple<_Args1...> __first, tuple<_Args2...> __second)
1554 : pair(__first, __second,
1555 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
1556 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
1559 template<class _T1, class _T2>
1560 template<typename... _Args1, std::size_t... _Indexes1,
1561 typename... _Args2, std::size_t... _Indexes2>
1564 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1565 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1566 : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1567 second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1572 _GLIBCXX_END_NAMESPACE_VERSION
1577 #endif // _GLIBCXX_TUPLE