OSDN Git Service

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