1 // class template tuple -*- C++ -*- 2 3 // Copyright (C) 2004, 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License along 17 // with this library; see the file COPYING. If not, write to the Free 18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19 // USA. 20 21 // As a special exception, you may use this file as part of a free software 22 // library without restriction. Specifically, if other files instantiate 23 // templates or use macros or inline functions from this file, or you compile 24 // this file and link it with other files to produce an executable, this 25 // file does not by itself cause the resulting executable to be covered by 26 // the GNU General Public License. This exception does not however 27 // invalidate any other reasons why the executable file might be covered by 28 // the GNU General Public License. 29 30 /** @file tr1/tuple_iterate.h 31 * This is an internal header file, included by other library headers. 32 * You should not attempt to use it directly. 33 */ 34 35 // Chris Jefferson <chris@bubblescope.net> 36 37 namespace std 38 { 39 _GLIBCXX_BEGIN_NAMESPACE(tr1) 40 41 /// @brief class tuple_size 42 template<_GLIBCXX_TEMPLATE_PARAMS> 43 struct tuple_size<tuple<_GLIBCXX_TEMPLATE_ARGS> > 44 { static const int value = _GLIBCXX_NUM_ARGS; }; 45 46 #if _GLIBCXX_NUM_ARGS > 0 47 template<_GLIBCXX_TEMPLATE_PARAMS> 48 const int tuple_size<tuple<_GLIBCXX_TEMPLATE_ARGS> >::value; 49 #endif 50 51 template<_GLIBCXX_TEMPLATE_PARAMS> 52 #ifdef _GLIBCXX_LAST_INCLUDE 53 class tuple 54 #else 55 class tuple<_GLIBCXX_TEMPLATE_ARGS> 56 #endif 57 { 58 _GLIBCXX_BIND_MEMBERS 59 60 public: 61 tuple() 62 { } 63 64 #if _GLIBCXX_NUM_ARGS == 2 65 template<typename _U1, typename _U2> 66 tuple(const std::pair<_U1, _U2>& __u) : 67 _M_arg1(__u.first), _M_arg2(__u.second) 68 { } 69 70 template<typename _U1, typename _U2> 71 tuple& 72 operator=(const std::pair<_U1, _U2>& __u) 73 { 74 _M_arg1 = __u.first; 75 _M_arg2 = __u.second; 76 return *this; 77 } 78 #endif 79 80 #if _GLIBCXX_NUM_ARGS > 0 81 explicit tuple(_GLIBCXX_TUPLE_ADD_CREF) : 82 _GLIBCXX_BIND_MEMBERS_INIT 83 { } 84 85 template<_GLIBCXX_TEMPLATE_PARAMS_U> 86 tuple(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in) : 87 _GLIBCXX_TUPLE_COPY_INIT 88 { } 89 90 91 template<_GLIBCXX_TEMPLATE_PARAMS_U> 92 tuple& 93 operator=(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in) 94 { 95 _GLIBCXX_TUPLE_ASSIGN 96 return *this; 97 } 98 99 tuple(const tuple& __in) : 100 _GLIBCXX_TUPLE_COPY_INIT 101 { } 102 103 #else 104 105 tuple(const tuple&) 106 { } 107 108 #endif 109 110 tuple& 111 operator=(const tuple& __in __attribute__((__unused__)) ) 112 { 113 _GLIBCXX_TUPLE_ASSIGN 114 return *this; 115 } 116 117 template<int __i, typename __Type> 118 friend class __get_helper; 119 120 template<_GLIBCXX_TUPLE_ALL_TEMPLATE_PARAMS_UNNAMED> 121 friend class tuple; 122 }; 123 124 #ifndef _GLIBCXX_LAST_INCLUDE 125 126 template<typename _Tp> 127 struct __get_helper<_GLIBCXX_NUM_ARGS, _Tp> 128 { 129 static typename __add_ref<typename tuple_element<_GLIBCXX_NUM_ARGS, 130 _Tp>::type>::type 131 get_value(_Tp& __in) 132 { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); } 133 134 static typename __add_c_ref<typename tuple_element<_GLIBCXX_NUM_ARGS, 135 _Tp>::type>::type 136 get_value(const _Tp& __in) 137 { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); } 138 }; 139 140 /// @brief class tuple_element 141 template<_GLIBCXX_TUPLE_ALL_TEMPLATE_PARAMS> 142 struct tuple_element<_GLIBCXX_NUM_ARGS, tuple<_GLIBCXX_TUPLE_ALL_TEMPLATE_ARGS> > 143 { typedef _GLIBCXX_T_NUM_ARGS_PLUS_1 type; }; 144 145 #endif 146 #if _GLIBCXX_NUM_ARGS == 0 147 148 tuple<> 149 inline make_tuple() 150 { return tuple<>(); } 151 152 tuple<> 153 inline tie() 154 { return tuple<>(); } 155 #else 156 157 template<_GLIBCXX_TEMPLATE_PARAMS> 158 typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>::__type 159 inline make_tuple(_GLIBCXX_PARAMS) 160 { 161 return typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>:: 162 __type(_GLIBCXX_ARGS); 163 } 164 165 template<_GLIBCXX_TEMPLATE_PARAMS> 166 tuple<_GLIBCXX_REF_TEMPLATE_ARGS> 167 inline tie(_GLIBCXX_REF_PARAMS) 168 { return make_tuple(_GLIBCXX_REF_WRAP_PARAMS); } 169 #endif 170 171 _GLIBCXX_END_NAMESPACE 172 } 173