1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997-2020 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;
55 if (!__noskip && bool(__in.flags() & ios_base::skipws))
57 const __int_type __eof = traits_type::eof();
58 __streambuf_type* __sb = __in.rdbuf();
59 __int_type __c = __sb->sgetc();
61 const __ctype_type& __ct = __check_facet(__in._M_ctype);
62 while (!traits_type::eq_int_type(__c, __eof)
63 && __ct.is(ctype_base::space,
64 traits_type::to_char_type(__c)))
67 // _GLIBCXX_RESOLVE_LIB_DEFECTS
68 // 195. Should basic_istream::sentry's constructor ever
70 if (traits_type::eq_int_type(__c, __eof))
71 __err |= ios_base::eofbit;
74 __catch(__cxxabiv1::__forced_unwind&)
76 __in._M_setstate(ios_base::badbit);
77 __throw_exception_again;
80 { __in._M_setstate(ios_base::badbit); }
82 if (__in.good() && __err == ios_base::goodbit)
86 __err |= ios_base::failbit;
91 template<typename _CharT, typename _Traits>
92 template<typename _ValueT>
93 basic_istream<_CharT, _Traits>&
94 basic_istream<_CharT, _Traits>::
95 _M_extract(_ValueT& __v)
97 sentry __cerb(*this, false);
100 ios_base::iostate __err = ios_base::goodbit;
103 const __num_get_type& __ng = __check_facet(this->_M_num_get);
104 __ng.get(*this, 0, *this, __err, __v);
106 __catch(__cxxabiv1::__forced_unwind&)
108 this->_M_setstate(ios_base::badbit);
109 __throw_exception_again;
112 { this->_M_setstate(ios_base::badbit); }
114 this->setstate(__err);
119 template<typename _CharT, typename _Traits>
120 basic_istream<_CharT, _Traits>&
121 basic_istream<_CharT, _Traits>::
122 operator>>(short& __n)
124 // _GLIBCXX_RESOLVE_LIB_DEFECTS
125 // 118. basic_istream uses nonexistent num_get member functions.
126 sentry __cerb(*this, false);
129 ios_base::iostate __err = ios_base::goodbit;
133 const __num_get_type& __ng = __check_facet(this->_M_num_get);
134 __ng.get(*this, 0, *this, __err, __l);
136 // _GLIBCXX_RESOLVE_LIB_DEFECTS
137 // 696. istream::operator>>(int&) broken.
138 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
140 __err |= ios_base::failbit;
141 __n = __gnu_cxx::__numeric_traits<short>::__min;
143 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
145 __err |= ios_base::failbit;
146 __n = __gnu_cxx::__numeric_traits<short>::__max;
151 __catch(__cxxabiv1::__forced_unwind&)
153 this->_M_setstate(ios_base::badbit);
154 __throw_exception_again;
157 { this->_M_setstate(ios_base::badbit); }
159 this->setstate(__err);
164 template<typename _CharT, typename _Traits>
165 basic_istream<_CharT, _Traits>&
166 basic_istream<_CharT, _Traits>::
169 // _GLIBCXX_RESOLVE_LIB_DEFECTS
170 // 118. basic_istream uses nonexistent num_get member functions.
171 sentry __cerb(*this, false);
174 ios_base::iostate __err = ios_base::goodbit;
178 const __num_get_type& __ng = __check_facet(this->_M_num_get);
179 __ng.get(*this, 0, *this, __err, __l);
181 // _GLIBCXX_RESOLVE_LIB_DEFECTS
182 // 696. istream::operator>>(int&) broken.
183 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
185 __err |= ios_base::failbit;
186 __n = __gnu_cxx::__numeric_traits<int>::__min;
188 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
190 __err |= ios_base::failbit;
191 __n = __gnu_cxx::__numeric_traits<int>::__max;
196 __catch(__cxxabiv1::__forced_unwind&)
198 this->_M_setstate(ios_base::badbit);
199 __throw_exception_again;
202 { this->_M_setstate(ios_base::badbit); }
204 this->setstate(__err);
209 template<typename _CharT, typename _Traits>
210 basic_istream<_CharT, _Traits>&
211 basic_istream<_CharT, _Traits>::
212 operator>>(__streambuf_type* __sbout)
214 ios_base::iostate __err = ios_base::goodbit;
215 sentry __cerb(*this, false);
216 if (__cerb && __sbout)
221 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
222 __err |= ios_base::failbit;
224 __err |= ios_base::eofbit;
226 __catch(__cxxabiv1::__forced_unwind&)
228 this->_M_setstate(ios_base::failbit);
229 __throw_exception_again;
232 { this->_M_setstate(ios_base::failbit); }
235 __err |= ios_base::failbit;
237 this->setstate(__err);
241 template<typename _CharT, typename _Traits>
242 typename basic_istream<_CharT, _Traits>::int_type
243 basic_istream<_CharT, _Traits>::
246 const int_type __eof = traits_type::eof();
247 int_type __c = __eof;
249 ios_base::iostate __err = ios_base::goodbit;
250 sentry __cerb(*this, true);
255 __c = this->rdbuf()->sbumpc();
256 // 27.6.1.1 paragraph 3
257 if (!traits_type::eq_int_type(__c, __eof))
260 __err |= ios_base::eofbit;
262 __catch(__cxxabiv1::__forced_unwind&)
264 this->_M_setstate(ios_base::badbit);
265 __throw_exception_again;
268 { this->_M_setstate(ios_base::badbit); }
271 __err |= ios_base::failbit;
273 this->setstate(__err);
277 template<typename _CharT, typename _Traits>
278 basic_istream<_CharT, _Traits>&
279 basic_istream<_CharT, _Traits>::
283 ios_base::iostate __err = ios_base::goodbit;
284 sentry __cerb(*this, true);
289 const int_type __cb = this->rdbuf()->sbumpc();
290 // 27.6.1.1 paragraph 3
291 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
294 __c = traits_type::to_char_type(__cb);
297 __err |= ios_base::eofbit;
299 __catch(__cxxabiv1::__forced_unwind&)
301 this->_M_setstate(ios_base::badbit);
302 __throw_exception_again;
305 { this->_M_setstate(ios_base::badbit); }
308 __err |= ios_base::failbit;
310 this->setstate(__err);
314 template<typename _CharT, typename _Traits>
315 basic_istream<_CharT, _Traits>&
316 basic_istream<_CharT, _Traits>::
317 get(char_type* __s, streamsize __n, char_type __delim)
320 ios_base::iostate __err = ios_base::goodbit;
321 sentry __cerb(*this, true);
326 const int_type __idelim = traits_type::to_int_type(__delim);
327 const int_type __eof = traits_type::eof();
328 __streambuf_type* __sb = this->rdbuf();
329 int_type __c = __sb->sgetc();
331 while (_M_gcount + 1 < __n
332 && !traits_type::eq_int_type(__c, __eof)
333 && !traits_type::eq_int_type(__c, __idelim))
335 *__s++ = traits_type::to_char_type(__c);
337 __c = __sb->snextc();
339 if (traits_type::eq_int_type(__c, __eof))
340 __err |= ios_base::eofbit;
342 __catch(__cxxabiv1::__forced_unwind&)
344 this->_M_setstate(ios_base::badbit);
345 __throw_exception_again;
348 { this->_M_setstate(ios_base::badbit); }
350 // _GLIBCXX_RESOLVE_LIB_DEFECTS
351 // 243. get and getline when sentry reports failure.
355 __err |= ios_base::failbit;
357 this->setstate(__err);
361 template<typename _CharT, typename _Traits>
362 basic_istream<_CharT, _Traits>&
363 basic_istream<_CharT, _Traits>::
364 get(__streambuf_type& __sb, char_type __delim)
367 ios_base::iostate __err = ios_base::goodbit;
368 sentry __cerb(*this, true);
373 const int_type __idelim = traits_type::to_int_type(__delim);
374 const int_type __eof = traits_type::eof();
375 __streambuf_type* __this_sb = this->rdbuf();
376 int_type __c = __this_sb->sgetc();
377 char_type __c2 = traits_type::to_char_type(__c);
379 while (!traits_type::eq_int_type(__c, __eof)
380 && !traits_type::eq_int_type(__c, __idelim)
381 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
384 __c = __this_sb->snextc();
385 __c2 = traits_type::to_char_type(__c);
387 if (traits_type::eq_int_type(__c, __eof))
388 __err |= ios_base::eofbit;
390 __catch(__cxxabiv1::__forced_unwind&)
392 this->_M_setstate(ios_base::badbit);
393 __throw_exception_again;
396 { this->_M_setstate(ios_base::badbit); }
399 __err |= ios_base::failbit;
401 this->setstate(__err);
405 template<typename _CharT, typename _Traits>
406 basic_istream<_CharT, _Traits>&
407 basic_istream<_CharT, _Traits>::
408 getline(char_type* __s, streamsize __n, char_type __delim)
411 ios_base::iostate __err = ios_base::goodbit;
412 sentry __cerb(*this, true);
417 const int_type __idelim = traits_type::to_int_type(__delim);
418 const int_type __eof = traits_type::eof();
419 __streambuf_type* __sb = this->rdbuf();
420 int_type __c = __sb->sgetc();
422 while (_M_gcount + 1 < __n
423 && !traits_type::eq_int_type(__c, __eof)
424 && !traits_type::eq_int_type(__c, __idelim))
426 *__s++ = traits_type::to_char_type(__c);
427 __c = __sb->snextc();
430 if (traits_type::eq_int_type(__c, __eof))
431 __err |= ios_base::eofbit;
434 if (traits_type::eq_int_type(__c, __idelim))
440 __err |= ios_base::failbit;
443 __catch(__cxxabiv1::__forced_unwind&)
445 this->_M_setstate(ios_base::badbit);
446 __throw_exception_again;
449 { this->_M_setstate(ios_base::badbit); }
451 // _GLIBCXX_RESOLVE_LIB_DEFECTS
452 // 243. get and getline when sentry reports failure.
456 __err |= ios_base::failbit;
458 this->setstate(__err);
462 // We provide three overloads, since the first two are much simpler
463 // than the general case. Also, the latter two can thus adopt the
464 // same "batchy" strategy used by getline above.
465 template<typename _CharT, typename _Traits>
466 basic_istream<_CharT, _Traits>&
467 basic_istream<_CharT, _Traits>::
471 sentry __cerb(*this, true);
474 ios_base::iostate __err = ios_base::goodbit;
477 const int_type __eof = traits_type::eof();
478 __streambuf_type* __sb = this->rdbuf();
480 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
481 __err |= ios_base::eofbit;
485 __catch(__cxxabiv1::__forced_unwind&)
487 this->_M_setstate(ios_base::badbit);
488 __throw_exception_again;
491 { this->_M_setstate(ios_base::badbit); }
493 this->setstate(__err);
498 template<typename _CharT, typename _Traits>
499 basic_istream<_CharT, _Traits>&
500 basic_istream<_CharT, _Traits>::
501 ignore(streamsize __n)
504 sentry __cerb(*this, true);
505 if (__cerb && __n > 0)
507 ios_base::iostate __err = ios_base::goodbit;
510 const int_type __eof = traits_type::eof();
511 __streambuf_type* __sb = this->rdbuf();
512 int_type __c = __sb->sgetc();
514 // N.B. On LFS-enabled platforms streamsize is still 32 bits
515 // wide: if we want to implement the standard mandated behavior
516 // for n == max() (see 27.6.1.3/24) we are at risk of signed
517 // integer overflow: thus these contortions. Also note that,
518 // by definition, when more than 2G chars are actually ignored,
519 // _M_gcount (the return value of gcount, that is) cannot be
520 // really correct, being unavoidably too small.
521 bool __large_ignore = false;
524 while (_M_gcount < __n
525 && !traits_type::eq_int_type(__c, __eof))
528 __c = __sb->snextc();
530 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
531 && !traits_type::eq_int_type(__c, __eof))
534 __gnu_cxx::__numeric_traits<streamsize>::__min;
535 __large_ignore = true;
542 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
544 if (traits_type::eq_int_type(__c, __eof))
545 __err |= ios_base::eofbit;
547 __catch(__cxxabiv1::__forced_unwind&)
549 this->_M_setstate(ios_base::badbit);
550 __throw_exception_again;
553 { this->_M_setstate(ios_base::badbit); }
555 this->setstate(__err);
560 template<typename _CharT, typename _Traits>
561 basic_istream<_CharT, _Traits>&
562 basic_istream<_CharT, _Traits>::
563 ignore(streamsize __n, int_type __delim)
566 sentry __cerb(*this, true);
567 if (__cerb && __n > 0)
569 ios_base::iostate __err = ios_base::goodbit;
572 const int_type __eof = traits_type::eof();
573 __streambuf_type* __sb = this->rdbuf();
574 int_type __c = __sb->sgetc();
576 // See comment above.
577 bool __large_ignore = false;
580 while (_M_gcount < __n
581 && !traits_type::eq_int_type(__c, __eof)
582 && !traits_type::eq_int_type(__c, __delim))
585 __c = __sb->snextc();
587 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
588 && !traits_type::eq_int_type(__c, __eof)
589 && !traits_type::eq_int_type(__c, __delim))
592 __gnu_cxx::__numeric_traits<streamsize>::__min;
593 __large_ignore = true;
600 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
602 if (traits_type::eq_int_type(__c, __eof))
603 __err |= ios_base::eofbit;
604 else if (traits_type::eq_int_type(__c, __delim))
607 < __gnu_cxx::__numeric_traits<streamsize>::__max)
612 __catch(__cxxabiv1::__forced_unwind&)
614 this->_M_setstate(ios_base::badbit);
615 __throw_exception_again;
618 { this->_M_setstate(ios_base::badbit); }
620 this->setstate(__err);
625 template<typename _CharT, typename _Traits>
626 typename basic_istream<_CharT, _Traits>::int_type
627 basic_istream<_CharT, _Traits>::
630 int_type __c = traits_type::eof();
632 sentry __cerb(*this, true);
635 ios_base::iostate __err = ios_base::goodbit;
638 __c = this->rdbuf()->sgetc();
639 if (traits_type::eq_int_type(__c, traits_type::eof()))
640 __err |= ios_base::eofbit;
642 __catch(__cxxabiv1::__forced_unwind&)
644 this->_M_setstate(ios_base::badbit);
645 __throw_exception_again;
648 { this->_M_setstate(ios_base::badbit); }
650 this->setstate(__err);
655 template<typename _CharT, typename _Traits>
656 basic_istream<_CharT, _Traits>&
657 basic_istream<_CharT, _Traits>::
658 read(char_type* __s, streamsize __n)
661 sentry __cerb(*this, true);
664 ios_base::iostate __err = ios_base::goodbit;
667 _M_gcount = this->rdbuf()->sgetn(__s, __n);
668 if (_M_gcount != __n)
669 __err |= (ios_base::eofbit | ios_base::failbit);
671 __catch(__cxxabiv1::__forced_unwind&)
673 this->_M_setstate(ios_base::badbit);
674 __throw_exception_again;
677 { this->_M_setstate(ios_base::badbit); }
679 this->setstate(__err);
684 template<typename _CharT, typename _Traits>
686 basic_istream<_CharT, _Traits>::
687 readsome(char_type* __s, streamsize __n)
690 sentry __cerb(*this, true);
693 ios_base::iostate __err = ios_base::goodbit;
696 // Cannot compare int_type with streamsize generically.
697 const streamsize __num = this->rdbuf()->in_avail();
699 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
700 else if (__num == -1)
701 __err |= ios_base::eofbit;
703 __catch(__cxxabiv1::__forced_unwind&)
705 this->_M_setstate(ios_base::badbit);
706 __throw_exception_again;
709 { this->_M_setstate(ios_base::badbit); }
711 this->setstate(__err);
716 template<typename _CharT, typename _Traits>
717 basic_istream<_CharT, _Traits>&
718 basic_istream<_CharT, _Traits>::
719 putback(char_type __c)
721 // _GLIBCXX_RESOLVE_LIB_DEFECTS
722 // 60. What is a formatted input function?
724 // Clear eofbit per N3168.
725 this->clear(this->rdstate() & ~ios_base::eofbit);
726 sentry __cerb(*this, true);
729 ios_base::iostate __err = ios_base::goodbit;
732 const int_type __eof = traits_type::eof();
733 __streambuf_type* __sb = this->rdbuf();
735 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
736 __err |= ios_base::badbit;
738 __catch(__cxxabiv1::__forced_unwind&)
740 this->_M_setstate(ios_base::badbit);
741 __throw_exception_again;
744 { this->_M_setstate(ios_base::badbit); }
746 this->setstate(__err);
751 template<typename _CharT, typename _Traits>
752 basic_istream<_CharT, _Traits>&
753 basic_istream<_CharT, _Traits>::
756 // _GLIBCXX_RESOLVE_LIB_DEFECTS
757 // 60. What is a formatted input function?
759 // Clear eofbit per N3168.
760 this->clear(this->rdstate() & ~ios_base::eofbit);
761 sentry __cerb(*this, true);
764 ios_base::iostate __err = ios_base::goodbit;
767 const int_type __eof = traits_type::eof();
768 __streambuf_type* __sb = this->rdbuf();
770 || traits_type::eq_int_type(__sb->sungetc(), __eof))
771 __err |= ios_base::badbit;
773 __catch(__cxxabiv1::__forced_unwind&)
775 this->_M_setstate(ios_base::badbit);
776 __throw_exception_again;
779 { this->_M_setstate(ios_base::badbit); }
781 this->setstate(__err);
786 template<typename _CharT, typename _Traits>
788 basic_istream<_CharT, _Traits>::
791 // _GLIBCXX_RESOLVE_LIB_DEFECTS
792 // DR60. Do not change _M_gcount.
794 sentry __cerb(*this, true);
797 ios_base::iostate __err = ios_base::goodbit;
800 __streambuf_type* __sb = this->rdbuf();
803 if (__sb->pubsync() == -1)
804 __err |= ios_base::badbit;
809 __catch(__cxxabiv1::__forced_unwind&)
811 this->_M_setstate(ios_base::badbit);
812 __throw_exception_again;
815 { this->_M_setstate(ios_base::badbit); }
817 this->setstate(__err);
822 template<typename _CharT, typename _Traits>
823 typename basic_istream<_CharT, _Traits>::pos_type
824 basic_istream<_CharT, _Traits>::
827 // _GLIBCXX_RESOLVE_LIB_DEFECTS
828 // DR60. Do not change _M_gcount.
829 pos_type __ret = pos_type(-1);
830 sentry __cerb(*this, true);
836 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
839 __catch(__cxxabiv1::__forced_unwind&)
841 this->_M_setstate(ios_base::badbit);
842 __throw_exception_again;
845 { this->_M_setstate(ios_base::badbit); }
850 template<typename _CharT, typename _Traits>
851 basic_istream<_CharT, _Traits>&
852 basic_istream<_CharT, _Traits>::
853 seekg(pos_type __pos)
855 // _GLIBCXX_RESOLVE_LIB_DEFECTS
856 // DR60. Do not change _M_gcount.
857 // Clear eofbit per N3168.
858 this->clear(this->rdstate() & ~ios_base::eofbit);
859 sentry __cerb(*this, true);
862 ios_base::iostate __err = ios_base::goodbit;
867 // 136. seekp, seekg setting wrong streams?
868 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
871 // 129. Need error indication from seekp() and seekg()
872 if (__p == pos_type(off_type(-1)))
873 __err |= ios_base::failbit;
876 __catch(__cxxabiv1::__forced_unwind&)
878 this->_M_setstate(ios_base::badbit);
879 __throw_exception_again;
882 { this->_M_setstate(ios_base::badbit); }
884 this->setstate(__err);
889 template<typename _CharT, typename _Traits>
890 basic_istream<_CharT, _Traits>&
891 basic_istream<_CharT, _Traits>::
892 seekg(off_type __off, ios_base::seekdir __dir)
894 // _GLIBCXX_RESOLVE_LIB_DEFECTS
895 // DR60. Do not change _M_gcount.
896 // Clear eofbit per N3168.
897 this->clear(this->rdstate() & ~ios_base::eofbit);
898 sentry __cerb(*this, true);
901 ios_base::iostate __err = ios_base::goodbit;
906 // 136. seekp, seekg setting wrong streams?
907 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
910 // 129. Need error indication from seekp() and seekg()
911 if (__p == pos_type(off_type(-1)))
912 __err |= ios_base::failbit;
915 __catch(__cxxabiv1::__forced_unwind&)
917 this->_M_setstate(ios_base::badbit);
918 __throw_exception_again;
921 { this->_M_setstate(ios_base::badbit); }
923 this->setstate(__err);
928 // 27.6.1.2.3 Character extraction templates
929 template<typename _CharT, typename _Traits>
930 basic_istream<_CharT, _Traits>&
931 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
933 typedef basic_istream<_CharT, _Traits> __istream_type;
934 typedef typename __istream_type::int_type __int_type;
936 typename __istream_type::sentry __cerb(__in, false);
939 ios_base::iostate __err = ios_base::goodbit;
942 const __int_type __cb = __in.rdbuf()->sbumpc();
943 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
944 __c = _Traits::to_char_type(__cb);
946 __err |= (ios_base::eofbit | ios_base::failbit);
948 __catch(__cxxabiv1::__forced_unwind&)
950 __in._M_setstate(ios_base::badbit);
951 __throw_exception_again;
954 { __in._M_setstate(ios_base::badbit); }
956 __in.setstate(__err);
961 template<typename _CharT, typename _Traits>
962 basic_istream<_CharT, _Traits>&
963 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
965 typedef basic_istream<_CharT, _Traits> __istream_type;
966 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
967 typedef typename _Traits::int_type int_type;
968 typedef _CharT char_type;
969 typedef ctype<_CharT> __ctype_type;
971 streamsize __extracted = 0;
972 ios_base::iostate __err = ios_base::goodbit;
973 typename __istream_type::sentry __cerb(__in, false);
978 // Figure out how many characters to extract.
979 streamsize __num = __in.width();
981 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
983 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
985 const int_type __eof = _Traits::eof();
986 __streambuf_type* __sb = __in.rdbuf();
987 int_type __c = __sb->sgetc();
989 while (__extracted < __num - 1
990 && !_Traits::eq_int_type(__c, __eof)
991 && !__ct.is(ctype_base::space,
992 _Traits::to_char_type(__c)))
994 *__s++ = _Traits::to_char_type(__c);
996 __c = __sb->snextc();
998 if (_Traits::eq_int_type(__c, __eof))
999 __err |= ios_base::eofbit;
1001 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1002 // 68. Extractors for char* should store null at end
1006 __catch(__cxxabiv1::__forced_unwind&)
1008 __in._M_setstate(ios_base::badbit);
1009 __throw_exception_again;
1012 { __in._M_setstate(ios_base::badbit); }
1015 __err |= ios_base::failbit;
1017 __in.setstate(__err);
1021 // 27.6.1.4 Standard basic_istream manipulators
1022 template<typename _CharT, typename _Traits>
1023 basic_istream<_CharT, _Traits>&
1024 ws(basic_istream<_CharT, _Traits>& __in)
1026 typedef basic_istream<_CharT, _Traits> __istream_type;
1027 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1028 typedef typename __istream_type::int_type __int_type;
1029 typedef ctype<_CharT> __ctype_type;
1031 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1032 const __int_type __eof = _Traits::eof();
1033 __streambuf_type* __sb = __in.rdbuf();
1034 __int_type __c = __sb->sgetc();
1036 while (!_Traits::eq_int_type(__c, __eof)
1037 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1038 __c = __sb->snextc();
1040 if (_Traits::eq_int_type(__c, __eof))
1041 __in.setstate(ios_base::eofbit);
1045 // Inhibit implicit instantiations for required instantiations,
1046 // which are defined via explicit instantiations elsewhere.
1047 #if _GLIBCXX_EXTERN_TEMPLATE
1048 extern template class basic_istream<char>;
1049 extern template istream& ws(istream&);
1050 extern template istream& operator>>(istream&, char&);
1051 extern template istream& operator>>(istream&, char*);
1052 extern template istream& operator>>(istream&, unsigned char&);
1053 extern template istream& operator>>(istream&, signed char&);
1054 extern template istream& operator>>(istream&, unsigned char*);
1055 extern template istream& operator>>(istream&, signed char*);
1057 extern template istream& istream::_M_extract(unsigned short&);
1058 extern template istream& istream::_M_extract(unsigned int&);
1059 extern template istream& istream::_M_extract(long&);
1060 extern template istream& istream::_M_extract(unsigned long&);
1061 extern template istream& istream::_M_extract(bool&);
1062 #ifdef _GLIBCXX_USE_LONG_LONG
1063 extern template istream& istream::_M_extract(long long&);
1064 extern template istream& istream::_M_extract(unsigned long long&);
1066 extern template istream& istream::_M_extract(float&);
1067 extern template istream& istream::_M_extract(double&);
1068 extern template istream& istream::_M_extract(long double&);
1069 extern template istream& istream::_M_extract(void*&);
1071 extern template class basic_iostream<char>;
1073 #ifdef _GLIBCXX_USE_WCHAR_T
1074 extern template class basic_istream<wchar_t>;
1075 extern template wistream& ws(wistream&);
1076 extern template wistream& operator>>(wistream&, wchar_t&);
1077 extern template wistream& operator>>(wistream&, wchar_t*);
1079 extern template wistream& wistream::_M_extract(unsigned short&);
1080 extern template wistream& wistream::_M_extract(unsigned int&);
1081 extern template wistream& wistream::_M_extract(long&);
1082 extern template wistream& wistream::_M_extract(unsigned long&);
1083 extern template wistream& wistream::_M_extract(bool&);
1084 #ifdef _GLIBCXX_USE_LONG_LONG
1085 extern template wistream& wistream::_M_extract(long long&);
1086 extern template wistream& wistream::_M_extract(unsigned long long&);
1088 extern template wistream& wistream::_M_extract(float&);
1089 extern template wistream& wistream::_M_extract(double&);
1090 extern template wistream& wistream::_M_extract(long double&);
1091 extern template wistream& wistream::_M_extract(void*&);
1093 extern template class basic_iostream<wchar_t>;
1097 _GLIBCXX_END_NAMESPACE_VERSION