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