libstdc++
istream
Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2015 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 //
00026 // ISO C++ 14882: 27.6.1  Input streams
00027 //
00028 
00029 /** @file include/istream
00030  *  This is a Standard C++ Library header.
00031  */
00032 
00033 #ifndef _GLIBCXX_ISTREAM
00034 #define _GLIBCXX_ISTREAM 1
00035 
00036 #pragma GCC system_header
00037 
00038 #include <ios>
00039 #include <ostream>
00040 
00041 namespace std _GLIBCXX_VISIBILITY(default)
00042 {
00043 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00044 
00045   /**
00046    *  @brief  Template class basic_istream.
00047    *  @ingroup io
00048    *
00049    *  @tparam _CharT  Type of character stream.
00050    *  @tparam _Traits  Traits for character type, defaults to
00051    *                   char_traits<_CharT>.
00052    *
00053    *  This is the base class for all input streams.  It provides text
00054    *  formatting of all builtin types, and communicates with any class
00055    *  derived from basic_streambuf to do the actual input.
00056   */
00057   template<typename _CharT, typename _Traits>
00058     class basic_istream : virtual public basic_ios<_CharT, _Traits>
00059     {
00060     public:
00061       // Types (inherited from basic_ios (27.4.4)):
00062       typedef _CharT                                    char_type;
00063       typedef typename _Traits::int_type                int_type;
00064       typedef typename _Traits::pos_type                pos_type;
00065       typedef typename _Traits::off_type                off_type;
00066       typedef _Traits                                   traits_type;
00067 
00068       // Non-standard Types:
00069       typedef basic_streambuf<_CharT, _Traits>          __streambuf_type;
00070       typedef basic_ios<_CharT, _Traits>                __ios_type;
00071       typedef basic_istream<_CharT, _Traits>            __istream_type;
00072       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
00073                                                         __num_get_type;
00074       typedef ctype<_CharT>                             __ctype_type;
00075 
00076     protected:
00077       // Data Members:
00078       /**
00079        *  The number of characters extracted in the previous unformatted
00080        *  function; see gcount().
00081       */
00082       streamsize                _M_gcount;
00083 
00084     public:
00085       /**
00086        *  @brief  Base constructor.
00087        *
00088        *  This ctor is almost never called by the user directly, rather from
00089        *  derived classes' initialization lists, which pass a pointer to
00090        *  their own stream buffer.
00091       */
00092       explicit
00093       basic_istream(__streambuf_type* __sb)
00094       : _M_gcount(streamsize(0))
00095       { this->init(__sb); }
00096 
00097       /**
00098        *  @brief  Base destructor.
00099        *
00100        *  This does very little apart from providing a virtual base dtor.
00101       */
00102       virtual
00103       ~basic_istream()
00104       { _M_gcount = streamsize(0); }
00105 
00106       /// Safe prefix/suffix operations.
00107       class sentry;
00108       friend class sentry;
00109 
00110       //@{
00111       /**
00112        *  @brief  Interface for manipulators.
00113        *
00114        *  Manipulators such as @c std::ws and @c std::dec use these
00115        *  functions in constructs like
00116        *  <code>std::cin >> std::ws</code>.
00117        *  For more information, see the iomanip header.
00118       */
00119       __istream_type&
00120       operator>>(__istream_type& (*__pf)(__istream_type&))
00121       { return __pf(*this); }
00122 
00123       __istream_type&
00124       operator>>(__ios_type& (*__pf)(__ios_type&))
00125       {
00126         __pf(*this);
00127         return *this;
00128       }
00129 
00130       __istream_type&
00131       operator>>(ios_base& (*__pf)(ios_base&))
00132       {
00133         __pf(*this);
00134         return *this;
00135       }
00136       //@}
00137 
00138       //@{
00139       /**
00140        *  @name Extractors
00141        *
00142        *  All the @c operator>> functions (aka <em>formatted input
00143        *  functions</em>) have some common behavior.  Each starts by
00144        *  constructing a temporary object of type std::basic_istream::sentry
00145        *  with the second argument (noskipws) set to false.  This has several
00146        *  effects, concluding with the setting of a status flag; see the
00147        *  sentry documentation for more.
00148        *
00149        *  If the sentry status is good, the function tries to extract
00150        *  whatever data is appropriate for the type of the argument.
00151        *
00152        *  If an exception is thrown during extraction, ios_base::badbit
00153        *  will be turned on in the stream's error state without causing an
00154        *  ios_base::failure to be thrown.  The original exception will then
00155        *  be rethrown.
00156       */
00157 
00158       //@{
00159       /**
00160        *  @brief  Integer arithmetic extractors
00161        *  @param  __n A variable of builtin integral type.
00162        *  @return  @c *this if successful
00163        *
00164        *  These functions use the stream's current locale (specifically, the
00165        *  @c num_get facet) to parse the input data.
00166       */
00167       __istream_type&
00168       operator>>(bool& __n)
00169       { return _M_extract(__n); }
00170 
00171       __istream_type&
00172       operator>>(short& __n);
00173 
00174       __istream_type&
00175       operator>>(unsigned short& __n)
00176       { return _M_extract(__n); }
00177 
00178       __istream_type&
00179       operator>>(int& __n);
00180 
00181       __istream_type&
00182       operator>>(unsigned int& __n)
00183       { return _M_extract(__n); }
00184 
00185       __istream_type&
00186       operator>>(long& __n)
00187       { return _M_extract(__n); }
00188 
00189       __istream_type&
00190       operator>>(unsigned long& __n)
00191       { return _M_extract(__n); }
00192 
00193 #ifdef _GLIBCXX_USE_LONG_LONG
00194       __istream_type&
00195       operator>>(long long& __n)
00196       { return _M_extract(__n); }
00197 
00198       __istream_type&
00199       operator>>(unsigned long long& __n)
00200       { return _M_extract(__n); }
00201 #endif
00202       //@}
00203 
00204       //@{
00205       /**
00206        *  @brief  Floating point arithmetic extractors
00207        *  @param  __f A variable of builtin floating point type.
00208        *  @return  @c *this if successful
00209        *
00210        *  These functions use the stream's current locale (specifically, the
00211        *  @c num_get facet) to parse the input data.
00212       */
00213       __istream_type&
00214       operator>>(float& __f)
00215       { return _M_extract(__f); }
00216 
00217       __istream_type&
00218       operator>>(double& __f)
00219       { return _M_extract(__f); }
00220 
00221       __istream_type&
00222       operator>>(long double& __f)
00223       { return _M_extract(__f); }
00224       //@}
00225 
00226       /**
00227        *  @brief  Basic arithmetic extractors
00228        *  @param  __p A variable of pointer type.
00229        *  @return  @c *this if successful
00230        *
00231        *  These functions use the stream's current locale (specifically, the
00232        *  @c num_get facet) to parse the input data.
00233       */
00234       __istream_type&
00235       operator>>(void*& __p)
00236       { return _M_extract(__p); }
00237 
00238       /**
00239        *  @brief  Extracting into another streambuf.
00240        *  @param  __sb  A pointer to a streambuf
00241        *
00242        *  This function behaves like one of the basic arithmetic extractors,
00243        *  in that it also constructs a sentry object and has the same error
00244        *  handling behavior.
00245        *
00246        *  If @p __sb is NULL, the stream will set failbit in its error state.
00247        *
00248        *  Characters are extracted from this stream and inserted into the
00249        *  @p __sb streambuf until one of the following occurs:
00250        *
00251        *  - the input stream reaches end-of-file,
00252        *  - insertion into the output buffer fails (in this case, the
00253        *    character that would have been inserted is not extracted), or
00254        *  - an exception occurs (and in this case is caught)
00255        *
00256        *  If the function inserts no characters, failbit is set.
00257       */
00258       __istream_type&
00259       operator>>(__streambuf_type* __sb);
00260       //@}
00261 
00262       // [27.6.1.3] unformatted input
00263       /**
00264        *  @brief  Character counting
00265        *  @return  The number of characters extracted by the previous
00266        *           unformatted input function dispatched for this stream.
00267       */
00268       streamsize
00269       gcount() const
00270       { return _M_gcount; }
00271 
00272       //@{
00273       /**
00274        *  @name Unformatted Input Functions
00275        *
00276        *  All the unformatted input functions have some common behavior.
00277        *  Each starts by constructing a temporary object of type
00278        *  std::basic_istream::sentry with the second argument (noskipws)
00279        *  set to true.  This has several effects, concluding with the
00280        *  setting of a status flag; see the sentry documentation for more.
00281        *
00282        *  If the sentry status is good, the function tries to extract
00283        *  whatever data is appropriate for the type of the argument.
00284        *
00285        *  The number of characters extracted is stored for later retrieval
00286        *  by gcount().
00287        *
00288        *  If an exception is thrown during extraction, ios_base::badbit
00289        *  will be turned on in the stream's error state without causing an
00290        *  ios_base::failure to be thrown.  The original exception will then
00291        *  be rethrown.
00292       */
00293 
00294       /**
00295        *  @brief  Simple extraction.
00296        *  @return  A character, or eof().
00297        *
00298        *  Tries to extract a character.  If none are available, sets failbit
00299        *  and returns traits::eof().
00300       */
00301       int_type
00302       get();
00303 
00304       /**
00305        *  @brief  Simple extraction.
00306        *  @param  __c  The character in which to store data.
00307        *  @return  *this
00308        *
00309        *  Tries to extract a character and store it in @a __c.  If none are
00310        *  available, sets failbit and returns traits::eof().
00311        *
00312        *  @note  This function is not overloaded on signed char and
00313        *         unsigned char.
00314       */
00315       __istream_type&
00316       get(char_type& __c);
00317 
00318       /**
00319        *  @brief  Simple multiple-character extraction.
00320        *  @param  __s  Pointer to an array.
00321        *  @param  __n  Maximum number of characters to store in @a __s.
00322        *  @param  __delim  A "stop" character.
00323        *  @return  *this
00324        *
00325        *  Characters are extracted and stored into @a __s until one of the
00326        *  following happens:
00327        *
00328        *  - @c __n-1 characters are stored
00329        *  - the input sequence reaches EOF
00330        *  - the next character equals @a __delim, in which case the character
00331        *    is not extracted
00332        *
00333        * If no characters are stored, failbit is set in the stream's error
00334        * state.
00335        *
00336        * In any case, a null character is stored into the next location in
00337        * the array.
00338        *
00339        *  @note  This function is not overloaded on signed char and
00340        *         unsigned char.
00341       */
00342       __istream_type&
00343       get(char_type* __s, streamsize __n, char_type __delim);
00344 
00345       /**
00346        *  @brief  Simple multiple-character extraction.
00347        *  @param  __s  Pointer to an array.
00348        *  @param  __n  Maximum number of characters to store in @a s.
00349        *  @return  *this
00350        *
00351        *  Returns @c get(__s,__n,widen(&apos;\\n&apos;)).
00352       */
00353       __istream_type&
00354       get(char_type* __s, streamsize __n)
00355       { return this->get(__s, __n, this->widen('\n')); }
00356 
00357       /**
00358        *  @brief  Extraction into another streambuf.
00359        *  @param  __sb  A streambuf in which to store data.
00360        *  @param  __delim  A "stop" character.
00361        *  @return  *this
00362        *
00363        *  Characters are extracted and inserted into @a __sb until one of the
00364        *  following happens:
00365        *
00366        *  - the input sequence reaches EOF
00367        *  - insertion into the output buffer fails (in this case, the
00368        *    character that would have been inserted is not extracted)
00369        *  - the next character equals @a __delim (in this case, the character
00370        *    is not extracted)
00371        *  - an exception occurs (and in this case is caught)
00372        *
00373        * If no characters are stored, failbit is set in the stream's error
00374        * state.
00375       */
00376       __istream_type&
00377       get(__streambuf_type& __sb, char_type __delim);
00378 
00379       /**
00380        *  @brief  Extraction into another streambuf.
00381        *  @param  __sb  A streambuf in which to store data.
00382        *  @return  *this
00383        *
00384        *  Returns @c get(__sb,widen(&apos;\\n&apos;)).
00385       */
00386       __istream_type&
00387       get(__streambuf_type& __sb)
00388       { return this->get(__sb, this->widen('\n')); }
00389 
00390       /**
00391        *  @brief  String extraction.
00392        *  @param  __s  A character array in which to store the data.
00393        *  @param  __n  Maximum number of characters to extract.
00394        *  @param  __delim  A "stop" character.
00395        *  @return  *this
00396        *
00397        *  Extracts and stores characters into @a __s until one of the
00398        *  following happens.  Note that these criteria are required to be
00399        *  tested in the order listed here, to allow an input line to exactly
00400        *  fill the @a __s array without setting failbit.
00401        *
00402        *  -# the input sequence reaches end-of-file, in which case eofbit
00403        *     is set in the stream error state
00404        *  -# the next character equals @c __delim, in which case the character
00405        *     is extracted (and therefore counted in @c gcount()) but not stored
00406        *  -# @c __n-1 characters are stored, in which case failbit is set
00407        *     in the stream error state
00408        *
00409        *  If no characters are extracted, failbit is set.  (An empty line of
00410        *  input should therefore not cause failbit to be set.)
00411        *
00412        *  In any case, a null character is stored in the next location in
00413        *  the array.
00414       */
00415       __istream_type&
00416       getline(char_type* __s, streamsize __n, char_type __delim);
00417 
00418       /**
00419        *  @brief  String extraction.
00420        *  @param  __s  A character array in which to store the data.
00421        *  @param  __n  Maximum number of characters to extract.
00422        *  @return  *this
00423        *
00424        *  Returns @c getline(__s,__n,widen(&apos;\\n&apos;)).
00425       */
00426       __istream_type&
00427       getline(char_type* __s, streamsize __n)
00428       { return this->getline(__s, __n, this->widen('\n')); }
00429 
00430       /**
00431        *  @brief  Discarding characters
00432        *  @param  __n  Number of characters to discard.
00433        *  @param  __delim  A "stop" character.
00434        *  @return  *this
00435        *
00436        *  Extracts characters and throws them away until one of the
00437        *  following happens:
00438        *  - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
00439        *    characters are extracted
00440        *  - the input sequence reaches end-of-file
00441        *  - the next character equals @a __delim (in this case, the character
00442        *    is extracted); note that this condition will never occur if
00443        *    @a __delim equals @c traits::eof().
00444        *
00445        *  NB: Provide three overloads, instead of the single function
00446        *  (with defaults) mandated by the Standard: this leads to a
00447        *  better performing implementation, while still conforming to
00448        *  the Standard.
00449       */
00450       __istream_type&
00451       ignore(streamsize __n, int_type __delim);
00452 
00453       __istream_type&
00454       ignore(streamsize __n);
00455 
00456       __istream_type&
00457       ignore();
00458 
00459       /**
00460        *  @brief  Looking ahead in the stream
00461        *  @return  The next character, or eof().
00462        *
00463        *  If, after constructing the sentry object, @c good() is false,
00464        *  returns @c traits::eof().  Otherwise reads but does not extract
00465        *  the next input character.
00466       */
00467       int_type
00468       peek();
00469 
00470       /**
00471        *  @brief  Extraction without delimiters.
00472        *  @param  __s  A character array.
00473        *  @param  __n  Maximum number of characters to store.
00474        *  @return  *this
00475        *
00476        *  If the stream state is @c good(), extracts characters and stores
00477        *  them into @a __s until one of the following happens:
00478        *  - @a __n characters are stored
00479        *  - the input sequence reaches end-of-file, in which case the error
00480        *    state is set to @c failbit|eofbit.
00481        *
00482        *  @note  This function is not overloaded on signed char and
00483        *         unsigned char.
00484       */
00485       __istream_type&
00486       read(char_type* __s, streamsize __n);
00487 
00488       /**
00489        *  @brief  Extraction until the buffer is exhausted, but no more.
00490        *  @param  __s  A character array.
00491        *  @param  __n  Maximum number of characters to store.
00492        *  @return  The number of characters extracted.
00493        *
00494        *  Extracts characters and stores them into @a __s depending on the
00495        *  number of characters remaining in the streambuf's buffer,
00496        *  @c rdbuf()->in_avail(), called @c A here:
00497        *  - if @c A @c == @c -1, sets eofbit and extracts no characters
00498        *  - if @c A @c == @c 0, extracts no characters
00499        *  - if @c A @c > @c 0, extracts @c min(A,n)
00500        *
00501        *  The goal is to empty the current buffer, and to not request any
00502        *  more from the external input sequence controlled by the streambuf.
00503       */
00504       streamsize
00505       readsome(char_type* __s, streamsize __n);
00506 
00507       /**
00508        *  @brief  Unextracting a single character.
00509        *  @param  __c  The character to push back into the input stream.
00510        *  @return  *this
00511        *
00512        *  If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
00513        *
00514        *  If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
00515        *  the error state.
00516        *
00517        *  @note  This function first clears eofbit.  Since no characters
00518        *         are extracted, the next call to @c gcount() will return 0,
00519        *         as required by DR 60.
00520       */
00521       __istream_type&
00522       putback(char_type __c);
00523 
00524       /**
00525        *  @brief  Unextracting the previous character.
00526        *  @return  *this
00527        *
00528        *  If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
00529        *
00530        *  If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
00531        *  the error state.
00532        *
00533        *  @note  This function first clears eofbit.  Since no characters
00534        *         are extracted, the next call to @c gcount() will return 0,
00535        *         as required by DR 60.
00536       */
00537       __istream_type&
00538       unget();
00539 
00540       /**
00541        *  @brief  Synchronizing the stream buffer.
00542        *  @return  0 on success, -1 on failure
00543        *
00544        *  If @c rdbuf() is a null pointer, returns -1.
00545        *
00546        *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
00547        *  sets badbit and returns -1.
00548        *
00549        *  Otherwise, returns 0.
00550        *
00551        *  @note  This function does not count the number of characters
00552        *         extracted, if any, and therefore does not affect the next
00553        *         call to @c gcount().
00554       */
00555       int
00556       sync();
00557 
00558       /**
00559        *  @brief  Getting the current read position.
00560        *  @return  A file position object.
00561        *
00562        *  If @c fail() is not false, returns @c pos_type(-1) to indicate
00563        *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
00564        *
00565        *  @note  This function does not count the number of characters
00566        *         extracted, if any, and therefore does not affect the next
00567        *         call to @c gcount().  At variance with putback, unget and
00568        *         seekg, eofbit is not cleared first.
00569       */
00570       pos_type
00571       tellg();
00572 
00573       /**
00574        *  @brief  Changing the current read position.
00575        *  @param  __pos  A file position object.
00576        *  @return  *this
00577        *
00578        *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos).  If
00579        *  that function fails, sets failbit.
00580        *
00581        *  @note  This function first clears eofbit.  It does not count the
00582        *         number of characters extracted, if any, and therefore does
00583        *         not affect the next call to @c gcount().
00584       */
00585       __istream_type&
00586       seekg(pos_type);
00587 
00588       /**
00589        *  @brief  Changing the current read position.
00590        *  @param  __off  A file offset object.
00591        *  @param  __dir  The direction in which to seek.
00592        *  @return  *this
00593        *
00594        *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
00595        *  If that function fails, sets failbit.
00596        *
00597        *  @note  This function first clears eofbit.  It does not count the
00598        *         number of characters extracted, if any, and therefore does
00599        *         not affect the next call to @c gcount().
00600       */
00601       __istream_type&
00602       seekg(off_type, ios_base::seekdir);
00603       //@}
00604 
00605     protected:
00606       basic_istream()
00607       : _M_gcount(streamsize(0))
00608       { this->init(0); }
00609 
00610 #if __cplusplus >= 201103L
00611       basic_istream(const basic_istream&) = delete;
00612 
00613       basic_istream(basic_istream&& __rhs)
00614       : __ios_type(), _M_gcount(__rhs._M_gcount)
00615       {
00616         __ios_type::move(__rhs);
00617         __rhs._M_gcount = 0;
00618       }
00619 
00620       // 27.7.3.3 Assign/swap
00621 
00622       basic_istream& operator=(const basic_istream&) = delete;
00623 
00624       basic_istream&
00625       operator=(basic_istream&& __rhs)
00626       {
00627         swap(__rhs);
00628         return *this;
00629       }
00630 
00631       void
00632       swap(basic_istream& __rhs)
00633       {
00634         __ios_type::swap(__rhs);
00635         std::swap(_M_gcount, __rhs._M_gcount);
00636       }
00637 #endif
00638 
00639       template<typename _ValueT>
00640         __istream_type&
00641         _M_extract(_ValueT& __v);
00642     };
00643 
00644   /// Explicit specialization declarations, defined in src/istream.cc.
00645   template<>
00646     basic_istream<char>&
00647     basic_istream<char>::
00648     getline(char_type* __s, streamsize __n, char_type __delim);
00649 
00650   template<>
00651     basic_istream<char>&
00652     basic_istream<char>::
00653     ignore(streamsize __n);
00654 
00655   template<>
00656     basic_istream<char>&
00657     basic_istream<char>::
00658     ignore(streamsize __n, int_type __delim);
00659 
00660 #ifdef _GLIBCXX_USE_WCHAR_T
00661   template<>
00662     basic_istream<wchar_t>&
00663     basic_istream<wchar_t>::
00664     getline(char_type* __s, streamsize __n, char_type __delim);
00665 
00666   template<>
00667     basic_istream<wchar_t>&
00668     basic_istream<wchar_t>::
00669     ignore(streamsize __n);
00670 
00671   template<>
00672     basic_istream<wchar_t>&
00673     basic_istream<wchar_t>::
00674     ignore(streamsize __n, int_type __delim);
00675 #endif
00676 
00677   /**
00678    *  @brief  Performs setup work for input streams.
00679    *
00680    *  Objects of this class are created before all of the standard
00681    *  extractors are run.  It is responsible for <em>exception-safe
00682    *  prefix and suffix operations,</em> although only prefix actions
00683    *  are currently required by the standard.
00684   */
00685   template<typename _CharT, typename _Traits>
00686     class basic_istream<_CharT, _Traits>::sentry
00687     {
00688       // Data Members.
00689       bool _M_ok;
00690 
00691     public:
00692       /// Easy access to dependent types.
00693       typedef _Traits                                   traits_type;
00694       typedef basic_streambuf<_CharT, _Traits>          __streambuf_type;
00695       typedef basic_istream<_CharT, _Traits>            __istream_type;
00696       typedef typename __istream_type::__ctype_type     __ctype_type;
00697       typedef typename _Traits::int_type                __int_type;
00698 
00699       /**
00700        *  @brief  The constructor performs all the work.
00701        *  @param  __is  The input stream to guard.
00702        *  @param  __noskipws  Whether to consume whitespace or not.
00703        *
00704        *  If the stream state is good (@a __is.good() is true), then the
00705        *  following actions are performed, otherwise the sentry state
00706        *  is false (<em>not okay</em>) and failbit is set in the
00707        *  stream state.
00708        *
00709        *  The sentry's preparatory actions are:
00710        *
00711        *  -# if the stream is tied to an output stream, @c is.tie()->flush()
00712        *     is called to synchronize the output sequence
00713        *  -# if @a __noskipws is false, and @c ios_base::skipws is set in
00714        *     @c is.flags(), the sentry extracts and discards whitespace
00715        *     characters from the stream.  The currently imbued locale is
00716        *     used to determine whether each character is whitespace.
00717        *
00718        *  If the stream state is still good, then the sentry state becomes
00719        *  true (@a okay).
00720       */
00721       explicit
00722       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00723 
00724       /**
00725        *  @brief  Quick status checking.
00726        *  @return  The sentry state.
00727        *
00728        *  For ease of use, sentries may be converted to booleans.  The
00729        *  return value is that of the sentry state (true == okay).
00730       */
00731 #if __cplusplus >= 201103L
00732       explicit
00733 #endif
00734       operator bool() const
00735       { return _M_ok; }
00736     };
00737 
00738   //@{
00739   /**
00740    *  @brief  Character extractors
00741    *  @param  __in  An input stream.
00742    *  @param  __c  A character reference.
00743    *  @return  in
00744    *
00745    *  Behaves like one of the formatted arithmetic extractors described in
00746    *  std::basic_istream.  After constructing a sentry object with good
00747    *  status, this function extracts a character (if one is available) and
00748    *  stores it in @a __c.  Otherwise, sets failbit in the input stream.
00749   */
00750   template<typename _CharT, typename _Traits>
00751     basic_istream<_CharT, _Traits>&
00752     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00753 
00754   template<class _Traits>
00755     inline basic_istream<char, _Traits>&
00756     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00757     { return (__in >> reinterpret_cast<char&>(__c)); }
00758 
00759   template<class _Traits>
00760     inline basic_istream<char, _Traits>&
00761     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00762     { return (__in >> reinterpret_cast<char&>(__c)); }
00763   //@}
00764 
00765   //@{
00766   /**
00767    *  @brief  Character string extractors
00768    *  @param  __in  An input stream.
00769    *  @param  __s  A pointer to a character array.
00770    *  @return  __in
00771    *
00772    *  Behaves like one of the formatted arithmetic extractors described in
00773    *  std::basic_istream.  After constructing a sentry object with good
00774    *  status, this function extracts up to @c n characters and stores them
00775    *  into the array starting at @a __s.  @c n is defined as:
00776    *
00777    *  - if @c width() is greater than zero, @c n is width() otherwise
00778    *  - @c n is <em>the number of elements of the largest array of *
00779    *  - @c char_type that can store a terminating @c eos.</em>
00780    *  - [27.6.1.2.3]/6
00781    *
00782    *  Characters are extracted and stored until one of the following happens:
00783    *  - @c n-1 characters are stored
00784    *  - EOF is reached
00785    *  - the next character is whitespace according to the current locale
00786    *  - the next character is a null byte (i.e., @c charT() )
00787    *
00788    *  @c width(0) is then called for the input stream.
00789    *
00790    *  If no characters are extracted, sets failbit.
00791   */
00792   template<typename _CharT, typename _Traits>
00793     basic_istream<_CharT, _Traits>&
00794     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00795 
00796   // Explicit specialization declaration, defined in src/istream.cc.
00797   template<>
00798     basic_istream<char>&
00799     operator>>(basic_istream<char>& __in, char* __s);
00800 
00801   template<class _Traits>
00802     inline basic_istream<char, _Traits>&
00803     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
00804     { return (__in >> reinterpret_cast<char*>(__s)); }
00805 
00806   template<class _Traits>
00807     inline basic_istream<char, _Traits>&
00808     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
00809     { return (__in >> reinterpret_cast<char*>(__s)); }
00810   //@}
00811 
00812   /**
00813    *  @brief  Template class basic_iostream
00814    *  @ingroup io
00815    *
00816    *  @tparam _CharT  Type of character stream.
00817    *  @tparam _Traits  Traits for character type, defaults to
00818    *                   char_traits<_CharT>.
00819    *
00820    *  This class multiply inherits from the input and output stream classes
00821    *  simply to provide a single interface.
00822   */
00823   template<typename _CharT, typename _Traits>
00824     class basic_iostream
00825     : public basic_istream<_CharT, _Traits>,
00826       public basic_ostream<_CharT, _Traits>
00827     {
00828     public:
00829       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00830       // 271. basic_iostream missing typedefs
00831       // Types (inherited):
00832       typedef _CharT                                    char_type;
00833       typedef typename _Traits::int_type                int_type;
00834       typedef typename _Traits::pos_type                pos_type;
00835       typedef typename _Traits::off_type                off_type;
00836       typedef _Traits                                   traits_type;
00837 
00838       // Non-standard Types:
00839       typedef basic_istream<_CharT, _Traits>            __istream_type;
00840       typedef basic_ostream<_CharT, _Traits>            __ostream_type;
00841 
00842       /**
00843        *  @brief  Constructor does nothing.
00844        *
00845        *  Both of the parent classes are initialized with the same
00846        *  streambuf pointer passed to this constructor.
00847       */
00848       explicit
00849       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00850       : __istream_type(__sb), __ostream_type(__sb) { }
00851 
00852       /**
00853        *  @brief  Destructor does nothing.
00854       */
00855       virtual
00856       ~basic_iostream() { }
00857 
00858     protected:
00859       basic_iostream()
00860       : __istream_type(), __ostream_type() { }
00861 
00862 #if __cplusplus >= 201103L
00863       basic_iostream(const basic_iostream&) = delete;
00864 
00865       basic_iostream(basic_iostream&& __rhs)
00866       : __istream_type(std::move(__rhs)), __ostream_type(*this)
00867       { }
00868 
00869       // 27.7.3.3 Assign/swap
00870 
00871       basic_iostream& operator=(const basic_iostream&) = delete;
00872 
00873       basic_iostream&
00874       operator=(basic_iostream&& __rhs)
00875       {
00876         swap(__rhs);
00877         return *this;
00878       }
00879 
00880       void
00881       swap(basic_iostream& __rhs)
00882       { __istream_type::swap(__rhs); }
00883 #endif
00884     };
00885 
00886   /**
00887    *  @brief  Quick and easy way to eat whitespace
00888    *
00889    *  This manipulator extracts whitespace characters, stopping when the
00890    *  next character is non-whitespace, or when the input sequence is empty.
00891    *  If the sequence is empty, @c eofbit is set in the stream, but not
00892    *  @c failbit.
00893    *
00894    *  The current locale is used to distinguish whitespace characters.
00895    *
00896    *  Example:
00897    *  @code
00898    *     MyClass   mc;
00899    *
00900    *     std::cin >> std::ws >> mc;
00901    *  @endcode
00902    *  will skip leading whitespace before calling operator>> on cin and your
00903    *  object.  Note that the same effect can be achieved by creating a
00904    *  std::basic_istream::sentry inside your definition of operator>>.
00905   */
00906   template<typename _CharT, typename _Traits>
00907     basic_istream<_CharT, _Traits>&
00908     ws(basic_istream<_CharT, _Traits>& __is);
00909 
00910 #if __cplusplus >= 201103L
00911   // [27.7.1.6] Rvalue stream extraction
00912   /**
00913    *  @brief  Generic extractor for rvalue stream
00914    *  @param  __is  An input stream.
00915    *  @param  __x  A reference to the extraction target.
00916    *  @return  is
00917    *
00918    *  This is just a forwarding function to allow extraction from
00919    *  rvalue streams since they won't bind to the extractor functions
00920    *  that take an lvalue reference.
00921   */
00922   template<typename _CharT, typename _Traits, typename _Tp>
00923     inline basic_istream<_CharT, _Traits>&
00924     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
00925     { 
00926       __is >> __x;
00927       return __is;
00928     }
00929 #endif // C++11
00930 
00931 _GLIBCXX_END_NAMESPACE_VERSION
00932 } // namespace
00933 
00934 #include <bits/istream.tcc>
00935 
00936 #endif  /* _GLIBCXX_ISTREAM */