1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/istream.tcc
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{istream}
31 // ISO C++ 14882: 27.6.1 Input streams
35 #define _ISTREAM_TCC 1
37 #pragma GCC system_header
39 #include <bits/cxxabi_forced.h>
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
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 // Clear eofbit per N3168.
717 this->clear(this->rdstate() & ~ios_base::eofbit);
718 sentry __cerb(*this, true);
721 ios_base::iostate __err = ios_base::goodbit;
724 const int_type __eof = traits_type::eof();
725 __streambuf_type* __sb = this->rdbuf();
727 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
728 __err |= ios_base::badbit;
730 __catch(__cxxabiv1::__forced_unwind&)
732 this->_M_setstate(ios_base::badbit);
733 __throw_exception_again;
736 { this->_M_setstate(ios_base::badbit); }
738 this->setstate(__err);
743 template<typename _CharT, typename _Traits>
744 basic_istream<_CharT, _Traits>&
745 basic_istream<_CharT, _Traits>::
748 // _GLIBCXX_RESOLVE_LIB_DEFECTS
749 // 60. What is a formatted input function?
751 // Clear eofbit per N3168.
752 this->clear(this->rdstate() & ~ios_base::eofbit);
753 sentry __cerb(*this, true);
756 ios_base::iostate __err = ios_base::goodbit;
759 const int_type __eof = traits_type::eof();
760 __streambuf_type* __sb = this->rdbuf();
762 || traits_type::eq_int_type(__sb->sungetc(), __eof))
763 __err |= ios_base::badbit;
765 __catch(__cxxabiv1::__forced_unwind&)
767 this->_M_setstate(ios_base::badbit);
768 __throw_exception_again;
771 { this->_M_setstate(ios_base::badbit); }
773 this->setstate(__err);
778 template<typename _CharT, typename _Traits>
780 basic_istream<_CharT, _Traits>::
783 // _GLIBCXX_RESOLVE_LIB_DEFECTS
784 // DR60. Do not change _M_gcount.
786 sentry __cerb(*this, true);
789 ios_base::iostate __err = ios_base::goodbit;
792 __streambuf_type* __sb = this->rdbuf();
795 if (__sb->pubsync() == -1)
796 __err |= ios_base::badbit;
801 __catch(__cxxabiv1::__forced_unwind&)
803 this->_M_setstate(ios_base::badbit);
804 __throw_exception_again;
807 { this->_M_setstate(ios_base::badbit); }
809 this->setstate(__err);
814 template<typename _CharT, typename _Traits>
815 typename basic_istream<_CharT, _Traits>::pos_type
816 basic_istream<_CharT, _Traits>::
819 // _GLIBCXX_RESOLVE_LIB_DEFECTS
820 // DR60. Do not change _M_gcount.
821 pos_type __ret = pos_type(-1);
822 sentry __cerb(*this, true);
828 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
831 __catch(__cxxabiv1::__forced_unwind&)
833 this->_M_setstate(ios_base::badbit);
834 __throw_exception_again;
837 { this->_M_setstate(ios_base::badbit); }
842 template<typename _CharT, typename _Traits>
843 basic_istream<_CharT, _Traits>&
844 basic_istream<_CharT, _Traits>::
845 seekg(pos_type __pos)
847 // _GLIBCXX_RESOLVE_LIB_DEFECTS
848 // DR60. Do not change _M_gcount.
849 // Clear eofbit per N3168.
850 this->clear(this->rdstate() & ~ios_base::eofbit);
851 sentry __cerb(*this, true);
854 ios_base::iostate __err = ios_base::goodbit;
859 // 136. seekp, seekg setting wrong streams?
860 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
863 // 129. Need error indication from seekp() and seekg()
864 if (__p == pos_type(off_type(-1)))
865 __err |= ios_base::failbit;
868 __catch(__cxxabiv1::__forced_unwind&)
870 this->_M_setstate(ios_base::badbit);
871 __throw_exception_again;
874 { this->_M_setstate(ios_base::badbit); }
876 this->setstate(__err);
881 template<typename _CharT, typename _Traits>
882 basic_istream<_CharT, _Traits>&
883 basic_istream<_CharT, _Traits>::
884 seekg(off_type __off, ios_base::seekdir __dir)
886 // _GLIBCXX_RESOLVE_LIB_DEFECTS
887 // DR60. Do not change _M_gcount.
888 // Clear eofbit per N3168.
889 this->clear(this->rdstate() & ~ios_base::eofbit);
890 sentry __cerb(*this, true);
893 ios_base::iostate __err = ios_base::goodbit;
898 // 136. seekp, seekg setting wrong streams?
899 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
902 // 129. Need error indication from seekp() and seekg()
903 if (__p == pos_type(off_type(-1)))
904 __err |= ios_base::failbit;
907 __catch(__cxxabiv1::__forced_unwind&)
909 this->_M_setstate(ios_base::badbit);
910 __throw_exception_again;
913 { this->_M_setstate(ios_base::badbit); }
915 this->setstate(__err);
920 // 27.6.1.2.3 Character extraction templates
921 template<typename _CharT, typename _Traits>
922 basic_istream<_CharT, _Traits>&
923 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
925 typedef basic_istream<_CharT, _Traits> __istream_type;
926 typedef typename __istream_type::int_type __int_type;
928 typename __istream_type::sentry __cerb(__in, false);
931 ios_base::iostate __err = ios_base::goodbit;
934 const __int_type __cb = __in.rdbuf()->sbumpc();
935 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
936 __c = _Traits::to_char_type(__cb);
938 __err |= (ios_base::eofbit | ios_base::failbit);
940 __catch(__cxxabiv1::__forced_unwind&)
942 __in._M_setstate(ios_base::badbit);
943 __throw_exception_again;
946 { __in._M_setstate(ios_base::badbit); }
948 __in.setstate(__err);
953 template<typename _CharT, typename _Traits>
954 basic_istream<_CharT, _Traits>&
955 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
957 typedef basic_istream<_CharT, _Traits> __istream_type;
958 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
959 typedef typename _Traits::int_type int_type;
960 typedef _CharT char_type;
961 typedef ctype<_CharT> __ctype_type;
963 streamsize __extracted = 0;
964 ios_base::iostate __err = ios_base::goodbit;
965 typename __istream_type::sentry __cerb(__in, false);
970 // Figure out how many characters to extract.
971 streamsize __num = __in.width();
973 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
975 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
977 const int_type __eof = _Traits::eof();
978 __streambuf_type* __sb = __in.rdbuf();
979 int_type __c = __sb->sgetc();
981 while (__extracted < __num - 1
982 && !_Traits::eq_int_type(__c, __eof)
983 && !__ct.is(ctype_base::space,
984 _Traits::to_char_type(__c)))
986 *__s++ = _Traits::to_char_type(__c);
988 __c = __sb->snextc();
990 if (_Traits::eq_int_type(__c, __eof))
991 __err |= ios_base::eofbit;
993 // _GLIBCXX_RESOLVE_LIB_DEFECTS
994 // 68. Extractors for char* should store null at end
998 __catch(__cxxabiv1::__forced_unwind&)
1000 __in._M_setstate(ios_base::badbit);
1001 __throw_exception_again;
1004 { __in._M_setstate(ios_base::badbit); }
1007 __err |= ios_base::failbit;
1009 __in.setstate(__err);
1013 // 27.6.1.4 Standard basic_istream manipulators
1014 template<typename _CharT, typename _Traits>
1015 basic_istream<_CharT, _Traits>&
1016 ws(basic_istream<_CharT, _Traits>& __in)
1018 typedef basic_istream<_CharT, _Traits> __istream_type;
1019 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1020 typedef typename __istream_type::int_type __int_type;
1021 typedef ctype<_CharT> __ctype_type;
1023 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1024 const __int_type __eof = _Traits::eof();
1025 __streambuf_type* __sb = __in.rdbuf();
1026 __int_type __c = __sb->sgetc();
1028 while (!_Traits::eq_int_type(__c, __eof)
1029 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1030 __c = __sb->snextc();
1032 if (_Traits::eq_int_type(__c, __eof))
1033 __in.setstate(ios_base::eofbit);
1037 // Inhibit implicit instantiations for required instantiations,
1038 // which are defined via explicit instantiations elsewhere.
1039 #if _GLIBCXX_EXTERN_TEMPLATE
1040 extern template class basic_istream<char>;
1041 extern template istream& ws(istream&);
1042 extern template istream& operator>>(istream&, char&);
1043 extern template istream& operator>>(istream&, char*);
1044 extern template istream& operator>>(istream&, unsigned char&);
1045 extern template istream& operator>>(istream&, signed char&);
1046 extern template istream& operator>>(istream&, unsigned char*);
1047 extern template istream& operator>>(istream&, signed char*);
1049 extern template istream& istream::_M_extract(unsigned short&);
1050 extern template istream& istream::_M_extract(unsigned int&);
1051 extern template istream& istream::_M_extract(long&);
1052 extern template istream& istream::_M_extract(unsigned long&);
1053 extern template istream& istream::_M_extract(bool&);
1054 #ifdef _GLIBCXX_USE_LONG_LONG
1055 extern template istream& istream::_M_extract(long long&);
1056 extern template istream& istream::_M_extract(unsigned long long&);
1058 extern template istream& istream::_M_extract(float&);
1059 extern template istream& istream::_M_extract(double&);
1060 extern template istream& istream::_M_extract(long double&);
1061 extern template istream& istream::_M_extract(void*&);
1063 extern template class basic_iostream<char>;
1065 #ifdef _GLIBCXX_USE_WCHAR_T
1066 extern template class basic_istream<wchar_t>;
1067 extern template wistream& ws(wistream&);
1068 extern template wistream& operator>>(wistream&, wchar_t&);
1069 extern template wistream& operator>>(wistream&, wchar_t*);
1071 extern template wistream& wistream::_M_extract(unsigned short&);
1072 extern template wistream& wistream::_M_extract(unsigned int&);
1073 extern template wistream& wistream::_M_extract(long&);
1074 extern template wistream& wistream::_M_extract(unsigned long&);
1075 extern template wistream& wistream::_M_extract(bool&);
1076 #ifdef _GLIBCXX_USE_LONG_LONG
1077 extern template wistream& wistream::_M_extract(long long&);
1078 extern template wistream& wistream::_M_extract(unsigned long long&);
1080 extern template wistream& wistream::_M_extract(float&);
1081 extern template wistream& wistream::_M_extract(double&);
1082 extern template wistream& wistream::_M_extract(long double&);
1083 extern template wistream& wistream::_M_extract(void*&);
1085 extern template class basic_iostream<wchar_t>;
1089 _GLIBCXX_END_NAMESPACE_VERSION