1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997-2024 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;
56 if (!__noskip && bool(__in.flags() & ios_base::skipws))
58 const __int_type __eof = traits_type::eof();
59 __streambuf_type* __sb = __in.rdbuf();
60 __int_type __c = __sb->sgetc();
62 const __ctype_type& __ct = __check_facet(__in._M_ctype);
63 while (!traits_type::eq_int_type(__c, __eof)
64 && __ct.is(ctype_base::space,
65 traits_type::to_char_type(__c)))
68 // _GLIBCXX_RESOLVE_LIB_DEFECTS
69 // 195. Should basic_istream::sentry's constructor ever
71 if (traits_type::eq_int_type(__c, __eof))
72 __err |= ios_base::eofbit;
75 __catch(__cxxabiv1::__forced_unwind&)
77 __in._M_setstate(ios_base::badbit);
78 __throw_exception_again;
81 { __in._M_setstate(ios_base::badbit); }
84 if (__in.good() && __err == ios_base::goodbit)
88 __err |= ios_base::failbit;
93 template<typename _CharT, typename _Traits>
94 template<typename _ValueT>
95 basic_istream<_CharT, _Traits>&
96 basic_istream<_CharT, _Traits>::
97 _M_extract(_ValueT& __v)
99 sentry __cerb(*this, false);
102 ios_base::iostate __err = ios_base::goodbit;
105 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
106 const __num_get_type& __ng = __check_facet(this->_M_num_get);
108 const __num_get_type& __ng
109 = use_facet<__num_get_type>(this->_M_ios_locale);
111 __ng.get(*this, 0, *this, __err, __v);
113 __catch(__cxxabiv1::__forced_unwind&)
115 this->_M_setstate(ios_base::badbit);
116 __throw_exception_again;
119 { this->_M_setstate(ios_base::badbit); }
121 this->setstate(__err);
126 template<typename _CharT, typename _Traits>
127 basic_istream<_CharT, _Traits>&
128 basic_istream<_CharT, _Traits>::
129 operator>>(short& __n)
131 // _GLIBCXX_RESOLVE_LIB_DEFECTS
132 // 118. basic_istream uses nonexistent num_get member functions.
133 sentry __cerb(*this, false);
136 ios_base::iostate __err = ios_base::goodbit;
140 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
141 const __num_get_type& __ng = __check_facet(this->_M_num_get);
143 const __num_get_type& __ng
144 = use_facet<__num_get_type>(this->_M_ios_locale);
146 __ng.get(*this, 0, *this, __err, __l);
148 // _GLIBCXX_RESOLVE_LIB_DEFECTS
149 // 696. istream::operator>>(int&) broken.
150 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
152 __err |= ios_base::failbit;
153 __n = __gnu_cxx::__numeric_traits<short>::__min;
155 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
157 __err |= ios_base::failbit;
158 __n = __gnu_cxx::__numeric_traits<short>::__max;
163 __catch(__cxxabiv1::__forced_unwind&)
165 this->_M_setstate(ios_base::badbit);
166 __throw_exception_again;
169 { this->_M_setstate(ios_base::badbit); }
171 this->setstate(__err);
176 template<typename _CharT, typename _Traits>
177 basic_istream<_CharT, _Traits>&
178 basic_istream<_CharT, _Traits>::
181 // _GLIBCXX_RESOLVE_LIB_DEFECTS
182 // 118. basic_istream uses nonexistent num_get member functions.
183 sentry __cerb(*this, false);
186 ios_base::iostate __err = ios_base::goodbit;
190 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
191 const __num_get_type& __ng = __check_facet(this->_M_num_get);
193 const __num_get_type& __ng
194 = use_facet<__num_get_type>(this->_M_ios_locale);
196 __ng.get(*this, 0, *this, __err, __l);
198 // _GLIBCXX_RESOLVE_LIB_DEFECTS
199 // 696. istream::operator>>(int&) broken.
200 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
202 __err |= ios_base::failbit;
203 __n = __gnu_cxx::__numeric_traits<int>::__min;
205 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
207 __err |= ios_base::failbit;
208 __n = __gnu_cxx::__numeric_traits<int>::__max;
213 __catch(__cxxabiv1::__forced_unwind&)
215 this->_M_setstate(ios_base::badbit);
216 __throw_exception_again;
219 { this->_M_setstate(ios_base::badbit); }
221 this->setstate(__err);
226 template<typename _CharT, typename _Traits>
227 basic_istream<_CharT, _Traits>&
228 basic_istream<_CharT, _Traits>::
229 operator>>(__streambuf_type* __sbout)
231 ios_base::iostate __err = ios_base::goodbit;
232 sentry __cerb(*this, false);
233 if (__cerb && __sbout)
238 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
239 __err |= ios_base::failbit;
241 __err |= ios_base::eofbit;
243 __catch(__cxxabiv1::__forced_unwind&)
245 this->_M_setstate(ios_base::failbit);
246 __throw_exception_again;
249 { this->_M_setstate(ios_base::failbit); }
252 __err |= ios_base::failbit;
254 this->setstate(__err);
258 template<typename _CharT, typename _Traits>
259 typename basic_istream<_CharT, _Traits>::int_type
260 basic_istream<_CharT, _Traits>::
263 const int_type __eof = traits_type::eof();
264 int_type __c = __eof;
266 ios_base::iostate __err = ios_base::goodbit;
267 sentry __cerb(*this, true);
272 __c = this->rdbuf()->sbumpc();
273 // 27.6.1.1 paragraph 3
274 if (!traits_type::eq_int_type(__c, __eof))
277 __err |= ios_base::eofbit;
279 __catch(__cxxabiv1::__forced_unwind&)
281 this->_M_setstate(ios_base::badbit);
282 __throw_exception_again;
285 { this->_M_setstate(ios_base::badbit); }
288 __err |= ios_base::failbit;
290 this->setstate(__err);
294 template<typename _CharT, typename _Traits>
295 basic_istream<_CharT, _Traits>&
296 basic_istream<_CharT, _Traits>::
300 ios_base::iostate __err = ios_base::goodbit;
301 sentry __cerb(*this, true);
306 const int_type __cb = this->rdbuf()->sbumpc();
307 // 27.6.1.1 paragraph 3
308 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
311 __c = traits_type::to_char_type(__cb);
314 __err |= ios_base::eofbit;
316 __catch(__cxxabiv1::__forced_unwind&)
318 this->_M_setstate(ios_base::badbit);
319 __throw_exception_again;
322 { this->_M_setstate(ios_base::badbit); }
325 __err |= ios_base::failbit;
327 this->setstate(__err);
331 template<typename _CharT, typename _Traits>
332 basic_istream<_CharT, _Traits>&
333 basic_istream<_CharT, _Traits>::
334 get(char_type* __s, streamsize __n, char_type __delim)
337 ios_base::iostate __err = ios_base::goodbit;
338 sentry __cerb(*this, true);
343 const int_type __idelim = traits_type::to_int_type(__delim);
344 const int_type __eof = traits_type::eof();
345 __streambuf_type* __sb = this->rdbuf();
346 int_type __c = __sb->sgetc();
348 while (_M_gcount + 1 < __n
349 && !traits_type::eq_int_type(__c, __eof)
350 && !traits_type::eq_int_type(__c, __idelim))
352 *__s++ = traits_type::to_char_type(__c);
354 __c = __sb->snextc();
356 if (traits_type::eq_int_type(__c, __eof))
357 __err |= ios_base::eofbit;
359 __catch(__cxxabiv1::__forced_unwind&)
361 this->_M_setstate(ios_base::badbit);
362 __throw_exception_again;
365 { this->_M_setstate(ios_base::badbit); }
367 // _GLIBCXX_RESOLVE_LIB_DEFECTS
368 // 243. get and getline when sentry reports failure.
372 __err |= ios_base::failbit;
374 this->setstate(__err);
378 template<typename _CharT, typename _Traits>
379 basic_istream<_CharT, _Traits>&
380 basic_istream<_CharT, _Traits>::
381 get(__streambuf_type& __sb, char_type __delim)
384 ios_base::iostate __err = ios_base::goodbit;
385 sentry __cerb(*this, true);
390 const int_type __idelim = traits_type::to_int_type(__delim);
391 const int_type __eof = traits_type::eof();
392 __streambuf_type* __this_sb = this->rdbuf();
393 int_type __c = __this_sb->sgetc();
394 char_type __c2 = traits_type::to_char_type(__c);
395 unsigned long long __gcount = 0;
397 while (!traits_type::eq_int_type(__c, __eof)
398 && !traits_type::eq_int_type(__c, __idelim)
399 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
402 __c = __this_sb->snextc();
403 __c2 = traits_type::to_char_type(__c);
405 if (traits_type::eq_int_type(__c, __eof))
406 __err |= ios_base::eofbit;
407 // _GLIBCXX_RESOLVE_LIB_DEFECTS
408 // 3464. istream::gcount() can overflow
409 if (__gcount <= __gnu_cxx::__numeric_traits<streamsize>::__max)
410 _M_gcount = __gcount;
412 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
414 __catch(__cxxabiv1::__forced_unwind&)
416 this->_M_setstate(ios_base::badbit);
417 __throw_exception_again;
420 { this->_M_setstate(ios_base::badbit); }
423 __err |= ios_base::failbit;
425 this->setstate(__err);
429 template<typename _CharT, typename _Traits>
430 basic_istream<_CharT, _Traits>&
431 basic_istream<_CharT, _Traits>::
432 getline(char_type* __s, streamsize __n, char_type __delim)
435 ios_base::iostate __err = ios_base::goodbit;
436 sentry __cerb(*this, true);
441 const int_type __idelim = traits_type::to_int_type(__delim);
442 const int_type __eof = traits_type::eof();
443 __streambuf_type* __sb = this->rdbuf();
444 int_type __c = __sb->sgetc();
446 while (_M_gcount + 1 < __n
447 && !traits_type::eq_int_type(__c, __eof)
448 && !traits_type::eq_int_type(__c, __idelim))
450 *__s++ = traits_type::to_char_type(__c);
451 __c = __sb->snextc();
454 if (traits_type::eq_int_type(__c, __eof))
455 __err |= ios_base::eofbit;
458 if (traits_type::eq_int_type(__c, __idelim))
464 __err |= ios_base::failbit;
467 __catch(__cxxabiv1::__forced_unwind&)
469 this->_M_setstate(ios_base::badbit);
470 __throw_exception_again;
473 { this->_M_setstate(ios_base::badbit); }
475 // _GLIBCXX_RESOLVE_LIB_DEFECTS
476 // 243. get and getline when sentry reports failure.
480 __err |= ios_base::failbit;
482 this->setstate(__err);
486 // We provide three overloads, since the first two are much simpler
487 // than the general case. Also, the latter two can thus adopt the
488 // same "batchy" strategy used by getline above.
489 template<typename _CharT, typename _Traits>
490 basic_istream<_CharT, _Traits>&
491 basic_istream<_CharT, _Traits>::
495 sentry __cerb(*this, true);
498 ios_base::iostate __err = ios_base::goodbit;
501 const int_type __eof = traits_type::eof();
502 __streambuf_type* __sb = this->rdbuf();
504 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
505 __err |= ios_base::eofbit;
509 __catch(__cxxabiv1::__forced_unwind&)
511 this->_M_setstate(ios_base::badbit);
512 __throw_exception_again;
515 { this->_M_setstate(ios_base::badbit); }
517 this->setstate(__err);
522 template<typename _CharT, typename _Traits>
523 basic_istream<_CharT, _Traits>&
524 basic_istream<_CharT, _Traits>::
525 ignore(streamsize __n)
528 sentry __cerb(*this, true);
529 if (__cerb && __n > 0)
531 ios_base::iostate __err = ios_base::goodbit;
534 const int_type __eof = traits_type::eof();
535 __streambuf_type* __sb = this->rdbuf();
536 int_type __c = __sb->sgetc();
538 // N.B. On LFS-enabled platforms streamsize is still 32 bits
539 // wide: if we want to implement the standard mandated behavior
540 // for n == max() (see 27.6.1.3/24) we are at risk of signed
541 // integer overflow: thus these contortions. Also note that,
542 // by definition, when more than 2G chars are actually ignored,
543 // _M_gcount (the return value of gcount, that is) cannot be
544 // really correct, being unavoidably too small.
545 bool __large_ignore = false;
548 while (_M_gcount < __n
549 && !traits_type::eq_int_type(__c, __eof))
552 __c = __sb->snextc();
554 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
555 && !traits_type::eq_int_type(__c, __eof))
558 __gnu_cxx::__numeric_traits<streamsize>::__min;
559 __large_ignore = true;
565 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
568 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
570 if (traits_type::eq_int_type(__c, __eof))
571 __err |= ios_base::eofbit;
573 else if (_M_gcount < __n)
575 if (traits_type::eq_int_type(__c, __eof))
576 __err |= ios_base::eofbit;
579 __catch(__cxxabiv1::__forced_unwind&)
581 this->_M_setstate(ios_base::badbit);
582 __throw_exception_again;
585 { this->_M_setstate(ios_base::badbit); }
587 this->setstate(__err);
592 template<typename _CharT, typename _Traits>
593 basic_istream<_CharT, _Traits>&
594 basic_istream<_CharT, _Traits>::
595 ignore(streamsize __n, int_type __delim)
598 sentry __cerb(*this, true);
599 if (__cerb && __n > 0)
601 ios_base::iostate __err = ios_base::goodbit;
604 const int_type __eof = traits_type::eof();
605 __streambuf_type* __sb = this->rdbuf();
606 int_type __c = __sb->sgetc();
608 // See comment above.
609 bool __large_ignore = false;
612 while (_M_gcount < __n
613 && !traits_type::eq_int_type(__c, __eof)
614 && !traits_type::eq_int_type(__c, __delim))
617 __c = __sb->snextc();
619 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
620 && !traits_type::eq_int_type(__c, __eof)
621 && !traits_type::eq_int_type(__c, __delim))
624 __gnu_cxx::__numeric_traits<streamsize>::__min;
625 __large_ignore = true;
631 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
634 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
636 if (traits_type::eq_int_type(__c, __eof))
637 __err |= ios_base::eofbit;
640 if (_M_gcount != __n)
645 else if (_M_gcount < __n) // implies __c == __delim or EOF
647 if (traits_type::eq_int_type(__c, __eof))
648 __err |= ios_base::eofbit;
656 __catch(__cxxabiv1::__forced_unwind&)
658 this->_M_setstate(ios_base::badbit);
659 __throw_exception_again;
662 { this->_M_setstate(ios_base::badbit); }
664 this->setstate(__err);
669 template<typename _CharT, typename _Traits>
670 typename basic_istream<_CharT, _Traits>::int_type
671 basic_istream<_CharT, _Traits>::
674 int_type __c = traits_type::eof();
676 sentry __cerb(*this, true);
679 ios_base::iostate __err = ios_base::goodbit;
682 __c = this->rdbuf()->sgetc();
683 if (traits_type::eq_int_type(__c, traits_type::eof()))
684 __err |= ios_base::eofbit;
686 __catch(__cxxabiv1::__forced_unwind&)
688 this->_M_setstate(ios_base::badbit);
689 __throw_exception_again;
692 { this->_M_setstate(ios_base::badbit); }
694 this->setstate(__err);
699 template<typename _CharT, typename _Traits>
700 basic_istream<_CharT, _Traits>&
701 basic_istream<_CharT, _Traits>::
702 read(char_type* __s, streamsize __n)
705 sentry __cerb(*this, true);
708 ios_base::iostate __err = ios_base::goodbit;
711 _M_gcount = this->rdbuf()->sgetn(__s, __n);
712 if (_M_gcount != __n)
713 __err |= (ios_base::eofbit | ios_base::failbit);
715 __catch(__cxxabiv1::__forced_unwind&)
717 this->_M_setstate(ios_base::badbit);
718 __throw_exception_again;
721 { this->_M_setstate(ios_base::badbit); }
723 this->setstate(__err);
728 template<typename _CharT, typename _Traits>
730 basic_istream<_CharT, _Traits>::
731 readsome(char_type* __s, streamsize __n)
734 sentry __cerb(*this, true);
737 ios_base::iostate __err = ios_base::goodbit;
740 // Cannot compare int_type with streamsize generically.
741 const streamsize __num = this->rdbuf()->in_avail();
743 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
744 else if (__num == -1)
745 __err |= ios_base::eofbit;
747 __catch(__cxxabiv1::__forced_unwind&)
749 this->_M_setstate(ios_base::badbit);
750 __throw_exception_again;
753 { this->_M_setstate(ios_base::badbit); }
755 this->setstate(__err);
760 template<typename _CharT, typename _Traits>
761 basic_istream<_CharT, _Traits>&
762 basic_istream<_CharT, _Traits>::
763 putback(char_type __c)
765 // _GLIBCXX_RESOLVE_LIB_DEFECTS
766 // 60. What is a formatted input function?
768 // Clear eofbit per N3168.
769 this->clear(this->rdstate() & ~ios_base::eofbit);
770 sentry __cerb(*this, true);
773 ios_base::iostate __err = ios_base::goodbit;
776 const int_type __eof = traits_type::eof();
777 __streambuf_type* __sb = this->rdbuf();
779 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
780 __err |= ios_base::badbit;
782 __catch(__cxxabiv1::__forced_unwind&)
784 this->_M_setstate(ios_base::badbit);
785 __throw_exception_again;
788 { this->_M_setstate(ios_base::badbit); }
790 this->setstate(__err);
795 template<typename _CharT, typename _Traits>
796 basic_istream<_CharT, _Traits>&
797 basic_istream<_CharT, _Traits>::
800 // _GLIBCXX_RESOLVE_LIB_DEFECTS
801 // 60. What is a formatted input function?
803 // Clear eofbit per N3168.
804 this->clear(this->rdstate() & ~ios_base::eofbit);
805 sentry __cerb(*this, true);
808 ios_base::iostate __err = ios_base::goodbit;
811 const int_type __eof = traits_type::eof();
812 __streambuf_type* __sb = this->rdbuf();
814 || traits_type::eq_int_type(__sb->sungetc(), __eof))
815 __err |= ios_base::badbit;
817 __catch(__cxxabiv1::__forced_unwind&)
819 this->_M_setstate(ios_base::badbit);
820 __throw_exception_again;
823 { this->_M_setstate(ios_base::badbit); }
825 this->setstate(__err);
830 template<typename _CharT, typename _Traits>
832 basic_istream<_CharT, _Traits>::
835 // _GLIBCXX_RESOLVE_LIB_DEFECTS
836 // DR60. Do not change _M_gcount.
838 sentry __cerb(*this, true);
841 ios_base::iostate __err = ios_base::goodbit;
844 __streambuf_type* __sb = this->rdbuf();
847 if (__sb->pubsync() == -1)
848 __err |= ios_base::badbit;
853 __catch(__cxxabiv1::__forced_unwind&)
855 this->_M_setstate(ios_base::badbit);
856 __throw_exception_again;
859 { this->_M_setstate(ios_base::badbit); }
861 this->setstate(__err);
866 template<typename _CharT, typename _Traits>
867 typename basic_istream<_CharT, _Traits>::pos_type
868 basic_istream<_CharT, _Traits>::
871 // _GLIBCXX_RESOLVE_LIB_DEFECTS
872 // DR60. Do not change _M_gcount.
873 pos_type __ret = pos_type(-1);
874 sentry __cerb(*this, true);
880 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
883 __catch(__cxxabiv1::__forced_unwind&)
885 this->_M_setstate(ios_base::badbit);
886 __throw_exception_again;
889 { this->_M_setstate(ios_base::badbit); }
894 template<typename _CharT, typename _Traits>
895 basic_istream<_CharT, _Traits>&
896 basic_istream<_CharT, _Traits>::
897 seekg(pos_type __pos)
899 // _GLIBCXX_RESOLVE_LIB_DEFECTS
900 // DR60. Do not change _M_gcount.
901 // Clear eofbit per N3168.
902 this->clear(this->rdstate() & ~ios_base::eofbit);
903 sentry __cerb(*this, true);
906 ios_base::iostate __err = ios_base::goodbit;
911 // 136. seekp, seekg setting wrong streams?
912 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
915 // 129. Need error indication from seekp() and seekg()
916 if (__p == pos_type(off_type(-1)))
917 __err |= ios_base::failbit;
920 __catch(__cxxabiv1::__forced_unwind&)
922 this->_M_setstate(ios_base::badbit);
923 __throw_exception_again;
926 { this->_M_setstate(ios_base::badbit); }
928 this->setstate(__err);
933 template<typename _CharT, typename _Traits>
934 basic_istream<_CharT, _Traits>&
935 basic_istream<_CharT, _Traits>::
936 seekg(off_type __off, ios_base::seekdir __dir)
938 // _GLIBCXX_RESOLVE_LIB_DEFECTS
939 // DR60. Do not change _M_gcount.
940 // Clear eofbit per N3168.
941 this->clear(this->rdstate() & ~ios_base::eofbit);
942 sentry __cerb(*this, true);
945 ios_base::iostate __err = ios_base::goodbit;
950 // 136. seekp, seekg setting wrong streams?
951 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
954 // 129. Need error indication from seekp() and seekg()
955 if (__p == pos_type(off_type(-1)))
956 __err |= ios_base::failbit;
959 __catch(__cxxabiv1::__forced_unwind&)
961 this->_M_setstate(ios_base::badbit);
962 __throw_exception_again;
965 { this->_M_setstate(ios_base::badbit); }
967 this->setstate(__err);
972 // 27.6.1.2.3 Character extraction templates
973 template<typename _CharT, typename _Traits>
974 basic_istream<_CharT, _Traits>&
975 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
977 typedef basic_istream<_CharT, _Traits> __istream_type;
978 typedef typename __istream_type::int_type __int_type;
980 typename __istream_type::sentry __cerb(__in, false);
983 ios_base::iostate __err = ios_base::goodbit;
986 const __int_type __cb = __in.rdbuf()->sbumpc();
987 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
988 __c = _Traits::to_char_type(__cb);
990 __err |= (ios_base::eofbit | ios_base::failbit);
992 __catch(__cxxabiv1::__forced_unwind&)
994 __in._M_setstate(ios_base::badbit);
995 __throw_exception_again;
998 { __in._M_setstate(ios_base::badbit); }
1000 __in.setstate(__err);
1005 template<typename _CharT, typename _Traits>
1007 __istream_extract(basic_istream<_CharT, _Traits>& __in, _CharT* __s,
1010 typedef basic_istream<_CharT, _Traits> __istream_type;
1011 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1012 typedef typename _Traits::int_type int_type;
1013 typedef _CharT char_type;
1014 typedef ctype<_CharT> __ctype_type;
1016 streamsize __extracted = 0;
1017 ios_base::iostate __err = ios_base::goodbit;
1018 typename __istream_type::sentry __cerb(__in, false);
1023 // Figure out how many characters to extract.
1024 streamsize __width = __in.width();
1025 if (0 < __width && __width < __num)
1028 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1030 const int_type __eof = _Traits::eof();
1031 __streambuf_type* __sb = __in.rdbuf();
1032 int_type __c = __sb->sgetc();
1034 while (__extracted < __num - 1
1035 && !_Traits::eq_int_type(__c, __eof)
1036 && !__ct.is(ctype_base::space,
1037 _Traits::to_char_type(__c)))
1039 *__s++ = _Traits::to_char_type(__c);
1041 __c = __sb->snextc();
1044 if (__extracted < __num - 1
1045 && _Traits::eq_int_type(__c, __eof))
1046 __err |= ios_base::eofbit;
1048 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1049 // 68. Extractors for char* should store null at end
1053 __catch(__cxxabiv1::__forced_unwind&)
1055 __in._M_setstate(ios_base::badbit);
1056 __throw_exception_again;
1059 { __in._M_setstate(ios_base::badbit); }
1062 __err |= ios_base::failbit;
1064 __in.setstate(__err);
1067 // 27.6.1.4 Standard basic_istream manipulators
1068 template<typename _CharT, typename _Traits>
1069 basic_istream<_CharT, _Traits>&
1070 ws(basic_istream<_CharT, _Traits>& __in)
1072 typedef basic_istream<_CharT, _Traits> __istream_type;
1073 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1074 typedef typename __istream_type::int_type __int_type;
1075 typedef ctype<_CharT> __ctype_type;
1077 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1078 // 451. behavior of std::ws
1079 typename __istream_type::sentry __cerb(__in, true);
1082 ios_base::iostate __err = ios_base::goodbit;
1085 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1086 const __int_type __eof = _Traits::eof();
1087 __streambuf_type* __sb = __in.rdbuf();
1088 __int_type __c = __sb->sgetc();
1092 if (_Traits::eq_int_type(__c, __eof))
1094 __err = ios_base::eofbit;
1097 if (!__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1099 __c = __sb->snextc();
1102 __catch (const __cxxabiv1::__forced_unwind&)
1104 __in._M_setstate(ios_base::badbit);
1105 __throw_exception_again;
1109 __in._M_setstate(ios_base::badbit);
1112 __in.setstate(__err);
1117 // Inhibit implicit instantiations for required instantiations,
1118 // which are defined via explicit instantiations elsewhere.
1119 #if _GLIBCXX_EXTERN_TEMPLATE
1120 extern template class basic_istream<char>;
1121 extern template istream& ws(istream&);
1122 extern template istream& operator>>(istream&, char&);
1123 extern template istream& operator>>(istream&, unsigned char&);
1124 extern template istream& operator>>(istream&, signed char&);
1126 extern template istream& istream::_M_extract(unsigned short&);
1127 extern template istream& istream::_M_extract(unsigned int&);
1128 extern template istream& istream::_M_extract(long&);
1129 extern template istream& istream::_M_extract(unsigned long&);
1130 extern template istream& istream::_M_extract(bool&);
1131 #ifdef _GLIBCXX_USE_LONG_LONG
1132 extern template istream& istream::_M_extract(long long&);
1133 extern template istream& istream::_M_extract(unsigned long long&);
1135 extern template istream& istream::_M_extract(float&);
1136 extern template istream& istream::_M_extract(double&);
1137 extern template istream& istream::_M_extract(long double&);
1138 extern template istream& istream::_M_extract(void*&);
1140 extern template class basic_iostream<char>;
1142 #ifdef _GLIBCXX_USE_WCHAR_T
1143 extern template class basic_istream<wchar_t>;
1144 extern template wistream& ws(wistream&);
1145 extern template wistream& operator>>(wistream&, wchar_t&);
1146 extern template void __istream_extract(wistream&, wchar_t*, streamsize);
1148 extern template wistream& wistream::_M_extract(unsigned short&);
1149 extern template wistream& wistream::_M_extract(unsigned int&);
1150 extern template wistream& wistream::_M_extract(long&);
1151 extern template wistream& wistream::_M_extract(unsigned long&);
1152 extern template wistream& wistream::_M_extract(bool&);
1153 #ifdef _GLIBCXX_USE_LONG_LONG
1154 extern template wistream& wistream::_M_extract(long long&);
1155 extern template wistream& wistream::_M_extract(unsigned long long&);
1157 extern template wistream& wistream::_M_extract(float&);
1158 extern template wistream& wistream::_M_extract(double&);
1159 extern template wistream& wistream::_M_extract(long double&);
1160 extern template wistream& wistream::_M_extract(void*&);
1162 extern template class basic_iostream<wchar_t>;
1166 _GLIBCXX_END_NAMESPACE_VERSION