]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/std/tuple
Support allocators in tuples of zero size.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / tuple
1 // <tuple> -*- C++ -*-
2
3 // Copyright (C) 2007-2016 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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.
19
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/>.
24
25 /** @file include/tuple
26 * This is a Standard C++ Library header.
27 */
28
29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
31
32 #pragma GCC system_header
33
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
36 #else
37
38 #include <utility>
39 #include <array>
40 #include <bits/uses_allocator.h>
41
42 namespace std _GLIBCXX_VISIBILITY(default)
43 {
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45
46 /**
47 * @addtogroup utilities
48 * @{
49 */
50
51 template<std::size_t _Idx, typename _Head, bool _IsEmptyNotFinal>
52 struct _Head_base;
53
54 template<std::size_t _Idx, typename _Head>
55 struct _Head_base<_Idx, _Head, true>
56 : public _Head
57 {
58 constexpr _Head_base()
59 : _Head() { }
60
61 constexpr _Head_base(const _Head& __h)
62 : _Head(__h) { }
63
64 constexpr _Head_base(const _Head_base&) = default;
65 constexpr _Head_base(_Head_base&&) = default;
66
67 template<typename _UHead>
68 constexpr _Head_base(_UHead&& __h)
69 : _Head(std::forward<_UHead>(__h)) { }
70
71 _Head_base(allocator_arg_t, __uses_alloc0)
72 : _Head() { }
73
74 template<typename _Alloc>
75 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
76 : _Head(allocator_arg, *__a._M_a) { }
77
78 template<typename _Alloc>
79 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
80 : _Head(*__a._M_a) { }
81
82 template<typename _UHead>
83 _Head_base(__uses_alloc0, _UHead&& __uhead)
84 : _Head(std::forward<_UHead>(__uhead)) { }
85
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)) { }
89
90 template<typename _Alloc, typename _UHead>
91 _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
92 : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
93
94 static constexpr _Head&
95 _M_head(_Head_base& __b) noexcept { return __b; }
96
97 static constexpr const _Head&
98 _M_head(const _Head_base& __b) noexcept { return __b; }
99 };
100
101 template<std::size_t _Idx, typename _Head>
102 struct _Head_base<_Idx, _Head, false>
103 {
104 constexpr _Head_base()
105 : _M_head_impl() { }
106
107 constexpr _Head_base(const _Head& __h)
108 : _M_head_impl(__h) { }
109
110 constexpr _Head_base(const _Head_base&) = default;
111 constexpr _Head_base(_Head_base&&) = default;
112
113 template<typename _UHead>
114 constexpr _Head_base(_UHead&& __h)
115 : _M_head_impl(std::forward<_UHead>(__h)) { }
116
117 _Head_base(allocator_arg_t, __uses_alloc0)
118 : _M_head_impl() { }
119
120 template<typename _Alloc>
121 _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
122 : _M_head_impl(allocator_arg, *__a._M_a) { }
123
124 template<typename _Alloc>
125 _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
126 : _M_head_impl(*__a._M_a) { }
127
128 template<typename _UHead>
129 _Head_base(__uses_alloc0, _UHead&& __uhead)
130 : _M_head_impl(std::forward<_UHead>(__uhead)) { }
131
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))
135 { }
136
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) { }
140
141 static constexpr _Head&
142 _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
143
144 static constexpr const _Head&
145 _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
146
147 _Head _M_head_impl;
148 };
149
150 /**
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
156 * get() operation.
157 */
158 template<std::size_t _Idx, typename... _Elements>
159 struct _Tuple_impl;
160
161 template<typename _Tp>
162 struct __is_empty_non_tuple : is_empty<_Tp> { };
163
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 { };
167
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;
173
174 /**
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).
178 */
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>
183 {
184 template<std::size_t, typename...> friend class _Tuple_impl;
185
186 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
187 typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
188
189 static constexpr _Head&
190 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
191
192 static constexpr const _Head&
193 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
194
195 static constexpr _Inherited&
196 _M_tail(_Tuple_impl& __t) noexcept { return __t; }
197
198 static constexpr const _Inherited&
199 _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
200
201 constexpr _Tuple_impl()
202 : _Inherited(), _Base() { }
203
204 explicit
205 constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
206 : _Inherited(__tail...), _Base(__head) { }
207
208 template<typename _UHead, typename... _UTail, typename = typename
209 enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
210 explicit
211 constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
212 : _Inherited(std::forward<_UTail>(__tail)...),
213 _Base(std::forward<_UHead>(__head)) { }
214
215 constexpr _Tuple_impl(const _Tuple_impl&) = default;
216
217 constexpr
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))) { }
223
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)) { }
228
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))) { }
235
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)) { }
240
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) { }
246
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)) { }
255
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)) { }
261
262 template<typename _Alloc>
263 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
264 _Tuple_impl&& __in)
265 : _Inherited(__tag, __a, std::move(_M_tail(__in))),
266 _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
267 std::forward<_Head>(_M_head(__in))) { }
268
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)) { }
276
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),
283 std::forward<_UHead>
284 (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
285
286 _Tuple_impl&
287 operator=(const _Tuple_impl& __in)
288 {
289 _M_head(*this) = _M_head(__in);
290 _M_tail(*this) = _M_tail(__in);
291 return *this;
292 }
293
294 _Tuple_impl&
295 operator=(_Tuple_impl&& __in)
296 noexcept(__and_<is_nothrow_move_assignable<_Head>,
297 is_nothrow_move_assignable<_Inherited>>::value)
298 {
299 _M_head(*this) = std::forward<_Head>(_M_head(__in));
300 _M_tail(*this) = std::move(_M_tail(__in));
301 return *this;
302 }
303
304 template<typename... _UElements>
305 _Tuple_impl&
306 operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
307 {
308 _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
309 _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
310 return *this;
311 }
312
313 template<typename _UHead, typename... _UTails>
314 _Tuple_impl&
315 operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
316 {
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));
321 return *this;
322 }
323
324 protected:
325 void
326 _M_swap(_Tuple_impl& __in)
327 noexcept(__is_nothrow_swappable<_Head>::value
328 && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
329 {
330 using std::swap;
331 swap(_M_head(*this), _M_head(__in));
332 _Inherited::_M_swap(_M_tail(__in));
333 }
334 };
335
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>
340 {
341 template<std::size_t, typename...> friend class _Tuple_impl;
342
343 typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
344
345 static constexpr _Head&
346 _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
347
348 static constexpr const _Head&
349 _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
350
351 constexpr _Tuple_impl()
352 : _Base() { }
353
354 explicit
355 constexpr _Tuple_impl(const _Head& __head)
356 : _Base(__head) { }
357
358 template<typename _UHead>
359 explicit
360 constexpr _Tuple_impl(_UHead&& __head)
361 : _Base(std::forward<_UHead>(__head)) { }
362
363 constexpr _Tuple_impl(const _Tuple_impl&) = default;
364
365 constexpr
366 _Tuple_impl(_Tuple_impl&& __in)
367 noexcept(is_nothrow_move_constructible<_Head>::value)
368 : _Base(std::forward<_Head>(_M_head(__in))) { }
369
370 template<typename _UHead>
371 constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
372 : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
373
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)))
377 { }
378
379 template<typename _Alloc>
380 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
381 : _Base(__tag, __use_alloc<_Head>(__a)) { }
382
383 template<typename _Alloc>
384 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
385 const _Head& __head)
386 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
387
388 template<typename _Alloc, typename _UHead>
389 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
390 _UHead&& __head)
391 : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
392 std::forward<_UHead>(__head)) { }
393
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)) { }
398
399 template<typename _Alloc>
400 _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
401 _Tuple_impl&& __in)
402 : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
403 std::forward<_Head>(_M_head(__in))) { }
404
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)) { }
410
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)))
416 { }
417
418 _Tuple_impl&
419 operator=(const _Tuple_impl& __in)
420 {
421 _M_head(*this) = _M_head(__in);
422 return *this;
423 }
424
425 _Tuple_impl&
426 operator=(_Tuple_impl&& __in)
427 noexcept(is_nothrow_move_assignable<_Head>::value)
428 {
429 _M_head(*this) = std::forward<_Head>(_M_head(__in));
430 return *this;
431 }
432
433 template<typename _UHead>
434 _Tuple_impl&
435 operator=(const _Tuple_impl<_Idx, _UHead>& __in)
436 {
437 _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
438 return *this;
439 }
440
441 template<typename _UHead>
442 _Tuple_impl&
443 operator=(_Tuple_impl<_Idx, _UHead>&& __in)
444 {
445 _M_head(*this)
446 = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
447 return *this;
448 }
449
450 protected:
451 void
452 _M_swap(_Tuple_impl& __in)
453 noexcept(__is_nothrow_swappable<_Head>::value)
454 {
455 using std::swap;
456 swap(_M_head(*this), _M_head(__in));
457 }
458 };
459
460 template<typename... _Elements>
461 class tuple;
462
463 // Concept utility functions, reused in conditionally-explicit
464 // constructors.
465 template<bool, typename... _Elements>
466 struct _TC
467 {
468 template<typename... _UElements>
469 static constexpr bool _ConstructibleTuple()
470 {
471 return __and_<is_constructible<_Elements, const _UElements&>...>::value;
472 }
473
474 template<typename... _UElements>
475 static constexpr bool _ImplicitlyConvertibleTuple()
476 {
477 return __and_<is_convertible<const _UElements&, _Elements>...>::value;
478 }
479
480 template<typename... _UElements>
481 static constexpr bool _MoveConstructibleTuple()
482 {
483 return __and_<is_constructible<_Elements, _UElements&&>...>::value;
484 }
485
486 template<typename... _UElements>
487 static constexpr bool _ImplicitlyMoveConvertibleTuple()
488 {
489 return __and_<is_convertible<_UElements&&, _Elements>...>::value;
490 }
491
492 template<typename _SrcTuple>
493 static constexpr bool _NonNestedTuple()
494 {
495 return __and_<__not_<is_same<tuple<_Elements...>,
496 typename remove_cv<
497 typename remove_reference<_SrcTuple>::type
498 >::type>>,
499 __not_<is_convertible<_SrcTuple, _Elements...>>,
500 __not_<is_constructible<_Elements..., _SrcTuple>>
501 >::value;
502 }
503 template<typename... _UElements>
504 static constexpr bool _NotSameTuple()
505 {
506 return __not_<is_same<tuple<_Elements...>,
507 typename remove_const<
508 typename remove_reference<_UElements...>::type
509 >::type>>::value;
510 }
511 };
512
513 template<typename... _Elements>
514 struct _TC<false, _Elements...>
515 {
516 template<typename... _UElements>
517 static constexpr bool _ConstructibleTuple()
518 {
519 return false;
520 }
521
522 template<typename... _UElements>
523 static constexpr bool _ImplicitlyConvertibleTuple()
524 {
525 return false;
526 }
527
528 template<typename... _UElements>
529 static constexpr bool _MoveConstructibleTuple()
530 {
531 return false;
532 }
533
534 template<typename... _UElements>
535 static constexpr bool _ImplicitlyMoveConvertibleTuple()
536 {
537 return false;
538 }
539
540 template<typename... _UElements>
541 static constexpr bool _NonNestedTuple()
542 {
543 return true;
544 }
545 template<typename... _UElements>
546 static constexpr bool _NotSameTuple()
547 {
548 return true;
549 }
550 };
551
552 /// Primary class template, tuple
553 template<typename... _Elements>
554 class tuple : public _Tuple_impl<0, _Elements...>
555 {
556 typedef _Tuple_impl<0, _Elements...> _Inherited;
557
558 // Used for constraining the default constructor so
559 // that it becomes dependent on the constraints.
560 template<typename _Dummy>
561 struct _TC2
562 {
563 static constexpr bool _DefaultConstructibleTuple()
564 {
565 return __and_<is_default_constructible<_Elements>...>::value;
566 }
567 static constexpr bool _ImplicitlyDefaultConstructibleTuple()
568 {
569 return __and_<__is_implicitly_default_constructible<_Elements>...>
570 ::value;
571 }
572 };
573
574 public:
575 template<typename _Dummy = void,
576 typename enable_if<_TC2<_Dummy>::
577 _ImplicitlyDefaultConstructibleTuple(),
578 bool>::type = true>
579 constexpr tuple()
580 : _Inherited() { }
581
582 template<typename _Dummy = void,
583 typename enable_if<_TC2<_Dummy>::
584 _DefaultConstructibleTuple()
585 &&
586 !_TC2<_Dummy>::
587 _ImplicitlyDefaultConstructibleTuple(),
588 bool>::type = false>
589 explicit constexpr tuple()
590 : _Inherited() { }
591
592 // Shortcut for the cases where constructors taking _Elements...
593 // need to be constrained.
594 template<typename _Dummy> using _TCC =
595 _TC<is_same<_Dummy, void>::value,
596 _Elements...>;
597
598 template<typename _Dummy = void,
599 typename enable_if<
600 _TCC<_Dummy>::template
601 _ConstructibleTuple<_Elements...>()
602 && _TCC<_Dummy>::template
603 _ImplicitlyConvertibleTuple<_Elements...>()
604 && (sizeof...(_Elements) >= 1),
605 bool>::type=true>
606 constexpr tuple(const _Elements&... __elements)
607 : _Inherited(__elements...) { }
608
609 template<typename _Dummy = void,
610 typename enable_if<
611 _TCC<_Dummy>::template
612 _ConstructibleTuple<_Elements...>()
613 && !_TCC<_Dummy>::template
614 _ImplicitlyConvertibleTuple<_Elements...>()
615 && (sizeof...(_Elements) >= 1),
616 bool>::type=false>
617 explicit constexpr tuple(const _Elements&... __elements)
618 : _Inherited(__elements...) { }
619
620 // Shortcut for the cases where constructors taking _UElements...
621 // need to be constrained.
622 template<typename... _UElements> using _TMC =
623 _TC<(sizeof...(_Elements) == sizeof...(_UElements))
624 && (_TC<(sizeof...(_UElements)==1), _Elements...>::
625 template _NotSameTuple<_UElements...>()),
626 _Elements...>;
627
628 // Shortcut for the cases where constructors taking tuple<_UElements...>
629 // need to be constrained.
630 template<typename... _UElements> using _TMCT =
631 _TC<(sizeof...(_Elements) == sizeof...(_UElements))
632 && !is_same<tuple<_Elements...>,
633 tuple<_UElements...>>::value,
634 _Elements...>;
635
636 template<typename... _UElements, typename
637 enable_if<
638 _TMC<_UElements...>::template
639 _MoveConstructibleTuple<_UElements...>()
640 && _TMC<_UElements...>::template
641 _ImplicitlyMoveConvertibleTuple<_UElements...>()
642 && (sizeof...(_Elements) >= 1),
643 bool>::type=true>
644 constexpr tuple(_UElements&&... __elements)
645 : _Inherited(std::forward<_UElements>(__elements)...) { }
646
647 template<typename... _UElements, typename
648 enable_if<
649 _TMC<_UElements...>::template
650 _MoveConstructibleTuple<_UElements...>()
651 && !_TMC<_UElements...>::template
652 _ImplicitlyMoveConvertibleTuple<_UElements...>()
653 && (sizeof...(_Elements) >= 1),
654 bool>::type=false>
655 explicit constexpr tuple(_UElements&&... __elements)
656 : _Inherited(std::forward<_UElements>(__elements)...) { }
657
658 constexpr tuple(const tuple&) = default;
659
660 constexpr tuple(tuple&&) = default;
661
662 // Shortcut for the cases where constructors taking tuples
663 // must avoid creating temporaries.
664 template<typename _Dummy> using _TNTC =
665 _TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1,
666 _Elements...>;
667
668 template<typename... _UElements, typename _Dummy = void, typename
669 enable_if<_TMCT<_UElements...>::template
670 _ConstructibleTuple<_UElements...>()
671 && _TMCT<_UElements...>::template
672 _ImplicitlyConvertibleTuple<_UElements...>()
673 && _TNTC<_Dummy>::template
674 _NonNestedTuple<const tuple<_UElements...>&>(),
675 bool>::type=true>
676 constexpr tuple(const tuple<_UElements...>& __in)
677 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
678 { }
679
680 template<typename... _UElements, typename _Dummy = void, typename
681 enable_if<_TMCT<_UElements...>::template
682 _ConstructibleTuple<_UElements...>()
683 && !_TMCT<_UElements...>::template
684 _ImplicitlyConvertibleTuple<_UElements...>()
685 && _TNTC<_Dummy>::template
686 _NonNestedTuple<const tuple<_UElements...>&>(),
687 bool>::type=false>
688 explicit constexpr tuple(const tuple<_UElements...>& __in)
689 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
690 { }
691
692 template<typename... _UElements, typename _Dummy = void, typename
693 enable_if<_TMCT<_UElements...>::template
694 _MoveConstructibleTuple<_UElements...>()
695 && _TMCT<_UElements...>::template
696 _ImplicitlyMoveConvertibleTuple<_UElements...>()
697 && _TNTC<_Dummy>::template
698 _NonNestedTuple<tuple<_UElements...>&&>(),
699 bool>::type=true>
700 constexpr tuple(tuple<_UElements...>&& __in)
701 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
702
703 template<typename... _UElements, typename _Dummy = void, typename
704 enable_if<_TMCT<_UElements...>::template
705 _MoveConstructibleTuple<_UElements...>()
706 && !_TMCT<_UElements...>::template
707 _ImplicitlyMoveConvertibleTuple<_UElements...>()
708 && _TNTC<_Dummy>::template
709 _NonNestedTuple<tuple<_UElements...>&&>(),
710 bool>::type=false>
711 explicit constexpr tuple(tuple<_UElements...>&& __in)
712 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
713
714 // Allocator-extended constructors.
715
716 template<typename _Alloc>
717 tuple(allocator_arg_t __tag, const _Alloc& __a)
718 : _Inherited(__tag, __a) { }
719
720 template<typename _Alloc, typename _Dummy = void,
721 typename enable_if<
722 _TCC<_Dummy>::template
723 _ConstructibleTuple<_Elements...>()
724 && _TCC<_Dummy>::template
725 _ImplicitlyConvertibleTuple<_Elements...>(),
726 bool>::type=true>
727 tuple(allocator_arg_t __tag, const _Alloc& __a,
728 const _Elements&... __elements)
729 : _Inherited(__tag, __a, __elements...) { }
730
731 template<typename _Alloc, typename _Dummy = void,
732 typename enable_if<
733 _TCC<_Dummy>::template
734 _ConstructibleTuple<_Elements...>()
735 && !_TCC<_Dummy>::template
736 _ImplicitlyConvertibleTuple<_Elements...>(),
737 bool>::type=false>
738 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
739 const _Elements&... __elements)
740 : _Inherited(__tag, __a, __elements...) { }
741
742 template<typename _Alloc, typename... _UElements, typename
743 enable_if<_TMC<_UElements...>::template
744 _MoveConstructibleTuple<_UElements...>()
745 && _TMC<_UElements...>::template
746 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
747 bool>::type=true>
748 tuple(allocator_arg_t __tag, const _Alloc& __a,
749 _UElements&&... __elements)
750 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
751 { }
752
753 template<typename _Alloc, typename... _UElements, typename
754 enable_if<_TMC<_UElements...>::template
755 _MoveConstructibleTuple<_UElements...>()
756 && !_TMC<_UElements...>::template
757 _ImplicitlyMoveConvertibleTuple<_UElements...>(),
758 bool>::type=false>
759 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
760 _UElements&&... __elements)
761 : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
762 { }
763
764 template<typename _Alloc>
765 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
766 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
767
768 template<typename _Alloc>
769 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
770 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
771
772 template<typename _Alloc, typename _Dummy = void,
773 typename... _UElements, typename
774 enable_if<_TMCT<_UElements...>::template
775 _ConstructibleTuple<_UElements...>()
776 && _TMCT<_UElements...>::template
777 _ImplicitlyConvertibleTuple<_UElements...>()
778 && _TNTC<_Dummy>::template
779 _NonNestedTuple<tuple<_UElements...>&&>(),
780 bool>::type=true>
781 tuple(allocator_arg_t __tag, const _Alloc& __a,
782 const tuple<_UElements...>& __in)
783 : _Inherited(__tag, __a,
784 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
785 { }
786
787 template<typename _Alloc, typename _Dummy = void,
788 typename... _UElements, typename
789 enable_if<_TMCT<_UElements...>::template
790 _ConstructibleTuple<_UElements...>()
791 && !_TMCT<_UElements...>::template
792 _ImplicitlyConvertibleTuple<_UElements...>()
793 && _TNTC<_Dummy>::template
794 _NonNestedTuple<tuple<_UElements...>&&>(),
795 bool>::type=false>
796 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
797 const tuple<_UElements...>& __in)
798 : _Inherited(__tag, __a,
799 static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
800 { }
801
802 template<typename _Alloc, typename _Dummy = void,
803 typename... _UElements, typename
804 enable_if<_TMCT<_UElements...>::template
805 _MoveConstructibleTuple<_UElements...>()
806 && _TMCT<_UElements...>::template
807 _ImplicitlyMoveConvertibleTuple<_UElements...>()
808 && _TNTC<_Dummy>::template
809 _NonNestedTuple<tuple<_UElements...>&&>(),
810 bool>::type=true>
811 tuple(allocator_arg_t __tag, const _Alloc& __a,
812 tuple<_UElements...>&& __in)
813 : _Inherited(__tag, __a,
814 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
815 { }
816
817 template<typename _Alloc, typename _Dummy = void,
818 typename... _UElements, typename
819 enable_if<_TMCT<_UElements...>::template
820 _MoveConstructibleTuple<_UElements...>()
821 && !_TMCT<_UElements...>::template
822 _ImplicitlyMoveConvertibleTuple<_UElements...>()
823 && _TNTC<_Dummy>::template
824 _NonNestedTuple<tuple<_UElements...>&&>(),
825 bool>::type=false>
826 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
827 tuple<_UElements...>&& __in)
828 : _Inherited(__tag, __a,
829 static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
830 { }
831
832 tuple&
833 operator=(const tuple& __in)
834 {
835 static_cast<_Inherited&>(*this) = __in;
836 return *this;
837 }
838
839 tuple&
840 operator=(tuple&& __in)
841 noexcept(is_nothrow_move_assignable<_Inherited>::value)
842 {
843 static_cast<_Inherited&>(*this) = std::move(__in);
844 return *this;
845 }
846
847 template<typename... _UElements, typename = typename
848 enable_if<sizeof...(_UElements)
849 == sizeof...(_Elements)>::type>
850 tuple&
851 operator=(const tuple<_UElements...>& __in)
852 {
853 static_cast<_Inherited&>(*this) = __in;
854 return *this;
855 }
856
857 template<typename... _UElements, typename = typename
858 enable_if<sizeof...(_UElements)
859 == sizeof...(_Elements)>::type>
860 tuple&
861 operator=(tuple<_UElements...>&& __in)
862 {
863 static_cast<_Inherited&>(*this) = std::move(__in);
864 return *this;
865 }
866
867 void
868 swap(tuple& __in)
869 noexcept(noexcept(__in._M_swap(__in)))
870 { _Inherited::_M_swap(__in); }
871 };
872
873 // Explicit specialization, zero-element tuple.
874 template<>
875 class tuple<>
876 {
877 public:
878 void swap(tuple&) noexcept { /* no-op */ }
879 // We need the default since we're going to define no-op
880 // allocator constructors.
881 tuple() = default;
882 // No-op allocator constructors.
883 template<typename _Alloc>
884 tuple(allocator_arg_t, const _Alloc&) { }
885 template<typename _Alloc>
886 tuple(allocator_arg_t, const _Alloc&, const tuple&) { }
887 };
888
889 /// Partial specialization, 2-element tuple.
890 /// Includes construction and assignment from a pair.
891 template<typename _T1, typename _T2>
892 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
893 {
894 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
895
896 public:
897 template <typename _U1 = _T1,
898 typename _U2 = _T2,
899 typename enable_if<__and_<
900 __is_implicitly_default_constructible<_U1>,
901 __is_implicitly_default_constructible<_U2>>
902 ::value, bool>::type = true>
903
904 constexpr tuple()
905 : _Inherited() { }
906
907 template <typename _U1 = _T1,
908 typename _U2 = _T2,
909 typename enable_if<
910 __and_<
911 is_default_constructible<_U1>,
912 is_default_constructible<_U2>,
913 __not_<
914 __and_<__is_implicitly_default_constructible<_U1>,
915 __is_implicitly_default_constructible<_U2>>>>
916 ::value, bool>::type = false>
917
918 explicit constexpr tuple()
919 : _Inherited() { }
920
921 // Shortcut for the cases where constructors taking _T1, _T2
922 // need to be constrained.
923 template<typename _Dummy> using _TCC =
924 _TC<is_same<_Dummy, void>::value, _T1, _T2>;
925
926 template<typename _Dummy = void, typename
927 enable_if<_TCC<_Dummy>::template
928 _ConstructibleTuple<_T1, _T2>()
929 && _TCC<_Dummy>::template
930 _ImplicitlyConvertibleTuple<_T1, _T2>(),
931 bool>::type = true>
932 constexpr tuple(const _T1& __a1, const _T2& __a2)
933 : _Inherited(__a1, __a2) { }
934
935 template<typename _Dummy = void, typename
936 enable_if<_TCC<_Dummy>::template
937 _ConstructibleTuple<_T1, _T2>()
938 && !_TCC<_Dummy>::template
939 _ImplicitlyConvertibleTuple<_T1, _T2>(),
940 bool>::type = false>
941 explicit constexpr tuple(const _T1& __a1, const _T2& __a2)
942 : _Inherited(__a1, __a2) { }
943
944 // Shortcut for the cases where constructors taking _U1, _U2
945 // need to be constrained.
946 using _TMC = _TC<true, _T1, _T2>;
947
948 template<typename _U1, typename _U2, typename
949 enable_if<_TMC::template
950 _MoveConstructibleTuple<_U1, _U2>()
951 && _TMC::template
952 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
953 bool>::type = true>
954 constexpr tuple(_U1&& __a1, _U2&& __a2)
955 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
956
957 template<typename _U1, typename _U2, typename
958 enable_if<_TMC::template
959 _MoveConstructibleTuple<_U1, _U2>()
960 && !_TMC::template
961 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
962 bool>::type = false>
963 explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
964 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
965
966 constexpr tuple(const tuple&) = default;
967
968 constexpr tuple(tuple&&) = default;
969
970 template<typename _U1, typename _U2, typename
971 enable_if<_TMC::template
972 _ConstructibleTuple<_U1, _U2>()
973 && _TMC::template
974 _ImplicitlyConvertibleTuple<_U1, _U2>(),
975 bool>::type = true>
976 constexpr tuple(const tuple<_U1, _U2>& __in)
977 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
978
979 template<typename _U1, typename _U2, typename
980 enable_if<_TMC::template
981 _ConstructibleTuple<_U1, _U2>()
982 && !_TMC::template
983 _ImplicitlyConvertibleTuple<_U1, _U2>(),
984 bool>::type = false>
985 explicit constexpr tuple(const tuple<_U1, _U2>& __in)
986 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
987
988 template<typename _U1, typename _U2, typename
989 enable_if<_TMC::template
990 _MoveConstructibleTuple<_U1, _U2>()
991 && _TMC::template
992 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
993 bool>::type = true>
994 constexpr tuple(tuple<_U1, _U2>&& __in)
995 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
996
997 template<typename _U1, typename _U2, typename
998 enable_if<_TMC::template
999 _MoveConstructibleTuple<_U1, _U2>()
1000 && !_TMC::template
1001 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1002 bool>::type = false>
1003 explicit constexpr tuple(tuple<_U1, _U2>&& __in)
1004 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
1005
1006 template<typename _U1, typename _U2, typename
1007 enable_if<_TMC::template
1008 _ConstructibleTuple<_U1, _U2>()
1009 && _TMC::template
1010 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1011 bool>::type = true>
1012 constexpr tuple(const pair<_U1, _U2>& __in)
1013 : _Inherited(__in.first, __in.second) { }
1014
1015 template<typename _U1, typename _U2, typename
1016 enable_if<_TMC::template
1017 _ConstructibleTuple<_U1, _U2>()
1018 && !_TMC::template
1019 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1020 bool>::type = false>
1021 explicit constexpr tuple(const pair<_U1, _U2>& __in)
1022 : _Inherited(__in.first, __in.second) { }
1023
1024 template<typename _U1, typename _U2, typename
1025 enable_if<_TMC::template
1026 _MoveConstructibleTuple<_U1, _U2>()
1027 && _TMC::template
1028 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1029 bool>::type = true>
1030 constexpr tuple(pair<_U1, _U2>&& __in)
1031 : _Inherited(std::forward<_U1>(__in.first),
1032 std::forward<_U2>(__in.second)) { }
1033
1034 template<typename _U1, typename _U2, typename
1035 enable_if<_TMC::template
1036 _MoveConstructibleTuple<_U1, _U2>()
1037 && !_TMC::template
1038 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1039 bool>::type = false>
1040 explicit constexpr tuple(pair<_U1, _U2>&& __in)
1041 : _Inherited(std::forward<_U1>(__in.first),
1042 std::forward<_U2>(__in.second)) { }
1043
1044 // Allocator-extended constructors.
1045
1046 template<typename _Alloc>
1047 tuple(allocator_arg_t __tag, const _Alloc& __a)
1048 : _Inherited(__tag, __a) { }
1049
1050 template<typename _Alloc, typename _Dummy = void,
1051 typename enable_if<
1052 _TCC<_Dummy>::template
1053 _ConstructibleTuple<_T1, _T2>()
1054 && _TCC<_Dummy>::template
1055 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1056 bool>::type=true>
1057
1058 tuple(allocator_arg_t __tag, const _Alloc& __a,
1059 const _T1& __a1, const _T2& __a2)
1060 : _Inherited(__tag, __a, __a1, __a2) { }
1061
1062 template<typename _Alloc, typename _Dummy = void,
1063 typename enable_if<
1064 _TCC<_Dummy>::template
1065 _ConstructibleTuple<_T1, _T2>()
1066 && !_TCC<_Dummy>::template
1067 _ImplicitlyConvertibleTuple<_T1, _T2>(),
1068 bool>::type=false>
1069
1070 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1071 const _T1& __a1, const _T2& __a2)
1072 : _Inherited(__tag, __a, __a1, __a2) { }
1073
1074 template<typename _Alloc, typename _U1, typename _U2, typename
1075 enable_if<_TMC::template
1076 _MoveConstructibleTuple<_U1, _U2>()
1077 && _TMC::template
1078 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1079 bool>::type = true>
1080 tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
1081 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1082 std::forward<_U2>(__a2)) { }
1083
1084 template<typename _Alloc, typename _U1, typename _U2, typename
1085 enable_if<_TMC::template
1086 _MoveConstructibleTuple<_U1, _U2>()
1087 && !_TMC::template
1088 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1089 bool>::type = false>
1090 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1091 _U1&& __a1, _U2&& __a2)
1092 : _Inherited(__tag, __a, std::forward<_U1>(__a1),
1093 std::forward<_U2>(__a2)) { }
1094
1095 template<typename _Alloc>
1096 tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
1097 : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { }
1098
1099 template<typename _Alloc>
1100 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
1101 : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
1102
1103 template<typename _Alloc, typename _U1, typename _U2, typename
1104 enable_if<_TMC::template
1105 _ConstructibleTuple<_U1, _U2>()
1106 && _TMC::template
1107 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1108 bool>::type = true>
1109 tuple(allocator_arg_t __tag, const _Alloc& __a,
1110 const tuple<_U1, _U2>& __in)
1111 : _Inherited(__tag, __a,
1112 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1113 { }
1114
1115 template<typename _Alloc, typename _U1, typename _U2, typename
1116 enable_if<_TMC::template
1117 _ConstructibleTuple<_U1, _U2>()
1118 && !_TMC::template
1119 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1120 bool>::type = false>
1121 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1122 const tuple<_U1, _U2>& __in)
1123 : _Inherited(__tag, __a,
1124 static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
1125 { }
1126
1127 template<typename _Alloc, typename _U1, typename _U2, typename
1128 enable_if<_TMC::template
1129 _MoveConstructibleTuple<_U1, _U2>()
1130 && _TMC::template
1131 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1132 bool>::type = true>
1133 tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
1134 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1135 { }
1136
1137 template<typename _Alloc, typename _U1, typename _U2, typename
1138 enable_if<_TMC::template
1139 _MoveConstructibleTuple<_U1, _U2>()
1140 && !_TMC::template
1141 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1142 bool>::type = false>
1143 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1144 tuple<_U1, _U2>&& __in)
1145 : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
1146 { }
1147
1148 template<typename _Alloc, typename _U1, typename _U2, typename
1149 enable_if<_TMC::template
1150 _ConstructibleTuple<_U1, _U2>()
1151 && _TMC::template
1152 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1153 bool>::type = true>
1154 tuple(allocator_arg_t __tag, const _Alloc& __a,
1155 const pair<_U1, _U2>& __in)
1156 : _Inherited(__tag, __a, __in.first, __in.second) { }
1157
1158 template<typename _Alloc, typename _U1, typename _U2, typename
1159 enable_if<_TMC::template
1160 _ConstructibleTuple<_U1, _U2>()
1161 && !_TMC::template
1162 _ImplicitlyConvertibleTuple<_U1, _U2>(),
1163 bool>::type = false>
1164 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1165 const pair<_U1, _U2>& __in)
1166 : _Inherited(__tag, __a, __in.first, __in.second) { }
1167
1168 template<typename _Alloc, typename _U1, typename _U2, typename
1169 enable_if<_TMC::template
1170 _MoveConstructibleTuple<_U1, _U2>()
1171 && _TMC::template
1172 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1173 bool>::type = true>
1174 tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
1175 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1176 std::forward<_U2>(__in.second)) { }
1177
1178 template<typename _Alloc, typename _U1, typename _U2, typename
1179 enable_if<_TMC::template
1180 _MoveConstructibleTuple<_U1, _U2>()
1181 && !_TMC::template
1182 _ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
1183 bool>::type = false>
1184 explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
1185 pair<_U1, _U2>&& __in)
1186 : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
1187 std::forward<_U2>(__in.second)) { }
1188
1189 tuple&
1190 operator=(const tuple& __in)
1191 {
1192 static_cast<_Inherited&>(*this) = __in;
1193 return *this;
1194 }
1195
1196 tuple&
1197 operator=(tuple&& __in)
1198 noexcept(is_nothrow_move_assignable<_Inherited>::value)
1199 {
1200 static_cast<_Inherited&>(*this) = std::move(__in);
1201 return *this;
1202 }
1203
1204 template<typename _U1, typename _U2>
1205 tuple&
1206 operator=(const tuple<_U1, _U2>& __in)
1207 {
1208 static_cast<_Inherited&>(*this) = __in;
1209 return *this;
1210 }
1211
1212 template<typename _U1, typename _U2>
1213 tuple&
1214 operator=(tuple<_U1, _U2>&& __in)
1215 {
1216 static_cast<_Inherited&>(*this) = std::move(__in);
1217 return *this;
1218 }
1219
1220 template<typename _U1, typename _U2>
1221 tuple&
1222 operator=(const pair<_U1, _U2>& __in)
1223 {
1224 this->_M_head(*this) = __in.first;
1225 this->_M_tail(*this)._M_head(*this) = __in.second;
1226 return *this;
1227 }
1228
1229 template<typename _U1, typename _U2>
1230 tuple&
1231 operator=(pair<_U1, _U2>&& __in)
1232 {
1233 this->_M_head(*this) = std::forward<_U1>(__in.first);
1234 this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
1235 return *this;
1236 }
1237
1238 void
1239 swap(tuple& __in)
1240 noexcept(noexcept(__in._M_swap(__in)))
1241 { _Inherited::_M_swap(__in); }
1242 };
1243
1244
1245 /**
1246 * Recursive case for tuple_element: strip off the first element in
1247 * the tuple and retrieve the (i-1)th element of the remaining tuple.
1248 */
1249 template<std::size_t __i, typename _Head, typename... _Tail>
1250 struct tuple_element<__i, tuple<_Head, _Tail...> >
1251 : tuple_element<__i - 1, tuple<_Tail...> > { };
1252
1253 /**
1254 * Basis case for tuple_element: The first element is the one we're seeking.
1255 */
1256 template<typename _Head, typename... _Tail>
1257 struct tuple_element<0, tuple<_Head, _Tail...> >
1258 {
1259 typedef _Head type;
1260 };
1261
1262 /// class tuple_size
1263 template<typename... _Elements>
1264 struct tuple_size<tuple<_Elements...>>
1265 : public integral_constant<std::size_t, sizeof...(_Elements)> { };
1266
1267 template<std::size_t __i, typename _Head, typename... _Tail>
1268 constexpr _Head&
1269 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1270 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1271
1272 template<std::size_t __i, typename _Head, typename... _Tail>
1273 constexpr const _Head&
1274 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1275 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1276
1277 /// Return a reference to the ith element of a tuple.
1278 template<std::size_t __i, typename... _Elements>
1279 constexpr __tuple_element_t<__i, tuple<_Elements...>>&
1280 get(tuple<_Elements...>& __t) noexcept
1281 { return std::__get_helper<__i>(__t); }
1282
1283 /// Return a const reference to the ith element of a const tuple.
1284 template<std::size_t __i, typename... _Elements>
1285 constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
1286 get(const tuple<_Elements...>& __t) noexcept
1287 { return std::__get_helper<__i>(__t); }
1288
1289 /// Return an rvalue reference to the ith element of a tuple rvalue.
1290 template<std::size_t __i, typename... _Elements>
1291 constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
1292 get(tuple<_Elements...>&& __t) noexcept
1293 {
1294 typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type;
1295 return std::forward<__element_type&&>(std::get<__i>(__t));
1296 }
1297
1298 #if __cplusplus > 201103L
1299
1300 #define __cpp_lib_tuples_by_type 201304
1301
1302 template<typename _Head, size_t __i, typename... _Tail>
1303 constexpr _Head&
1304 __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1305 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1306
1307 template<typename _Head, size_t __i, typename... _Tail>
1308 constexpr const _Head&
1309 __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
1310 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
1311
1312 /// Return a reference to the unique element of type _Tp of a tuple.
1313 template <typename _Tp, typename... _Types>
1314 constexpr _Tp&
1315 get(tuple<_Types...>& __t) noexcept
1316 { return std::__get_helper2<_Tp>(__t); }
1317
1318 /// Return a reference to the unique element of type _Tp of a tuple rvalue.
1319 template <typename _Tp, typename... _Types>
1320 constexpr _Tp&&
1321 get(tuple<_Types...>&& __t) noexcept
1322 { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
1323
1324 /// Return a const reference to the unique element of type _Tp of a tuple.
1325 template <typename _Tp, typename... _Types>
1326 constexpr const _Tp&
1327 get(const tuple<_Types...>& __t) noexcept
1328 { return std::__get_helper2<_Tp>(__t); }
1329 #endif
1330
1331 // This class performs the comparison operations on tuples
1332 template<typename _Tp, typename _Up, size_t __i, size_t __size>
1333 struct __tuple_compare
1334 {
1335 static constexpr bool
1336 __eq(const _Tp& __t, const _Up& __u)
1337 {
1338 return bool(std::get<__i>(__t) == std::get<__i>(__u))
1339 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u);
1340 }
1341
1342 static constexpr bool
1343 __less(const _Tp& __t, const _Up& __u)
1344 {
1345 return bool(std::get<__i>(__t) < std::get<__i>(__u))
1346 || (!bool(std::get<__i>(__u) < std::get<__i>(__t))
1347 && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u));
1348 }
1349 };
1350
1351 template<typename _Tp, typename _Up, size_t __size>
1352 struct __tuple_compare<_Tp, _Up, __size, __size>
1353 {
1354 static constexpr bool
1355 __eq(const _Tp&, const _Up&) { return true; }
1356
1357 static constexpr bool
1358 __less(const _Tp&, const _Up&) { return false; }
1359 };
1360
1361 template<typename... _TElements, typename... _UElements>
1362 constexpr bool
1363 operator==(const tuple<_TElements...>& __t,
1364 const tuple<_UElements...>& __u)
1365 {
1366 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1367 "tuple objects can only be compared if they have equal sizes.");
1368 using __compare = __tuple_compare<tuple<_TElements...>,
1369 tuple<_UElements...>,
1370 0, sizeof...(_TElements)>;
1371 return __compare::__eq(__t, __u);
1372 }
1373
1374 template<typename... _TElements, typename... _UElements>
1375 constexpr bool
1376 operator<(const tuple<_TElements...>& __t,
1377 const tuple<_UElements...>& __u)
1378 {
1379 static_assert(sizeof...(_TElements) == sizeof...(_UElements),
1380 "tuple objects can only be compared if they have equal sizes.");
1381 using __compare = __tuple_compare<tuple<_TElements...>,
1382 tuple<_UElements...>,
1383 0, sizeof...(_TElements)>;
1384 return __compare::__less(__t, __u);
1385 }
1386
1387 template<typename... _TElements, typename... _UElements>
1388 constexpr bool
1389 operator!=(const tuple<_TElements...>& __t,
1390 const tuple<_UElements...>& __u)
1391 { return !(__t == __u); }
1392
1393 template<typename... _TElements, typename... _UElements>
1394 constexpr bool
1395 operator>(const tuple<_TElements...>& __t,
1396 const tuple<_UElements...>& __u)
1397 { return __u < __t; }
1398
1399 template<typename... _TElements, typename... _UElements>
1400 constexpr bool
1401 operator<=(const tuple<_TElements...>& __t,
1402 const tuple<_UElements...>& __u)
1403 { return !(__u < __t); }
1404
1405 template<typename... _TElements, typename... _UElements>
1406 constexpr bool
1407 operator>=(const tuple<_TElements...>& __t,
1408 const tuple<_UElements...>& __u)
1409 { return !(__t < __u); }
1410
1411 // NB: DR 705.
1412 template<typename... _Elements>
1413 constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
1414 make_tuple(_Elements&&... __args)
1415 {
1416 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
1417 __result_type;
1418 return __result_type(std::forward<_Elements>(__args)...);
1419 }
1420
1421 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1422 // 2275. Why is forward_as_tuple not constexpr?
1423 template<typename... _Elements>
1424 constexpr tuple<_Elements&&...>
1425 forward_as_tuple(_Elements&&... __args) noexcept
1426 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
1427
1428 template<typename... _Tps>
1429 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
1430 { };
1431
1432 // Internal type trait that allows us to sfinae-protect tuple_cat.
1433 template<typename _Tp>
1434 struct __is_tuple_like
1435 : public __is_tuple_like_impl<typename std::remove_cv
1436 <typename std::remove_reference<_Tp>::type>::type>::type
1437 { };
1438
1439 template<size_t, typename, typename, size_t>
1440 struct __make_tuple_impl;
1441
1442 template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm>
1443 struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
1444 : __make_tuple_impl<_Idx + 1,
1445 tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>,
1446 _Tuple, _Nm>
1447 { };
1448
1449 template<std::size_t _Nm, typename _Tuple, typename... _Tp>
1450 struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
1451 {
1452 typedef tuple<_Tp...> __type;
1453 };
1454
1455 template<typename _Tuple>
1456 struct __do_make_tuple
1457 : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
1458 { };
1459
1460 // Returns the std::tuple equivalent of a tuple-like type.
1461 template<typename _Tuple>
1462 struct __make_tuple
1463 : public __do_make_tuple<typename std::remove_cv
1464 <typename std::remove_reference<_Tuple>::type>::type>
1465 { };
1466
1467 // Combines several std::tuple's into a single one.
1468 template<typename...>
1469 struct __combine_tuples;
1470
1471 template<>
1472 struct __combine_tuples<>
1473 {
1474 typedef tuple<> __type;
1475 };
1476
1477 template<typename... _Ts>
1478 struct __combine_tuples<tuple<_Ts...>>
1479 {
1480 typedef tuple<_Ts...> __type;
1481 };
1482
1483 template<typename... _T1s, typename... _T2s, typename... _Rem>
1484 struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...>
1485 {
1486 typedef typename __combine_tuples<tuple<_T1s..., _T2s...>,
1487 _Rem...>::__type __type;
1488 };
1489
1490 // Computes the result type of tuple_cat given a set of tuple-like types.
1491 template<typename... _Tpls>
1492 struct __tuple_cat_result
1493 {
1494 typedef typename __combine_tuples
1495 <typename __make_tuple<_Tpls>::__type...>::__type __type;
1496 };
1497
1498 // Helper to determine the index set for the first tuple-like
1499 // type of a given set.
1500 template<typename...>
1501 struct __make_1st_indices;
1502
1503 template<>
1504 struct __make_1st_indices<>
1505 {
1506 typedef std::_Index_tuple<> __type;
1507 };
1508
1509 template<typename _Tp, typename... _Tpls>
1510 struct __make_1st_indices<_Tp, _Tpls...>
1511 {
1512 typedef typename std::_Build_index_tuple<std::tuple_size<
1513 typename std::remove_reference<_Tp>::type>::value>::__type __type;
1514 };
1515
1516 // Performs the actual concatenation by step-wise expanding tuple-like
1517 // objects into the elements, which are finally forwarded into the
1518 // result tuple.
1519 template<typename _Ret, typename _Indices, typename... _Tpls>
1520 struct __tuple_concater;
1521
1522 template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
1523 struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
1524 {
1525 template<typename... _Us>
1526 static constexpr _Ret
1527 _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1528 {
1529 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1530 typedef __tuple_concater<_Ret, __idx, _Tpls...> __next;
1531 return __next::_S_do(std::forward<_Tpls>(__tps)...,
1532 std::forward<_Us>(__us)...,
1533 std::get<_Is>(std::forward<_Tp>(__tp))...);
1534 }
1535 };
1536
1537 template<typename _Ret>
1538 struct __tuple_concater<_Ret, std::_Index_tuple<>>
1539 {
1540 template<typename... _Us>
1541 static constexpr _Ret
1542 _S_do(_Us&&... __us)
1543 {
1544 return _Ret(std::forward<_Us>(__us)...);
1545 }
1546 };
1547
1548 /// tuple_cat
1549 template<typename... _Tpls, typename = typename
1550 enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1551 constexpr auto
1552 tuple_cat(_Tpls&&... __tpls)
1553 -> typename __tuple_cat_result<_Tpls...>::__type
1554 {
1555 typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1556 typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1557 typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1558 return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1559 }
1560
1561 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1562 // 2301. Why is tie not constexpr?
1563 /// tie
1564 template<typename... _Elements>
1565 constexpr tuple<_Elements&...>
1566 tie(_Elements&... __args) noexcept
1567 { return tuple<_Elements&...>(__args...); }
1568
1569 /// swap
1570 template<typename... _Elements>
1571 inline void
1572 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1573 noexcept(noexcept(__x.swap(__y)))
1574 { __x.swap(__y); }
1575
1576 // A class (and instance) which can be used in 'tie' when an element
1577 // of a tuple is not required
1578 struct _Swallow_assign
1579 {
1580 template<class _Tp>
1581 const _Swallow_assign&
1582 operator=(const _Tp&) const
1583 { return *this; }
1584 };
1585
1586 const _Swallow_assign ignore{};
1587
1588 /// Partial specialization for tuples
1589 template<typename... _Types, typename _Alloc>
1590 struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { };
1591
1592 // See stl_pair.h...
1593 template<class _T1, class _T2>
1594 template<typename... _Args1, typename... _Args2>
1595 inline
1596 pair<_T1, _T2>::
1597 pair(piecewise_construct_t,
1598 tuple<_Args1...> __first, tuple<_Args2...> __second)
1599 : pair(__first, __second,
1600 typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
1601 typename _Build_index_tuple<sizeof...(_Args2)>::__type())
1602 { }
1603
1604 template<class _T1, class _T2>
1605 template<typename... _Args1, std::size_t... _Indexes1,
1606 typename... _Args2, std::size_t... _Indexes2>
1607 inline
1608 pair<_T1, _T2>::
1609 pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1610 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1611 : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1612 second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1613 { }
1614
1615 /// @}
1616
1617 _GLIBCXX_END_NAMESPACE_VERSION
1618 } // namespace std
1619
1620 #endif // C++11
1621
1622 #endif // _GLIBCXX_TUPLE