Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/c++/13/tr1/tuple
$ cat -n /usr/include/c++/13/tr1/tuple 1 // class template tuple -*- C++ -*- 2 3 // Copyright (C) 2004-2023 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 //
. 24 25 /** @file tr1/tuple 26 * This is a TR1 C++ Library header. 27 */ 28 29 // Chris Jefferson
30 // Variadic Templates support by Douglas Gregor
31 32 #ifndef _GLIBCXX_TR1_TUPLE 33 #define _GLIBCXX_TR1_TUPLE 1 34 35 #pragma GCC system_header 36 37 #include
// TR1 38 39 #include
40 41 namespace std _GLIBCXX_VISIBILITY(default) 42 { 43 _GLIBCXX_BEGIN_NAMESPACE_VERSION 44 45 namespace tr1 46 { 47 // Adds a const reference to a non-reference type. 48 template
49 struct __add_c_ref 50 { typedef const _Tp& type; }; 51 52 template
53 struct __add_c_ref<_Tp&> 54 { typedef _Tp& type; }; 55 56 // Adds a reference to a non-reference type. 57 template
58 struct __add_ref 59 { typedef _Tp& type; }; 60 61 template
62 struct __add_ref<_Tp&> 63 { typedef _Tp& type; }; 64 65 /** 66 * Contains the actual implementation of the @c tuple template, stored 67 * as a recursive inheritance hierarchy from the first element (most 68 * derived class) to the last (least derived class). The @c Idx 69 * parameter gives the 0-based index of the element stored at this 70 * point in the hierarchy; we use it to implement a constant-time 71 * get() operation. 72 */ 73 template
74 struct _Tuple_impl; 75 76 /** 77 * Zero-element tuple implementation. This is the basis case for the 78 * inheritance recursion. 79 */ 80 template
81 struct _Tuple_impl<_Idx> { }; 82 83 /** 84 * Recursive tuple implementation. Here we store the @c Head element 85 * and derive from a @c Tuple_impl containing the remaining elements 86 * (which contains the @c Tail). 87 */ 88 template
89 struct _Tuple_impl<_Idx, _Head, _Tail...> 90 : public _Tuple_impl<_Idx + 1, _Tail...> 91 { 92 typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; 93 94 _Head _M_head; 95 96 _Inherited& _M_tail() { return *this; } 97 const _Inherited& _M_tail() const { return *this; } 98 99 _Tuple_impl() : _Inherited(), _M_head() { } 100 101 explicit 102 _Tuple_impl(typename __add_c_ref<_Head>::type __head, 103 typename __add_c_ref<_Tail>::type... __tail) 104 : _Inherited(__tail...), _M_head(__head) { } 105 106 template
107 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) 108 : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } 109 110 _Tuple_impl(const _Tuple_impl& __in) 111 : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } 112 113 template
114 _Tuple_impl& 115 operator=(const _Tuple_impl<_Idx, _UElements...>& __in) 116 { 117 _M_head = __in._M_head; 118 _M_tail() = __in._M_tail(); 119 return *this; 120 } 121 122 _Tuple_impl& 123 operator=(const _Tuple_impl& __in) 124 { 125 _M_head = __in._M_head; 126 _M_tail() = __in._M_tail(); 127 return *this; 128 } 129 }; 130 131 template
132 class tuple : public _Tuple_impl<0, _Elements...> 133 { 134 typedef _Tuple_impl<0, _Elements...> _Inherited; 135 136 public: 137 tuple() : _Inherited() { } 138 139 explicit 140 tuple(typename __add_c_ref<_Elements>::type... __elements) 141 : _Inherited(__elements...) { } 142 143 template
144 tuple(const tuple<_UElements...>& __in) 145 : _Inherited(__in) { } 146 147 tuple(const tuple& __in) 148 : _Inherited(__in) { } 149 150 template
151 tuple& 152 operator=(const tuple<_UElements...>& __in) 153 { 154 static_cast<_Inherited&>(*this) = __in; 155 return *this; 156 } 157 158 tuple& 159 operator=(const tuple& __in) 160 { 161 static_cast<_Inherited&>(*this) = __in; 162 return *this; 163 } 164 }; 165 166 template<> class tuple<> { }; 167 168 // 2-element tuple, with construction and assignment from a pair. 169 template
170 class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2> 171 { 172 typedef _Tuple_impl<0, _T1, _T2> _Inherited; 173 174 public: 175 tuple() : _Inherited() { } 176 177 explicit 178 tuple(typename __add_c_ref<_T1>::type __a1, 179 typename __add_c_ref<_T2>::type __a2) 180 : _Inherited(__a1, __a2) { } 181 182 template
183 tuple(const tuple<_U1, _U2>& __in) 184 : _Inherited(__in) { } 185 186 tuple(const tuple& __in) 187 : _Inherited(__in) { } 188 189 template
190 tuple(const pair<_U1, _U2>& __in) 191 : _Inherited(_Tuple_impl<0, 192 typename __add_c_ref<_U1>::type, 193 typename __add_c_ref<_U2>::type>(__in.first, 194 __in.second)) 195 { } 196 197 template
198 tuple& 199 operator=(const tuple<_U1, _U2>& __in) 200 { 201 static_cast<_Inherited&>(*this) = __in; 202 return *this; 203 } 204 205 tuple& 206 operator=(const tuple& __in) 207 { 208 static_cast<_Inherited&>(*this) = __in; 209 return *this; 210 } 211 212 template
213 tuple& 214 operator=(const pair<_U1, _U2>& __in) 215 { 216 this->_M_head = __in.first; 217 this->_M_tail()._M_head = __in.second; 218 return *this; 219 } 220 }; 221 222 223 /// Gives the type of the ith element of a given tuple type. 224 template
225 struct tuple_element; 226 227 /** 228 * Recursive case for tuple_element: strip off the first element in 229 * the tuple and retrieve the (i-1)th element of the remaining tuple. 230 */ 231 template
232 struct tuple_element<__i, tuple<_Head, _Tail...> > 233 : tuple_element<__i - 1, tuple<_Tail...> > { }; 234 235 /** 236 * Basis case for tuple_element: The first element is the one we're seeking. 237 */ 238 template
239 struct tuple_element<0, tuple<_Head, _Tail...> > 240 { 241 typedef _Head type; 242 }; 243 244 /// Finds the size of a given tuple type. 245 template
246 struct tuple_size; 247 248 /// class tuple_size 249 template
250 struct tuple_size
> 251 { 252 static const int value = sizeof...(_Elements); 253 }; 254 255 template
256 const int tuple_size
>::value; 257 258 template
259 inline typename __add_ref<_Head>::type 260 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) 261 { 262 return __t._M_head; 263 } 264 265 template
266 inline typename __add_c_ref<_Head>::type 267 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) 268 { 269 return __t._M_head; 270 } 271 272 // Return a reference (const reference) to the ith element of a tuple. 273 // Any const or non-const ref elements are returned with their original type. 274 template
275 inline typename __add_ref< 276 typename tuple_element<__i, tuple<_Elements...> >::type 277 >::type 278 get(tuple<_Elements...>& __t) 279 { 280 return __get_helper<__i>(__t); 281 } 282 283 template
284 inline typename __add_c_ref< 285 typename tuple_element<__i, tuple<_Elements...> >::type 286 >::type 287 get(const tuple<_Elements...>& __t) 288 { 289 return __get_helper<__i>(__t); 290 } 291 292 // This class helps construct the various comparison operations on tuples 293 template
295 struct __tuple_compare; 296 297 template
298 struct __tuple_compare<0, __i, __j, _Tp, _Up> 299 { 300 static bool __eq(const _Tp& __t, const _Up& __u) 301 { 302 return (get<__i>(__t) == get<__i>(__u) && 303 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u)); 304 } 305 306 static bool __less(const _Tp& __t, const _Up& __u) 307 { 308 return ((get<__i>(__t) < get<__i>(__u)) 309 || !(get<__i>(__u) < get<__i>(__t)) && 310 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u)); 311 } 312 }; 313 314 template
315 struct __tuple_compare<0, __i, __i, _Tp, _Up> 316 { 317 static bool __eq(const _Tp&, const _Up&) 318 { return true; } 319 320 static bool __less(const _Tp&, const _Up&) 321 { return false; } 322 }; 323 324 template
325 bool 326 operator==(const tuple<_TElements...>& __t, 327 const tuple<_UElements...>& __u) 328 { 329 typedef tuple<_TElements...> _Tp; 330 typedef tuple<_UElements...> _Up; 331 return (__tuple_compare
::value - tuple_size<_Up>::value, 332 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); 333 } 334 335 template
336 bool 337 operator<(const tuple<_TElements...>& __t, 338 const tuple<_UElements...>& __u) 339 { 340 typedef tuple<_TElements...> _Tp; 341 typedef tuple<_UElements...> _Up; 342 return (__tuple_compare
::value - tuple_size<_Up>::value, 343 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); 344 } 345 346 template
347 inline bool 348 operator!=(const tuple<_TElements...>& __t, 349 const tuple<_UElements...>& __u) 350 { return !(__t == __u); } 351 352 template
353 inline bool 354 operator>(const tuple<_TElements...>& __t, 355 const tuple<_UElements...>& __u) 356 { return __u < __t; } 357 358 template
359 inline bool 360 operator<=(const tuple<_TElements...>& __t, 361 const tuple<_UElements...>& __u) 362 { return !(__u < __t); } 363 364 template
365 inline bool 366 operator>=(const tuple<_TElements...>& __t, 367 const tuple<_UElements...>& __u) 368 { return !(__t < __u); } 369 370 template
371 class reference_wrapper; 372 373 // Helper which adds a reference to a type when given a reference_wrapper 374 template
375 struct __strip_reference_wrapper 376 { 377 typedef _Tp __type; 378 }; 379 380 template
381 struct __strip_reference_wrapper
> 382 { 383 typedef _Tp& __type; 384 }; 385 386 template
387 struct __strip_reference_wrapper
> 388 { 389 typedef _Tp& __type; 390 }; 391 392 template
393 inline tuple
::__type...> 394 make_tuple(_Elements... __args) 395 { 396 typedef tuple
::__type...> 397 __result_type; 398 return __result_type(__args...); 399 } 400 401 template
402 inline tuple<_Elements&...> 403 tie(_Elements&... __args) 404 { 405 return tuple<_Elements&...>(__args...); 406 } 407 408 // A class (and instance) which can be used in 'tie' when an element 409 // of a tuple is not required 410 struct _Swallow_assign 411 { 412 template
413 _Swallow_assign& 414 operator=(const _Tp&) 415 { return *this; } 416 }; 417 418 // TODO: Put this in some kind of shared file. 419 namespace 420 { 421 _Swallow_assign ignore; 422 }; // anonymous namespace 423 } 424 425 _GLIBCXX_END_NAMESPACE_VERSION 426 } 427 428 #endif // _GLIBCXX_TR1_TUPLE
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™