]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/std/tuple
tuple: Use noexcept where appropriate.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / tuple
1 // <tuple> -*- C++ -*-
2
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011 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 #ifndef __GXX_EXPERIMENTAL_CXX0X__
35 # include <bits/c++0x_warning.h>
36 #else
37
38 #include <utility>
39
40 namespace std _GLIBCXX_VISIBILITY(default)
41 {
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43
44 // Adds a const reference to a non-reference type.
45 template<typename _Tp>
46 struct __add_c_ref
47 { typedef const _Tp& type; };
48
49 template<typename _Tp>
50 struct __add_c_ref<_Tp&>
51 { typedef _Tp& type; };
52
53 // Adds a reference to a non-reference type.
54 template<typename _Tp>
55 struct __add_ref
56 { typedef _Tp& type; };
57
58 template<typename _Tp>
59 struct __add_ref<_Tp&>
60 { typedef _Tp& type; };
61
62 // Adds an rvalue reference to a non-reference type.
63 template<typename _Tp>
64 struct __add_r_ref
65 { typedef _Tp&& type; };
66
67 template<typename _Tp>
68 struct __add_r_ref<_Tp&>
69 { typedef _Tp& type; };
70
71 template<std::size_t _Idx, typename _Head, bool _IsEmpty>
72 struct _Head_base;
73
74 template<std::size_t _Idx, typename _Head>
75 struct _Head_base<_Idx, _Head, true>
76 : public _Head
77 {
78 constexpr _Head_base()
79 : _Head() { }
80
81 constexpr _Head_base(const _Head& __h)
82 : _Head(__h) { }
83
84 template<typename _UHead>
85 _Head_base(_UHead&& __h)
86 : _Head(std::forward<_UHead>(__h)) { }
87
88 _Head& _M_head() { return *this; }
89 const _Head& _M_head() const { return *this; }
90 };
91
92 template<std::size_t _Idx, typename _Head>
93 struct _Head_base<_Idx, _Head, false>
94 {
95 constexpr _Head_base()
96 : _M_head_impl() { }
97
98 constexpr _Head_base(const _Head& __h)
99 : _M_head_impl(__h) { }
100
101 template<typename _UHead>
102 _Head_base(_UHead&& __h)
103 : _M_head_impl(std::forward<_UHead>(__h)) { }
104
105 _Head& _M_head() { return _M_head_impl; }
106 const _Head& _M_head() const { return _M_head_impl; }
107
108 _Head _M_head_impl;
109 };
110
111 /**
112 * Contains the actual implementation of the @c tuple template, stored
113 * as a recursive inheritance hierarchy from the first element (most
114 * derived class) to the last (least derived class). The @c Idx
115 * parameter gives the 0-based index of the element stored at this
116 * point in the hierarchy; we use it to implement a constant-time
117 * get() operation.
118 */
119 template<std::size_t _Idx, typename... _Elements>
120 struct _Tuple_impl;
121
122 /**
123 * Zero-element tuple implementation. This is the basis case for the
124 * inheritance recursion.
125 */
126 template<std::size_t _Idx>
127 struct _Tuple_impl<_Idx>
128 {
129 template<std::size_t, typename...> friend class _Tuple_impl;
130
131 protected:
132 void _M_swap(_Tuple_impl&) noexcept { /* no-op */ }
133 };
134
135 /**
136 * Recursive tuple implementation. Here we store the @c Head element
137 * and derive from a @c Tuple_impl containing the remaining elements
138 * (which contains the @c Tail).
139 */
140 template<std::size_t _Idx, typename _Head, typename... _Tail>
141 struct _Tuple_impl<_Idx, _Head, _Tail...>
142 : public _Tuple_impl<_Idx + 1, _Tail...>,
143 private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
144 {
145 template<std::size_t, typename...> friend class _Tuple_impl;
146
147 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
148 typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
149
150 _Head& _M_head() { return _Base::_M_head(); }
151 const _Head& _M_head() const { return _Base::_M_head(); }
152
153 _Inherited& _M_tail() { return *this; }
154 const _Inherited& _M_tail() const { return *this; }
155
156 constexpr _Tuple_impl()
157 : _Inherited(), _Base() { }
158
159 explicit
160 constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
161 : _Inherited(__tail...), _Base(__head) { }
162
163 template<typename _UHead, typename... _UTail>
164 explicit
165 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
166 : _Inherited(std::forward<_UTail>(__tail)...),
167 _Base(std::forward<_UHead>(__head)) { }
168
169 constexpr _Tuple_impl(const _Tuple_impl&) = default;
170
171 _Tuple_impl(_Tuple_impl&& __in)
172 : _Inherited(std::move(__in._M_tail())),
173 _Base(std::forward<_Head>(__in._M_head())) { }
174
175 template<typename... _UElements>
176 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
177 : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
178
179 template<typename _UHead, typename... _UTails>
180 _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
181 : _Inherited(std::move(__in._M_tail())),
182 _Base(std::forward<_UHead>(__in._M_head())) { }
183
184 _Tuple_impl&
185 operator=(const _Tuple_impl& __in)
186 {
187 _M_head() = __in._M_head();
188 _M_tail() = __in._M_tail();
189 return *this;
190 }
191
192 _Tuple_impl&
193 operator=(_Tuple_impl&& __in)
194 {
195 _M_head() = std::forward<_Head>(__in._M_head());
196 _M_tail() = std::move(__in._M_tail());
197 return *this;
198 }
199
200 template<typename... _UElements>
201 _Tuple_impl&
202 operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
203 {
204 _M_head() = __in._M_head();
205 _M_tail() = __in._M_tail();
206 return *this;
207 }
208
209 template<typename _UHead, typename... _UTails>
210 _Tuple_impl&
211 operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
212 {
213 _M_head() = std::forward<_UHead>(__in._M_head());
214 _M_tail() = std::move(__in._M_tail());
215 return *this;
216 }
217
218 protected:
219 void
220 _M_swap(_Tuple_impl& __in)
221 noexcept(noexcept(swap(std::declval<_Head&>(),
222 std::declval<_Head&>()))
223 && noexcept(__in._M_tail()._M_swap(__in._M_tail())))
224 {
225 using std::swap;
226 swap(this->_M_head(), __in._M_head());
227 _Inherited::_M_swap(__in._M_tail());
228 }
229 };
230
231 /// tuple
232 template<typename... _Elements>
233 class tuple : public _Tuple_impl<0, _Elements...>
234 {
235 typedef _Tuple_impl<0, _Elements...> _Inherited;
236
237 public:
238 constexpr tuple()
239 : _Inherited() { }
240
241 explicit
242 constexpr tuple(const _Elements&... __elements)
243 : _Inherited(__elements...) { }
244
245 template<typename... _UElements, typename = typename
246 std::enable_if<sizeof...(_UElements)
247 == sizeof...(_Elements)>::type>
248 explicit
249 tuple(_UElements&&... __elements)
250 : _Inherited(std::forward<_UElements>(__elements)...) { }
251
252 constexpr tuple(const tuple&) = default;
253
254 tuple(tuple&& __in)
255 : _Inherited(static_cast<_Inherited&&>(__in)) { }
256
257 template<typename... _UElements, typename = typename
258 std::enable_if<sizeof...(_UElements)
259 == sizeof...(_Elements)>::type>
260 tuple(const tuple<_UElements...>& __in)
261 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
262 { }
263
264 template<typename... _UElements, typename = typename
265 std::enable_if<sizeof...(_UElements)
266 == sizeof...(_Elements)>::type>
267 tuple(tuple<_UElements...>&& __in)
268 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
269
270 tuple&
271 operator=(const tuple& __in)
272 {
273 static_cast<_Inherited&>(*this) = __in;
274 return *this;
275 }
276
277 tuple&
278 operator=(tuple&& __in)
279 {
280 static_cast<_Inherited&>(*this) = std::move(__in);
281 return *this;
282 }
283
284 template<typename... _UElements, typename = typename
285 std::enable_if<sizeof...(_UElements)
286 == sizeof...(_Elements)>::type>
287 tuple&
288 operator=(const tuple<_UElements...>& __in)
289 {
290 static_cast<_Inherited&>(*this) = __in;
291 return *this;
292 }
293
294 template<typename... _UElements, typename = typename
295 std::enable_if<sizeof...(_UElements)
296 == sizeof...(_Elements)>::type>
297 tuple&
298 operator=(tuple<_UElements...>&& __in)
299 {
300 static_cast<_Inherited&>(*this) = std::move(__in);
301 return *this;
302 }
303
304 void
305 swap(tuple& __in)
306 noexcept(noexcept(__in._M_swap(__in)))
307 { _Inherited::_M_swap(__in); }
308 };
309
310 template<>
311 class tuple<>
312 {
313 public:
314 void swap(tuple&) noexcept { /* no-op */ }
315 };
316
317 /// tuple (2-element), with construction and assignment from a pair.
318 template<typename _T1, typename _T2>
319 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
320 {
321 typedef _Tuple_impl<0, _T1, _T2> _Inherited;
322
323 public:
324 constexpr tuple()
325 : _Inherited() { }
326
327 explicit
328 constexpr tuple(const _T1& __a1, const _T2& __a2)
329 : _Inherited(__a1, __a2) { }
330
331 template<typename _U1, typename _U2>
332 explicit
333 tuple(_U1&& __a1, _U2&& __a2)
334 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
335
336 constexpr tuple(const tuple&) = default;
337
338 tuple(tuple&& __in)
339 : _Inherited(static_cast<_Inherited&&>(__in)) { }
340
341 template<typename _U1, typename _U2>
342 tuple(const tuple<_U1, _U2>& __in)
343 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
344
345 template<typename _U1, typename _U2>
346 tuple(tuple<_U1, _U2>&& __in)
347 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
348
349 template<typename _U1, typename _U2>
350 tuple(const pair<_U1, _U2>& __in)
351 : _Inherited(__in.first, __in.second) { }
352
353 template<typename _U1, typename _U2>
354 tuple(pair<_U1, _U2>&& __in)
355 : _Inherited(std::forward<_U1>(__in.first),
356 std::forward<_U2>(__in.second)) { }
357
358 tuple&
359 operator=(const tuple& __in)
360 {
361 static_cast<_Inherited&>(*this) = __in;
362 return *this;
363 }
364
365 tuple&
366 operator=(tuple&& __in)
367 // noexcept has to wait is_nothrow_move_assignable
368 {
369 static_cast<_Inherited&>(*this) = std::move(__in);
370 return *this;
371 }
372
373 template<typename _U1, typename _U2>
374 tuple&
375 operator=(const tuple<_U1, _U2>& __in)
376 {
377 static_cast<_Inherited&>(*this) = __in;
378 return *this;
379 }
380
381 template<typename _U1, typename _U2>
382 tuple&
383 operator=(tuple<_U1, _U2>&& __in)
384 {
385 static_cast<_Inherited&>(*this) = std::move(__in);
386 return *this;
387 }
388
389 template<typename _U1, typename _U2>
390 tuple&
391 operator=(const pair<_U1, _U2>& __in)
392 {
393 this->_M_head() = __in.first;
394 this->_M_tail()._M_head() = __in.second;
395 return *this;
396 }
397
398 template<typename _U1, typename _U2>
399 tuple&
400 operator=(pair<_U1, _U2>&& __in) noexcept
401 {
402 this->_M_head() = std::forward<_U1>(__in.first);
403 this->_M_tail()._M_head() = std::forward<_U2>(__in.second);
404 return *this;
405 }
406
407 void
408 swap(tuple& __in)
409 noexcept(noexcept(__in._M_swap(__in)))
410 { _Inherited::_M_swap(__in); }
411 };
412
413 /// tuple (1-element).
414 template<typename _T1>
415 class tuple<_T1> : public _Tuple_impl<0, _T1>
416 {
417 typedef _Tuple_impl<0, _T1> _Inherited;
418
419 public:
420 constexpr tuple()
421 : _Inherited() { }
422
423 explicit
424 constexpr tuple(const _T1& __a1)
425 : _Inherited(__a1) { }
426
427 template<typename _U1, typename = typename
428 std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
429 explicit
430 tuple(_U1&& __a1)
431 : _Inherited(std::forward<_U1>(__a1)) { }
432
433 constexpr tuple(const tuple&) = default;
434
435 tuple(tuple&& __in)
436 : _Inherited(static_cast<_Inherited&&>(__in)) { }
437
438 template<typename _U1>
439 tuple(const tuple<_U1>& __in)
440 : _Inherited(static_cast<const _Tuple_impl<0, _U1>&>(__in)) { }
441
442 template<typename _U1>
443 tuple(tuple<_U1>&& __in)
444 : _Inherited(static_cast<_Tuple_impl<0, _U1>&&>(__in)) { }
445
446 tuple&
447 operator=(const tuple& __in)
448 {
449 static_cast<_Inherited&>(*this) = __in;
450 return *this;
451 }
452
453 tuple&
454 operator=(tuple&& __in)
455 {
456 static_cast<_Inherited&>(*this) = std::move(__in);
457 return *this;
458 }
459
460 template<typename _U1>
461 tuple&
462 operator=(const tuple<_U1>& __in)
463 {
464 static_cast<_Inherited&>(*this) = __in;
465 return *this;
466 }
467
468 template<typename _U1>
469 tuple&
470 operator=(tuple<_U1>&& __in)
471 {
472 static_cast<_Inherited&>(*this) = std::move(__in);
473 return *this;
474 }
475
476 void
477 swap(tuple& __in)
478 noexcept(noexcept(__in._M_swap(__in)))
479 { _Inherited::_M_swap(__in); }
480 };
481
482
483 /// Gives the type of the ith element of a given tuple type.
484 template<std::size_t __i, typename _Tp>
485 struct tuple_element;
486
487 /**
488 * Recursive case for tuple_element: strip off the first element in
489 * the tuple and retrieve the (i-1)th element of the remaining tuple.
490 */
491 template<std::size_t __i, typename _Head, typename... _Tail>
492 struct tuple_element<__i, tuple<_Head, _Tail...> >
493 : tuple_element<__i - 1, tuple<_Tail...> > { };
494
495 /**
496 * Basis case for tuple_element: The first element is the one we're seeking.
497 */
498 template<typename _Head, typename... _Tail>
499 struct tuple_element<0, tuple<_Head, _Tail...> >
500 {
501 typedef _Head type;
502 };
503
504 /// Finds the size of a given tuple type.
505 template<typename _Tp>
506 struct tuple_size;
507
508 /// class tuple_size
509 template<typename... _Elements>
510 struct tuple_size<tuple<_Elements...> >
511 {
512 static const std::size_t value = sizeof...(_Elements);
513 };
514
515 template<typename... _Elements>
516 const std::size_t tuple_size<tuple<_Elements...> >::value;
517
518 template<std::size_t __i, typename _Head, typename... _Tail>
519 inline typename __add_ref<_Head>::type
520 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t)
521 { return __t._M_head(); }
522
523 template<std::size_t __i, typename _Head, typename... _Tail>
524 inline typename __add_c_ref<_Head>::type
525 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t)
526 { return __t._M_head(); }
527
528 // Return a reference (const reference, rvalue reference) to the ith element
529 // of a tuple. Any const or non-const ref elements are returned with their
530 // original type.
531 template<std::size_t __i, typename... _Elements>
532 inline typename __add_ref<
533 typename tuple_element<__i, tuple<_Elements...>>::type
534 >::type
535 get(tuple<_Elements...>& __t) noexcept
536 { return __get_helper<__i>(__t); }
537
538 template<std::size_t __i, typename... _Elements>
539 inline typename __add_c_ref<
540 typename tuple_element<__i, tuple<_Elements...>>::type
541 >::type
542 get(const tuple<_Elements...>& __t) noexcept
543 { return __get_helper<__i>(__t); }
544
545 template<std::size_t __i, typename... _Elements>
546 inline typename __add_r_ref<
547 typename tuple_element<__i, tuple<_Elements...>>::type
548 >::type
549 get(tuple<_Elements...>&& __t) noexcept
550 { return std::forward<typename tuple_element<__i,
551 tuple<_Elements...>>::type&&>(get<__i>(__t)); }
552
553 // This class helps construct the various comparison operations on tuples
554 template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
555 typename _Tp, typename _Up>
556 struct __tuple_compare;
557
558 template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
559 struct __tuple_compare<0, __i, __j, _Tp, _Up>
560 {
561 static bool __eq(const _Tp& __t, const _Up& __u)
562 {
563 return (get<__i>(__t) == get<__i>(__u) &&
564 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
565 }
566
567 static bool __less(const _Tp& __t, const _Up& __u)
568 {
569 return ((get<__i>(__t) < get<__i>(__u))
570 || !(get<__i>(__u) < get<__i>(__t)) &&
571 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
572 }
573 };
574
575 template<std::size_t __i, typename _Tp, typename _Up>
576 struct __tuple_compare<0, __i, __i, _Tp, _Up>
577 {
578 static bool __eq(const _Tp&, const _Up&)
579 { return true; }
580
581 static bool __less(const _Tp&, const _Up&)
582 { return false; }
583 };
584
585 template<typename... _TElements, typename... _UElements>
586 bool
587 operator==(const tuple<_TElements...>& __t,
588 const tuple<_UElements...>& __u)
589 {
590 typedef tuple<_TElements...> _Tp;
591 typedef tuple<_UElements...> _Up;
592 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
593 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
594 }
595
596 template<typename... _TElements, typename... _UElements>
597 bool
598 operator<(const tuple<_TElements...>& __t,
599 const tuple<_UElements...>& __u)
600 {
601 typedef tuple<_TElements...> _Tp;
602 typedef tuple<_UElements...> _Up;
603 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
604 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
605 }
606
607 template<typename... _TElements, typename... _UElements>
608 inline bool
609 operator!=(const tuple<_TElements...>& __t,
610 const tuple<_UElements...>& __u)
611 { return !(__t == __u); }
612
613 template<typename... _TElements, typename... _UElements>
614 inline bool
615 operator>(const tuple<_TElements...>& __t,
616 const tuple<_UElements...>& __u)
617 { return __u < __t; }
618
619 template<typename... _TElements, typename... _UElements>
620 inline bool
621 operator<=(const tuple<_TElements...>& __t,
622 const tuple<_UElements...>& __u)
623 { return !(__u < __t); }
624
625 template<typename... _TElements, typename... _UElements>
626 inline bool
627 operator>=(const tuple<_TElements...>& __t,
628 const tuple<_UElements...>& __u)
629 { return !(__t < __u); }
630
631 // NB: DR 705.
632 template<typename... _Elements>
633 inline tuple<typename __decay_and_strip<_Elements>::__type...>
634 make_tuple(_Elements&&... __args)
635 {
636 typedef tuple<typename __decay_and_strip<_Elements>::__type...>
637 __result_type;
638 return __result_type(std::forward<_Elements>(__args)...);
639 }
640
641 template<typename... _Elements>
642 inline tuple<_Elements&&...>
643 forward_as_tuple(_Elements&&... __args) noexcept
644 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
645
646 template<std::size_t...> struct __index_holder { };
647
648 template<std::size_t __i, typename _IdxHolder, typename... _Elements>
649 struct __index_holder_impl;
650
651 template<std::size_t __i, std::size_t... _Indexes, typename _IdxHolder,
652 typename... _Elements>
653 struct __index_holder_impl<__i, __index_holder<_Indexes...>,
654 _IdxHolder, _Elements...>
655 {
656 typedef typename __index_holder_impl<__i + 1,
657 __index_holder<_Indexes..., __i>,
658 _Elements...>::type type;
659 };
660
661 template<std::size_t __i, std::size_t... _Indexes>
662 struct __index_holder_impl<__i, __index_holder<_Indexes...> >
663 { typedef __index_holder<_Indexes...> type; };
664
665 template<typename... _Elements>
666 struct __make_index_holder
667 : __index_holder_impl<0, __index_holder<>, _Elements...> { };
668
669 template<typename... _TElements, std::size_t... _TIdx,
670 typename... _UElements, std::size_t... _UIdx>
671 inline tuple<_TElements..., _UElements...>
672 __tuple_cat_helper(const tuple<_TElements...>& __t,
673 const __index_holder<_TIdx...>&,
674 const tuple<_UElements...>& __u,
675 const __index_holder<_UIdx...>&)
676 { return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)...,
677 get<_UIdx>(__u)...); }
678
679 template<typename... _TElements, std::size_t... _TIdx,
680 typename... _UElements, std::size_t... _UIdx>
681 inline tuple<_TElements..., _UElements...>
682 __tuple_cat_helper(tuple<_TElements...>&& __t,
683 const __index_holder<_TIdx...>&,
684 const tuple<_UElements...>& __u,
685 const __index_holder<_UIdx...>&)
686 { return tuple<_TElements..., _UElements...>
687 (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
688
689 template<typename... _TElements, std::size_t... _TIdx,
690 typename... _UElements, std::size_t... _UIdx>
691 inline tuple<_TElements..., _UElements...>
692 __tuple_cat_helper(const tuple<_TElements...>& __t,
693 const __index_holder<_TIdx...>&,
694 tuple<_UElements...>&& __u,
695 const __index_holder<_UIdx...>&)
696 { return tuple<_TElements..., _UElements...>
697 (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
698
699 template<typename... _TElements, std::size_t... _TIdx,
700 typename... _UElements, std::size_t... _UIdx>
701 inline tuple<_TElements..., _UElements...>
702 __tuple_cat_helper(tuple<_TElements...>&& __t,
703 const __index_holder<_TIdx...>&,
704 tuple<_UElements...>&& __u,
705 const __index_holder<_UIdx...>&)
706 { return tuple<_TElements..., _UElements...>
707 (std::forward<_TElements>(get<_TIdx>(__t))...,
708 std::forward<_UElements>(get<_UIdx>(__u))...); }
709
710 template<typename... _TElements, typename... _UElements>
711 inline tuple<_TElements..., _UElements...>
712 tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u)
713 {
714 return __tuple_cat_helper(__t, typename
715 __make_index_holder<_TElements...>::type(),
716 __u, typename
717 __make_index_holder<_UElements...>::type());
718 }
719
720 template<typename... _TElements, typename... _UElements>
721 inline tuple<_TElements..., _UElements...>
722 tuple_cat(tuple<_TElements...>&& __t, const tuple<_UElements...>& __u)
723 {
724 return __tuple_cat_helper(std::move(__t), typename
725 __make_index_holder<_TElements...>::type(),
726 __u, typename
727 __make_index_holder<_UElements...>::type());
728 }
729
730 template<typename... _TElements, typename... _UElements>
731 inline tuple<_TElements..., _UElements...>
732 tuple_cat(const tuple<_TElements...>& __t, tuple<_UElements...>&& __u)
733 {
734 return __tuple_cat_helper(__t, typename
735 __make_index_holder<_TElements...>::type(),
736 std::move(__u), typename
737 __make_index_holder<_UElements...>::type());
738 }
739
740 template<typename... _TElements, typename... _UElements>
741 inline tuple<_TElements..., _UElements...>
742 tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u)
743 {
744 return __tuple_cat_helper(std::move(__t), typename
745 __make_index_holder<_TElements...>::type(),
746 std::move(__u), typename
747 __make_index_holder<_UElements...>::type());
748 }
749
750 template<typename... _Elements>
751 inline tuple<_Elements&...>
752 tie(_Elements&... __args) noexcept
753 { return tuple<_Elements&...>(__args...); }
754
755 template<typename... _Elements>
756 inline void
757 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
758 noexcept(noexcept(__x.swap(__y)))
759 { __x.swap(__y); }
760
761 // A class (and instance) which can be used in 'tie' when an element
762 // of a tuple is not required
763 struct _Swallow_assign
764 {
765 template<class _Tp>
766 const _Swallow_assign&
767 operator=(const _Tp&) const
768 { return *this; }
769 };
770
771 const _Swallow_assign ignore{};
772
773 /**
774 * Stores a tuple of indices. Used by bind() to extract the elements
775 * in a tuple.
776 */
777 template<int... _Indexes>
778 struct _Index_tuple
779 {
780 typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
781 };
782
783 /// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
784 template<std::size_t _Num>
785 struct _Build_index_tuple
786 {
787 typedef typename _Build_index_tuple<_Num-1>::__type::__next __type;
788 };
789
790 template<>
791 struct _Build_index_tuple<0>
792 {
793 typedef _Index_tuple<> __type;
794 };
795
796 // See stl_pair.h...
797 template<class _T1, class _T2>
798 template<typename _Tp, typename... _Args>
799 inline _Tp
800 pair<_T1, _T2>::
801 __cons(tuple<_Args...>&& __tuple)
802 {
803 typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
804 _Indexes;
805 return __do_cons<_Tp>(std::move(__tuple), _Indexes());
806 }
807
808 template<class _T1, class _T2>
809 template<typename _Tp, typename... _Args, int... _Indexes>
810 inline _Tp
811 pair<_T1, _T2>::
812 __do_cons(tuple<_Args...>&& __tuple,
813 const _Index_tuple<_Indexes...>&)
814 { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
815
816 _GLIBCXX_END_NAMESPACE_VERSION
817 } // namespace
818
819 #endif // __GXX_EXPERIMENTAL_CXX0X__
820
821 #endif // _GLIBCXX_TUPLE