1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009
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 3, 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 // 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.
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/>.
28 * This is an internal header file, included by other library headers.
29 * You should not attempt to use it directly.
33 // ISO C++ 14882: 27.6.1 Input streams
37 #define _ISTREAM_TCC 1
39 #pragma GCC system_header
41 #include <cxxabi-forced.h>
43 _GLIBCXX_BEGIN_NAMESPACE(std)
45 template<typename _CharT, typename _Traits>
46 basic_istream<_CharT, _Traits>::sentry::
47 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
49 ios_base::iostate __err = ios_base::goodbit;
54 if (!__noskip && bool(__in.flags() & ios_base::skipws))
56 const __int_type __eof = traits_type::eof();
57 __streambuf_type* __sb = __in.rdbuf();
58 __int_type __c = __sb->sgetc();
60 const __ctype_type& __ct = __check_facet(__in._M_ctype);
61 while (!traits_type::eq_int_type(__c, __eof)
62 && __ct.is(ctype_base::space,
63 traits_type::to_char_type(__c)))
66 // _GLIBCXX_RESOLVE_LIB_DEFECTS
67 // 195. Should basic_istream::sentry's constructor ever
69 if (traits_type::eq_int_type(__c, __eof))
70 __err |= ios_base::eofbit;
74 if (__in.good() && __err == ios_base::goodbit)
78 __err |= ios_base::failbit;
83 template<typename _CharT, typename _Traits>
84 template<typename _ValueT>
85 basic_istream<_CharT, _Traits>&
86 basic_istream<_CharT, _Traits>::
87 _M_extract(_ValueT& __v)
89 sentry __cerb(*this, false);
92 ios_base::iostate __err = ios_base::goodbit;
95 const __num_get_type& __ng = __check_facet(this->_M_num_get);
96 __ng.get(*this, 0, *this, __err, __v);
98 __catch(__cxxabiv1::__forced_unwind&)
100 this->_M_setstate(ios_base::badbit);
101 __throw_exception_again;
104 { this->_M_setstate(ios_base::badbit); }
106 this->setstate(__err);
111 template<typename _CharT, typename _Traits>
112 basic_istream<_CharT, _Traits>&
113 basic_istream<_CharT, _Traits>::
114 operator>>(short& __n)
116 // _GLIBCXX_RESOLVE_LIB_DEFECTS
117 // 118. basic_istream uses nonexistent num_get member functions.
118 sentry __cerb(*this, false);
121 ios_base::iostate __err = ios_base::goodbit;
125 const __num_get_type& __ng = __check_facet(this->_M_num_get);
126 __ng.get(*this, 0, *this, __err, __l);
128 // _GLIBCXX_RESOLVE_LIB_DEFECTS
129 // 696. istream::operator>>(int&) broken.
130 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
132 __err |= ios_base::failbit;
133 __n = __gnu_cxx::__numeric_traits<short>::__min;
135 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
137 __err |= ios_base::failbit;
138 __n = __gnu_cxx::__numeric_traits<short>::__max;
143 __catch(__cxxabiv1::__forced_unwind&)
145 this->_M_setstate(ios_base::badbit);
146 __throw_exception_again;
149 { this->_M_setstate(ios_base::badbit); }
151 this->setstate(__err);
156 template<typename _CharT, typename _Traits>
157 basic_istream<_CharT, _Traits>&
158 basic_istream<_CharT, _Traits>::
161 // _GLIBCXX_RESOLVE_LIB_DEFECTS
162 // 118. basic_istream uses nonexistent num_get member functions.
163 sentry __cerb(*this, false);
166 ios_base::iostate __err = ios_base::goodbit;
170 const __num_get_type& __ng = __check_facet(this->_M_num_get);
171 __ng.get(*this, 0, *this, __err, __l);
173 // _GLIBCXX_RESOLVE_LIB_DEFECTS
174 // 696. istream::operator>>(int&) broken.
175 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
177 __err |= ios_base::failbit;
178 __n = __gnu_cxx::__numeric_traits<int>::__min;
180 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
182 __err |= ios_base::failbit;
183 __n = __gnu_cxx::__numeric_traits<int>::__max;
188 __catch(__cxxabiv1::__forced_unwind&)
190 this->_M_setstate(ios_base::badbit);
191 __throw_exception_again;
194 { this->_M_setstate(ios_base::badbit); }
196 this->setstate(__err);
201 template<typename _CharT, typename _Traits>
202 basic_istream<_CharT, _Traits>&
203 basic_istream<_CharT, _Traits>::
204 operator>>(__streambuf_type* __sbout)
206 ios_base::iostate __err = ios_base::goodbit;
207 sentry __cerb(*this, false);
208 if (__cerb && __sbout)
213 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
214 __err |= ios_base::failbit;
216 __err |= ios_base::eofbit;
218 __catch(__cxxabiv1::__forced_unwind&)
220 this->_M_setstate(ios_base::failbit);
221 __throw_exception_again;
224 { this->_M_setstate(ios_base::failbit); }
227 __err |= ios_base::failbit;
229 this->setstate(__err);
233 template<typename _CharT, typename _Traits>
234 typename basic_istream<_CharT, _Traits>::int_type
235 basic_istream<_CharT, _Traits>::
238 const int_type __eof = traits_type::eof();
239 int_type __c = __eof;
241 ios_base::iostate __err = ios_base::goodbit;
242 sentry __cerb(*this, true);
247 __c = this->rdbuf()->sbumpc();
248 // 27.6.1.1 paragraph 3
249 if (!traits_type::eq_int_type(__c, __eof))
252 __err |= ios_base::eofbit;
254 __catch(__cxxabiv1::__forced_unwind&)
256 this->_M_setstate(ios_base::badbit);
257 __throw_exception_again;
260 { this->_M_setstate(ios_base::badbit); }
263 __err |= ios_base::failbit;
265 this->setstate(__err);
269 template<typename _CharT, typename _Traits>
270 basic_istream<_CharT, _Traits>&
271 basic_istream<_CharT, _Traits>::
275 ios_base::iostate __err = ios_base::goodbit;
276 sentry __cerb(*this, true);
281 const int_type __cb = this->rdbuf()->sbumpc();
282 // 27.6.1.1 paragraph 3
283 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
286 __c = traits_type::to_char_type(__cb);
289 __err |= ios_base::eofbit;
291 __catch(__cxxabiv1::__forced_unwind&)
293 this->_M_setstate(ios_base::badbit);
294 __throw_exception_again;
297 { this->_M_setstate(ios_base::badbit); }
300 __err |= ios_base::failbit;
302 this->setstate(__err);
306 template<typename _CharT, typename _Traits>
307 basic_istream<_CharT, _Traits>&
308 basic_istream<_CharT, _Traits>::
309 get(char_type* __s, streamsize __n, char_type __delim)
312 ios_base::iostate __err = ios_base::goodbit;
313 sentry __cerb(*this, true);
318 const int_type __idelim = traits_type::to_int_type(__delim);
319 const int_type __eof = traits_type::eof();
320 __streambuf_type* __sb = this->rdbuf();
321 int_type __c = __sb->sgetc();
323 while (_M_gcount + 1 < __n
324 && !traits_type::eq_int_type(__c, __eof)
325 && !traits_type::eq_int_type(__c, __idelim))
327 *__s++ = traits_type::to_char_type(__c);
329 __c = __sb->snextc();
331 if (traits_type::eq_int_type(__c, __eof))
332 __err |= ios_base::eofbit;
334 __catch(__cxxabiv1::__forced_unwind&)
336 this->_M_setstate(ios_base::badbit);
337 __throw_exception_again;
340 { this->_M_setstate(ios_base::badbit); }
342 // _GLIBCXX_RESOLVE_LIB_DEFECTS
343 // 243. get and getline when sentry reports failure.
347 __err |= ios_base::failbit;
349 this->setstate(__err);
353 template<typename _CharT, typename _Traits>
354 basic_istream<_CharT, _Traits>&
355 basic_istream<_CharT, _Traits>::
356 get(__streambuf_type& __sb, char_type __delim)
359 ios_base::iostate __err = ios_base::goodbit;
360 sentry __cerb(*this, true);
365 const int_type __idelim = traits_type::to_int_type(__delim);
366 const int_type __eof = traits_type::eof();
367 __streambuf_type* __this_sb = this->rdbuf();
368 int_type __c = __this_sb->sgetc();
369 char_type __c2 = traits_type::to_char_type(__c);
371 while (!traits_type::eq_int_type(__c, __eof)
372 && !traits_type::eq_int_type(__c, __idelim)
373 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
376 __c = __this_sb->snextc();
377 __c2 = traits_type::to_char_type(__c);
379 if (traits_type::eq_int_type(__c, __eof))
380 __err |= ios_base::eofbit;
382 __catch(__cxxabiv1::__forced_unwind&)
384 this->_M_setstate(ios_base::badbit);
385 __throw_exception_again;
388 { this->_M_setstate(ios_base::badbit); }
391 __err |= ios_base::failbit;
393 this->setstate(__err);
397 template<typename _CharT, typename _Traits>
398 basic_istream<_CharT, _Traits>&
399 basic_istream<_CharT, _Traits>::
400 getline(char_type* __s, streamsize __n, char_type __delim)
403 ios_base::iostate __err = ios_base::goodbit;
404 sentry __cerb(*this, true);
409 const int_type __idelim = traits_type::to_int_type(__delim);
410 const int_type __eof = traits_type::eof();
411 __streambuf_type* __sb = this->rdbuf();
412 int_type __c = __sb->sgetc();
414 while (_M_gcount + 1 < __n
415 && !traits_type::eq_int_type(__c, __eof)
416 && !traits_type::eq_int_type(__c, __idelim))
418 *__s++ = traits_type::to_char_type(__c);
419 __c = __sb->snextc();
422 if (traits_type::eq_int_type(__c, __eof))
423 __err |= ios_base::eofbit;
426 if (traits_type::eq_int_type(__c, __idelim))
432 __err |= ios_base::failbit;
435 __catch(__cxxabiv1::__forced_unwind&)
437 this->_M_setstate(ios_base::badbit);
438 __throw_exception_again;
441 { this->_M_setstate(ios_base::badbit); }
443 // _GLIBCXX_RESOLVE_LIB_DEFECTS
444 // 243. get and getline when sentry reports failure.
448 __err |= ios_base::failbit;
450 this->setstate(__err);
454 // We provide three overloads, since the first two are much simpler
455 // than the general case. Also, the latter two can thus adopt the
456 // same "batchy" strategy used by getline above.
457 template<typename _CharT, typename _Traits>
458 basic_istream<_CharT, _Traits>&
459 basic_istream<_CharT, _Traits>::
463 sentry __cerb(*this, true);
466 ios_base::iostate __err = ios_base::goodbit;
469 const int_type __eof = traits_type::eof();
470 __streambuf_type* __sb = this->rdbuf();
472 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
473 __err |= ios_base::eofbit;
477 __catch(__cxxabiv1::__forced_unwind&)
479 this->_M_setstate(ios_base::badbit);
480 __throw_exception_again;
483 { this->_M_setstate(ios_base::badbit); }
485 this->setstate(__err);
490 template<typename _CharT, typename _Traits>
491 basic_istream<_CharT, _Traits>&
492 basic_istream<_CharT, _Traits>::
493 ignore(streamsize __n)
496 sentry __cerb(*this, true);
497 if (__cerb && __n > 0)
499 ios_base::iostate __err = ios_base::goodbit;
502 const int_type __eof = traits_type::eof();
503 __streambuf_type* __sb = this->rdbuf();
504 int_type __c = __sb->sgetc();
506 // N.B. On LFS-enabled platforms streamsize is still 32 bits
507 // wide: if we want to implement the standard mandated behavior
508 // for n == max() (see 27.6.1.3/24) we are at risk of signed
509 // integer overflow: thus these contortions. Also note that,
510 // by definition, when more than 2G chars are actually ignored,
511 // _M_gcount (the return value of gcount, that is) cannot be
512 // really correct, being unavoidably too small.
513 bool __large_ignore = false;
516 while (_M_gcount < __n
517 && !traits_type::eq_int_type(__c, __eof))
520 __c = __sb->snextc();
522 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
523 && !traits_type::eq_int_type(__c, __eof))
526 __gnu_cxx::__numeric_traits<streamsize>::__min;
527 __large_ignore = true;
534 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
536 if (traits_type::eq_int_type(__c, __eof))
537 __err |= ios_base::eofbit;
539 __catch(__cxxabiv1::__forced_unwind&)
541 this->_M_setstate(ios_base::badbit);
542 __throw_exception_again;
545 { this->_M_setstate(ios_base::badbit); }
547 this->setstate(__err);
552 template<typename _CharT, typename _Traits>
553 basic_istream<_CharT, _Traits>&
554 basic_istream<_CharT, _Traits>::
555 ignore(streamsize __n, int_type __delim)
558 sentry __cerb(*this, true);
559 if (__cerb && __n > 0)
561 ios_base::iostate __err = ios_base::goodbit;
564 const int_type __eof = traits_type::eof();
565 __streambuf_type* __sb = this->rdbuf();
566 int_type __c = __sb->sgetc();
568 // See comment above.
569 bool __large_ignore = false;
572 while (_M_gcount < __n
573 && !traits_type::eq_int_type(__c, __eof)
574 && !traits_type::eq_int_type(__c, __delim))
577 __c = __sb->snextc();
579 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
580 && !traits_type::eq_int_type(__c, __eof)
581 && !traits_type::eq_int_type(__c, __delim))
584 __gnu_cxx::__numeric_traits<streamsize>::__min;
585 __large_ignore = true;
592 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
594 if (traits_type::eq_int_type(__c, __eof))
595 __err |= ios_base::eofbit;
596 else if (traits_type::eq_int_type(__c, __delim))
599 < __gnu_cxx::__numeric_traits<streamsize>::__max)
604 __catch(__cxxabiv1::__forced_unwind&)
606 this->_M_setstate(ios_base::badbit);
607 __throw_exception_again;
610 { this->_M_setstate(ios_base::badbit); }
612 this->setstate(__err);
617 template<typename _CharT, typename _Traits>
618 typename basic_istream<_CharT, _Traits>::int_type
619 basic_istream<_CharT, _Traits>::
622 int_type __c = traits_type::eof();
624 sentry __cerb(*this, true);
627 ios_base::iostate __err = ios_base::goodbit;
630 __c = this->rdbuf()->sgetc();
631 if (traits_type::eq_int_type(__c, traits_type::eof()))
632 __err |= ios_base::eofbit;
634 __catch(__cxxabiv1::__forced_unwind&)
636 this->_M_setstate(ios_base::badbit);
637 __throw_exception_again;
640 { this->_M_setstate(ios_base::badbit); }
642 this->setstate(__err);
647 template<typename _CharT, typename _Traits>
648 basic_istream<_CharT, _Traits>&
649 basic_istream<_CharT, _Traits>::
650 read(char_type* __s, streamsize __n)
653 sentry __cerb(*this, true);
656 ios_base::iostate __err = ios_base::goodbit;
659 _M_gcount = this->rdbuf()->sgetn(__s, __n);
660 if (_M_gcount != __n)
661 __err |= (ios_base::eofbit | ios_base::failbit);
663 __catch(__cxxabiv1::__forced_unwind&)
665 this->_M_setstate(ios_base::badbit);
666 __throw_exception_again;
669 { this->_M_setstate(ios_base::badbit); }
671 this->setstate(__err);
676 template<typename _CharT, typename _Traits>
678 basic_istream<_CharT, _Traits>::
679 readsome(char_type* __s, streamsize __n)
682 sentry __cerb(*this, true);
685 ios_base::iostate __err = ios_base::goodbit;
688 // Cannot compare int_type with streamsize generically.
689 const streamsize __num = this->rdbuf()->in_avail();
691 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
692 else if (__num == -1)
693 __err |= ios_base::eofbit;
695 __catch(__cxxabiv1::__forced_unwind&)
697 this->_M_setstate(ios_base::badbit);
698 __throw_exception_again;
701 { this->_M_setstate(ios_base::badbit); }
703 this->setstate(__err);
708 template<typename _CharT, typename _Traits>
709 basic_istream<_CharT, _Traits>&
710 basic_istream<_CharT, _Traits>::
711 putback(char_type __c)
713 // _GLIBCXX_RESOLVE_LIB_DEFECTS
714 // 60. What is a formatted input function?
716 sentry __cerb(*this, true);
719 ios_base::iostate __err = ios_base::goodbit;
722 const int_type __eof = traits_type::eof();
723 __streambuf_type* __sb = this->rdbuf();
725 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
726 __err |= ios_base::badbit;
728 __catch(__cxxabiv1::__forced_unwind&)
730 this->_M_setstate(ios_base::badbit);
731 __throw_exception_again;
734 { this->_M_setstate(ios_base::badbit); }
736 this->setstate(__err);
741 template<typename _CharT, typename _Traits>
742 basic_istream<_CharT, _Traits>&
743 basic_istream<_CharT, _Traits>::
746 // _GLIBCXX_RESOLVE_LIB_DEFECTS
747 // 60. What is a formatted input function?
749 sentry __cerb(*this, true);
752 ios_base::iostate __err = ios_base::goodbit;
755 const int_type __eof = traits_type::eof();
756 __streambuf_type* __sb = this->rdbuf();
758 || traits_type::eq_int_type(__sb->sungetc(), __eof))
759 __err |= ios_base::badbit;
761 __catch(__cxxabiv1::__forced_unwind&)
763 this->_M_setstate(ios_base::badbit);
764 __throw_exception_again;
767 { this->_M_setstate(ios_base::badbit); }
769 this->setstate(__err);
774 template<typename _CharT, typename _Traits>
776 basic_istream<_CharT, _Traits>::
779 // _GLIBCXX_RESOLVE_LIB_DEFECTS
780 // DR60. Do not change _M_gcount.
782 sentry __cerb(*this, true);
785 ios_base::iostate __err = ios_base::goodbit;
788 __streambuf_type* __sb = this->rdbuf();
791 if (__sb->pubsync() == -1)
792 __err |= ios_base::badbit;
797 __catch(__cxxabiv1::__forced_unwind&)
799 this->_M_setstate(ios_base::badbit);
800 __throw_exception_again;
803 { this->_M_setstate(ios_base::badbit); }
805 this->setstate(__err);
810 template<typename _CharT, typename _Traits>
811 typename basic_istream<_CharT, _Traits>::pos_type
812 basic_istream<_CharT, _Traits>::
815 // _GLIBCXX_RESOLVE_LIB_DEFECTS
816 // DR60. Do not change _M_gcount.
817 pos_type __ret = pos_type(-1);
821 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
824 __catch(__cxxabiv1::__forced_unwind&)
826 this->_M_setstate(ios_base::badbit);
827 __throw_exception_again;
830 { this->_M_setstate(ios_base::badbit); }
834 template<typename _CharT, typename _Traits>
835 basic_istream<_CharT, _Traits>&
836 basic_istream<_CharT, _Traits>::
837 seekg(pos_type __pos)
839 // _GLIBCXX_RESOLVE_LIB_DEFECTS
840 // DR60. Do not change _M_gcount.
841 ios_base::iostate __err = ios_base::goodbit;
846 // 136. seekp, seekg setting wrong streams?
847 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
850 // 129. Need error indication from seekp() and seekg()
851 if (__p == pos_type(off_type(-1)))
852 __err |= ios_base::failbit;
855 __catch(__cxxabiv1::__forced_unwind&)
857 this->_M_setstate(ios_base::badbit);
858 __throw_exception_again;
861 { this->_M_setstate(ios_base::badbit); }
863 this->setstate(__err);
867 template<typename _CharT, typename _Traits>
868 basic_istream<_CharT, _Traits>&
869 basic_istream<_CharT, _Traits>::
870 seekg(off_type __off, ios_base::seekdir __dir)
872 // _GLIBCXX_RESOLVE_LIB_DEFECTS
873 // DR60. Do not change _M_gcount.
874 ios_base::iostate __err = ios_base::goodbit;
879 // 136. seekp, seekg setting wrong streams?
880 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
883 // 129. Need error indication from seekp() and seekg()
884 if (__p == pos_type(off_type(-1)))
885 __err |= ios_base::failbit;
888 __catch(__cxxabiv1::__forced_unwind&)
890 this->_M_setstate(ios_base::badbit);
891 __throw_exception_again;
894 { this->_M_setstate(ios_base::badbit); }
896 this->setstate(__err);
900 // 27.6.1.2.3 Character extraction templates
901 template<typename _CharT, typename _Traits>
902 basic_istream<_CharT, _Traits>&
903 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
905 typedef basic_istream<_CharT, _Traits> __istream_type;
906 typedef typename __istream_type::int_type __int_type;
908 typename __istream_type::sentry __cerb(__in, false);
911 ios_base::iostate __err = ios_base::goodbit;
914 const __int_type __cb = __in.rdbuf()->sbumpc();
915 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
916 __c = _Traits::to_char_type(__cb);
918 __err |= (ios_base::eofbit | ios_base::failbit);
920 __catch(__cxxabiv1::__forced_unwind&)
922 __in._M_setstate(ios_base::badbit);
923 __throw_exception_again;
926 { __in._M_setstate(ios_base::badbit); }
928 __in.setstate(__err);
933 template<typename _CharT, typename _Traits>
934 basic_istream<_CharT, _Traits>&
935 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
937 typedef basic_istream<_CharT, _Traits> __istream_type;
938 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
939 typedef typename _Traits::int_type int_type;
940 typedef _CharT char_type;
941 typedef ctype<_CharT> __ctype_type;
943 streamsize __extracted = 0;
944 ios_base::iostate __err = ios_base::goodbit;
945 typename __istream_type::sentry __cerb(__in, false);
950 // Figure out how many characters to extract.
951 streamsize __num = __in.width();
953 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
955 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
957 const int_type __eof = _Traits::eof();
958 __streambuf_type* __sb = __in.rdbuf();
959 int_type __c = __sb->sgetc();
961 while (__extracted < __num - 1
962 && !_Traits::eq_int_type(__c, __eof)
963 && !__ct.is(ctype_base::space,
964 _Traits::to_char_type(__c)))
966 *__s++ = _Traits::to_char_type(__c);
968 __c = __sb->snextc();
970 if (_Traits::eq_int_type(__c, __eof))
971 __err |= ios_base::eofbit;
973 // _GLIBCXX_RESOLVE_LIB_DEFECTS
974 // 68. Extractors for char* should store null at end
978 __catch(__cxxabiv1::__forced_unwind&)
980 __in._M_setstate(ios_base::badbit);
981 __throw_exception_again;
984 { __in._M_setstate(ios_base::badbit); }
987 __err |= ios_base::failbit;
989 __in.setstate(__err);
993 // 27.6.1.4 Standard basic_istream manipulators
994 template<typename _CharT, typename _Traits>
995 basic_istream<_CharT, _Traits>&
996 ws(basic_istream<_CharT, _Traits>& __in)
998 typedef basic_istream<_CharT, _Traits> __istream_type;
999 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1000 typedef typename __istream_type::int_type __int_type;
1001 typedef ctype<_CharT> __ctype_type;
1003 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1004 const __int_type __eof = _Traits::eof();
1005 __streambuf_type* __sb = __in.rdbuf();
1006 __int_type __c = __sb->sgetc();
1008 while (!_Traits::eq_int_type(__c, __eof)
1009 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1010 __c = __sb->snextc();
1012 if (_Traits::eq_int_type(__c, __eof))
1013 __in.setstate(ios_base::eofbit);
1017 // Inhibit implicit instantiations for required instantiations,
1018 // which are defined via explicit instantiations elsewhere.
1019 // NB: This syntax is a GNU extension.
1020 #if _GLIBCXX_EXTERN_TEMPLATE
1021 extern template class basic_istream<char>;
1022 extern template istream& ws(istream&);
1023 extern template istream& operator>>(istream&, char&);
1024 extern template istream& operator>>(istream&, char*);
1025 extern template istream& operator>>(istream&, unsigned char&);
1026 extern template istream& operator>>(istream&, signed char&);
1027 extern template istream& operator>>(istream&, unsigned char*);
1028 extern template istream& operator>>(istream&, signed char*);
1030 extern template istream& istream::_M_extract(unsigned short&);
1031 extern template istream& istream::_M_extract(unsigned int&);
1032 extern template istream& istream::_M_extract(long&);
1033 extern template istream& istream::_M_extract(unsigned long&);
1034 extern template istream& istream::_M_extract(bool&);
1035 #ifdef _GLIBCXX_USE_LONG_LONG
1036 extern template istream& istream::_M_extract(long long&);
1037 extern template istream& istream::_M_extract(unsigned long long&);
1039 extern template istream& istream::_M_extract(float&);
1040 extern template istream& istream::_M_extract(double&);
1041 extern template istream& istream::_M_extract(long double&);
1042 extern template istream& istream::_M_extract(void*&);
1044 extern template class basic_iostream<char>;
1046 #ifdef _GLIBCXX_USE_WCHAR_T
1047 extern template class basic_istream<wchar_t>;
1048 extern template wistream& ws(wistream&);
1049 extern template wistream& operator>>(wistream&, wchar_t&);
1050 extern template wistream& operator>>(wistream&, wchar_t*);
1052 extern template wistream& wistream::_M_extract(unsigned short&);
1053 extern template wistream& wistream::_M_extract(unsigned int&);
1054 extern template wistream& wistream::_M_extract(long&);
1055 extern template wistream& wistream::_M_extract(unsigned long&);
1056 extern template wistream& wistream::_M_extract(bool&);
1057 #ifdef _GLIBCXX_USE_LONG_LONG
1058 extern template wistream& wistream::_M_extract(long long&);
1059 extern template wistream& wistream::_M_extract(unsigned long long&);
1061 extern template wistream& wistream::_M_extract(float&);
1062 extern template wistream& wistream::_M_extract(double&);
1063 extern template wistream& wistream::_M_extract(long double&);
1064 extern template wistream& wistream::_M_extract(void*&);
1066 extern template class basic_iostream<wchar_t>;
1070 _GLIBCXX_END_NAMESPACE