]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/tuple
gcc_update (gcc/config/arm/arm-tables.opt): Also depend on gcc/config/arm/arm-fpus...
[thirdparty/gcc.git] / libstdc++-v3 / include / std / tuple
CommitLineData
af13a7a6
BK
1// <tuple> -*- C++ -*-
2
78a869ec 3// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
af13a7a6
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
af13a7a6
BK
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
748086b7
JJ
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/>.
af13a7a6
BK
24
25/** @file include/tuple
26 * This is a Standard C++ Library header.
27 */
28
4514bed6
BK
29#ifndef _GLIBCXX_TUPLE
30#define _GLIBCXX_TUPLE 1
af13a7a6
BK
31
32#pragma GCC system_header
33
e133ace8 34#ifndef __GXX_EXPERIMENTAL_CXX0X__
ab65a4c7 35# include <bits/c++0x_warning.h>
57317d2a 36#else
af13a7a6 37
e133ace8
PC
38#include <utility>
39
12ffa228
BK
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
53dc5044 43
894d0b15
CF
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
1aa1114b
PC
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
740508be 71 template<std::size_t _Idx, typename _Head, bool _IsEmpty>
ba60f6f9
PC
72 struct _Head_base;
73
740508be 74 template<std::size_t _Idx, typename _Head>
894d0b15
CF
75 struct _Head_base<_Idx, _Head, true>
76 : public _Head
77 {
0e6ac87e 78 constexpr _Head_base()
894d0b15
CF
79 : _Head() { }
80
094a14ef 81 constexpr _Head_base(const _Head& __h)
894d0b15
CF
82 : _Head(__h) { }
83
b5b5e640 84 template<typename _UHead>
fe960d92
CF
85 _Head_base(_UHead&& __h)
86 : _Head(std::forward<_UHead>(__h)) { }
894d0b15
CF
87
88 _Head& _M_head() { return *this; }
89 const _Head& _M_head() const { return *this; }
90 };
91
740508be 92 template<std::size_t _Idx, typename _Head>
894d0b15
CF
93 struct _Head_base<_Idx, _Head, false>
94 {
0e6ac87e 95 constexpr _Head_base()
894d0b15
CF
96 : _M_head_impl() { }
97
094a14ef 98 constexpr _Head_base(const _Head& __h)
894d0b15
CF
99 : _M_head_impl(__h) { }
100
b5b5e640 101 template<typename _UHead>
fe960d92
CF
102 _Head_base(_UHead&& __h)
103 : _M_head_impl(std::forward<_UHead>(__h)) { }
894d0b15
CF
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 /**
894d0b15
CF
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.
894d0b15 118 */
740508be 119 template<std::size_t _Idx, typename... _Elements>
894d0b15
CF
120 struct _Tuple_impl;
121
122 /**
894d0b15
CF
123 * Zero-element tuple implementation. This is the basis case for the
124 * inheritance recursion.
894d0b15 125 */
740508be 126 template<std::size_t _Idx>
3e93b275 127 struct _Tuple_impl<_Idx>
1aa1114b
PC
128 {
129 template<std::size_t, typename...> friend class _Tuple_impl;
130
fe960d92 131 protected:
1aa1114b 132 void _M_swap(_Tuple_impl&) noexcept { /* no-op */ }
3e93b275 133 };
894d0b15
CF
134
135 /**
894d0b15
CF
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).
894d0b15 139 */
740508be 140 template<std::size_t _Idx, typename _Head, typename... _Tail>
894d0b15
CF
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 {
1aa1114b
PC
145 template<std::size_t, typename...> friend class _Tuple_impl;
146
894d0b15
CF
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
0e6ac87e 156 constexpr _Tuple_impl()
894d0b15
CF
157 : _Inherited(), _Base() { }
158
159 explicit
094a14ef 160 constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
894d0b15
CF
161 : _Inherited(__tail...), _Base(__head) { }
162
ba60f6f9
PC
163 template<typename _UHead, typename... _UTail>
164 explicit
b5b5e640
PC
165 _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
166 : _Inherited(std::forward<_UTail>(__tail)...),
167 _Base(std::forward<_UHead>(__head)) { }
894d0b15 168
094a14ef 169 constexpr _Tuple_impl(const _Tuple_impl&) = default;
894d0b15 170
ba60f6f9 171 _Tuple_impl(_Tuple_impl&& __in)
094a14ef 172 : _Inherited(std::move(__in._M_tail())),
b5b5e640 173 _Base(std::forward<_Head>(__in._M_head())) { }
ba60f6f9 174
894d0b15 175 template<typename... _UElements>
ba60f6f9
PC
176 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
177 : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
178
78a869ec
TS
179 template<typename _UHead, typename... _UTails>
180 _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
4c650853 181 : _Inherited(std::move(__in._M_tail())),
78a869ec 182 _Base(std::forward<_UHead>(__in._M_head())) { }
894d0b15
CF
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 }
ba60f6f9
PC
191
192 _Tuple_impl&
193 operator=(_Tuple_impl&& __in)
194 {
78a869ec 195 _M_head() = std::forward<_Head>(__in._M_head());
ba60f6f9
PC
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
78a869ec 209 template<typename _UHead, typename... _UTails>
ba60f6f9 210 _Tuple_impl&
78a869ec 211 operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
ba60f6f9 212 {
78a869ec 213 _M_head() = std::forward<_UHead>(__in._M_head());
ba60f6f9
PC
214 _M_tail() = std::move(__in._M_tail());
215 return *this;
216 }
3e93b275 217
fe960d92 218 protected:
3e93b275 219 void
1aa1114b
PC
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())))
3e93b275 224 {
1aa1114b
PC
225 using std::swap;
226 swap(this->_M_head(), __in._M_head());
227 _Inherited::_M_swap(__in._M_tail());
3e93b275 228 }
894d0b15
CF
229 };
230
939759fc 231 /// tuple
894d0b15
CF
232 template<typename... _Elements>
233 class tuple : public _Tuple_impl<0, _Elements...>
234 {
235 typedef _Tuple_impl<0, _Elements...> _Inherited;
236
237 public:
0e6ac87e 238 constexpr tuple()
894d0b15
CF
239 : _Inherited() { }
240
241 explicit
094a14ef 242 constexpr tuple(const _Elements&... __elements)
894d0b15
CF
243 : _Inherited(__elements...) { }
244
0a5c2065
PC
245 template<typename... _UElements, typename = typename
246 std::enable_if<sizeof...(_UElements)
247 == sizeof...(_Elements)>::type>
ba60f6f9
PC
248 explicit
249 tuple(_UElements&&... __elements)
b5b5e640 250 : _Inherited(std::forward<_UElements>(__elements)...) { }
894d0b15 251
094a14ef 252 constexpr tuple(const tuple&) = default;
894d0b15 253
ba60f6f9 254 tuple(tuple&& __in)
4c650853 255 : _Inherited(static_cast<_Inherited&&>(__in)) { }
ba60f6f9 256
0a5c2065
PC
257 template<typename... _UElements, typename = typename
258 std::enable_if<sizeof...(_UElements)
259 == sizeof...(_Elements)>::type>
ba60f6f9 260 tuple(const tuple<_UElements...>& __in)
0a5c2065
PC
261 : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
262 { }
ba60f6f9 263
0a5c2065
PC
264 template<typename... _UElements, typename = typename
265 std::enable_if<sizeof...(_UElements)
266 == sizeof...(_Elements)>::type>
ba60f6f9 267 tuple(tuple<_UElements...>&& __in)
0a5c2065 268 : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
894d0b15
CF
269
270 tuple&
271 operator=(const tuple& __in)
272 {
273 static_cast<_Inherited&>(*this) = __in;
274 return *this;
275 }
ba60f6f9
PC
276
277 tuple&
278 operator=(tuple&& __in)
279 {
280 static_cast<_Inherited&>(*this) = std::move(__in);
281 return *this;
282 }
283
0a5c2065
PC
284 template<typename... _UElements, typename = typename
285 std::enable_if<sizeof...(_UElements)
286 == sizeof...(_Elements)>::type>
ba60f6f9
PC
287 tuple&
288 operator=(const tuple<_UElements...>& __in)
289 {
290 static_cast<_Inherited&>(*this) = __in;
291 return *this;
292 }
293
0a5c2065
PC
294 template<typename... _UElements, typename = typename
295 std::enable_if<sizeof...(_UElements)
296 == sizeof...(_Elements)>::type>
ba60f6f9
PC
297 tuple&
298 operator=(tuple<_UElements...>&& __in)
299 {
300 static_cast<_Inherited&>(*this) = std::move(__in);
301 return *this;
302 }
3e93b275
CF
303
304 void
ff74fd13 305 swap(tuple& __in)
1aa1114b
PC
306 noexcept(noexcept(__in._M_swap(__in)))
307 { _Inherited::_M_swap(__in); }
894d0b15
CF
308 };
309
939759fc 310 template<>
3e93b275
CF
311 class tuple<>
312 {
313 public:
1aa1114b 314 void swap(tuple&) noexcept { /* no-op */ }
3e93b275 315 };
939759fc
BK
316
317 /// tuple (2-element), with construction and assignment from a pair.
894d0b15
CF
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:
0e6ac87e 324 constexpr tuple()
894d0b15
CF
325 : _Inherited() { }
326
327 explicit
094a14ef 328 constexpr tuple(const _T1& __a1, const _T2& __a2)
894d0b15
CF
329 : _Inherited(__a1, __a2) { }
330
331 template<typename _U1, typename _U2>
ba60f6f9
PC
332 explicit
333 tuple(_U1&& __a1, _U2&& __a2)
334 : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
894d0b15 335
094a14ef 336 constexpr tuple(const tuple&) = default;
894d0b15 337
ba60f6f9 338 tuple(tuple&& __in)
4c650853 339 : _Inherited(static_cast<_Inherited&&>(__in)) { }
ba60f6f9
PC
340
341 template<typename _U1, typename _U2>
342 tuple(const tuple<_U1, _U2>& __in)
b5b5e640 343 : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
ba60f6f9
PC
344
345 template<typename _U1, typename _U2>
346 tuple(tuple<_U1, _U2>&& __in)
4c650853 347 : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
ba60f6f9 348
894d0b15
CF
349 template<typename _U1, typename _U2>
350 tuple(const pair<_U1, _U2>& __in)
b5b5e640 351 : _Inherited(__in.first, __in.second) { }
ba60f6f9 352
894d0b15 353 template<typename _U1, typename _U2>
ba60f6f9 354 tuple(pair<_U1, _U2>&& __in)
87b2e746
PC
355 : _Inherited(std::forward<_U1>(__in.first),
356 std::forward<_U2>(__in.second)) { }
894d0b15
CF
357
358 tuple&
359 operator=(const tuple& __in)
360 {
361 static_cast<_Inherited&>(*this) = __in;
362 return *this;
363 }
364
ba60f6f9
PC
365 tuple&
366 operator=(tuple&& __in)
1aa1114b 367 // noexcept has to wait is_nothrow_move_assignable
ba60f6f9
PC
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
894d0b15
CF
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 }
ba60f6f9
PC
397
398 template<typename _U1, typename _U2>
399 tuple&
1aa1114b 400 operator=(pair<_U1, _U2>&& __in) noexcept
ba60f6f9 401 {
0a5c2065
PC
402 this->_M_head() = std::forward<_U1>(__in.first);
403 this->_M_tail()._M_head() = std::forward<_U2>(__in.second);
ba60f6f9
PC
404 return *this;
405 }
3e93b275
CF
406
407 void
ff74fd13 408 swap(tuple& __in)
1aa1114b
PC
409 noexcept(noexcept(__in._M_swap(__in)))
410 { _Inherited::_M_swap(__in); }
894d0b15
CF
411 };
412
0a5c2065
PC
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:
0e6ac87e 420 constexpr tuple()
0a5c2065
PC
421 : _Inherited() { }
422
423 explicit
094a14ef 424 constexpr tuple(const _T1& __a1)
0a5c2065
PC
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
094a14ef 433 constexpr tuple(const tuple&) = default;
0a5c2065
PC
434
435 tuple(tuple&& __in)
436 : _Inherited(static_cast<_Inherited&&>(__in)) { }
437
438 template<typename _U1>
439 tuple(const tuple<_U1>& __in)
094a14ef 440 : _Inherited(static_cast<const _Tuple_impl<0, _U1>&>(__in)) { }
0a5c2065
PC
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)
1aa1114b
PC
478 noexcept(noexcept(__in._M_swap(__in)))
479 { _Inherited::_M_swap(__in); }
0a5c2065
PC
480 };
481
894d0b15
CF
482
483 /// Gives the type of the ith element of a given tuple type.
740508be 484 template<std::size_t __i, typename _Tp>
894d0b15
CF
485 struct tuple_element;
486
487 /**
894d0b15
CF
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.
894d0b15 490 */
740508be 491 template<std::size_t __i, typename _Head, typename... _Tail>
894d0b15
CF
492 struct tuple_element<__i, tuple<_Head, _Tail...> >
493 : tuple_element<__i - 1, tuple<_Tail...> > { };
494
495 /**
894d0b15 496 * Basis case for tuple_element: The first element is the one we're seeking.
894d0b15
CF
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
939759fc 508 /// class tuple_size
894d0b15
CF
509 template<typename... _Elements>
510 struct tuple_size<tuple<_Elements...> >
511 {
740508be 512 static const std::size_t value = sizeof...(_Elements);
894d0b15
CF
513 };
514
515 template<typename... _Elements>
740508be 516 const std::size_t tuple_size<tuple<_Elements...> >::value;
894d0b15 517
740508be 518 template<std::size_t __i, typename _Head, typename... _Tail>
894d0b15
CF
519 inline typename __add_ref<_Head>::type
520 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t)
521 { return __t._M_head(); }
522
740508be 523 template<std::size_t __i, typename _Head, typename... _Tail>
894d0b15
CF
524 inline typename __add_c_ref<_Head>::type
525 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t)
526 { return __t._M_head(); }
527
1aa1114b
PC
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.
740508be 531 template<std::size_t __i, typename... _Elements>
894d0b15 532 inline typename __add_ref<
1aa1114b 533 typename tuple_element<__i, tuple<_Elements...>>::type
894d0b15 534 >::type
1aa1114b 535 get(tuple<_Elements...>& __t) noexcept
894d0b15
CF
536 { return __get_helper<__i>(__t); }
537
740508be 538 template<std::size_t __i, typename... _Elements>
894d0b15 539 inline typename __add_c_ref<
1aa1114b 540 typename tuple_element<__i, tuple<_Elements...>>::type
894d0b15 541 >::type
1aa1114b 542 get(const tuple<_Elements...>& __t) noexcept
894d0b15
CF
543 { return __get_helper<__i>(__t); }
544
1aa1114b
PC
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
894d0b15 553 // This class helps construct the various comparison operations on tuples
740508be 554 template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
894d0b15
CF
555 typename _Tp, typename _Up>
556 struct __tuple_compare;
557
740508be 558 template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
894d0b15
CF
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) &&
740508be 564 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
894d0b15
CF
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)) &&
740508be 571 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
894d0b15
CF
572 }
573 };
574
740508be 575 template<std::size_t __i, typename _Tp, typename _Up>
894d0b15
CF
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;
230636fe 592 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
894d0b15
CF
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;
230636fe 603 return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
894d0b15
CF
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
5e108459 641 template<typename... _Elements>
00e9a944 642 inline tuple<_Elements&&...>
1aa1114b 643 forward_as_tuple(_Elements&&... __args) noexcept
00e9a944 644 { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
5e108459 645
740508be 646 template<std::size_t...> struct __index_holder { };
894d0b15 647
740508be 648 template<std::size_t __i, typename _IdxHolder, typename... _Elements>
894d0b15
CF
649 struct __index_holder_impl;
650
740508be
PC
651 template<std::size_t __i, std::size_t... _Indexes, typename _IdxHolder,
652 typename... _Elements>
894d0b15
CF
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
740508be 661 template<std::size_t __i, std::size_t... _Indexes>
894d0b15
CF
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
740508be
PC
669 template<typename... _TElements, std::size_t... _TIdx,
670 typename... _UElements, std::size_t... _UIdx>
894d0b15
CF
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
740508be
PC
679 template<typename... _TElements, std::size_t... _TIdx,
680 typename... _UElements, std::size_t... _UIdx>
894d0b15
CF
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...>&)
b5b5e640 686 { return tuple<_TElements..., _UElements...>
78a869ec 687 (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
894d0b15 688
740508be
PC
689 template<typename... _TElements, std::size_t... _TIdx,
690 typename... _UElements, std::size_t... _UIdx>
894d0b15
CF
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...>&)
b5b5e640 696 { return tuple<_TElements..., _UElements...>
78a869ec 697 (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
894d0b15 698
740508be
PC
699 template<typename... _TElements, std::size_t... _TIdx,
700 typename... _UElements, std::size_t... _UIdx>
894d0b15
CF
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...>&)
b5b5e640 706 { return tuple<_TElements..., _UElements...>
78a869ec
TS
707 (std::forward<_TElements>(get<_TIdx>(__t))...,
708 std::forward<_UElements>(get<_UIdx>(__u))...); }
894d0b15
CF
709
710 template<typename... _TElements, typename... _UElements>
711 inline tuple<_TElements..., _UElements...>
712 tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u)
740508be 713 {
894d0b15
CF
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
894d0b15
CF
750 template<typename... _Elements>
751 inline tuple<_Elements&...>
1aa1114b 752 tie(_Elements&... __args) noexcept
894d0b15
CF
753 { return tuple<_Elements&...>(__args...); }
754
3e93b275
CF
755 template<typename... _Elements>
756 inline void
757 swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1aa1114b 758 noexcept(noexcept(__x.swap(__y)))
3e93b275
CF
759 { __x.swap(__y); }
760
894d0b15
CF
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>
cff90044
JW
766 const _Swallow_assign&
767 operator=(const _Tp&) const
894d0b15
CF
768 { return *this; }
769 };
770
cff90044 771 const _Swallow_assign ignore{};
5e108459
PC
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))...); }
53dc5044 815
12ffa228
BK
816_GLIBCXX_END_NAMESPACE_VERSION
817} // namespace
af13a7a6 818
57317d2a
PC
819#endif // __GXX_EXPERIMENTAL_CXX0X__
820
4514bed6 821#endif // _GLIBCXX_TUPLE