tuple_iterate.h

Go to the documentation of this file.
00001 // class template tuple -*- C++ -*-
00002 
00003 // Copyright (C) 2004, 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 /** @file tr1/tuple_iterate.h
00031  *  This is an internal header file, included by other library headers.
00032  *  You should not attempt to use it directly.
00033  */
00034 
00035 // Chris Jefferson <chris@bubblescope.net>
00036 
00037 namespace std
00038 {
00039 _GLIBCXX_BEGIN_NAMESPACE(tr1)
00040 
00041 /// @brief class tuple_size
00042 template<_GLIBCXX_TEMPLATE_PARAMS>
00043   struct tuple_size<tuple<_GLIBCXX_TEMPLATE_ARGS> >
00044   { static const int value = _GLIBCXX_NUM_ARGS; };
00045 
00046 #if _GLIBCXX_NUM_ARGS > 0
00047 template<_GLIBCXX_TEMPLATE_PARAMS>
00048   const int tuple_size<tuple<_GLIBCXX_TEMPLATE_ARGS> >::value;
00049 #endif
00050 
00051 template<_GLIBCXX_TEMPLATE_PARAMS>
00052 #ifdef _GLIBCXX_LAST_INCLUDE
00053   class tuple
00054 #else
00055   class tuple<_GLIBCXX_TEMPLATE_ARGS>
00056 #endif
00057   {
00058     _GLIBCXX_BIND_MEMBERS
00059 
00060   public:
00061     tuple()
00062     { }
00063 
00064 #if _GLIBCXX_NUM_ARGS == 2
00065     template<typename _U1, typename _U2>
00066       tuple(const std::pair<_U1, _U2>& __u) :
00067       _M_arg1(__u.first), _M_arg2(__u.second)
00068       { }
00069 
00070     template<typename _U1, typename _U2>
00071       tuple&
00072       operator=(const std::pair<_U1, _U2>& __u)
00073       { 
00074     _M_arg1 = __u.first;
00075     _M_arg2 = __u.second;
00076     return *this;
00077       }
00078 #endif
00079 
00080 #if _GLIBCXX_NUM_ARGS > 0
00081     explicit tuple(_GLIBCXX_TUPLE_ADD_CREF) :
00082       _GLIBCXX_BIND_MEMBERS_INIT
00083     { }
00084 
00085     template<_GLIBCXX_TEMPLATE_PARAMS_U>
00086       tuple(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in) :
00087       _GLIBCXX_TUPLE_COPY_INIT
00088     { }
00089 
00090 
00091     template<_GLIBCXX_TEMPLATE_PARAMS_U>
00092       tuple&
00093       operator=(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in)
00094       {
00095         _GLIBCXX_TUPLE_ASSIGN
00096         return *this;
00097       }
00098 
00099     tuple(const tuple& __in) :
00100       _GLIBCXX_TUPLE_COPY_INIT
00101     { }
00102 
00103 #else
00104 
00105     tuple(const tuple&)
00106     { }
00107 
00108 #endif
00109 
00110     tuple&
00111     operator=(const tuple& __in __attribute__((__unused__)) )
00112     {
00113       _GLIBCXX_TUPLE_ASSIGN
00114         return *this;
00115     }
00116 
00117     template<int __i, typename __Type>
00118       friend class __get_helper;
00119 
00120     template<_GLIBCXX_TUPLE_ALL_TEMPLATE_PARAMS_UNNAMED>
00121       friend class tuple;
00122   };
00123 
00124 #ifndef _GLIBCXX_LAST_INCLUDE
00125 
00126 template<typename _Tp>
00127     struct __get_helper<_GLIBCXX_NUM_ARGS, _Tp>
00128     {
00129       static typename __add_ref<typename tuple_element<_GLIBCXX_NUM_ARGS,
00130                                                        _Tp>::type>::type
00131       get_value(_Tp& __in)
00132       { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); }
00133 
00134       static typename __add_c_ref<typename tuple_element<_GLIBCXX_NUM_ARGS,
00135                                                          _Tp>::type>::type
00136       get_value(const _Tp& __in)
00137       { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); }
00138     };
00139 
00140 /// @brief class tuple_element
00141 template<_GLIBCXX_TUPLE_ALL_TEMPLATE_PARAMS>
00142    struct tuple_element<_GLIBCXX_NUM_ARGS, tuple<_GLIBCXX_TUPLE_ALL_TEMPLATE_ARGS> >
00143   { typedef _GLIBCXX_T_NUM_ARGS_PLUS_1 type; };
00144 
00145 #endif
00146 #if _GLIBCXX_NUM_ARGS == 0
00147 
00148 tuple<>
00149 inline make_tuple()
00150 { return tuple<>(); }
00151 
00152 tuple<>
00153 inline tie()
00154 { return tuple<>(); }
00155 #else
00156 
00157 template<_GLIBCXX_TEMPLATE_PARAMS>
00158   typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>::__type
00159   inline make_tuple(_GLIBCXX_PARAMS)
00160   {
00161     return typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>::
00162       __type(_GLIBCXX_ARGS);
00163   }
00164 
00165 template<_GLIBCXX_TEMPLATE_PARAMS>
00166   tuple<_GLIBCXX_REF_TEMPLATE_ARGS>
00167   inline tie(_GLIBCXX_REF_PARAMS)
00168   { return make_tuple(_GLIBCXX_REF_WRAP_PARAMS); }
00169 #endif
00170 
00171 _GLIBCXX_END_NAMESPACE
00172 }

Generated on Thu Nov 1 13:12:47 2007 for libstdc++ by  doxygen 1.5.1