1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 // Free Software Foundation, Inc.
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 2, or (at your option)
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.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
38 // ISO C++ 14882: 27.6.1 Input streams
42 #define _ISTREAM_TCC 1
44 #pragma GCC system_header
47 #include <ostream> // For flush()
49 _GLIBCXX_BEGIN_NAMESPACE(std)
51 template<typename _CharT, typename _Traits>
52 basic_istream<_CharT, _Traits>::sentry::
53 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
55 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
60 if (!__noskip && (__in.flags() & ios_base::skipws))
62 const __int_type __eof = traits_type::eof();
63 __streambuf_type* __sb = __in.rdbuf();
64 __int_type __c = __sb->sgetc();
66 const __ctype_type& __ct = __check_facet(__in._M_ctype);
67 while (!traits_type::eq_int_type(__c, __eof)
68 && __ct.is(ctype_base::space,
69 traits_type::to_char_type(__c)))
72 // _GLIBCXX_RESOLVE_LIB_DEFECTS
73 // 195. Should basic_istream::sentry's constructor ever
75 if (traits_type::eq_int_type(__c, __eof))
76 __err |= ios_base::eofbit;
80 if (__in.good() && __err == ios_base::goodbit)
84 __err |= ios_base::failbit;
89 template<typename _CharT, typename _Traits>
90 template<typename _ValueT>
91 basic_istream<_CharT, _Traits>&
92 basic_istream<_CharT, _Traits>::
93 _M_extract(_ValueT& __v)
95 sentry __cerb(*this, false);
98 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
101 const __num_get_type& __ng = __check_facet(this->_M_num_get);
102 __ng.get(*this, 0, *this, __err, __v);
105 { this->_M_setstate(ios_base::badbit); }
107 this->setstate(__err);
112 template<typename _CharT, typename _Traits>
113 basic_istream<_CharT, _Traits>&
114 basic_istream<_CharT, _Traits>::
115 operator>>(short& __n)
117 // _GLIBCXX_RESOLVE_LIB_DEFECTS
118 // 118. basic_istream uses nonexistent num_get member functions.
123 if (numeric_limits<short>::min() <= __l
124 && __l <= numeric_limits<short>::max())
127 this->setstate(ios_base::failbit);
132 template<typename _CharT, typename _Traits>
133 basic_istream<_CharT, _Traits>&
134 basic_istream<_CharT, _Traits>::
137 // _GLIBCXX_RESOLVE_LIB_DEFECTS
138 // 118. basic_istream uses nonexistent num_get member functions.
143 if (numeric_limits<int>::min() <= __l
144 && __l <= numeric_limits<int>::max())
147 this->setstate(ios_base::failbit);
152 template<typename _CharT, typename _Traits>
153 basic_istream<_CharT, _Traits>&
154 basic_istream<_CharT, _Traits>::
155 operator>>(__streambuf_type* __sbout)
157 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
158 sentry __cerb(*this, false);
159 if (__cerb && __sbout)
164 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
165 __err |= ios_base::failbit;
167 __err |= ios_base::eofbit;
170 { this->_M_setstate(ios_base::failbit); }
173 __err |= ios_base::failbit;
175 this->setstate(__err);
179 template<typename _CharT, typename _Traits>
180 typename basic_istream<_CharT, _Traits>::int_type
181 basic_istream<_CharT, _Traits>::
184 const int_type __eof = traits_type::eof();
185 int_type __c = __eof;
187 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
188 sentry __cerb(*this, true);
193 __c = this->rdbuf()->sbumpc();
194 // 27.6.1.1 paragraph 3
195 if (!traits_type::eq_int_type(__c, __eof))
198 __err |= ios_base::eofbit;
201 { this->_M_setstate(ios_base::badbit); }
204 __err |= ios_base::failbit;
206 this->setstate(__err);
210 template<typename _CharT, typename _Traits>
211 basic_istream<_CharT, _Traits>&
212 basic_istream<_CharT, _Traits>::
216 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
217 sentry __cerb(*this, true);
222 const int_type __cb = this->rdbuf()->sbumpc();
223 // 27.6.1.1 paragraph 3
224 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
227 __c = traits_type::to_char_type(__cb);
230 __err |= ios_base::eofbit;
233 { this->_M_setstate(ios_base::badbit); }
236 __err |= ios_base::failbit;
238 this->setstate(__err);
242 template<typename _CharT, typename _Traits>
243 basic_istream<_CharT, _Traits>&
244 basic_istream<_CharT, _Traits>::
245 get(char_type* __s, streamsize __n, char_type __delim)
248 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
249 sentry __cerb(*this, true);
254 const int_type __idelim = traits_type::to_int_type(__delim);
255 const int_type __eof = traits_type::eof();
256 __streambuf_type* __sb = this->rdbuf();
257 int_type __c = __sb->sgetc();
259 while (_M_gcount + 1 < __n
260 && !traits_type::eq_int_type(__c, __eof)
261 && !traits_type::eq_int_type(__c, __idelim))
263 *__s++ = traits_type::to_char_type(__c);
265 __c = __sb->snextc();
267 if (traits_type::eq_int_type(__c, __eof))
268 __err |= ios_base::eofbit;
271 { this->_M_setstate(ios_base::badbit); }
273 // _GLIBCXX_RESOLVE_LIB_DEFECTS
274 // 243. get and getline when sentry reports failure.
278 __err |= ios_base::failbit;
280 this->setstate(__err);
284 template<typename _CharT, typename _Traits>
285 basic_istream<_CharT, _Traits>&
286 basic_istream<_CharT, _Traits>::
287 get(__streambuf_type& __sb, char_type __delim)
290 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
291 sentry __cerb(*this, true);
296 const int_type __idelim = traits_type::to_int_type(__delim);
297 const int_type __eof = traits_type::eof();
298 __streambuf_type* __this_sb = this->rdbuf();
299 int_type __c = __this_sb->sgetc();
300 char_type __c2 = traits_type::to_char_type(__c);
302 while (!traits_type::eq_int_type(__c, __eof)
303 && !traits_type::eq_int_type(__c, __idelim)
304 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
307 __c = __this_sb->snextc();
308 __c2 = traits_type::to_char_type(__c);
310 if (traits_type::eq_int_type(__c, __eof))
311 __err |= ios_base::eofbit;
314 { this->_M_setstate(ios_base::badbit); }
317 __err |= ios_base::failbit;
319 this->setstate(__err);
323 template<typename _CharT, typename _Traits>
324 basic_istream<_CharT, _Traits>&
325 basic_istream<_CharT, _Traits>::
326 getline(char_type* __s, streamsize __n, char_type __delim)
329 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
330 sentry __cerb(*this, true);
335 const int_type __idelim = traits_type::to_int_type(__delim);
336 const int_type __eof = traits_type::eof();
337 __streambuf_type* __sb = this->rdbuf();
338 int_type __c = __sb->sgetc();
340 while (_M_gcount + 1 < __n
341 && !traits_type::eq_int_type(__c, __eof)
342 && !traits_type::eq_int_type(__c, __idelim))
344 *__s++ = traits_type::to_char_type(__c);
345 __c = __sb->snextc();
348 if (traits_type::eq_int_type(__c, __eof))
349 __err |= ios_base::eofbit;
352 if (traits_type::eq_int_type(__c, __idelim))
358 __err |= ios_base::failbit;
362 { this->_M_setstate(ios_base::badbit); }
364 // _GLIBCXX_RESOLVE_LIB_DEFECTS
365 // 243. get and getline when sentry reports failure.
369 __err |= ios_base::failbit;
371 this->setstate(__err);
375 // We provide three overloads, since the first two are much simpler
376 // than the general case. Also, the latter two can thus adopt the
377 // same "batchy" strategy used by getline above.
378 template<typename _CharT, typename _Traits>
379 basic_istream<_CharT, _Traits>&
380 basic_istream<_CharT, _Traits>::
384 sentry __cerb(*this, true);
387 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
390 const int_type __eof = traits_type::eof();
391 __streambuf_type* __sb = this->rdbuf();
393 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
394 __err |= ios_base::eofbit;
399 { this->_M_setstate(ios_base::badbit); }
401 this->setstate(__err);
406 template<typename _CharT, typename _Traits>
407 basic_istream<_CharT, _Traits>&
408 basic_istream<_CharT, _Traits>::
409 ignore(streamsize __n)
412 sentry __cerb(*this, true);
413 if (__cerb && __n > 0)
415 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
418 const int_type __eof = traits_type::eof();
419 __streambuf_type* __sb = this->rdbuf();
420 int_type __c = __sb->sgetc();
422 // N.B. On LFS-enabled platforms streamsize is still 32 bits
423 // wide: if we want to implement the standard mandated behavior
424 // for n == max() (see 27.6.1.3/24) we are at risk of signed
425 // integer overflow: thus these contortions. Also note that,
426 // by definition, when more than 2G chars are actually ignored,
427 // _M_gcount (the return value of gcount, that is) cannot be
428 // really correct, being unavoidably too small.
429 bool __large_ignore = false;
432 while (_M_gcount < __n
433 && !traits_type::eq_int_type(__c, __eof))
436 __c = __sb->snextc();
438 if (__n == numeric_limits<streamsize>::max()
439 && !traits_type::eq_int_type(__c, __eof))
441 _M_gcount = numeric_limits<streamsize>::min();
442 __large_ignore = true;
449 _M_gcount = numeric_limits<streamsize>::max();
451 if (traits_type::eq_int_type(__c, __eof))
452 __err |= ios_base::eofbit;
455 { this->_M_setstate(ios_base::badbit); }
457 this->setstate(__err);
462 template<typename _CharT, typename _Traits>
463 basic_istream<_CharT, _Traits>&
464 basic_istream<_CharT, _Traits>::
465 ignore(streamsize __n, int_type __delim)
468 sentry __cerb(*this, true);
469 if (__cerb && __n > 0)
471 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
474 const int_type __eof = traits_type::eof();
475 __streambuf_type* __sb = this->rdbuf();
476 int_type __c = __sb->sgetc();
478 // See comment above.
479 bool __large_ignore = false;
482 while (_M_gcount < __n
483 && !traits_type::eq_int_type(__c, __eof)
484 && !traits_type::eq_int_type(__c, __delim))
487 __c = __sb->snextc();
489 if (__n == numeric_limits<streamsize>::max()
490 && !traits_type::eq_int_type(__c, __eof)
491 && !traits_type::eq_int_type(__c, __delim))
493 _M_gcount = numeric_limits<streamsize>::min();
494 __large_ignore = true;
501 _M_gcount = numeric_limits<streamsize>::max();
503 if (traits_type::eq_int_type(__c, __eof))
504 __err |= ios_base::eofbit;
505 else if (traits_type::eq_int_type(__c, __delim))
507 if (_M_gcount < numeric_limits<streamsize>::max())
513 { this->_M_setstate(ios_base::badbit); }
515 this->setstate(__err);
520 template<typename _CharT, typename _Traits>
521 typename basic_istream<_CharT, _Traits>::int_type
522 basic_istream<_CharT, _Traits>::
525 int_type __c = traits_type::eof();
527 sentry __cerb(*this, true);
530 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
533 __c = this->rdbuf()->sgetc();
534 if (traits_type::eq_int_type(__c, traits_type::eof()))
535 __err |= ios_base::eofbit;
538 { this->_M_setstate(ios_base::badbit); }
540 this->setstate(__err);
545 template<typename _CharT, typename _Traits>
546 basic_istream<_CharT, _Traits>&
547 basic_istream<_CharT, _Traits>::
548 read(char_type* __s, streamsize __n)
551 sentry __cerb(*this, true);
554 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
557 _M_gcount = this->rdbuf()->sgetn(__s, __n);
558 if (_M_gcount != __n)
559 __err |= (ios_base::eofbit | ios_base::failbit);
562 { this->_M_setstate(ios_base::badbit); }
564 this->setstate(__err);
569 template<typename _CharT, typename _Traits>
571 basic_istream<_CharT, _Traits>::
572 readsome(char_type* __s, streamsize __n)
575 sentry __cerb(*this, true);
578 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
581 // Cannot compare int_type with streamsize generically.
582 const streamsize __num = this->rdbuf()->in_avail();
584 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
585 else if (__num == -1)
586 __err |= ios_base::eofbit;
589 { this->_M_setstate(ios_base::badbit); }
591 this->setstate(__err);
596 template<typename _CharT, typename _Traits>
597 basic_istream<_CharT, _Traits>&
598 basic_istream<_CharT, _Traits>::
599 putback(char_type __c)
601 // _GLIBCXX_RESOLVE_LIB_DEFECTS
602 // 60. What is a formatted input function?
604 sentry __cerb(*this, true);
607 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
610 const int_type __eof = traits_type::eof();
611 __streambuf_type* __sb = this->rdbuf();
613 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
614 __err |= ios_base::badbit;
617 { this->_M_setstate(ios_base::badbit); }
619 this->setstate(__err);
624 template<typename _CharT, typename _Traits>
625 basic_istream<_CharT, _Traits>&
626 basic_istream<_CharT, _Traits>::
629 // _GLIBCXX_RESOLVE_LIB_DEFECTS
630 // 60. What is a formatted input function?
632 sentry __cerb(*this, true);
635 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
638 const int_type __eof = traits_type::eof();
639 __streambuf_type* __sb = this->rdbuf();
641 || traits_type::eq_int_type(__sb->sungetc(), __eof))
642 __err |= ios_base::badbit;
645 { this->_M_setstate(ios_base::badbit); }
647 this->setstate(__err);
652 template<typename _CharT, typename _Traits>
654 basic_istream<_CharT, _Traits>::
657 // _GLIBCXX_RESOLVE_LIB_DEFECTS
658 // DR60. Do not change _M_gcount.
660 sentry __cerb(*this, true);
663 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
666 __streambuf_type* __sb = this->rdbuf();
669 if (__sb->pubsync() == -1)
670 __err |= ios_base::badbit;
676 { this->_M_setstate(ios_base::badbit); }
678 this->setstate(__err);
683 template<typename _CharT, typename _Traits>
684 typename basic_istream<_CharT, _Traits>::pos_type
685 basic_istream<_CharT, _Traits>::
688 // _GLIBCXX_RESOLVE_LIB_DEFECTS
689 // DR60. Do not change _M_gcount.
690 pos_type __ret = pos_type(-1);
694 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
698 { this->_M_setstate(ios_base::badbit); }
702 template<typename _CharT, typename _Traits>
703 basic_istream<_CharT, _Traits>&
704 basic_istream<_CharT, _Traits>::
705 seekg(pos_type __pos)
707 // _GLIBCXX_RESOLVE_LIB_DEFECTS
708 // DR60. Do not change _M_gcount.
709 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
714 // 136. seekp, seekg setting wrong streams?
715 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
718 // 129. Need error indication from seekp() and seekg()
719 if (__p == pos_type(off_type(-1)))
720 __err |= ios_base::failbit;
724 { this->_M_setstate(ios_base::badbit); }
726 this->setstate(__err);
730 template<typename _CharT, typename _Traits>
731 basic_istream<_CharT, _Traits>&
732 basic_istream<_CharT, _Traits>::
733 seekg(off_type __off, ios_base::seekdir __dir)
735 // _GLIBCXX_RESOLVE_LIB_DEFECTS
736 // DR60. Do not change _M_gcount.
737 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
742 // 136. seekp, seekg setting wrong streams?
743 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
746 // 129. Need error indication from seekp() and seekg()
747 if (__p == pos_type(off_type(-1)))
748 __err |= ios_base::failbit;
752 { this->_M_setstate(ios_base::badbit); }
754 this->setstate(__err);
758 // 27.6.1.2.3 Character extraction templates
759 template<typename _CharT, typename _Traits>
760 basic_istream<_CharT, _Traits>&
761 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
763 typedef basic_istream<_CharT, _Traits> __istream_type;
764 typedef typename __istream_type::int_type __int_type;
766 typename __istream_type::sentry __cerb(__in, false);
769 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
772 const __int_type __cb = __in.rdbuf()->sbumpc();
773 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
774 __c = _Traits::to_char_type(__cb);
776 __err |= (ios_base::eofbit | ios_base::failbit);
779 { __in._M_setstate(ios_base::badbit); }
781 __in.setstate(__err);
786 template<typename _CharT, typename _Traits>
787 basic_istream<_CharT, _Traits>&
788 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
790 typedef basic_istream<_CharT, _Traits> __istream_type;
791 typedef typename __istream_type::__streambuf_type __streambuf_type;
792 typedef typename _Traits::int_type int_type;
793 typedef _CharT char_type;
794 typedef ctype<_CharT> __ctype_type;
796 streamsize __extracted = 0;
797 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
798 typename __istream_type::sentry __cerb(__in, false);
803 // Figure out how many characters to extract.
804 streamsize __num = __in.width();
806 __num = numeric_limits<streamsize>::max();
808 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
810 const int_type __eof = _Traits::eof();
811 __streambuf_type* __sb = __in.rdbuf();
812 int_type __c = __sb->sgetc();
814 while (__extracted < __num - 1
815 && !_Traits::eq_int_type(__c, __eof)
816 && !__ct.is(ctype_base::space,
817 _Traits::to_char_type(__c)))
819 *__s++ = _Traits::to_char_type(__c);
821 __c = __sb->snextc();
823 if (_Traits::eq_int_type(__c, __eof))
824 __err |= ios_base::eofbit;
826 // _GLIBCXX_RESOLVE_LIB_DEFECTS
827 // 68. Extractors for char* should store null at end
832 { __in._M_setstate(ios_base::badbit); }
835 __err |= ios_base::failbit;
837 __in.setstate(__err);
841 // 27.6.1.4 Standard basic_istream manipulators
842 template<typename _CharT, typename _Traits>
843 basic_istream<_CharT,_Traits>&
844 ws(basic_istream<_CharT,_Traits>& __in)
846 typedef basic_istream<_CharT, _Traits> __istream_type;
847 typedef typename __istream_type::__streambuf_type __streambuf_type;
848 typedef typename __istream_type::__ctype_type __ctype_type;
849 typedef typename __istream_type::int_type __int_type;
851 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
852 const __int_type __eof = _Traits::eof();
853 __streambuf_type* __sb = __in.rdbuf();
854 __int_type __c = __sb->sgetc();
856 while (!_Traits::eq_int_type(__c, __eof)
857 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
858 __c = __sb->snextc();
860 if (_Traits::eq_int_type(__c, __eof))
861 __in.setstate(ios_base::eofbit);
865 // 21.3.7.9 basic_string::getline and operators
866 template<typename _CharT, typename _Traits, typename _Alloc>
867 basic_istream<_CharT, _Traits>&
868 operator>>(basic_istream<_CharT, _Traits>& __in,
869 basic_string<_CharT, _Traits, _Alloc>& __str)
871 typedef basic_istream<_CharT, _Traits> __istream_type;
872 typedef typename __istream_type::int_type __int_type;
873 typedef typename __istream_type::__streambuf_type __streambuf_type;
874 typedef typename __istream_type::__ctype_type __ctype_type;
875 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
876 typedef typename __string_type::size_type __size_type;
878 __size_type __extracted = 0;
879 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
880 typename __istream_type::sentry __cerb(__in, false);
885 // Avoid reallocation for common case.
888 __size_type __len = 0;
889 const streamsize __w = __in.width();
890 const __size_type __n = __w > 0 ? static_cast<__size_type>(__w)
892 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
893 const __int_type __eof = _Traits::eof();
894 __streambuf_type* __sb = __in.rdbuf();
895 __int_type __c = __sb->sgetc();
897 while (__extracted < __n
898 && !_Traits::eq_int_type(__c, __eof)
899 && !__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
901 if (__len == sizeof(__buf) / sizeof(_CharT))
903 __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
906 __buf[__len++] = _Traits::to_char_type(__c);
908 __c = __sb->snextc();
910 __str.append(__buf, __len);
912 if (_Traits::eq_int_type(__c, __eof))
913 __err |= ios_base::eofbit;
918 // _GLIBCXX_RESOLVE_LIB_DEFECTS
919 // 91. Description of operator>> and getline() for string<>
920 // might cause endless loop
921 __in._M_setstate(ios_base::badbit);
924 // 211. operator>>(istream&, string&) doesn't set failbit
926 __err |= ios_base::failbit;
928 __in.setstate(__err);
932 template<typename _CharT, typename _Traits, typename _Alloc>
933 basic_istream<_CharT, _Traits>&
934 getline(basic_istream<_CharT, _Traits>& __in,
935 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
937 typedef basic_istream<_CharT, _Traits> __istream_type;
938 typedef typename __istream_type::int_type __int_type;
939 typedef typename __istream_type::__streambuf_type __streambuf_type;
940 typedef typename __istream_type::__ctype_type __ctype_type;
941 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
942 typedef typename __string_type::size_type __size_type;
944 __size_type __extracted = 0;
945 const __size_type __n = __str.max_size();
946 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
947 typename __istream_type::sentry __cerb(__in, true);
953 const __int_type __idelim = _Traits::to_int_type(__delim);
954 const __int_type __eof = _Traits::eof();
955 __streambuf_type* __sb = __in.rdbuf();
956 __int_type __c = __sb->sgetc();
958 while (__extracted < __n
959 && !_Traits::eq_int_type(__c, __eof)
960 && !_Traits::eq_int_type(__c, __idelim))
962 __str += _Traits::to_char_type(__c);
964 __c = __sb->snextc();
967 if (_Traits::eq_int_type(__c, __eof))
968 __err |= ios_base::eofbit;
969 else if (_Traits::eq_int_type(__c, __idelim))
975 __err |= ios_base::failbit;
979 // _GLIBCXX_RESOLVE_LIB_DEFECTS
980 // 91. Description of operator>> and getline() for string<>
981 // might cause endless loop
982 __in._M_setstate(ios_base::badbit);
986 __err |= ios_base::failbit;
988 __in.setstate(__err);
992 // Inhibit implicit instantiations for required instantiations,
993 // which are defined via explicit instantiations elsewhere.
994 // NB: This syntax is a GNU extension.
995 #if _GLIBCXX_EXTERN_TEMPLATE
996 extern template class basic_istream<char>;
997 extern template istream& ws(istream&);
998 extern template istream& operator>>(istream&, char&);
999 extern template istream& operator>>(istream&, char*);
1000 extern template istream& operator>>(istream&, unsigned char&);
1001 extern template istream& operator>>(istream&, signed char&);
1002 extern template istream& operator>>(istream&, unsigned char*);
1003 extern template istream& operator>>(istream&, signed char*);
1005 extern template istream& istream::_M_extract(unsigned short&);
1006 extern template istream& istream::_M_extract(unsigned int&);
1007 extern template istream& istream::_M_extract(long&);
1008 extern template istream& istream::_M_extract(unsigned long&);
1009 extern template istream& istream::_M_extract(bool&);
1010 #ifdef _GLIBCXX_USE_LONG_LONG
1011 extern template istream& istream::_M_extract(long long&);
1012 extern template istream& istream::_M_extract(unsigned long long&);
1014 extern template istream& istream::_M_extract(float&);
1015 extern template istream& istream::_M_extract(double&);
1016 extern template istream& istream::_M_extract(long double&);
1017 extern template istream& istream::_M_extract(void*&);
1019 extern template class basic_iostream<char>;
1021 #ifdef _GLIBCXX_USE_WCHAR_T
1022 extern template class basic_istream<wchar_t>;
1023 extern template wistream& ws(wistream&);
1024 extern template wistream& operator>>(wistream&, wchar_t&);
1025 extern template wistream& operator>>(wistream&, wchar_t*);
1027 extern template wistream& wistream::_M_extract(unsigned short&);
1028 extern template wistream& wistream::_M_extract(unsigned int&);
1029 extern template wistream& wistream::_M_extract(long&);
1030 extern template wistream& wistream::_M_extract(unsigned long&);
1031 extern template wistream& wistream::_M_extract(bool&);
1032 #ifdef _GLIBCXX_USE_LONG_LONG
1033 extern template wistream& wistream::_M_extract(long long&);
1034 extern template wistream& wistream::_M_extract(unsigned long long&);
1036 extern template wistream& wistream::_M_extract(float&);
1037 extern template wistream& wistream::_M_extract(double&);
1038 extern template wistream& wistream::_M_extract(long double&);
1039 extern template wistream& wistream::_M_extract(void*&);
1041 extern template class basic_iostream<wchar_t>;
1045 _GLIBCXX_END_NAMESPACE