1 1.1 mrg // Input streams -*- C++ -*- 2 1.1 mrg 3 1.14 mrg // Copyright (C) 1997-2022 Free Software Foundation, Inc. 4 1.1 mrg // 5 1.1 mrg // This file is part of the GNU ISO C++ Library. This library is free 6 1.1 mrg // software; you can redistribute it and/or modify it under the 7 1.1 mrg // terms of the GNU General Public License as published by the 8 1.1 mrg // Free Software Foundation; either version 3, or (at your option) 9 1.1 mrg // any later version. 10 1.1 mrg 11 1.1 mrg // This library is distributed in the hope that it will be useful, 12 1.1 mrg // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 mrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 mrg // GNU General Public License for more details. 15 1.1 mrg 16 1.1 mrg // Under Section 7 of GPL version 3, you are granted additional 17 1.1 mrg // permissions described in the GCC Runtime Library Exception, version 18 1.1 mrg // 3.1, as published by the Free Software Foundation. 19 1.1 mrg 20 1.1 mrg // You should have received a copy of the GNU General Public License and 21 1.1 mrg // a copy of the GCC Runtime Library Exception along with this program; 22 1.1 mrg // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 1.1 mrg // <http://www.gnu.org/licenses/>. 24 1.1 mrg 25 1.1 mrg // 26 1.1 mrg // ISO C++ 14882: 27.6.1 Input streams 27 1.1 mrg // 28 1.1 mrg 29 1.3 mrg /** @file include/istream 30 1.1 mrg * This is a Standard C++ Library header. 31 1.1 mrg */ 32 1.1 mrg 33 1.1 mrg #ifndef _GLIBCXX_ISTREAM 34 1.1 mrg #define _GLIBCXX_ISTREAM 1 35 1.1 mrg 36 1.1 mrg #pragma GCC system_header 37 1.1 mrg 38 1.1 mrg #include <ios> 39 1.1 mrg #include <ostream> 40 1.1 mrg 41 1.3 mrg namespace std _GLIBCXX_VISIBILITY(default) 42 1.3 mrg { 43 1.3 mrg _GLIBCXX_BEGIN_NAMESPACE_VERSION 44 1.1 mrg 45 1.1 mrg /** 46 1.3 mrg * @brief Template class basic_istream. 47 1.1 mrg * @ingroup io 48 1.1 mrg * 49 1.3 mrg * @tparam _CharT Type of character stream. 50 1.3 mrg * @tparam _Traits Traits for character type, defaults to 51 1.3 mrg * char_traits<_CharT>. 52 1.3 mrg * 53 1.1 mrg * This is the base class for all input streams. It provides text 54 1.1 mrg * formatting of all builtin types, and communicates with any class 55 1.1 mrg * derived from basic_streambuf to do the actual input. 56 1.1 mrg */ 57 1.1 mrg template<typename _CharT, typename _Traits> 58 1.1 mrg class basic_istream : virtual public basic_ios<_CharT, _Traits> 59 1.1 mrg { 60 1.1 mrg public: 61 1.1 mrg // Types (inherited from basic_ios (27.4.4)): 62 1.3 mrg typedef _CharT char_type; 63 1.1 mrg typedef typename _Traits::int_type int_type; 64 1.1 mrg typedef typename _Traits::pos_type pos_type; 65 1.1 mrg typedef typename _Traits::off_type off_type; 66 1.3 mrg typedef _Traits traits_type; 67 1.3 mrg 68 1.1 mrg // Non-standard Types: 69 1.1 mrg typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 70 1.1 mrg typedef basic_ios<_CharT, _Traits> __ios_type; 71 1.1 mrg typedef basic_istream<_CharT, _Traits> __istream_type; 72 1.3 mrg typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > 73 1.1 mrg __num_get_type; 74 1.3 mrg typedef ctype<_CharT> __ctype_type; 75 1.1 mrg 76 1.1 mrg protected: 77 1.1 mrg // Data Members: 78 1.1 mrg /** 79 1.1 mrg * The number of characters extracted in the previous unformatted 80 1.1 mrg * function; see gcount(). 81 1.1 mrg */ 82 1.1 mrg streamsize _M_gcount; 83 1.1 mrg 84 1.1 mrg public: 85 1.1 mrg /** 86 1.1 mrg * @brief Base constructor. 87 1.1 mrg * 88 1.1 mrg * This ctor is almost never called by the user directly, rather from 89 1.1 mrg * derived classes' initialization lists, which pass a pointer to 90 1.1 mrg * their own stream buffer. 91 1.1 mrg */ 92 1.1 mrg explicit 93 1.1 mrg basic_istream(__streambuf_type* __sb) 94 1.1 mrg : _M_gcount(streamsize(0)) 95 1.1 mrg { this->init(__sb); } 96 1.1 mrg 97 1.1 mrg /** 98 1.1 mrg * @brief Base destructor. 99 1.1 mrg * 100 1.1 mrg * This does very little apart from providing a virtual base dtor. 101 1.1 mrg */ 102 1.3 mrg virtual 103 1.3 mrg ~basic_istream() 104 1.1 mrg { _M_gcount = streamsize(0); } 105 1.1 mrg 106 1.3 mrg /// Safe prefix/suffix operations. 107 1.1 mrg class sentry; 108 1.1 mrg friend class sentry; 109 1.1 mrg 110 1.13 mrg ///@{ 111 1.1 mrg /** 112 1.1 mrg * @brief Interface for manipulators. 113 1.1 mrg * 114 1.1 mrg * Manipulators such as @c std::ws and @c std::dec use these 115 1.3 mrg * functions in constructs like 116 1.3 mrg * <code>std::cin >> std::ws</code>. 117 1.1 mrg * For more information, see the iomanip header. 118 1.1 mrg */ 119 1.1 mrg __istream_type& 120 1.1 mrg operator>>(__istream_type& (*__pf)(__istream_type&)) 121 1.1 mrg { return __pf(*this); } 122 1.1 mrg 123 1.1 mrg __istream_type& 124 1.1 mrg operator>>(__ios_type& (*__pf)(__ios_type&)) 125 1.3 mrg { 126 1.1 mrg __pf(*this); 127 1.1 mrg return *this; 128 1.1 mrg } 129 1.1 mrg 130 1.1 mrg __istream_type& 131 1.1 mrg operator>>(ios_base& (*__pf)(ios_base&)) 132 1.1 mrg { 133 1.1 mrg __pf(*this); 134 1.1 mrg return *this; 135 1.1 mrg } 136 1.13 mrg ///@} 137 1.3 mrg 138 1.13 mrg ///@{ 139 1.1 mrg /** 140 1.3 mrg * @name Extractors 141 1.1 mrg * 142 1.1 mrg * All the @c operator>> functions (aka <em>formatted input 143 1.1 mrg * functions</em>) have some common behavior. Each starts by 144 1.1 mrg * constructing a temporary object of type std::basic_istream::sentry 145 1.1 mrg * with the second argument (noskipws) set to false. This has several 146 1.1 mrg * effects, concluding with the setting of a status flag; see the 147 1.1 mrg * sentry documentation for more. 148 1.1 mrg * 149 1.1 mrg * If the sentry status is good, the function tries to extract 150 1.1 mrg * whatever data is appropriate for the type of the argument. 151 1.1 mrg * 152 1.1 mrg * If an exception is thrown during extraction, ios_base::badbit 153 1.8 mrg * will be turned on in the stream's error state (without causing an 154 1.8 mrg * ios_base::failure to be thrown) and the original exception will 155 1.8 mrg * be rethrown if badbit is set in the exceptions mask. 156 1.1 mrg */ 157 1.3 mrg 158 1.13 mrg ///@{ 159 1.1 mrg /** 160 1.3 mrg * @brief Integer arithmetic extractors 161 1.3 mrg * @param __n A variable of builtin integral type. 162 1.1 mrg * @return @c *this if successful 163 1.1 mrg * 164 1.1 mrg * These functions use the stream's current locale (specifically, the 165 1.1 mrg * @c num_get facet) to parse the input data. 166 1.1 mrg */ 167 1.3 mrg __istream_type& 168 1.1 mrg operator>>(bool& __n) 169 1.1 mrg { return _M_extract(__n); } 170 1.3 mrg 171 1.3 mrg __istream_type& 172 1.1 mrg operator>>(short& __n); 173 1.3 mrg 174 1.3 mrg __istream_type& 175 1.1 mrg operator>>(unsigned short& __n) 176 1.1 mrg { return _M_extract(__n); } 177 1.1 mrg 178 1.3 mrg __istream_type& 179 1.1 mrg operator>>(int& __n); 180 1.3 mrg 181 1.3 mrg __istream_type& 182 1.1 mrg operator>>(unsigned int& __n) 183 1.1 mrg { return _M_extract(__n); } 184 1.1 mrg 185 1.3 mrg __istream_type& 186 1.1 mrg operator>>(long& __n) 187 1.1 mrg { return _M_extract(__n); } 188 1.3 mrg 189 1.3 mrg __istream_type& 190 1.1 mrg operator>>(unsigned long& __n) 191 1.1 mrg { return _M_extract(__n); } 192 1.1 mrg 193 1.1 mrg #ifdef _GLIBCXX_USE_LONG_LONG 194 1.3 mrg __istream_type& 195 1.1 mrg operator>>(long long& __n) 196 1.1 mrg { return _M_extract(__n); } 197 1.1 mrg 198 1.3 mrg __istream_type& 199 1.1 mrg operator>>(unsigned long long& __n) 200 1.1 mrg { return _M_extract(__n); } 201 1.1 mrg #endif 202 1.13 mrg ///@} 203 1.1 mrg 204 1.13 mrg ///@{ 205 1.3 mrg /** 206 1.3 mrg * @brief Floating point arithmetic extractors 207 1.3 mrg * @param __f A variable of builtin floating point type. 208 1.3 mrg * @return @c *this if successful 209 1.3 mrg * 210 1.3 mrg * These functions use the stream's current locale (specifically, the 211 1.3 mrg * @c num_get facet) to parse the input data. 212 1.3 mrg */ 213 1.3 mrg __istream_type& 214 1.1 mrg operator>>(float& __f) 215 1.1 mrg { return _M_extract(__f); } 216 1.1 mrg 217 1.3 mrg __istream_type& 218 1.1 mrg operator>>(double& __f) 219 1.1 mrg { return _M_extract(__f); } 220 1.1 mrg 221 1.3 mrg __istream_type& 222 1.1 mrg operator>>(long double& __f) 223 1.1 mrg { return _M_extract(__f); } 224 1.13 mrg ///@} 225 1.1 mrg 226 1.3 mrg /** 227 1.3 mrg * @brief Basic arithmetic extractors 228 1.3 mrg * @param __p A variable of pointer type. 229 1.3 mrg * @return @c *this if successful 230 1.3 mrg * 231 1.3 mrg * These functions use the stream's current locale (specifically, the 232 1.3 mrg * @c num_get facet) to parse the input data. 233 1.3 mrg */ 234 1.3 mrg __istream_type& 235 1.1 mrg operator>>(void*& __p) 236 1.1 mrg { return _M_extract(__p); } 237 1.1 mrg 238 1.1 mrg /** 239 1.1 mrg * @brief Extracting into another streambuf. 240 1.3 mrg * @param __sb A pointer to a streambuf 241 1.1 mrg * 242 1.1 mrg * This function behaves like one of the basic arithmetic extractors, 243 1.1 mrg * in that it also constructs a sentry object and has the same error 244 1.1 mrg * handling behavior. 245 1.1 mrg * 246 1.3 mrg * If @p __sb is NULL, the stream will set failbit in its error state. 247 1.1 mrg * 248 1.1 mrg * Characters are extracted from this stream and inserted into the 249 1.3 mrg * @p __sb streambuf until one of the following occurs: 250 1.1 mrg * 251 1.1 mrg * - the input stream reaches end-of-file, 252 1.1 mrg * - insertion into the output buffer fails (in this case, the 253 1.1 mrg * character that would have been inserted is not extracted), or 254 1.1 mrg * - an exception occurs (and in this case is caught) 255 1.1 mrg * 256 1.1 mrg * If the function inserts no characters, failbit is set. 257 1.1 mrg */ 258 1.3 mrg __istream_type& 259 1.1 mrg operator>>(__streambuf_type* __sb); 260 1.13 mrg ///@} 261 1.3 mrg 262 1.1 mrg // [27.6.1.3] unformatted input 263 1.1 mrg /** 264 1.1 mrg * @brief Character counting 265 1.1 mrg * @return The number of characters extracted by the previous 266 1.1 mrg * unformatted input function dispatched for this stream. 267 1.1 mrg */ 268 1.3 mrg streamsize 269 1.3 mrg gcount() const 270 1.1 mrg { return _M_gcount; } 271 1.3 mrg 272 1.13 mrg ///@{ 273 1.1 mrg /** 274 1.1 mrg * @name Unformatted Input Functions 275 1.1 mrg * 276 1.1 mrg * All the unformatted input functions have some common behavior. 277 1.1 mrg * Each starts by constructing a temporary object of type 278 1.1 mrg * std::basic_istream::sentry with the second argument (noskipws) 279 1.1 mrg * set to true. This has several effects, concluding with the 280 1.1 mrg * setting of a status flag; see the sentry documentation for more. 281 1.1 mrg * 282 1.1 mrg * If the sentry status is good, the function tries to extract 283 1.1 mrg * whatever data is appropriate for the type of the argument. 284 1.1 mrg * 285 1.1 mrg * The number of characters extracted is stored for later retrieval 286 1.1 mrg * by gcount(). 287 1.1 mrg * 288 1.1 mrg * If an exception is thrown during extraction, ios_base::badbit 289 1.8 mrg * will be turned on in the stream's error state (without causing an 290 1.8 mrg * ios_base::failure to be thrown) and the original exception will 291 1.8 mrg * be rethrown if badbit is set in the exceptions mask. 292 1.1 mrg */ 293 1.3 mrg 294 1.1 mrg /** 295 1.1 mrg * @brief Simple extraction. 296 1.1 mrg * @return A character, or eof(). 297 1.1 mrg * 298 1.1 mrg * Tries to extract a character. If none are available, sets failbit 299 1.1 mrg * and returns traits::eof(). 300 1.1 mrg */ 301 1.3 mrg int_type 302 1.1 mrg get(); 303 1.1 mrg 304 1.1 mrg /** 305 1.1 mrg * @brief Simple extraction. 306 1.3 mrg * @param __c The character in which to store data. 307 1.1 mrg * @return *this 308 1.1 mrg * 309 1.3 mrg * Tries to extract a character and store it in @a __c. If none are 310 1.1 mrg * available, sets failbit and returns traits::eof(). 311 1.1 mrg * 312 1.1 mrg * @note This function is not overloaded on signed char and 313 1.1 mrg * unsigned char. 314 1.1 mrg */ 315 1.3 mrg __istream_type& 316 1.1 mrg get(char_type& __c); 317 1.1 mrg 318 1.1 mrg /** 319 1.1 mrg * @brief Simple multiple-character extraction. 320 1.3 mrg * @param __s Pointer to an array. 321 1.3 mrg * @param __n Maximum number of characters to store in @a __s. 322 1.3 mrg * @param __delim A "stop" character. 323 1.1 mrg * @return *this 324 1.1 mrg * 325 1.3 mrg * Characters are extracted and stored into @a __s until one of the 326 1.1 mrg * following happens: 327 1.1 mrg * 328 1.3 mrg * - @c __n-1 characters are stored 329 1.1 mrg * - the input sequence reaches EOF 330 1.3 mrg * - the next character equals @a __delim, in which case the character 331 1.1 mrg * is not extracted 332 1.1 mrg * 333 1.1 mrg * If no characters are stored, failbit is set in the stream's error 334 1.1 mrg * state. 335 1.1 mrg * 336 1.1 mrg * In any case, a null character is stored into the next location in 337 1.1 mrg * the array. 338 1.1 mrg * 339 1.1 mrg * @note This function is not overloaded on signed char and 340 1.1 mrg * unsigned char. 341 1.1 mrg */ 342 1.3 mrg __istream_type& 343 1.1 mrg get(char_type* __s, streamsize __n, char_type __delim); 344 1.1 mrg 345 1.1 mrg /** 346 1.1 mrg * @brief Simple multiple-character extraction. 347 1.3 mrg * @param __s Pointer to an array. 348 1.3 mrg * @param __n Maximum number of characters to store in @a s. 349 1.1 mrg * @return *this 350 1.1 mrg * 351 1.3 mrg * Returns @c get(__s,__n,widen('\\n')). 352 1.1 mrg */ 353 1.3 mrg __istream_type& 354 1.1 mrg get(char_type* __s, streamsize __n) 355 1.1 mrg { return this->get(__s, __n, this->widen('\n')); } 356 1.1 mrg 357 1.1 mrg /** 358 1.1 mrg * @brief Extraction into another streambuf. 359 1.3 mrg * @param __sb A streambuf in which to store data. 360 1.3 mrg * @param __delim A "stop" character. 361 1.1 mrg * @return *this 362 1.1 mrg * 363 1.3 mrg * Characters are extracted and inserted into @a __sb until one of the 364 1.1 mrg * following happens: 365 1.1 mrg * 366 1.1 mrg * - the input sequence reaches EOF 367 1.1 mrg * - insertion into the output buffer fails (in this case, the 368 1.1 mrg * character that would have been inserted is not extracted) 369 1.3 mrg * - the next character equals @a __delim (in this case, the character 370 1.1 mrg * is not extracted) 371 1.1 mrg * - an exception occurs (and in this case is caught) 372 1.1 mrg * 373 1.1 mrg * If no characters are stored, failbit is set in the stream's error 374 1.1 mrg * state. 375 1.1 mrg */ 376 1.1 mrg __istream_type& 377 1.1 mrg get(__streambuf_type& __sb, char_type __delim); 378 1.1 mrg 379 1.1 mrg /** 380 1.1 mrg * @brief Extraction into another streambuf. 381 1.3 mrg * @param __sb A streambuf in which to store data. 382 1.1 mrg * @return *this 383 1.1 mrg * 384 1.3 mrg * Returns @c get(__sb,widen('\\n')). 385 1.1 mrg */ 386 1.1 mrg __istream_type& 387 1.1 mrg get(__streambuf_type& __sb) 388 1.1 mrg { return this->get(__sb, this->widen('\n')); } 389 1.1 mrg 390 1.1 mrg /** 391 1.1 mrg * @brief String extraction. 392 1.3 mrg * @param __s A character array in which to store the data. 393 1.3 mrg * @param __n Maximum number of characters to extract. 394 1.3 mrg * @param __delim A "stop" character. 395 1.1 mrg * @return *this 396 1.1 mrg * 397 1.3 mrg * Extracts and stores characters into @a __s until one of the 398 1.1 mrg * following happens. Note that these criteria are required to be 399 1.1 mrg * tested in the order listed here, to allow an input line to exactly 400 1.3 mrg * fill the @a __s array without setting failbit. 401 1.1 mrg * 402 1.1 mrg * -# the input sequence reaches end-of-file, in which case eofbit 403 1.1 mrg * is set in the stream error state 404 1.3 mrg * -# the next character equals @c __delim, in which case the character 405 1.1 mrg * is extracted (and therefore counted in @c gcount()) but not stored 406 1.3 mrg * -# @c __n-1 characters are stored, in which case failbit is set 407 1.1 mrg * in the stream error state 408 1.1 mrg * 409 1.1 mrg * If no characters are extracted, failbit is set. (An empty line of 410 1.1 mrg * input should therefore not cause failbit to be set.) 411 1.1 mrg * 412 1.1 mrg * In any case, a null character is stored in the next location in 413 1.1 mrg * the array. 414 1.1 mrg */ 415 1.3 mrg __istream_type& 416 1.1 mrg getline(char_type* __s, streamsize __n, char_type __delim); 417 1.1 mrg 418 1.1 mrg /** 419 1.1 mrg * @brief String extraction. 420 1.3 mrg * @param __s A character array in which to store the data. 421 1.3 mrg * @param __n Maximum number of characters to extract. 422 1.1 mrg * @return *this 423 1.1 mrg * 424 1.3 mrg * Returns @c getline(__s,__n,widen('\\n')). 425 1.1 mrg */ 426 1.3 mrg __istream_type& 427 1.1 mrg getline(char_type* __s, streamsize __n) 428 1.1 mrg { return this->getline(__s, __n, this->widen('\n')); } 429 1.1 mrg 430 1.1 mrg /** 431 1.1 mrg * @brief Discarding characters 432 1.3 mrg * @param __n Number of characters to discard. 433 1.3 mrg * @param __delim A "stop" character. 434 1.1 mrg * @return *this 435 1.1 mrg * 436 1.1 mrg * Extracts characters and throws them away until one of the 437 1.1 mrg * following happens: 438 1.3 mrg * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n 439 1.1 mrg * characters are extracted 440 1.1 mrg * - the input sequence reaches end-of-file 441 1.3 mrg * - the next character equals @a __delim (in this case, the character 442 1.1 mrg * is extracted); note that this condition will never occur if 443 1.3 mrg * @a __delim equals @c traits::eof(). 444 1.1 mrg * 445 1.1 mrg * NB: Provide three overloads, instead of the single function 446 1.1 mrg * (with defaults) mandated by the Standard: this leads to a 447 1.1 mrg * better performing implementation, while still conforming to 448 1.1 mrg * the Standard. 449 1.1 mrg */ 450 1.3 mrg __istream_type& 451 1.3 mrg ignore(streamsize __n, int_type __delim); 452 1.1 mrg 453 1.3 mrg __istream_type& 454 1.1 mrg ignore(streamsize __n); 455 1.1 mrg 456 1.3 mrg __istream_type& 457 1.3 mrg ignore(); 458 1.3 mrg 459 1.1 mrg /** 460 1.1 mrg * @brief Looking ahead in the stream 461 1.1 mrg * @return The next character, or eof(). 462 1.1 mrg * 463 1.1 mrg * If, after constructing the sentry object, @c good() is false, 464 1.1 mrg * returns @c traits::eof(). Otherwise reads but does not extract 465 1.1 mrg * the next input character. 466 1.1 mrg */ 467 1.3 mrg int_type 468 1.1 mrg peek(); 469 1.3 mrg 470 1.1 mrg /** 471 1.1 mrg * @brief Extraction without delimiters. 472 1.3 mrg * @param __s A character array. 473 1.3 mrg * @param __n Maximum number of characters to store. 474 1.1 mrg * @return *this 475 1.1 mrg * 476 1.1 mrg * If the stream state is @c good(), extracts characters and stores 477 1.3 mrg * them into @a __s until one of the following happens: 478 1.3 mrg * - @a __n characters are stored 479 1.1 mrg * - the input sequence reaches end-of-file, in which case the error 480 1.1 mrg * state is set to @c failbit|eofbit. 481 1.1 mrg * 482 1.1 mrg * @note This function is not overloaded on signed char and 483 1.1 mrg * unsigned char. 484 1.1 mrg */ 485 1.3 mrg __istream_type& 486 1.1 mrg read(char_type* __s, streamsize __n); 487 1.1 mrg 488 1.1 mrg /** 489 1.1 mrg * @brief Extraction until the buffer is exhausted, but no more. 490 1.3 mrg * @param __s A character array. 491 1.3 mrg * @param __n Maximum number of characters to store. 492 1.1 mrg * @return The number of characters extracted. 493 1.1 mrg * 494 1.3 mrg * Extracts characters and stores them into @a __s depending on the 495 1.1 mrg * number of characters remaining in the streambuf's buffer, 496 1.1 mrg * @c rdbuf()->in_avail(), called @c A here: 497 1.1 mrg * - if @c A @c == @c -1, sets eofbit and extracts no characters 498 1.1 mrg * - if @c A @c == @c 0, extracts no characters 499 1.1 mrg * - if @c A @c > @c 0, extracts @c min(A,n) 500 1.1 mrg * 501 1.1 mrg * The goal is to empty the current buffer, and to not request any 502 1.1 mrg * more from the external input sequence controlled by the streambuf. 503 1.1 mrg */ 504 1.3 mrg streamsize 505 1.1 mrg readsome(char_type* __s, streamsize __n); 506 1.3 mrg 507 1.1 mrg /** 508 1.1 mrg * @brief Unextracting a single character. 509 1.3 mrg * @param __c The character to push back into the input stream. 510 1.1 mrg * @return *this 511 1.1 mrg * 512 1.1 mrg * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c). 513 1.1 mrg * 514 1.1 mrg * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in 515 1.1 mrg * the error state. 516 1.1 mrg * 517 1.3 mrg * @note This function first clears eofbit. Since no characters 518 1.3 mrg * are extracted, the next call to @c gcount() will return 0, 519 1.3 mrg * as required by DR 60. 520 1.1 mrg */ 521 1.3 mrg __istream_type& 522 1.1 mrg putback(char_type __c); 523 1.1 mrg 524 1.1 mrg /** 525 1.1 mrg * @brief Unextracting the previous character. 526 1.1 mrg * @return *this 527 1.1 mrg * 528 1.1 mrg * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c). 529 1.1 mrg * 530 1.1 mrg * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in 531 1.1 mrg * the error state. 532 1.1 mrg * 533 1.3 mrg * @note This function first clears eofbit. Since no characters 534 1.3 mrg * are extracted, the next call to @c gcount() will return 0, 535 1.3 mrg * as required by DR 60. 536 1.1 mrg */ 537 1.3 mrg __istream_type& 538 1.1 mrg unget(); 539 1.1 mrg 540 1.1 mrg /** 541 1.1 mrg * @brief Synchronizing the stream buffer. 542 1.1 mrg * @return 0 on success, -1 on failure 543 1.1 mrg * 544 1.1 mrg * If @c rdbuf() is a null pointer, returns -1. 545 1.1 mrg * 546 1.1 mrg * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1, 547 1.1 mrg * sets badbit and returns -1. 548 1.1 mrg * 549 1.1 mrg * Otherwise, returns 0. 550 1.1 mrg * 551 1.1 mrg * @note This function does not count the number of characters 552 1.1 mrg * extracted, if any, and therefore does not affect the next 553 1.1 mrg * call to @c gcount(). 554 1.1 mrg */ 555 1.3 mrg int 556 1.1 mrg sync(); 557 1.1 mrg 558 1.1 mrg /** 559 1.1 mrg * @brief Getting the current read position. 560 1.1 mrg * @return A file position object. 561 1.1 mrg * 562 1.1 mrg * If @c fail() is not false, returns @c pos_type(-1) to indicate 563 1.1 mrg * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in). 564 1.1 mrg * 565 1.1 mrg * @note This function does not count the number of characters 566 1.1 mrg * extracted, if any, and therefore does not affect the next 567 1.3 mrg * call to @c gcount(). At variance with putback, unget and 568 1.3 mrg * seekg, eofbit is not cleared first. 569 1.1 mrg */ 570 1.3 mrg pos_type 571 1.1 mrg tellg(); 572 1.1 mrg 573 1.1 mrg /** 574 1.1 mrg * @brief Changing the current read position. 575 1.3 mrg * @param __pos A file position object. 576 1.1 mrg * @return *this 577 1.1 mrg * 578 1.3 mrg * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If 579 1.1 mrg * that function fails, sets failbit. 580 1.1 mrg * 581 1.3 mrg * @note This function first clears eofbit. It does not count the 582 1.3 mrg * number of characters extracted, if any, and therefore does 583 1.3 mrg * not affect the next call to @c gcount(). 584 1.1 mrg */ 585 1.3 mrg __istream_type& 586 1.1 mrg seekg(pos_type); 587 1.1 mrg 588 1.1 mrg /** 589 1.1 mrg * @brief Changing the current read position. 590 1.3 mrg * @param __off A file offset object. 591 1.3 mrg * @param __dir The direction in which to seek. 592 1.1 mrg * @return *this 593 1.1 mrg * 594 1.3 mrg * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir). 595 1.1 mrg * If that function fails, sets failbit. 596 1.1 mrg * 597 1.3 mrg * @note This function first clears eofbit. It does not count the 598 1.3 mrg * number of characters extracted, if any, and therefore does 599 1.3 mrg * not affect the next call to @c gcount(). 600 1.1 mrg */ 601 1.3 mrg __istream_type& 602 1.1 mrg seekg(off_type, ios_base::seekdir); 603 1.13 mrg ///@} 604 1.1 mrg 605 1.1 mrg protected: 606 1.1 mrg basic_istream() 607 1.1 mrg : _M_gcount(streamsize(0)) 608 1.1 mrg { this->init(0); } 609 1.1 mrg 610 1.5 mrg #if __cplusplus >= 201103L 611 1.5 mrg basic_istream(const basic_istream&) = delete; 612 1.5 mrg 613 1.5 mrg basic_istream(basic_istream&& __rhs) 614 1.5 mrg : __ios_type(), _M_gcount(__rhs._M_gcount) 615 1.5 mrg { 616 1.5 mrg __ios_type::move(__rhs); 617 1.5 mrg __rhs._M_gcount = 0; 618 1.5 mrg } 619 1.5 mrg 620 1.5 mrg // 27.7.3.3 Assign/swap 621 1.5 mrg 622 1.5 mrg basic_istream& operator=(const basic_istream&) = delete; 623 1.5 mrg 624 1.5 mrg basic_istream& 625 1.5 mrg operator=(basic_istream&& __rhs) 626 1.5 mrg { 627 1.5 mrg swap(__rhs); 628 1.5 mrg return *this; 629 1.5 mrg } 630 1.5 mrg 631 1.5 mrg void 632 1.5 mrg swap(basic_istream& __rhs) 633 1.5 mrg { 634 1.5 mrg __ios_type::swap(__rhs); 635 1.5 mrg std::swap(_M_gcount, __rhs._M_gcount); 636 1.5 mrg } 637 1.5 mrg #endif 638 1.5 mrg 639 1.1 mrg template<typename _ValueT> 640 1.3 mrg __istream_type& 641 1.3 mrg _M_extract(_ValueT& __v); 642 1.1 mrg }; 643 1.1 mrg 644 1.3 mrg /// Explicit specialization declarations, defined in src/istream.cc. 645 1.3 mrg template<> 646 1.3 mrg basic_istream<char>& 647 1.1 mrg basic_istream<char>:: 648 1.1 mrg getline(char_type* __s, streamsize __n, char_type __delim); 649 1.3 mrg 650 1.1 mrg template<> 651 1.1 mrg basic_istream<char>& 652 1.1 mrg basic_istream<char>:: 653 1.1 mrg ignore(streamsize __n); 654 1.3 mrg 655 1.1 mrg template<> 656 1.1 mrg basic_istream<char>& 657 1.1 mrg basic_istream<char>:: 658 1.1 mrg ignore(streamsize __n, int_type __delim); 659 1.1 mrg 660 1.1 mrg #ifdef _GLIBCXX_USE_WCHAR_T 661 1.3 mrg template<> 662 1.3 mrg basic_istream<wchar_t>& 663 1.1 mrg basic_istream<wchar_t>:: 664 1.1 mrg getline(char_type* __s, streamsize __n, char_type __delim); 665 1.1 mrg 666 1.1 mrg template<> 667 1.1 mrg basic_istream<wchar_t>& 668 1.1 mrg basic_istream<wchar_t>:: 669 1.1 mrg ignore(streamsize __n); 670 1.3 mrg 671 1.1 mrg template<> 672 1.1 mrg basic_istream<wchar_t>& 673 1.1 mrg basic_istream<wchar_t>:: 674 1.1 mrg ignore(streamsize __n, int_type __delim); 675 1.1 mrg #endif 676 1.1 mrg 677 1.1 mrg /** 678 1.1 mrg * @brief Performs setup work for input streams. 679 1.1 mrg * 680 1.1 mrg * Objects of this class are created before all of the standard 681 1.1 mrg * extractors are run. It is responsible for <em>exception-safe 682 1.1 mrg * prefix and suffix operations,</em> although only prefix actions 683 1.1 mrg * are currently required by the standard. 684 1.1 mrg */ 685 1.1 mrg template<typename _CharT, typename _Traits> 686 1.1 mrg class basic_istream<_CharT, _Traits>::sentry 687 1.1 mrg { 688 1.1 mrg // Data Members. 689 1.1 mrg bool _M_ok; 690 1.1 mrg 691 1.1 mrg public: 692 1.3 mrg /// Easy access to dependent types. 693 1.1 mrg typedef _Traits traits_type; 694 1.1 mrg typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 695 1.1 mrg typedef basic_istream<_CharT, _Traits> __istream_type; 696 1.1 mrg typedef typename __istream_type::__ctype_type __ctype_type; 697 1.1 mrg typedef typename _Traits::int_type __int_type; 698 1.1 mrg 699 1.1 mrg /** 700 1.1 mrg * @brief The constructor performs all the work. 701 1.3 mrg * @param __is The input stream to guard. 702 1.3 mrg * @param __noskipws Whether to consume whitespace or not. 703 1.1 mrg * 704 1.3 mrg * If the stream state is good (@a __is.good() is true), then the 705 1.1 mrg * following actions are performed, otherwise the sentry state 706 1.1 mrg * is false (<em>not okay</em>) and failbit is set in the 707 1.1 mrg * stream state. 708 1.1 mrg * 709 1.1 mrg * The sentry's preparatory actions are: 710 1.1 mrg * 711 1.1 mrg * -# if the stream is tied to an output stream, @c is.tie()->flush() 712 1.1 mrg * is called to synchronize the output sequence 713 1.3 mrg * -# if @a __noskipws is false, and @c ios_base::skipws is set in 714 1.1 mrg * @c is.flags(), the sentry extracts and discards whitespace 715 1.1 mrg * characters from the stream. The currently imbued locale is 716 1.1 mrg * used to determine whether each character is whitespace. 717 1.1 mrg * 718 1.1 mrg * If the stream state is still good, then the sentry state becomes 719 1.1 mrg * true (@a okay). 720 1.1 mrg */ 721 1.1 mrg explicit 722 1.1 mrg sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); 723 1.1 mrg 724 1.1 mrg /** 725 1.1 mrg * @brief Quick status checking. 726 1.1 mrg * @return The sentry state. 727 1.1 mrg * 728 1.1 mrg * For ease of use, sentries may be converted to booleans. The 729 1.1 mrg * return value is that of the sentry state (true == okay). 730 1.1 mrg */ 731 1.3 mrg #if __cplusplus >= 201103L 732 1.1 mrg explicit 733 1.1 mrg #endif 734 1.1 mrg operator bool() const 735 1.1 mrg { return _M_ok; } 736 1.1 mrg }; 737 1.1 mrg 738 1.13 mrg ///@{ 739 1.1 mrg /** 740 1.1 mrg * @brief Character extractors 741 1.3 mrg * @param __in An input stream. 742 1.3 mrg * @param __c A character reference. 743 1.1 mrg * @return in 744 1.1 mrg * 745 1.1 mrg * Behaves like one of the formatted arithmetic extractors described in 746 1.1 mrg * std::basic_istream. After constructing a sentry object with good 747 1.1 mrg * status, this function extracts a character (if one is available) and 748 1.3 mrg * stores it in @a __c. Otherwise, sets failbit in the input stream. 749 1.1 mrg */ 750 1.1 mrg template<typename _CharT, typename _Traits> 751 1.1 mrg basic_istream<_CharT, _Traits>& 752 1.1 mrg operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c); 753 1.1 mrg 754 1.1 mrg template<class _Traits> 755 1.1 mrg inline basic_istream<char, _Traits>& 756 1.1 mrg operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) 757 1.1 mrg { return (__in >> reinterpret_cast<char&>(__c)); } 758 1.1 mrg 759 1.1 mrg template<class _Traits> 760 1.1 mrg inline basic_istream<char, _Traits>& 761 1.1 mrg operator>>(basic_istream<char, _Traits>& __in, signed char& __c) 762 1.1 mrg { return (__in >> reinterpret_cast<char&>(__c)); } 763 1.13 mrg ///@} 764 1.1 mrg 765 1.14 mrg 766 1.14 mrg template<typename _CharT, typename _Traits> 767 1.14 mrg void 768 1.14 mrg __istream_extract(basic_istream<_CharT, _Traits>&, _CharT*, streamsize); 769 1.14 mrg 770 1.14 mrg void __istream_extract(istream&, char*, streamsize); 771 1.14 mrg 772 1.13 mrg ///@{ 773 1.1 mrg /** 774 1.1 mrg * @brief Character string extractors 775 1.3 mrg * @param __in An input stream. 776 1.14 mrg * @param __s A character array (or a pointer to an array before C++20). 777 1.3 mrg * @return __in 778 1.1 mrg * 779 1.1 mrg * Behaves like one of the formatted arithmetic extractors described in 780 1.14 mrg * `std::basic_istream`. After constructing a sentry object with good 781 1.14 mrg * status, this function extracts up to `n` characters and stores them 782 1.14 mrg * into the array `__s`. `n` is defined as: 783 1.14 mrg * 784 1.14 mrg * - if `width()` is greater than zero, `n` is `min(width(), n)` 785 1.14 mrg * - otherwise `n` is the number of elements of the array 786 1.14 mrg * - (before C++20 the pointer is assumed to point to an array of 787 1.14 mrg * the largest possible size for an array of `char_type`). 788 1.1 mrg * 789 1.1 mrg * Characters are extracted and stored until one of the following happens: 790 1.14 mrg * - `n - 1` characters are stored 791 1.1 mrg * - EOF is reached 792 1.1 mrg * - the next character is whitespace according to the current locale 793 1.1 mrg * 794 1.14 mrg * `width(0)` is then called for the input stream. 795 1.1 mrg * 796 1.1 mrg * If no characters are extracted, sets failbit. 797 1.1 mrg */ 798 1.14 mrg 799 1.14 mrg #if __cplusplus <= 201703L 800 1.1 mrg template<typename _CharT, typename _Traits> 801 1.14 mrg __attribute__((__nonnull__(2), __access__(__write_only__, 2))) 802 1.14 mrg inline basic_istream<_CharT, _Traits>& 803 1.14 mrg operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) 804 1.14 mrg { 805 1.14 mrg #ifdef __OPTIMIZE__ 806 1.14 mrg // Function inlining might make the buffer size known, allowing us to 807 1.14 mrg // prevent overflow. 808 1.14 mrg size_t __n = __builtin_object_size(__s, 0); 809 1.14 mrg if (__n < sizeof(_CharT)) 810 1.14 mrg { 811 1.14 mrg // There is not even space for the required null terminator. 812 1.14 mrg __glibcxx_assert(__n >= sizeof(_CharT)); 813 1.14 mrg // No point calling __istream_extract, but still need to reset width. 814 1.14 mrg __in.width(0); 815 1.14 mrg __in.setstate(ios_base::failbit); 816 1.14 mrg } 817 1.14 mrg else if (__n != (size_t)-1) 818 1.14 mrg { 819 1.14 mrg __n /= sizeof(_CharT); 820 1.14 mrg streamsize __w = __in.width(); 821 1.14 mrg std::__istream_extract(__in, __s, __n); 822 1.14 mrg if (__in.good() && (__w <= 0 || __n < __w)) 823 1.14 mrg { 824 1.14 mrg // Stopped extracting early to avoid overflowing the buffer, 825 1.14 mrg // but might have stopped anyway (and set eofbit) if at EOF. 826 1.14 mrg const typename _Traits::int_type __c = __in.rdbuf()->sgetc(); 827 1.14 mrg const bool __eof = _Traits::eq_int_type(__c, _Traits::eof()); 828 1.14 mrg if (__builtin_expect(__eof, true)) // Assume EOF, not overflow. 829 1.14 mrg __in.setstate(ios_base::eofbit); 830 1.14 mrg } 831 1.14 mrg } 832 1.14 mrg else 833 1.14 mrg #endif // __OPTIMIZE 834 1.14 mrg { 835 1.14 mrg // Buffer size is unknown, have to assume it's huge. 836 1.14 mrg streamsize __n = __gnu_cxx::__numeric_traits<streamsize>::__max; 837 1.14 mrg __n /= sizeof(_CharT); 838 1.14 mrg std::__istream_extract(__in, __s, __n); 839 1.14 mrg } 840 1.14 mrg return __in; 841 1.14 mrg } 842 1.1 mrg 843 1.1 mrg template<class _Traits> 844 1.14 mrg __attribute__((__nonnull__(2), __access__(__write_only__, 2))) 845 1.1 mrg inline basic_istream<char, _Traits>& 846 1.1 mrg operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) 847 1.14 mrg { return __in >> reinterpret_cast<char*>(__s); } 848 1.1 mrg 849 1.1 mrg template<class _Traits> 850 1.14 mrg __attribute__((__nonnull__(2), __access__(__write_only__, 2))) 851 1.1 mrg inline basic_istream<char, _Traits>& 852 1.1 mrg operator>>(basic_istream<char, _Traits>& __in, signed char* __s) 853 1.14 mrg { return __in >> reinterpret_cast<char*>(__s); } 854 1.14 mrg #else 855 1.14 mrg // _GLIBCXX_RESOLVE_LIB_DEFECTS 856 1.14 mrg // 2499. operator>>(istream&, char*) makes it hard to avoid buffer overflows 857 1.14 mrg template<typename _CharT, typename _Traits, size_t _Num> 858 1.14 mrg inline basic_istream<_CharT, _Traits>& 859 1.14 mrg operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num]) 860 1.14 mrg { 861 1.14 mrg static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max); 862 1.14 mrg std::__istream_extract(__in, __s, _Num); 863 1.14 mrg return __in; 864 1.14 mrg } 865 1.14 mrg 866 1.14 mrg template<class _Traits, size_t _Num> 867 1.14 mrg inline basic_istream<char, _Traits>& 868 1.14 mrg operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num]) 869 1.14 mrg { return __in >> reinterpret_cast<char(&)[_Num]>(__s); } 870 1.14 mrg 871 1.14 mrg template<class _Traits, size_t _Num> 872 1.14 mrg inline basic_istream<char, _Traits>& 873 1.14 mrg operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num]) 874 1.14 mrg { return __in >> reinterpret_cast<char(&)[_Num]>(__s); } 875 1.14 mrg #endif 876 1.13 mrg ///@} 877 1.1 mrg 878 1.1 mrg /** 879 1.3 mrg * @brief Template class basic_iostream 880 1.1 mrg * @ingroup io 881 1.1 mrg * 882 1.3 mrg * @tparam _CharT Type of character stream. 883 1.3 mrg * @tparam _Traits Traits for character type, defaults to 884 1.3 mrg * char_traits<_CharT>. 885 1.3 mrg * 886 1.1 mrg * This class multiply inherits from the input and output stream classes 887 1.1 mrg * simply to provide a single interface. 888 1.1 mrg */ 889 1.1 mrg template<typename _CharT, typename _Traits> 890 1.1 mrg class basic_iostream 891 1.3 mrg : public basic_istream<_CharT, _Traits>, 892 1.1 mrg public basic_ostream<_CharT, _Traits> 893 1.1 mrg { 894 1.1 mrg public: 895 1.1 mrg // _GLIBCXX_RESOLVE_LIB_DEFECTS 896 1.1 mrg // 271. basic_iostream missing typedefs 897 1.1 mrg // Types (inherited): 898 1.3 mrg typedef _CharT char_type; 899 1.1 mrg typedef typename _Traits::int_type int_type; 900 1.1 mrg typedef typename _Traits::pos_type pos_type; 901 1.1 mrg typedef typename _Traits::off_type off_type; 902 1.3 mrg typedef _Traits traits_type; 903 1.1 mrg 904 1.1 mrg // Non-standard Types: 905 1.1 mrg typedef basic_istream<_CharT, _Traits> __istream_type; 906 1.1 mrg typedef basic_ostream<_CharT, _Traits> __ostream_type; 907 1.1 mrg 908 1.1 mrg /** 909 1.1 mrg * @brief Constructor does nothing. 910 1.1 mrg * 911 1.1 mrg * Both of the parent classes are initialized with the same 912 1.1 mrg * streambuf pointer passed to this constructor. 913 1.1 mrg */ 914 1.1 mrg explicit 915 1.1 mrg basic_iostream(basic_streambuf<_CharT, _Traits>* __sb) 916 1.1 mrg : __istream_type(__sb), __ostream_type(__sb) { } 917 1.1 mrg 918 1.1 mrg /** 919 1.1 mrg * @brief Destructor does nothing. 920 1.1 mrg */ 921 1.3 mrg virtual 922 1.1 mrg ~basic_iostream() { } 923 1.1 mrg 924 1.1 mrg protected: 925 1.1 mrg basic_iostream() 926 1.1 mrg : __istream_type(), __ostream_type() { } 927 1.5 mrg 928 1.5 mrg #if __cplusplus >= 201103L 929 1.5 mrg basic_iostream(const basic_iostream&) = delete; 930 1.5 mrg 931 1.5 mrg basic_iostream(basic_iostream&& __rhs) 932 1.5 mrg : __istream_type(std::move(__rhs)), __ostream_type(*this) 933 1.5 mrg { } 934 1.5 mrg 935 1.5 mrg // 27.7.3.3 Assign/swap 936 1.5 mrg 937 1.5 mrg basic_iostream& operator=(const basic_iostream&) = delete; 938 1.5 mrg 939 1.5 mrg basic_iostream& 940 1.5 mrg operator=(basic_iostream&& __rhs) 941 1.5 mrg { 942 1.5 mrg swap(__rhs); 943 1.5 mrg return *this; 944 1.5 mrg } 945 1.5 mrg 946 1.5 mrg void 947 1.5 mrg swap(basic_iostream& __rhs) 948 1.5 mrg { __istream_type::swap(__rhs); } 949 1.5 mrg #endif 950 1.1 mrg }; 951 1.1 mrg 952 1.1 mrg /** 953 1.1 mrg * @brief Quick and easy way to eat whitespace 954 1.1 mrg * 955 1.1 mrg * This manipulator extracts whitespace characters, stopping when the 956 1.1 mrg * next character is non-whitespace, or when the input sequence is empty. 957 1.1 mrg * If the sequence is empty, @c eofbit is set in the stream, but not 958 1.1 mrg * @c failbit. 959 1.1 mrg * 960 1.1 mrg * The current locale is used to distinguish whitespace characters. 961 1.1 mrg * 962 1.1 mrg * Example: 963 1.1 mrg * @code 964 1.1 mrg * MyClass mc; 965 1.1 mrg * 966 1.1 mrg * std::cin >> std::ws >> mc; 967 1.1 mrg * @endcode 968 1.1 mrg * will skip leading whitespace before calling operator>> on cin and your 969 1.1 mrg * object. Note that the same effect can be achieved by creating a 970 1.1 mrg * std::basic_istream::sentry inside your definition of operator>>. 971 1.1 mrg */ 972 1.1 mrg template<typename _CharT, typename _Traits> 973 1.3 mrg basic_istream<_CharT, _Traits>& 974 1.1 mrg ws(basic_istream<_CharT, _Traits>& __is); 975 1.1 mrg 976 1.3 mrg #if __cplusplus >= 201103L 977 1.14 mrg // C++11 27.7.2.6 Rvalue stream extraction [istream.rvalue] 978 1.14 mrg // _GLIBCXX_RESOLVE_LIB_DEFECTS 979 1.14 mrg // 2328. Rvalue stream extraction should use perfect forwarding 980 1.14 mrg // 1203. More useful rvalue stream insertion 981 1.10 mrg 982 1.14 mrg #if __cpp_lib_concepts 983 1.14 mrg template<typename _Is, typename _Tp> 984 1.14 mrg requires __derived_from_ios_base<_Is> 985 1.14 mrg && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); } 986 1.14 mrg using __rvalue_stream_extraction_t = _Is&&; 987 1.14 mrg #else 988 1.14 mrg template<typename _Is, typename _Tp, 989 1.14 mrg typename = _Require_derived_from_ios_base<_Is>, 990 1.14 mrg typename = decltype(std::declval<_Is&>() >> std::declval<_Tp>())> 991 1.14 mrg using __rvalue_stream_extraction_t = _Is&&; 992 1.14 mrg #endif 993 1.10 mrg 994 1.1 mrg /** 995 1.1 mrg * @brief Generic extractor for rvalue stream 996 1.3 mrg * @param __is An input stream. 997 1.3 mrg * @param __x A reference to the extraction target. 998 1.14 mrg * @return __is 999 1.1 mrg * 1000 1.1 mrg * This is just a forwarding function to allow extraction from 1001 1.1 mrg * rvalue streams since they won't bind to the extractor functions 1002 1.1 mrg * that take an lvalue reference. 1003 1.1 mrg */ 1004 1.10 mrg template<typename _Istream, typename _Tp> 1005 1.14 mrg inline __rvalue_stream_extraction_t<_Istream, _Tp> 1006 1.10 mrg operator>>(_Istream&& __is, _Tp&& __x) 1007 1.10 mrg { 1008 1.14 mrg __is >> std::forward<_Tp>(__x); 1009 1.14 mrg return std::move(__is); 1010 1.3 mrg } 1011 1.3 mrg #endif // C++11 1012 1.1 mrg 1013 1.3 mrg _GLIBCXX_END_NAMESPACE_VERSION 1014 1.3 mrg } // namespace 1015 1.1 mrg 1016 1.3 mrg #include <bits/istream.tcc> 1017 1.1 mrg 1018 1.1 mrg #endif /* _GLIBCXX_ISTREAM */ 1019