tuple

Go to the documentation of this file.
00001 // <tuple> -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file include/tuple
00026  *  This is a Standard C++ Library header.
00027  */
00028 
00029 #ifndef _GLIBCXX_TUPLE
00030 #define _GLIBCXX_TUPLE 1
00031 
00032 #pragma GCC system_header
00033 
00034 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00035 # include <bits/c++0x_warning.h>
00036 #else
00037 
00038 #include <utility>
00039 
00040 namespace std
00041 {
00042   // Adds a const reference to a non-reference type.
00043   template<typename _Tp>
00044     struct __add_c_ref
00045     { typedef const _Tp& type; };
00046 
00047   template<typename _Tp>
00048     struct __add_c_ref<_Tp&>
00049     { typedef _Tp& type; };
00050 
00051   // Adds a reference to a non-reference type.
00052   template<typename _Tp>
00053     struct __add_ref
00054     { typedef _Tp& type; };
00055 
00056   template<typename _Tp>
00057     struct __add_ref<_Tp&>
00058     { typedef _Tp& type; };
00059 
00060   template<std::size_t _Idx, typename _Head, bool _IsEmpty>
00061     struct _Head_base;
00062 
00063   template<std::size_t _Idx, typename _Head>
00064     struct _Head_base<_Idx, _Head, true>
00065     : public _Head
00066     {
00067       _Head_base()
00068       : _Head() { }
00069 
00070       _Head_base(const _Head& __h)
00071       : _Head(__h) { }
00072 
00073       template<typename _UHead>
00074         _Head_base(_UHead&& __h)
00075     : _Head(std::forward<_UHead>(__h)) { }
00076 
00077       _Head&       _M_head()       { return *this; }
00078       const _Head& _M_head() const { return *this; }
00079     
00080       void _M_swap_impl(_Head&) { /* no-op */ }
00081     };
00082 
00083   template<std::size_t _Idx, typename _Head>
00084     struct _Head_base<_Idx, _Head, false>
00085     {
00086       _Head_base()
00087       : _M_head_impl() { }
00088 
00089       _Head_base(const _Head& __h)
00090       : _M_head_impl(__h) { }
00091 
00092       template<typename _UHead>
00093         _Head_base(_UHead&& __h)
00094     : _M_head_impl(std::forward<_UHead>(__h)) { }
00095 
00096       _Head&       _M_head()       { return _M_head_impl; }
00097       const _Head& _M_head() const { return _M_head_impl; }        
00098 
00099       void
00100       _M_swap_impl(_Head& __h)
00101       { 
00102     using std::swap;
00103     swap(__h, _M_head_impl);
00104       }
00105 
00106       _Head _M_head_impl; 
00107     };
00108 
00109   /**
00110    * Contains the actual implementation of the @c tuple template, stored
00111    * as a recursive inheritance hierarchy from the first element (most
00112    * derived class) to the last (least derived class). The @c Idx
00113    * parameter gives the 0-based index of the element stored at this
00114    * point in the hierarchy; we use it to implement a constant-time
00115    * get() operation.
00116    */
00117   template<std::size_t _Idx, typename... _Elements>
00118     struct _Tuple_impl; 
00119 
00120   /**
00121    * Zero-element tuple implementation. This is the basis case for the 
00122    * inheritance recursion.
00123    */
00124   template<std::size_t _Idx>
00125     struct _Tuple_impl<_Idx>
00126     { 
00127     protected:
00128       void _M_swap_impl(_Tuple_impl&) { /* no-op */ }
00129     };
00130 
00131   /**
00132    * Recursive tuple implementation. Here we store the @c Head element
00133    * and derive from a @c Tuple_impl containing the remaining elements
00134    * (which contains the @c Tail).
00135    */
00136   template<std::size_t _Idx, typename _Head, typename... _Tail>
00137     struct _Tuple_impl<_Idx, _Head, _Tail...>
00138     : public _Tuple_impl<_Idx + 1, _Tail...>,
00139       private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
00140     {
00141       typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
00142       typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
00143 
00144       _Head&            _M_head()       { return _Base::_M_head(); }
00145       const _Head&      _M_head() const { return _Base::_M_head(); }
00146 
00147       _Inherited&       _M_tail()       { return *this; }
00148       const _Inherited& _M_tail() const { return *this; }
00149 
00150       _Tuple_impl()
00151       : _Inherited(), _Base() { }
00152 
00153       explicit 
00154       _Tuple_impl(const _Head& __head, const _Tail&... __tail)
00155       : _Inherited(__tail...), _Base(__head) { }
00156 
00157       template<typename _UHead, typename... _UTail> 
00158         explicit
00159         _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
00160     : _Inherited(std::forward<_UTail>(__tail)...),
00161       _Base(std::forward<_UHead>(__head)) { }
00162 
00163       _Tuple_impl(const _Tuple_impl& __in)
00164       : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
00165 
00166       _Tuple_impl(_Tuple_impl&& __in)
00167       : _Inherited(std::move(__in._M_tail())),
00168     _Base(std::forward<_Head>(__in._M_head())) { }
00169 
00170       template<typename... _UElements>
00171         _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
00172     : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
00173 
00174       template<typename... _UElements>
00175         _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
00176     : _Inherited(std::move(__in._M_tail())),
00177       _Base(std::move(__in._M_head())) { }
00178 
00179       _Tuple_impl&
00180       operator=(const _Tuple_impl& __in)
00181       {
00182     _M_head() = __in._M_head();
00183     _M_tail() = __in._M_tail();
00184     return *this;
00185       }
00186 
00187       _Tuple_impl&
00188       operator=(_Tuple_impl&& __in)
00189       {
00190     _M_head() = std::move(__in._M_head());
00191     _M_tail() = std::move(__in._M_tail());
00192     return *this;
00193       }
00194 
00195       template<typename... _UElements>
00196         _Tuple_impl&
00197         operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
00198         {
00199       _M_head() = __in._M_head();
00200       _M_tail() = __in._M_tail();
00201       return *this;
00202     }
00203 
00204       template<typename... _UElements>
00205         _Tuple_impl&
00206         operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
00207         {
00208       _M_head() = std::move(__in._M_head());
00209       _M_tail() = std::move(__in._M_tail());
00210       return *this;
00211     }
00212 
00213     protected:
00214       void
00215       _M_swap_impl(_Tuple_impl& __in)
00216       {
00217     _Base::_M_swap_impl(__in._M_head());
00218     _Inherited::_M_swap_impl(__in._M_tail());
00219       }
00220     };
00221 
00222   /// tuple
00223   template<typename... _Elements> 
00224     class tuple : public _Tuple_impl<0, _Elements...>
00225     {
00226       typedef _Tuple_impl<0, _Elements...> _Inherited;
00227 
00228     public:
00229       tuple()
00230       : _Inherited() { }
00231 
00232       explicit
00233       tuple(const _Elements&... __elements)
00234       : _Inherited(__elements...) { }
00235 
00236       template<typename... _UElements>
00237         explicit
00238         tuple(_UElements&&... __elements)
00239     : _Inherited(std::forward<_UElements>(__elements)...) { }
00240 
00241       tuple(const tuple&) = default;
00242 
00243       tuple(tuple&& __in)
00244       : _Inherited(static_cast<_Inherited&&>(__in)) { }
00245 
00246       template<typename... _UElements>
00247         tuple(const tuple<_UElements...>& __in)
00248     : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
00249     { }
00250 
00251       template<typename... _UElements>
00252         tuple(tuple<_UElements...>&& __in)
00253     : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
00254 
00255       // XXX http://gcc.gnu.org/ml/libstdc++/2008-02/msg00047.html
00256       template<typename... _UElements>
00257         tuple(tuple<_UElements...>& __in)
00258     : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
00259     { }
00260 
00261       tuple&
00262       operator=(const tuple& __in)
00263       {
00264     static_cast<_Inherited&>(*this) = __in;
00265     return *this;
00266       }
00267 
00268       tuple&
00269       operator=(tuple&& __in)
00270       {
00271     static_cast<_Inherited&>(*this) = std::move(__in);
00272     return *this;
00273       }
00274 
00275       template<typename... _UElements>
00276         tuple&
00277         operator=(const tuple<_UElements...>& __in)
00278         {
00279       static_cast<_Inherited&>(*this) = __in;
00280       return *this;
00281     }
00282 
00283       template<typename... _UElements>
00284         tuple&
00285         operator=(tuple<_UElements...>&& __in)
00286         {
00287       static_cast<_Inherited&>(*this) = std::move(__in);
00288       return *this;
00289     }
00290 
00291       void
00292       swap(tuple& __in)
00293       { _Inherited::_M_swap_impl(__in); }
00294     };
00295 
00296 
00297   template<>  
00298     class tuple<>
00299     {
00300     public:
00301       void swap(tuple&) { /* no-op */ }
00302     };
00303 
00304   /// tuple (2-element), with construction and assignment from a pair.
00305   template<typename _T1, typename _T2>
00306     class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
00307     {
00308       typedef _Tuple_impl<0, _T1, _T2> _Inherited;
00309 
00310     public:
00311       tuple()
00312       : _Inherited() { }
00313 
00314       explicit
00315       tuple(const _T1& __a1, const _T2& __a2)
00316       : _Inherited(__a1, __a2) { }
00317 
00318       template<typename _U1, typename _U2>
00319         explicit
00320         tuple(_U1&& __a1, _U2&& __a2)
00321     : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
00322 
00323       tuple(const tuple&) = default;
00324 
00325       tuple(tuple&& __in)
00326       : _Inherited(static_cast<_Inherited&&>(__in)) { }
00327 
00328       template<typename _U1, typename _U2>
00329         tuple(const tuple<_U1, _U2>& __in)
00330     : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
00331 
00332       template<typename _U1, typename _U2>
00333         tuple(tuple<_U1, _U2>&& __in)
00334     : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
00335 
00336       template<typename _U1, typename _U2>
00337         tuple(const pair<_U1, _U2>& __in)
00338     : _Inherited(__in.first, __in.second) { }
00339 
00340       template<typename _U1, typename _U2>
00341         tuple(pair<_U1, _U2>&& __in)
00342     : _Inherited(std::forward<_U1>(__in.first),
00343              std::forward<_U2>(__in.second)) { }
00344 
00345       tuple&
00346       operator=(const tuple& __in)
00347       {
00348     static_cast<_Inherited&>(*this) = __in;
00349     return *this;
00350       }
00351 
00352       tuple&
00353       operator=(tuple&& __in)
00354       {
00355     static_cast<_Inherited&>(*this) = std::move(__in);
00356     return *this;
00357       }
00358 
00359       template<typename _U1, typename _U2>
00360         tuple&
00361         operator=(const tuple<_U1, _U2>& __in)
00362         {
00363       static_cast<_Inherited&>(*this) = __in;
00364       return *this;
00365     }
00366 
00367       template<typename _U1, typename _U2>
00368         tuple&
00369         operator=(tuple<_U1, _U2>&& __in)
00370         {
00371       static_cast<_Inherited&>(*this) = std::move(__in);
00372       return *this;
00373     }
00374 
00375       template<typename _U1, typename _U2>
00376         tuple&
00377         operator=(const pair<_U1, _U2>& __in)
00378         {
00379       this->_M_head() = __in.first;
00380       this->_M_tail()._M_head() = __in.second;
00381       return *this;
00382     }
00383 
00384       template<typename _U1, typename _U2>
00385         tuple&
00386         operator=(pair<_U1, _U2>&& __in)
00387         {
00388       this->_M_head() = std::move(__in.first);
00389       this->_M_tail()._M_head() = std::move(__in.second);
00390       return *this;
00391     }
00392 
00393       void
00394       swap(tuple& __in)
00395       { 
00396     using std::swap;
00397     swap(this->_M_head(), __in._M_head());
00398     swap(this->_M_tail()._M_head(), __in._M_tail()._M_head());  
00399       }
00400     };
00401 
00402 
00403   /// Gives the type of the ith element of a given tuple type.
00404   template<std::size_t __i, typename _Tp>
00405     struct tuple_element;
00406 
00407   /**
00408    * Recursive case for tuple_element: strip off the first element in
00409    * the tuple and retrieve the (i-1)th element of the remaining tuple.
00410    */
00411   template<std::size_t __i, typename _Head, typename... _Tail>
00412     struct tuple_element<__i, tuple<_Head, _Tail...> >
00413     : tuple_element<__i - 1, tuple<_Tail...> > { };
00414 
00415   /**
00416    * Basis case for tuple_element: The first element is the one we're seeking.
00417    */
00418   template<typename _Head, typename... _Tail>
00419     struct tuple_element<0, tuple<_Head, _Tail...> >
00420     {
00421       typedef _Head type;
00422     };
00423 
00424   /// Finds the size of a given tuple type.
00425   template<typename _Tp>
00426     struct tuple_size;
00427 
00428   /// class tuple_size
00429   template<typename... _Elements>
00430     struct tuple_size<tuple<_Elements...> >
00431     {
00432       static const std::size_t value = sizeof...(_Elements);
00433     };
00434 
00435   template<typename... _Elements>
00436     const std::size_t tuple_size<tuple<_Elements...> >::value;
00437 
00438   template<std::size_t __i, typename _Head, typename... _Tail>
00439     inline typename __add_ref<_Head>::type
00440     __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t)
00441     { return __t._M_head(); }
00442 
00443   template<std::size_t __i, typename _Head, typename... _Tail>
00444     inline typename __add_c_ref<_Head>::type
00445     __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t)
00446     { return __t._M_head(); }
00447 
00448   // Return a reference (const reference) to the ith element of a tuple.
00449   // Any const or non-const ref elements are returned with their original type.
00450   template<std::size_t __i, typename... _Elements>
00451     inline typename __add_ref<
00452                       typename tuple_element<__i, tuple<_Elements...> >::type
00453                     >::type
00454     get(tuple<_Elements...>& __t)
00455     { return __get_helper<__i>(__t); }
00456 
00457   template<std::size_t __i, typename... _Elements>
00458     inline typename __add_c_ref<
00459                       typename tuple_element<__i, tuple<_Elements...> >::type
00460                     >::type
00461     get(const tuple<_Elements...>& __t)
00462     { return __get_helper<__i>(__t); }
00463 
00464   // This class helps construct the various comparison operations on tuples
00465   template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
00466        typename _Tp, typename _Up>
00467     struct __tuple_compare;
00468 
00469   template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
00470     struct __tuple_compare<0, __i, __j, _Tp, _Up>
00471     {
00472       static bool __eq(const _Tp& __t, const _Up& __u)
00473       {
00474     return (get<__i>(__t) == get<__i>(__u) &&
00475         __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
00476       }
00477      
00478       static bool __less(const _Tp& __t, const _Up& __u)
00479       {
00480     return ((get<__i>(__t) < get<__i>(__u))
00481         || !(get<__i>(__u) < get<__i>(__t)) &&
00482         __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
00483       }
00484     };
00485 
00486   template<std::size_t __i, typename _Tp, typename _Up>
00487     struct __tuple_compare<0, __i, __i, _Tp, _Up>
00488     {
00489       static bool __eq(const _Tp&, const _Up&)
00490       { return true; }
00491      
00492       static bool __less(const _Tp&, const _Up&)
00493       { return false; }
00494     };
00495 
00496   template<typename... _TElements, typename... _UElements>
00497     bool
00498     operator==(const tuple<_TElements...>& __t,
00499            const tuple<_UElements...>& __u)
00500     {
00501       typedef tuple<_TElements...> _Tp;
00502       typedef tuple<_UElements...> _Up;
00503       return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
00504           0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
00505     }
00506 
00507   template<typename... _TElements, typename... _UElements>
00508     bool
00509     operator<(const tuple<_TElements...>& __t,
00510           const tuple<_UElements...>& __u)
00511     {
00512       typedef tuple<_TElements...> _Tp;
00513       typedef tuple<_UElements...> _Up;
00514       return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
00515           0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
00516     }
00517 
00518   template<typename... _TElements, typename... _UElements>
00519     inline bool
00520     operator!=(const tuple<_TElements...>& __t,
00521            const tuple<_UElements...>& __u)
00522     { return !(__t == __u); }
00523 
00524   template<typename... _TElements, typename... _UElements>
00525     inline bool
00526     operator>(const tuple<_TElements...>& __t,
00527           const tuple<_UElements...>& __u)
00528     { return __u < __t; }
00529 
00530   template<typename... _TElements, typename... _UElements>
00531     inline bool
00532     operator<=(const tuple<_TElements...>& __t,
00533            const tuple<_UElements...>& __u)
00534     { return !(__u < __t); }
00535 
00536   template<typename... _TElements, typename... _UElements>
00537     inline bool
00538     operator>=(const tuple<_TElements...>& __t,
00539            const tuple<_UElements...>& __u)
00540     { return !(__t < __u); }
00541 
00542   // NB: DR 705.
00543   template<typename... _Elements>
00544     inline tuple<typename __decay_and_strip<_Elements>::__type...>
00545     make_tuple(_Elements&&... __args)
00546     {
00547       typedef tuple<typename __decay_and_strip<_Elements>::__type...>
00548     __result_type;
00549       return __result_type(std::forward<_Elements>(__args)...);
00550     }
00551 
00552   template<typename _Tp, bool = is_array<_Tp>::value>
00553     struct __pa_add_rvalue_reference_helper
00554     { typedef typename std::add_rvalue_reference<_Tp>::type __type; };
00555 
00556   template<typename _Tp>
00557     struct __pa_add_rvalue_reference_helper<_Tp, true>
00558     { typedef _Tp& __type; };
00559 
00560   template<typename _Tp>
00561     struct __pa_add_rvalue_reference
00562     : public __pa_add_rvalue_reference_helper<_Tp>
00563     { };
00564 
00565   template<typename... _Elements>
00566     inline tuple<typename __pa_add_rvalue_reference<_Elements>::__type...>
00567     pack_arguments(_Elements&&... __args)
00568     {
00569       typedef tuple<typename __pa_add_rvalue_reference<_Elements>::__type...>
00570     __result_type;
00571       return __result_type(std::forward<_Elements>(__args)...);
00572     }
00573 
00574   template<std::size_t...> struct __index_holder { };    
00575 
00576   template<std::size_t __i, typename _IdxHolder, typename... _Elements>
00577     struct __index_holder_impl;
00578 
00579   template<std::size_t __i, std::size_t... _Indexes, typename _IdxHolder,
00580        typename... _Elements>
00581     struct __index_holder_impl<__i, __index_holder<_Indexes...>,
00582                    _IdxHolder, _Elements...> 
00583     {
00584       typedef typename __index_holder_impl<__i + 1,
00585                        __index_holder<_Indexes..., __i>,
00586                        _Elements...>::type type;
00587     };
00588  
00589   template<std::size_t __i, std::size_t... _Indexes>
00590     struct __index_holder_impl<__i, __index_holder<_Indexes...> >
00591     { typedef __index_holder<_Indexes...> type; };
00592 
00593   template<typename... _Elements>
00594     struct __make_index_holder 
00595     : __index_holder_impl<0, __index_holder<>, _Elements...> { };
00596     
00597   template<typename... _TElements, std::size_t... _TIdx,
00598        typename... _UElements, std::size_t... _UIdx> 
00599     inline tuple<_TElements..., _UElements...> 
00600     __tuple_cat_helper(const tuple<_TElements...>& __t,
00601                const __index_holder<_TIdx...>&,
00602                        const tuple<_UElements...>& __u,
00603                const __index_holder<_UIdx...>&)
00604     { return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)...,
00605                          get<_UIdx>(__u)...); }
00606 
00607   template<typename... _TElements, std::size_t... _TIdx,
00608        typename... _UElements, std::size_t... _UIdx> 
00609     inline tuple<_TElements..., _UElements...> 
00610     __tuple_cat_helper(tuple<_TElements...>&& __t,
00611                const __index_holder<_TIdx...>&, 
00612                const tuple<_UElements...>& __u,
00613                const __index_holder<_UIdx...>&)
00614     { return tuple<_TElements..., _UElements...>
00615     (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
00616 
00617   template<typename... _TElements, std::size_t... _TIdx,
00618        typename... _UElements, std::size_t... _UIdx>
00619     inline tuple<_TElements..., _UElements...> 
00620     __tuple_cat_helper(const tuple<_TElements...>& __t,
00621                const __index_holder<_TIdx...>&, 
00622                tuple<_UElements...>&& __u,
00623                const __index_holder<_UIdx...>&)
00624     { return tuple<_TElements..., _UElements...>
00625     (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
00626 
00627   template<typename... _TElements, std::size_t... _TIdx,
00628        typename... _UElements, std::size_t... _UIdx> 
00629     inline tuple<_TElements..., _UElements...> 
00630     __tuple_cat_helper(tuple<_TElements...>&& __t,
00631                const __index_holder<_TIdx...>&, 
00632                tuple<_UElements...>&& __u,
00633                const __index_holder<_UIdx...>&)
00634     { return tuple<_TElements..., _UElements...>
00635     (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
00636 
00637   template<typename... _TElements, typename... _UElements>
00638     inline tuple<_TElements..., _UElements...> 
00639     tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u)
00640     {
00641       return __tuple_cat_helper(__t, typename
00642                 __make_index_holder<_TElements...>::type(),
00643                 __u, typename
00644                 __make_index_holder<_UElements...>::type());
00645     }
00646 
00647   template<typename... _TElements, typename... _UElements>
00648     inline tuple<_TElements..., _UElements...> 
00649     tuple_cat(tuple<_TElements...>&& __t, const tuple<_UElements...>& __u)
00650     {
00651       return __tuple_cat_helper(std::move(__t), typename
00652                  __make_index_holder<_TElements...>::type(),
00653                  __u, typename
00654                  __make_index_holder<_UElements...>::type());
00655     }
00656 
00657   template<typename... _TElements, typename... _UElements>
00658     inline tuple<_TElements..., _UElements...> 
00659     tuple_cat(const tuple<_TElements...>& __t, tuple<_UElements...>&& __u)
00660     {
00661       return __tuple_cat_helper(__t, typename
00662                 __make_index_holder<_TElements...>::type(),
00663                 std::move(__u), typename
00664                 __make_index_holder<_UElements...>::type());
00665     }
00666 
00667   template<typename... _TElements, typename... _UElements>
00668     inline tuple<_TElements..., _UElements...>
00669     tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u)
00670     {
00671       return __tuple_cat_helper(std::move(__t), typename
00672                 __make_index_holder<_TElements...>::type(),
00673                 std::move(__u), typename
00674                 __make_index_holder<_UElements...>::type());
00675     }
00676 
00677   template<typename... _Elements>
00678     inline tuple<_Elements&...>
00679     tie(_Elements&... __args)
00680     { return tuple<_Elements&...>(__args...); }
00681 
00682   template<typename... _Elements>
00683     inline void 
00684     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
00685     { __x.swap(__y); }
00686 
00687   // A class (and instance) which can be used in 'tie' when an element
00688   // of a tuple is not required
00689   struct _Swallow_assign
00690   {
00691     template<class _Tp>
00692       const _Swallow_assign&
00693       operator=(const _Tp&) const
00694       { return *this; }
00695   };
00696 
00697   const _Swallow_assign ignore{};
00698 
00699   /**
00700    * Stores a tuple of indices. Used by bind() to extract the elements
00701    * in a tuple. 
00702    */
00703   template<int... _Indexes>
00704     struct _Index_tuple
00705     {
00706       typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
00707     };
00708 
00709   /// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
00710   template<std::size_t _Num>
00711     struct _Build_index_tuple
00712     {
00713       typedef typename _Build_index_tuple<_Num-1>::__type::__next __type;
00714     };
00715 
00716   template<>
00717     struct _Build_index_tuple<0>
00718     {
00719       typedef _Index_tuple<> __type;
00720     };
00721 
00722   // See stl_pair.h...
00723   template<class _T1, class _T2>
00724     template<typename _Tp, typename... _Args>
00725       inline _Tp
00726       pair<_T1, _T2>::
00727       __cons(tuple<_Args...>&& __tuple)
00728       {
00729     typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
00730       _Indexes;
00731     return __do_cons<_Tp>(std::move(__tuple), _Indexes());
00732       }
00733 
00734   template<class _T1, class _T2>
00735     template<typename _Tp, typename... _Args, int... _Indexes>
00736       inline _Tp
00737       pair<_T1, _T2>::
00738       __do_cons(tuple<_Args...>&& __tuple,
00739         const _Index_tuple<_Indexes...>&)
00740       { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
00741 }
00742 
00743 #endif // __GXX_EXPERIMENTAL_CXX0X__
00744 
00745 #endif // _GLIBCXX_TUPLE