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