libstdc++
istream
Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2013 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       template<typename _ValueT>
00611     __istream_type&
00612     _M_extract(_ValueT& __v);
00613     };
00614 
00615   /// Explicit specialization declarations, defined in src/istream.cc.
00616   template<>
00617     basic_istream<char>&
00618     basic_istream<char>::
00619     getline(char_type* __s, streamsize __n, char_type __delim);
00620 
00621   template<>
00622     basic_istream<char>&
00623     basic_istream<char>::
00624     ignore(streamsize __n);
00625 
00626   template<>
00627     basic_istream<char>&
00628     basic_istream<char>::
00629     ignore(streamsize __n, int_type __delim);
00630 
00631 #ifdef _GLIBCXX_USE_WCHAR_T
00632   template<>
00633     basic_istream<wchar_t>&
00634     basic_istream<wchar_t>::
00635     getline(char_type* __s, streamsize __n, char_type __delim);
00636 
00637   template<>
00638     basic_istream<wchar_t>&
00639     basic_istream<wchar_t>::
00640     ignore(streamsize __n);
00641 
00642   template<>
00643     basic_istream<wchar_t>&
00644     basic_istream<wchar_t>::
00645     ignore(streamsize __n, int_type __delim);
00646 #endif
00647 
00648   /**
00649    *  @brief  Performs setup work for input streams.
00650    *
00651    *  Objects of this class are created before all of the standard
00652    *  extractors are run.  It is responsible for <em>exception-safe
00653    *  prefix and suffix operations,</em> although only prefix actions
00654    *  are currently required by the standard.
00655   */
00656   template<typename _CharT, typename _Traits>
00657     class basic_istream<_CharT, _Traits>::sentry
00658     {
00659       // Data Members.
00660       bool _M_ok;
00661 
00662     public:
00663       /// Easy access to dependent types.
00664       typedef _Traits                   traits_type;
00665       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00666       typedef basic_istream<_CharT, _Traits>        __istream_type;
00667       typedef typename __istream_type::__ctype_type     __ctype_type;
00668       typedef typename _Traits::int_type        __int_type;
00669 
00670       /**
00671        *  @brief  The constructor performs all the work.
00672        *  @param  __is  The input stream to guard.
00673        *  @param  __noskipws  Whether to consume whitespace or not.
00674        *
00675        *  If the stream state is good (@a __is.good() is true), then the
00676        *  following actions are performed, otherwise the sentry state
00677        *  is false (<em>not okay</em>) and failbit is set in the
00678        *  stream state.
00679        *
00680        *  The sentry's preparatory actions are:
00681        *
00682        *  -# if the stream is tied to an output stream, @c is.tie()->flush()
00683        *     is called to synchronize the output sequence
00684        *  -# if @a __noskipws is false, and @c ios_base::skipws is set in
00685        *     @c is.flags(), the sentry extracts and discards whitespace
00686        *     characters from the stream.  The currently imbued locale is
00687        *     used to determine whether each character is whitespace.
00688        *
00689        *  If the stream state is still good, then the sentry state becomes
00690        *  true (@a okay).
00691       */
00692       explicit
00693       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00694 
00695       /**
00696        *  @brief  Quick status checking.
00697        *  @return  The sentry state.
00698        *
00699        *  For ease of use, sentries may be converted to booleans.  The
00700        *  return value is that of the sentry state (true == okay).
00701       */
00702 #if __cplusplus >= 201103L
00703       explicit
00704 #endif
00705       operator bool() const
00706       { return _M_ok; }
00707     };
00708 
00709   //@{
00710   /**
00711    *  @brief  Character extractors
00712    *  @param  __in  An input stream.
00713    *  @param  __c  A character reference.
00714    *  @return  in
00715    *
00716    *  Behaves like one of the formatted arithmetic extractors described in
00717    *  std::basic_istream.  After constructing a sentry object with good
00718    *  status, this function extracts a character (if one is available) and
00719    *  stores it in @a __c.  Otherwise, sets failbit in the input stream.
00720   */
00721   template<typename _CharT, typename _Traits>
00722     basic_istream<_CharT, _Traits>&
00723     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00724 
00725   template<class _Traits>
00726     inline basic_istream<char, _Traits>&
00727     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00728     { return (__in >> reinterpret_cast<char&>(__c)); }
00729 
00730   template<class _Traits>
00731     inline basic_istream<char, _Traits>&
00732     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00733     { return (__in >> reinterpret_cast<char&>(__c)); }
00734   //@}
00735 
00736   //@{
00737   /**
00738    *  @brief  Character string extractors
00739    *  @param  __in  An input stream.
00740    *  @param  __s  A pointer to a character array.
00741    *  @return  __in
00742    *
00743    *  Behaves like one of the formatted arithmetic extractors described in
00744    *  std::basic_istream.  After constructing a sentry object with good
00745    *  status, this function extracts up to @c n characters and stores them
00746    *  into the array starting at @a __s.  @c n is defined as:
00747    *
00748    *  - if @c width() is greater than zero, @c n is width() otherwise
00749    *  - @c n is <em>the number of elements of the largest array of *
00750    *  - @c char_type that can store a terminating @c eos.</em>
00751    *  - [27.6.1.2.3]/6
00752    *
00753    *  Characters are extracted and stored until one of the following happens:
00754    *  - @c n-1 characters are stored
00755    *  - EOF is reached
00756    *  - the next character is whitespace according to the current locale
00757    *  - the next character is a null byte (i.e., @c charT() )
00758    *
00759    *  @c width(0) is then called for the input stream.
00760    *
00761    *  If no characters are extracted, sets failbit.
00762   */
00763   template<typename _CharT, typename _Traits>
00764     basic_istream<_CharT, _Traits>&
00765     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00766 
00767   // Explicit specialization declaration, defined in src/istream.cc.
00768   template<>
00769     basic_istream<char>&
00770     operator>>(basic_istream<char>& __in, char* __s);
00771 
00772   template<class _Traits>
00773     inline basic_istream<char, _Traits>&
00774     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
00775     { return (__in >> reinterpret_cast<char*>(__s)); }
00776 
00777   template<class _Traits>
00778     inline basic_istream<char, _Traits>&
00779     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
00780     { return (__in >> reinterpret_cast<char*>(__s)); }
00781   //@}
00782 
00783   /**
00784    *  @brief  Template class basic_iostream
00785    *  @ingroup io
00786    *
00787    *  @tparam _CharT  Type of character stream.
00788    *  @tparam _Traits  Traits for character type, defaults to
00789    *                   char_traits<_CharT>.
00790    *
00791    *  This class multiply inherits from the input and output stream classes
00792    *  simply to provide a single interface.
00793   */
00794   template<typename _CharT, typename _Traits>
00795     class basic_iostream
00796     : public basic_istream<_CharT, _Traits>,
00797       public basic_ostream<_CharT, _Traits>
00798     {
00799     public:
00800       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00801       // 271. basic_iostream missing typedefs
00802       // Types (inherited):
00803       typedef _CharT                    char_type;
00804       typedef typename _Traits::int_type        int_type;
00805       typedef typename _Traits::pos_type        pos_type;
00806       typedef typename _Traits::off_type        off_type;
00807       typedef _Traits                   traits_type;
00808 
00809       // Non-standard Types:
00810       typedef basic_istream<_CharT, _Traits>        __istream_type;
00811       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00812 
00813       /**
00814        *  @brief  Constructor does nothing.
00815        *
00816        *  Both of the parent classes are initialized with the same
00817        *  streambuf pointer passed to this constructor.
00818       */
00819       explicit
00820       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00821       : __istream_type(__sb), __ostream_type(__sb) { }
00822 
00823       /**
00824        *  @brief  Destructor does nothing.
00825       */
00826       virtual
00827       ~basic_iostream() { }
00828 
00829     protected:
00830       basic_iostream()
00831       : __istream_type(), __ostream_type() { }
00832     };
00833 
00834   /**
00835    *  @brief  Quick and easy way to eat whitespace
00836    *
00837    *  This manipulator extracts whitespace characters, stopping when the
00838    *  next character is non-whitespace, or when the input sequence is empty.
00839    *  If the sequence is empty, @c eofbit is set in the stream, but not
00840    *  @c failbit.
00841    *
00842    *  The current locale is used to distinguish whitespace characters.
00843    *
00844    *  Example:
00845    *  @code
00846    *     MyClass   mc;
00847    *
00848    *     std::cin >> std::ws >> mc;
00849    *  @endcode
00850    *  will skip leading whitespace before calling operator>> on cin and your
00851    *  object.  Note that the same effect can be achieved by creating a
00852    *  std::basic_istream::sentry inside your definition of operator>>.
00853   */
00854   template<typename _CharT, typename _Traits>
00855     basic_istream<_CharT, _Traits>&
00856     ws(basic_istream<_CharT, _Traits>& __is);
00857 
00858 #if __cplusplus >= 201103L
00859   // [27.7.1.6] Rvalue stream extraction
00860   /**
00861    *  @brief  Generic extractor for rvalue stream
00862    *  @param  __is  An input stream.
00863    *  @param  __x  A reference to the extraction target.
00864    *  @return  is
00865    *
00866    *  This is just a forwarding function to allow extraction from
00867    *  rvalue streams since they won't bind to the extractor functions
00868    *  that take an lvalue reference.
00869   */
00870   template<typename _CharT, typename _Traits, typename _Tp>
00871     inline basic_istream<_CharT, _Traits>&
00872     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
00873     { return (__is >> __x); }
00874 #endif // C++11
00875 
00876 _GLIBCXX_END_NAMESPACE_VERSION
00877 } // namespace
00878 
00879 #include <bits/istream.tcc>
00880 
00881 #endif  /* _GLIBCXX_ISTREAM */