Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / std / tuple
blob87dbcb78df6b9bf483b2402ed3bf5cb3c9cb4c2d
1 // <tuple> -*- C++ -*-
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.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/tuple
26  *  This is a Standard C++ Library header.
27  */
29 #ifndef _GLIBCXX_TUPLE
30 #define _GLIBCXX_TUPLE 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
35 # include <bits/c++0x_warning.h>
36 #else
38 #include <utility>
40 _GLIBCXX_BEGIN_NAMESPACE(std)
42   // Adds a const reference to a non-reference type.
43   template<typename _Tp>
44     struct __add_c_ref
45     { typedef const _Tp& type; };
47   template<typename _Tp>
48     struct __add_c_ref<_Tp&>
49     { typedef _Tp& type; };
51   // Adds a reference to a non-reference type.
52   template<typename _Tp>
53     struct __add_ref
54     { typedef _Tp& type; };
56   template<typename _Tp>
57     struct __add_ref<_Tp&>
58     { typedef _Tp& type; };
60   template<std::size_t _Idx, typename _Head, bool _IsEmpty>
61     struct _Head_base;
63   template<std::size_t _Idx, typename _Head>
64     struct _Head_base<_Idx, _Head, true>
65     : public _Head
66     {
67       constexpr _Head_base()
68       : _Head() { }
70       constexpr _Head_base(const _Head& __h)
71       : _Head(__h) { }
73       template<typename _UHead>
74         _Head_base(_UHead&& __h)
75         : _Head(std::forward<_UHead>(__h)) { }
77       _Head&       _M_head()       { return *this; }
78       const _Head& _M_head() const { return *this; }
79     
80       void 
81       _M_swap_impl(_Head& __h)
82       {
83         using std::swap;
84         swap(__h, _M_head());
85       }
86     };
88   template<std::size_t _Idx, typename _Head>
89     struct _Head_base<_Idx, _Head, false>
90     {
91       constexpr _Head_base()
92       : _M_head_impl() { }
94       constexpr _Head_base(const _Head& __h)
95       : _M_head_impl(__h) { }
97       template<typename _UHead>
98         _Head_base(_UHead&& __h)
99         : _M_head_impl(std::forward<_UHead>(__h)) { }
101       _Head&       _M_head()       { return _M_head_impl; }
102       const _Head& _M_head() const { return _M_head_impl; }        
104       void
105       _M_swap_impl(_Head& __h)
106       { 
107         using std::swap;
108         swap(__h, _M_head());
109       }
111       _Head _M_head_impl; 
112     };
114   /**
115    * Contains the actual implementation of the @c tuple template, stored
116    * as a recursive inheritance hierarchy from the first element (most
117    * derived class) to the last (least derived class). The @c Idx
118    * parameter gives the 0-based index of the element stored at this
119    * point in the hierarchy; we use it to implement a constant-time
120    * get() operation.
121    */
122   template<std::size_t _Idx, typename... _Elements>
123     struct _Tuple_impl; 
125   /**
126    * Zero-element tuple implementation. This is the basis case for the 
127    * inheritance recursion.
128    */
129   template<std::size_t _Idx>
130     struct _Tuple_impl<_Idx>
131     { 
132     protected:
133       void _M_swap_impl(_Tuple_impl&) { /* no-op */ }
134     };
136   /**
137    * Recursive tuple implementation. Here we store the @c Head element
138    * and derive from a @c Tuple_impl containing the remaining elements
139    * (which contains the @c Tail).
140    */
141   template<std::size_t _Idx, typename _Head, typename... _Tail>
142     struct _Tuple_impl<_Idx, _Head, _Tail...>
143     : public _Tuple_impl<_Idx + 1, _Tail...>,
144       private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
145     {
146       typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
147       typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
149       _Head&            _M_head()       { return _Base::_M_head(); }
150       const _Head&      _M_head() const { return _Base::_M_head(); }
152       _Inherited&       _M_tail()       { return *this; }
153       const _Inherited& _M_tail() const { return *this; }
155       constexpr _Tuple_impl()
156       : _Inherited(), _Base() { }
158       explicit 
159       constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
160       : _Inherited(__tail...), _Base(__head) { }
162       template<typename _UHead, typename... _UTail> 
163         explicit
164         _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
165         : _Inherited(std::forward<_UTail>(__tail)...),
166           _Base(std::forward<_UHead>(__head)) { }
168       constexpr _Tuple_impl(const _Tuple_impl&) = default;
170       _Tuple_impl(_Tuple_impl&& __in)
171       : _Inherited(std::move(__in._M_tail())), 
172         _Base(std::forward<_Head>(__in._M_head())) { }
174       template<typename... _UElements>
175         _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
176         : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
178       template<typename... _UElements>
179         _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
180         : _Inherited(std::move(__in._M_tail())),
181           _Base(std::move(__in._M_head())) { }
183       _Tuple_impl&
184       operator=(const _Tuple_impl& __in)
185       {
186         _M_head() = __in._M_head();
187         _M_tail() = __in._M_tail();
188         return *this;
189       }
191       _Tuple_impl&
192       operator=(_Tuple_impl&& __in)
193       {
194         _M_head() = std::move(__in._M_head());
195         _M_tail() = std::move(__in._M_tail());
196         return *this;
197       }
199       template<typename... _UElements>
200         _Tuple_impl&
201         operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
202         {
203           _M_head() = __in._M_head();
204           _M_tail() = __in._M_tail();
205           return *this;
206         }
208       template<typename... _UElements>
209         _Tuple_impl&
210         operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
211         {
212           _M_head() = std::move(__in._M_head());
213           _M_tail() = std::move(__in._M_tail());
214           return *this;
215         }
217     protected:
218       void
219       _M_swap_impl(_Tuple_impl& __in)
220       {
221         _Base::_M_swap_impl(__in._M_head());
222         _Inherited::_M_swap_impl(__in._M_tail());
223       }
224     };
226   /// tuple
227   template<typename... _Elements> 
228     class tuple : public _Tuple_impl<0, _Elements...>
229     {
230       typedef _Tuple_impl<0, _Elements...> _Inherited;
232     public:
233       constexpr tuple()
234       : _Inherited() { }
236       explicit
237       constexpr tuple(const _Elements&... __elements)
238       : _Inherited(__elements...) { }
240       template<typename... _UElements, typename = typename
241                std::enable_if<sizeof...(_UElements)
242                               == sizeof...(_Elements)>::type>
243         explicit
244         tuple(_UElements&&... __elements)
245         : _Inherited(std::forward<_UElements>(__elements)...) { }
247       constexpr tuple(const tuple&) = default;
249       tuple(tuple&& __in)
250       : _Inherited(static_cast<_Inherited&&>(__in)) { }
252       template<typename... _UElements, typename = typename
253                std::enable_if<sizeof...(_UElements)
254                               == sizeof...(_Elements)>::type>
255         tuple(const tuple<_UElements...>& __in)
256         : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
257         { }
259       template<typename... _UElements, typename = typename
260                std::enable_if<sizeof...(_UElements)
261                               == sizeof...(_Elements)>::type>
262         tuple(tuple<_UElements...>&& __in)
263         : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
265       tuple&
266       operator=(const tuple& __in)
267       {
268         static_cast<_Inherited&>(*this) = __in;
269         return *this;
270       }
272       tuple&
273       operator=(tuple&& __in)
274       {
275         static_cast<_Inherited&>(*this) = std::move(__in);
276         return *this;
277       }
279       template<typename... _UElements, typename = typename
280                std::enable_if<sizeof...(_UElements)
281                               == sizeof...(_Elements)>::type>
282         tuple&
283         operator=(const tuple<_UElements...>& __in)
284         {
285           static_cast<_Inherited&>(*this) = __in;
286           return *this;
287         }
289       template<typename... _UElements, typename = typename
290                std::enable_if<sizeof...(_UElements)
291                               == sizeof...(_Elements)>::type>
292         tuple&
293         operator=(tuple<_UElements...>&& __in)
294         {
295           static_cast<_Inherited&>(*this) = std::move(__in);
296           return *this;
297         }
299       void
300       swap(tuple& __in)
301       { _Inherited::_M_swap_impl(__in); }
302     };
304   template<>  
305     class tuple<>
306     {
307     public:
308       void swap(tuple&) { /* no-op */ }
309     };
311   /// tuple (2-element), with construction and assignment from a pair.
312   template<typename _T1, typename _T2>
313     class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
314     {
315       typedef _Tuple_impl<0, _T1, _T2> _Inherited;
317     public:
318       constexpr tuple()
319       : _Inherited() { }
321       explicit
322       constexpr tuple(const _T1& __a1, const _T2& __a2)
323       : _Inherited(__a1, __a2) { }
325       template<typename _U1, typename _U2>
326         explicit
327         tuple(_U1&& __a1, _U2&& __a2)
328         : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
330       constexpr tuple(const tuple&) = default;
332       tuple(tuple&& __in)
333       : _Inherited(static_cast<_Inherited&&>(__in)) { }
335       template<typename _U1, typename _U2>
336         tuple(const tuple<_U1, _U2>& __in)
337         : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
339       template<typename _U1, typename _U2>
340         tuple(tuple<_U1, _U2>&& __in)
341         : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
343       template<typename _U1, typename _U2>
344         tuple(const pair<_U1, _U2>& __in)
345         : _Inherited(__in.first, __in.second) { }
347       template<typename _U1, typename _U2>
348         tuple(pair<_U1, _U2>&& __in)
349         : _Inherited(std::forward<_U1>(__in.first),
350                      std::forward<_U2>(__in.second)) { }
352       tuple&
353       operator=(const tuple& __in)
354       {
355         static_cast<_Inherited&>(*this) = __in;
356         return *this;
357       }
359       tuple&
360       operator=(tuple&& __in)
361       {
362         static_cast<_Inherited&>(*this) = std::move(__in);
363         return *this;
364       }
366       template<typename _U1, typename _U2>
367         tuple&
368         operator=(const tuple<_U1, _U2>& __in)
369         {
370           static_cast<_Inherited&>(*this) = __in;
371           return *this;
372         }
374       template<typename _U1, typename _U2>
375         tuple&
376         operator=(tuple<_U1, _U2>&& __in)
377         {
378           static_cast<_Inherited&>(*this) = std::move(__in);
379           return *this;
380         }
382       template<typename _U1, typename _U2>
383         tuple&
384         operator=(const pair<_U1, _U2>& __in)
385         {
386           this->_M_head() = __in.first;
387           this->_M_tail()._M_head() = __in.second;
388           return *this;
389         }
391       template<typename _U1, typename _U2>
392         tuple&
393         operator=(pair<_U1, _U2>&& __in)
394         {
395           this->_M_head() = std::forward<_U1>(__in.first);
396           this->_M_tail()._M_head() = std::forward<_U2>(__in.second);
397           return *this;
398         }
400       void
401       swap(tuple& __in)
402       { 
403         using std::swap;
404         swap(this->_M_head(), __in._M_head());
405         swap(this->_M_tail()._M_head(), __in._M_tail()._M_head());      
406       }
407     };
409   /// tuple (1-element).
410   template<typename _T1>
411     class tuple<_T1> : public _Tuple_impl<0, _T1>
412     {
413       typedef _Tuple_impl<0, _T1> _Inherited;
415     public:
416       constexpr tuple()
417       : _Inherited() { }
419       explicit
420       constexpr tuple(const _T1& __a1)
421       : _Inherited(__a1) { }
423       template<typename _U1, typename = typename
424                std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
425         explicit
426         tuple(_U1&& __a1)
427         : _Inherited(std::forward<_U1>(__a1)) { }
429       constexpr tuple(const tuple&) = default;
431       tuple(tuple&& __in)
432       : _Inherited(static_cast<_Inherited&&>(__in)) { }
434       template<typename _U1>
435         tuple(const tuple<_U1>& __in)
436         : _Inherited(static_cast<const _Tuple_impl<0, _U1>&>(__in)) { }
438       template<typename _U1>
439         tuple(tuple<_U1>&& __in)
440         : _Inherited(static_cast<_Tuple_impl<0, _U1>&&>(__in)) { }
442       tuple&
443       operator=(const tuple& __in)
444       {
445         static_cast<_Inherited&>(*this) = __in;
446         return *this;
447       }
449       tuple&
450       operator=(tuple&& __in)
451       {
452         static_cast<_Inherited&>(*this) = std::move(__in);
453         return *this;
454       }
456       template<typename _U1>
457         tuple&
458         operator=(const tuple<_U1>& __in)
459         {
460           static_cast<_Inherited&>(*this) = __in;
461           return *this;
462         }
464       template<typename _U1>
465         tuple&
466         operator=(tuple<_U1>&& __in)
467         {
468           static_cast<_Inherited&>(*this) = std::move(__in);
469           return *this;
470         }
472       void
473       swap(tuple& __in)
474       { _Inherited::_M_swap_impl(__in); }
475     };
478   /// Gives the type of the ith element of a given tuple type.
479   template<std::size_t __i, typename _Tp>
480     struct tuple_element;
482   /**
483    * Recursive case for tuple_element: strip off the first element in
484    * the tuple and retrieve the (i-1)th element of the remaining tuple.
485    */
486   template<std::size_t __i, typename _Head, typename... _Tail>
487     struct tuple_element<__i, tuple<_Head, _Tail...> >
488     : tuple_element<__i - 1, tuple<_Tail...> > { };
490   /**
491    * Basis case for tuple_element: The first element is the one we're seeking.
492    */
493   template<typename _Head, typename... _Tail>
494     struct tuple_element<0, tuple<_Head, _Tail...> >
495     {
496       typedef _Head type;
497     };
499   /// Finds the size of a given tuple type.
500   template<typename _Tp>
501     struct tuple_size;
503   /// class tuple_size
504   template<typename... _Elements>
505     struct tuple_size<tuple<_Elements...> >
506     {
507       static const std::size_t value = sizeof...(_Elements);
508     };
510   template<typename... _Elements>
511     const std::size_t tuple_size<tuple<_Elements...> >::value;
513   template<std::size_t __i, typename _Head, typename... _Tail>
514     inline typename __add_ref<_Head>::type
515     __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t)
516     { return __t._M_head(); }
518   template<std::size_t __i, typename _Head, typename... _Tail>
519     inline typename __add_c_ref<_Head>::type
520     __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t)
521     { return __t._M_head(); }
523   // Return a reference (const reference) to the ith element of a tuple.
524   // Any const or non-const ref elements are returned with their original type.
525   template<std::size_t __i, typename... _Elements>
526     inline typename __add_ref<
527                       typename tuple_element<__i, tuple<_Elements...> >::type
528                     >::type
529     get(tuple<_Elements...>& __t)
530     { return __get_helper<__i>(__t); }
532   template<std::size_t __i, typename... _Elements>
533     inline typename __add_c_ref<
534                       typename tuple_element<__i, tuple<_Elements...> >::type
535                     >::type
536     get(const tuple<_Elements...>& __t)
537     { return __get_helper<__i>(__t); }
539   // This class helps construct the various comparison operations on tuples
540   template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
541            typename _Tp, typename _Up>
542     struct __tuple_compare;
544   template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
545     struct __tuple_compare<0, __i, __j, _Tp, _Up>
546     {
547       static bool __eq(const _Tp& __t, const _Up& __u)
548       {
549         return (get<__i>(__t) == get<__i>(__u) &&
550                 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
551       }
552      
553       static bool __less(const _Tp& __t, const _Up& __u)
554       {
555         return ((get<__i>(__t) < get<__i>(__u))
556                 || !(get<__i>(__u) < get<__i>(__t)) &&
557                 __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
558       }
559     };
561   template<std::size_t __i, typename _Tp, typename _Up>
562     struct __tuple_compare<0, __i, __i, _Tp, _Up>
563     {
564       static bool __eq(const _Tp&, const _Up&)
565       { return true; }
566      
567       static bool __less(const _Tp&, const _Up&)
568       { return false; }
569     };
571   template<typename... _TElements, typename... _UElements>
572     bool
573     operator==(const tuple<_TElements...>& __t,
574                const tuple<_UElements...>& __u)
575     {
576       typedef tuple<_TElements...> _Tp;
577       typedef tuple<_UElements...> _Up;
578       return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
579               0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
580     }
582   template<typename... _TElements, typename... _UElements>
583     bool
584     operator<(const tuple<_TElements...>& __t,
585               const tuple<_UElements...>& __u)
586     {
587       typedef tuple<_TElements...> _Tp;
588       typedef tuple<_UElements...> _Up;
589       return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
590               0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
591     }
593   template<typename... _TElements, typename... _UElements>
594     inline bool
595     operator!=(const tuple<_TElements...>& __t,
596                const tuple<_UElements...>& __u)
597     { return !(__t == __u); }
599   template<typename... _TElements, typename... _UElements>
600     inline bool
601     operator>(const tuple<_TElements...>& __t,
602               const tuple<_UElements...>& __u)
603     { return __u < __t; }
605   template<typename... _TElements, typename... _UElements>
606     inline bool
607     operator<=(const tuple<_TElements...>& __t,
608                const tuple<_UElements...>& __u)
609     { return !(__u < __t); }
611   template<typename... _TElements, typename... _UElements>
612     inline bool
613     operator>=(const tuple<_TElements...>& __t,
614                const tuple<_UElements...>& __u)
615     { return !(__t < __u); }
617   // NB: DR 705.
618   template<typename... _Elements>
619     inline tuple<typename __decay_and_strip<_Elements>::__type...>
620     make_tuple(_Elements&&... __args)
621     {
622       typedef tuple<typename __decay_and_strip<_Elements>::__type...>
623         __result_type;
624       return __result_type(std::forward<_Elements>(__args)...);
625     }
627   template<typename... _Elements>
628     inline tuple<_Elements&&...>
629     forward_as_tuple(_Elements&&... __args)
630     { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
632   template<std::size_t...> struct __index_holder { };    
634   template<std::size_t __i, typename _IdxHolder, typename... _Elements>
635     struct __index_holder_impl;
637   template<std::size_t __i, std::size_t... _Indexes, typename _IdxHolder,
638            typename... _Elements>
639     struct __index_holder_impl<__i, __index_holder<_Indexes...>,
640                                _IdxHolder, _Elements...> 
641     {
642       typedef typename __index_holder_impl<__i + 1,
643                                            __index_holder<_Indexes..., __i>,
644                                            _Elements...>::type type;
645     };
647   template<std::size_t __i, std::size_t... _Indexes>
648     struct __index_holder_impl<__i, __index_holder<_Indexes...> >
649     { typedef __index_holder<_Indexes...> type; };
651   template<typename... _Elements>
652     struct __make_index_holder 
653     : __index_holder_impl<0, __index_holder<>, _Elements...> { };
654     
655   template<typename... _TElements, std::size_t... _TIdx,
656            typename... _UElements, std::size_t... _UIdx> 
657     inline tuple<_TElements..., _UElements...> 
658     __tuple_cat_helper(const tuple<_TElements...>& __t,
659                        const __index_holder<_TIdx...>&,
660                        const tuple<_UElements...>& __u,
661                        const __index_holder<_UIdx...>&)
662     { return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)...,
663                                                  get<_UIdx>(__u)...); }
665   template<typename... _TElements, std::size_t... _TIdx,
666            typename... _UElements, std::size_t... _UIdx> 
667     inline tuple<_TElements..., _UElements...> 
668     __tuple_cat_helper(tuple<_TElements...>&& __t,
669                        const __index_holder<_TIdx...>&, 
670                        const tuple<_UElements...>& __u,
671                        const __index_holder<_UIdx...>&)
672     { return tuple<_TElements..., _UElements...>
673         (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
675   template<typename... _TElements, std::size_t... _TIdx,
676            typename... _UElements, std::size_t... _UIdx>
677     inline tuple<_TElements..., _UElements...> 
678     __tuple_cat_helper(const tuple<_TElements...>& __t,
679                        const __index_holder<_TIdx...>&, 
680                        tuple<_UElements...>&& __u,
681                        const __index_holder<_UIdx...>&)
682     { return tuple<_TElements..., _UElements...>
683         (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
685   template<typename... _TElements, std::size_t... _TIdx,
686            typename... _UElements, std::size_t... _UIdx> 
687     inline tuple<_TElements..., _UElements...> 
688     __tuple_cat_helper(tuple<_TElements...>&& __t,
689                        const __index_holder<_TIdx...>&, 
690                        tuple<_UElements...>&& __u,
691                        const __index_holder<_UIdx...>&)
692     { return tuple<_TElements..., _UElements...>
693         (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
695   template<typename... _TElements, typename... _UElements>
696     inline tuple<_TElements..., _UElements...> 
697     tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u)
698     {
699       return __tuple_cat_helper(__t, typename
700                                 __make_index_holder<_TElements...>::type(),
701                                 __u, typename
702                                 __make_index_holder<_UElements...>::type());
703     }
705   template<typename... _TElements, typename... _UElements>
706     inline tuple<_TElements..., _UElements...> 
707     tuple_cat(tuple<_TElements...>&& __t, const tuple<_UElements...>& __u)
708     {
709       return __tuple_cat_helper(std::move(__t), typename
710                                  __make_index_holder<_TElements...>::type(),
711                                  __u, typename
712                                  __make_index_holder<_UElements...>::type());
713     }
715   template<typename... _TElements, typename... _UElements>
716     inline tuple<_TElements..., _UElements...> 
717     tuple_cat(const tuple<_TElements...>& __t, tuple<_UElements...>&& __u)
718     {
719       return __tuple_cat_helper(__t, typename
720                                 __make_index_holder<_TElements...>::type(),
721                                 std::move(__u), typename
722                                 __make_index_holder<_UElements...>::type());
723     }
725   template<typename... _TElements, typename... _UElements>
726     inline tuple<_TElements..., _UElements...>
727     tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u)
728     {
729       return __tuple_cat_helper(std::move(__t), typename
730                                 __make_index_holder<_TElements...>::type(),
731                                 std::move(__u), typename
732                                 __make_index_holder<_UElements...>::type());
733     }
735   template<typename... _Elements>
736     inline tuple<_Elements&...>
737     tie(_Elements&... __args)
738     { return tuple<_Elements&...>(__args...); }
740   template<typename... _Elements>
741     inline void 
742     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
743     { __x.swap(__y); }
745   // A class (and instance) which can be used in 'tie' when an element
746   // of a tuple is not required
747   struct _Swallow_assign
748   {
749     template<class _Tp>
750       const _Swallow_assign&
751       operator=(const _Tp&) const
752       { return *this; }
753   };
755   const _Swallow_assign ignore{};
757   /**
758    * Stores a tuple of indices. Used by bind() to extract the elements
759    * in a tuple. 
760    */
761   template<int... _Indexes>
762     struct _Index_tuple
763     {
764       typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
765     };
767   /// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
768   template<std::size_t _Num>
769     struct _Build_index_tuple
770     {
771       typedef typename _Build_index_tuple<_Num-1>::__type::__next __type;
772     };
774   template<>
775     struct _Build_index_tuple<0>
776     {
777       typedef _Index_tuple<> __type;
778     };
780   // See stl_pair.h...
781   template<class _T1, class _T2>
782     template<typename _Tp, typename... _Args>
783       inline _Tp
784       pair<_T1, _T2>::
785       __cons(tuple<_Args...>&& __tuple)
786       {
787         typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
788           _Indexes;
789         return __do_cons<_Tp>(std::move(__tuple), _Indexes());
790       }
792   template<class _T1, class _T2>
793     template<typename _Tp, typename... _Args, int... _Indexes>
794       inline _Tp
795       pair<_T1, _T2>::
796       __do_cons(tuple<_Args...>&& __tuple,
797                 const _Index_tuple<_Indexes...>&)
798       { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
800 _GLIBCXX_END_NAMESPACE
802 #endif // __GXX_EXPERIMENTAL_CXX0X__
804 #endif // _GLIBCXX_TUPLE