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 #ifdef _GLIBCXX_SYSHDR
38 #pragma GCC system_header
41 #pragma GCC diagnostic push
42 #pragma GCC diagnostic ignored "-Wc++11-extensions" // extern template
44 #include <bits/cxxabi_forced.h>
46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<typename _CharT, typename _Traits>
51 basic_istream<_CharT, _Traits>::sentry::
52 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
54 ios_base::iostate __err = ios_base::goodbit;
61 if (!__noskip && bool(__in.flags() & ios_base::skipws))
63 const __int_type __eof = traits_type::eof();
64 __streambuf_type* __sb = __in.rdbuf();
65 __int_type __c = __sb->sgetc();
67 const __ctype_type& __ct = __check_facet(__in._M_ctype);
68 while (!traits_type::eq_int_type(__c, __eof)
69 && __ct.is(ctype_base::space,
70 traits_type::to_char_type(__c)))
73 // _GLIBCXX_RESOLVE_LIB_DEFECTS
74 // 195. Should basic_istream::sentry's constructor ever
76 if (traits_type::eq_int_type(__c, __eof))
77 __err |= ios_base::eofbit;
80 __catch(__cxxabiv1::__forced_unwind&)
82 __in._M_setstate(ios_base::badbit);
83 __throw_exception_again;
86 { __in._M_setstate(ios_base::badbit); }
89 if (__in.good() && __err == ios_base::goodbit)
93 __err |= ios_base::failbit;
98 template<typename _CharT, typename _Traits>
99 template<typename _ValueT>
100 basic_istream<_CharT, _Traits>&
101 basic_istream<_CharT, _Traits>::
102 _M_extract(_ValueT& __v)
104 sentry __cerb(*this, false);
107 ios_base::iostate __err = ios_base::goodbit;
110 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
111 const __num_get_type& __ng = __check_facet(this->_M_num_get);
113 const __num_get_type& __ng
114 = use_facet<__num_get_type>(this->_M_ios_locale);
116 __ng.get(*this, 0, *this, __err, __v);
118 __catch(__cxxabiv1::__forced_unwind&)
120 this->_M_setstate(ios_base::badbit);
121 __throw_exception_again;
124 { this->_M_setstate(ios_base::badbit); }
126 this->setstate(__err);
131 template<typename _CharT, typename _Traits>
132 basic_istream<_CharT, _Traits>&
133 basic_istream<_CharT, _Traits>::
134 operator>>(short& __n)
136 // _GLIBCXX_RESOLVE_LIB_DEFECTS
137 // 118. basic_istream uses nonexistent num_get member functions.
138 sentry __cerb(*this, false);
141 ios_base::iostate __err = ios_base::goodbit;
145 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
146 const __num_get_type& __ng = __check_facet(this->_M_num_get);
148 const __num_get_type& __ng
149 = use_facet<__num_get_type>(this->_M_ios_locale);
151 __ng.get(*this, 0, *this, __err, __l);
153 // _GLIBCXX_RESOLVE_LIB_DEFECTS
154 // 696. istream::operator>>(int&) broken.
155 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
157 __err |= ios_base::failbit;
158 __n = __gnu_cxx::__numeric_traits<short>::__min;
160 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
162 __err |= ios_base::failbit;
163 __n = __gnu_cxx::__numeric_traits<short>::__max;
168 __catch(__cxxabiv1::__forced_unwind&)
170 this->_M_setstate(ios_base::badbit);
171 __throw_exception_again;
174 { this->_M_setstate(ios_base::badbit); }
176 this->setstate(__err);
181 template<typename _CharT, typename _Traits>
182 basic_istream<_CharT, _Traits>&
183 basic_istream<_CharT, _Traits>::
186 // _GLIBCXX_RESOLVE_LIB_DEFECTS
187 // 118. basic_istream uses nonexistent num_get member functions.
188 sentry __cerb(*this, false);
191 ios_base::iostate __err = ios_base::goodbit;
195 #ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
196 const __num_get_type& __ng = __check_facet(this->_M_num_get);
198 const __num_get_type& __ng
199 = use_facet<__num_get_type>(this->_M_ios_locale);
201 __ng.get(*this, 0, *this, __err, __l);
203 // _GLIBCXX_RESOLVE_LIB_DEFECTS
204 // 696. istream::operator>>(int&) broken.
205 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
207 __err |= ios_base::failbit;
208 __n = __gnu_cxx::__numeric_traits<int>::__min;
210 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
212 __err |= ios_base::failbit;
213 __n = __gnu_cxx::__numeric_traits<int>::__max;
218 __catch(__cxxabiv1::__forced_unwind&)
220 this->_M_setstate(ios_base::badbit);
221 __throw_exception_again;
224 { this->_M_setstate(ios_base::badbit); }
226 this->setstate(__err);
231 template<typename _CharT, typename _Traits>
232 basic_istream<_CharT, _Traits>&
233 basic_istream<_CharT, _Traits>::
234 operator>>(__streambuf_type* __sbout)
236 ios_base::iostate __err = ios_base::goodbit;
237 sentry __cerb(*this, false);
238 if (__cerb && __sbout)
243 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
244 __err |= ios_base::failbit;
246 __err |= ios_base::eofbit;
248 __catch(__cxxabiv1::__forced_unwind&)
250 this->_M_setstate(ios_base::failbit);
251 __throw_exception_again;
254 { this->_M_setstate(ios_base::failbit); }
257 __err |= ios_base::failbit;
259 this->setstate(__err);
263 template<typename _CharT, typename _Traits>
264 typename basic_istream<_CharT, _Traits>::int_type
265 basic_istream<_CharT, _Traits>::
268 const int_type __eof = traits_type::eof();
269 int_type __c = __eof;
271 ios_base::iostate __err = ios_base::goodbit;
272 sentry __cerb(*this, true);
277 __c = this->rdbuf()->sbumpc();
278 // 27.6.1.1 paragraph 3
279 if (!traits_type::eq_int_type(__c, __eof))
282 __err |= ios_base::eofbit;
284 __catch(__cxxabiv1::__forced_unwind&)
286 this->_M_setstate(ios_base::badbit);
287 __throw_exception_again;
290 { this->_M_setstate(ios_base::badbit); }
293 __err |= ios_base::failbit;
295 this->setstate(__err);
299 template<typename _CharT, typename _Traits>
300 basic_istream<_CharT, _Traits>&
301 basic_istream<_CharT, _Traits>::
305 ios_base::iostate __err = ios_base::goodbit;
306 sentry __cerb(*this, true);
311 const int_type __cb = this->rdbuf()->sbumpc();
312 // 27.6.1.1 paragraph 3
313 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
316 __c = traits_type::to_char_type(__cb);
319 __err |= ios_base::eofbit;
321 __catch(__cxxabiv1::__forced_unwind&)
323 this->_M_setstate(ios_base::badbit);
324 __throw_exception_again;
327 { this->_M_setstate(ios_base::badbit); }
330 __err |= ios_base::failbit;
332 this->setstate(__err);
336 template<typename _CharT, typename _Traits>
337 basic_istream<_CharT, _Traits>&
338 basic_istream<_CharT, _Traits>::
339 get(char_type* __s, streamsize __n, char_type __delim)
342 ios_base::iostate __err = ios_base::goodbit;
343 sentry __cerb(*this, true);
348 const int_type __idelim = traits_type::to_int_type(__delim);
349 const int_type __eof = traits_type::eof();
350 __streambuf_type* __sb = this->rdbuf();
351 int_type __c = __sb->sgetc();
353 while (_M_gcount + 1 < __n
354 && !traits_type::eq_int_type(__c, __eof)
355 && !traits_type::eq_int_type(__c, __idelim))
357 *__s++ = traits_type::to_char_type(__c);
359 __c = __sb->snextc();
361 if (traits_type::eq_int_type(__c, __eof))
362 __err |= ios_base::eofbit;
364 __catch(__cxxabiv1::__forced_unwind&)
366 this->_M_setstate(ios_base::badbit);
367 __throw_exception_again;
370 { this->_M_setstate(ios_base::badbit); }
372 // _GLIBCXX_RESOLVE_LIB_DEFECTS
373 // 243. get and getline when sentry reports failure.
377 __err |= ios_base::failbit;
379 this->setstate(__err);
383 template<typename _CharT, typename _Traits>
384 basic_istream<_CharT, _Traits>&
385 basic_istream<_CharT, _Traits>::
386 get(__streambuf_type& __sb, char_type __delim)
389 ios_base::iostate __err = ios_base::goodbit;
390 sentry __cerb(*this, true);
395 const int_type __idelim = traits_type::to_int_type(__delim);
396 const int_type __eof = traits_type::eof();
397 __streambuf_type* __this_sb = this->rdbuf();
398 int_type __c = __this_sb->sgetc();
399 char_type __c2 = traits_type::to_char_type(__c);
400 #pragma GCC diagnostic push
401 #pragma GCC diagnostic ignored "-Wlong-long"
402 unsigned long long __gcount = 0;
403 #pragma GCC diagnostic pop
405 while (!traits_type::eq_int_type(__c, __eof)
406 && !traits_type::eq_int_type(__c, __idelim)
407 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
410 __c = __this_sb->snextc();
411 __c2 = traits_type::to_char_type(__c);
413 if (traits_type::eq_int_type(__c, __eof))
414 __err |= ios_base::eofbit;
415 // _GLIBCXX_RESOLVE_LIB_DEFECTS
416 // 3464. istream::gcount() can overflow
417 if (__gcount <= __gnu_cxx::__numeric_traits<streamsize>::__max)
418 _M_gcount = __gcount;
420 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
422 __catch(__cxxabiv1::__forced_unwind&)
424 this->_M_setstate(ios_base::badbit);
425 __throw_exception_again;
428 { this->_M_setstate(ios_base::badbit); }
431 __err |= ios_base::failbit;
433 this->setstate(__err);
437 template<typename _CharT, typename _Traits>
438 basic_istream<_CharT, _Traits>&
439 basic_istream<_CharT, _Traits>::
440 getline(char_type* __s, streamsize __n, char_type __delim)
443 ios_base::iostate __err = ios_base::goodbit;
444 sentry __cerb(*this, true);
449 const int_type __idelim = traits_type::to_int_type(__delim);
450 const int_type __eof = traits_type::eof();
451 __streambuf_type* __sb = this->rdbuf();
452 int_type __c = __sb->sgetc();
454 while (_M_gcount + 1 < __n
455 && !traits_type::eq_int_type(__c, __eof)
456 && !traits_type::eq_int_type(__c, __idelim))
458 *__s++ = traits_type::to_char_type(__c);
459 __c = __sb->snextc();
462 if (traits_type::eq_int_type(__c, __eof))
463 __err |= ios_base::eofbit;
466 if (traits_type::eq_int_type(__c, __idelim))
472 __err |= ios_base::failbit;
475 __catch(__cxxabiv1::__forced_unwind&)
477 this->_M_setstate(ios_base::badbit);
478 __throw_exception_again;
481 { this->_M_setstate(ios_base::badbit); }
483 // _GLIBCXX_RESOLVE_LIB_DEFECTS
484 // 243. get and getline when sentry reports failure.
488 __err |= ios_base::failbit;
490 this->setstate(__err);
494 // We provide three overloads, since the first two are much simpler
495 // than the general case. Also, the latter two can thus adopt the
496 // same "batchy" strategy used by getline above.
497 template<typename _CharT, typename _Traits>
498 basic_istream<_CharT, _Traits>&
499 basic_istream<_CharT, _Traits>::
503 sentry __cerb(*this, true);
506 ios_base::iostate __err = ios_base::goodbit;
509 const int_type __eof = traits_type::eof();
510 __streambuf_type* __sb = this->rdbuf();
512 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
513 __err |= ios_base::eofbit;
517 __catch(__cxxabiv1::__forced_unwind&)
519 this->_M_setstate(ios_base::badbit);
520 __throw_exception_again;
523 { this->_M_setstate(ios_base::badbit); }
525 this->setstate(__err);
530 template<typename _CharT, typename _Traits>
531 basic_istream<_CharT, _Traits>&
532 basic_istream<_CharT, _Traits>::
533 ignore(streamsize __n)
536 sentry __cerb(*this, true);
537 if (__cerb && __n > 0)
539 ios_base::iostate __err = ios_base::goodbit;
542 const int_type __eof = traits_type::eof();
543 __streambuf_type* __sb = this->rdbuf();
544 int_type __c = __sb->sgetc();
546 // N.B. On LFS-enabled platforms streamsize is still 32 bits
547 // wide: if we want to implement the standard mandated behavior
548 // for n == max() (see 27.6.1.3/24) we are at risk of signed
549 // integer overflow: thus these contortions. Also note that,
550 // by definition, when more than 2G chars are actually ignored,
551 // _M_gcount (the return value of gcount, that is) cannot be
552 // really correct, being unavoidably too small.
553 bool __large_ignore = false;
556 while (_M_gcount < __n
557 && !traits_type::eq_int_type(__c, __eof))
560 __c = __sb->snextc();
562 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
563 && !traits_type::eq_int_type(__c, __eof))
566 __gnu_cxx::__numeric_traits<streamsize>::__min;
567 __large_ignore = true;
573 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
576 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
578 if (traits_type::eq_int_type(__c, __eof))
579 __err |= ios_base::eofbit;
581 else if (_M_gcount < __n)
583 if (traits_type::eq_int_type(__c, __eof))
584 __err |= ios_base::eofbit;
587 __catch(__cxxabiv1::__forced_unwind&)
589 this->_M_setstate(ios_base::badbit);
590 __throw_exception_again;
593 { this->_M_setstate(ios_base::badbit); }
595 this->setstate(__err);
600 template<typename _CharT, typename _Traits>
601 basic_istream<_CharT, _Traits>&
602 basic_istream<_CharT, _Traits>::
603 ignore(streamsize __n, int_type __delim)
606 sentry __cerb(*this, true);
607 if (__cerb && __n > 0)
609 ios_base::iostate __err = ios_base::goodbit;
612 const int_type __eof = traits_type::eof();
613 __streambuf_type* __sb = this->rdbuf();
614 int_type __c = __sb->sgetc();
616 // See comment above.
617 bool __large_ignore = false;
620 while (_M_gcount < __n
621 && !traits_type::eq_int_type(__c, __eof)
622 && !traits_type::eq_int_type(__c, __delim))
625 __c = __sb->snextc();
627 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
628 && !traits_type::eq_int_type(__c, __eof)
629 && !traits_type::eq_int_type(__c, __delim))
632 __gnu_cxx::__numeric_traits<streamsize>::__min;
633 __large_ignore = true;
639 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
642 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
644 if (traits_type::eq_int_type(__c, __eof))
645 __err |= ios_base::eofbit;
648 if (_M_gcount != __n)
653 else if (_M_gcount < __n) // implies __c == __delim or EOF
655 if (traits_type::eq_int_type(__c, __eof))
656 __err |= ios_base::eofbit;
664 __catch(__cxxabiv1::__forced_unwind&)
666 this->_M_setstate(ios_base::badbit);
667 __throw_exception_again;
670 { this->_M_setstate(ios_base::badbit); }
672 this->setstate(__err);
677 template<typename _CharT, typename _Traits>
678 typename basic_istream<_CharT, _Traits>::int_type
679 basic_istream<_CharT, _Traits>::
682 int_type __c = traits_type::eof();
684 sentry __cerb(*this, true);
687 ios_base::iostate __err = ios_base::goodbit;
690 __c = this->rdbuf()->sgetc();
691 if (traits_type::eq_int_type(__c, traits_type::eof()))
692 __err |= ios_base::eofbit;
694 __catch(__cxxabiv1::__forced_unwind&)
696 this->_M_setstate(ios_base::badbit);
697 __throw_exception_again;
700 { this->_M_setstate(ios_base::badbit); }
702 this->setstate(__err);
707 template<typename _CharT, typename _Traits>
708 basic_istream<_CharT, _Traits>&
709 basic_istream<_CharT, _Traits>::
710 read(char_type* __s, streamsize __n)
713 sentry __cerb(*this, true);
716 ios_base::iostate __err = ios_base::goodbit;
719 _M_gcount = this->rdbuf()->sgetn(__s, __n);
720 if (_M_gcount != __n)
721 __err |= (ios_base::eofbit | ios_base::failbit);
723 __catch(__cxxabiv1::__forced_unwind&)
725 this->_M_setstate(ios_base::badbit);
726 __throw_exception_again;
729 { this->_M_setstate(ios_base::badbit); }
731 this->setstate(__err);
736 template<typename _CharT, typename _Traits>
738 basic_istream<_CharT, _Traits>::
739 readsome(char_type* __s, streamsize __n)
742 sentry __cerb(*this, true);
745 ios_base::iostate __err = ios_base::goodbit;
748 // Cannot compare int_type with streamsize generically.
749 const streamsize __num = this->rdbuf()->in_avail();
751 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
752 else if (__num == -1)
753 __err |= ios_base::eofbit;
755 __catch(__cxxabiv1::__forced_unwind&)
757 this->_M_setstate(ios_base::badbit);
758 __throw_exception_again;
761 { this->_M_setstate(ios_base::badbit); }
763 this->setstate(__err);
768 template<typename _CharT, typename _Traits>
769 basic_istream<_CharT, _Traits>&
770 basic_istream<_CharT, _Traits>::
771 putback(char_type __c)
773 // _GLIBCXX_RESOLVE_LIB_DEFECTS
774 // 60. What is a formatted input function?
776 // Clear eofbit per N3168.
777 this->clear(this->rdstate() & ~ios_base::eofbit);
778 sentry __cerb(*this, true);
781 ios_base::iostate __err = ios_base::goodbit;
784 const int_type __eof = traits_type::eof();
785 __streambuf_type* __sb = this->rdbuf();
787 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
788 __err |= ios_base::badbit;
790 __catch(__cxxabiv1::__forced_unwind&)
792 this->_M_setstate(ios_base::badbit);
793 __throw_exception_again;
796 { this->_M_setstate(ios_base::badbit); }
798 this->setstate(__err);
803 template<typename _CharT, typename _Traits>
804 basic_istream<_CharT, _Traits>&
805 basic_istream<_CharT, _Traits>::
808 // _GLIBCXX_RESOLVE_LIB_DEFECTS
809 // 60. What is a formatted input function?
811 // Clear eofbit per N3168.
812 this->clear(this->rdstate() & ~ios_base::eofbit);
813 sentry __cerb(*this, true);
816 ios_base::iostate __err = ios_base::goodbit;
819 const int_type __eof = traits_type::eof();
820 __streambuf_type* __sb = this->rdbuf();
822 || traits_type::eq_int_type(__sb->sungetc(), __eof))
823 __err |= ios_base::badbit;
825 __catch(__cxxabiv1::__forced_unwind&)
827 this->_M_setstate(ios_base::badbit);
828 __throw_exception_again;
831 { this->_M_setstate(ios_base::badbit); }
833 this->setstate(__err);
838 template<typename _CharT, typename _Traits>
840 basic_istream<_CharT, _Traits>::
843 // _GLIBCXX_RESOLVE_LIB_DEFECTS
844 // DR60. Do not change _M_gcount.
846 sentry __cerb(*this, true);
849 ios_base::iostate __err = ios_base::goodbit;
852 __streambuf_type* __sb = this->rdbuf();
855 if (__sb->pubsync() == -1)
856 __err |= ios_base::badbit;
861 __catch(__cxxabiv1::__forced_unwind&)
863 this->_M_setstate(ios_base::badbit);
864 __throw_exception_again;
867 { this->_M_setstate(ios_base::badbit); }
869 this->setstate(__err);
874 template<typename _CharT, typename _Traits>
875 typename basic_istream<_CharT, _Traits>::pos_type
876 basic_istream<_CharT, _Traits>::
879 // _GLIBCXX_RESOLVE_LIB_DEFECTS
880 // DR60. Do not change _M_gcount.
881 pos_type __ret = pos_type(-1);
882 sentry __cerb(*this, true);
888 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
891 __catch(__cxxabiv1::__forced_unwind&)
893 this->_M_setstate(ios_base::badbit);
894 __throw_exception_again;
897 { this->_M_setstate(ios_base::badbit); }
902 template<typename _CharT, typename _Traits>
903 basic_istream<_CharT, _Traits>&
904 basic_istream<_CharT, _Traits>::
905 seekg(pos_type __pos)
907 // _GLIBCXX_RESOLVE_LIB_DEFECTS
908 // DR60. Do not change _M_gcount.
909 // Clear eofbit per N3168.
910 this->clear(this->rdstate() & ~ios_base::eofbit);
911 sentry __cerb(*this, true);
914 ios_base::iostate __err = ios_base::goodbit;
919 // 136. seekp, seekg setting wrong streams?
920 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
923 // 129. Need error indication from seekp() and seekg()
924 if (__p == pos_type(off_type(-1)))
925 __err |= ios_base::failbit;
928 __catch(__cxxabiv1::__forced_unwind&)
930 this->_M_setstate(ios_base::badbit);
931 __throw_exception_again;
934 { this->_M_setstate(ios_base::badbit); }
936 this->setstate(__err);
941 template<typename _CharT, typename _Traits>
942 basic_istream<_CharT, _Traits>&
943 basic_istream<_CharT, _Traits>::
944 seekg(off_type __off, ios_base::seekdir __dir)
946 // _GLIBCXX_RESOLVE_LIB_DEFECTS
947 // DR60. Do not change _M_gcount.
948 // Clear eofbit per N3168.
949 this->clear(this->rdstate() & ~ios_base::eofbit);
950 sentry __cerb(*this, true);
953 ios_base::iostate __err = ios_base::goodbit;
958 // 136. seekp, seekg setting wrong streams?
959 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
962 // 129. Need error indication from seekp() and seekg()
963 if (__p == pos_type(off_type(-1)))
964 __err |= ios_base::failbit;
967 __catch(__cxxabiv1::__forced_unwind&)
969 this->_M_setstate(ios_base::badbit);
970 __throw_exception_again;
973 { this->_M_setstate(ios_base::badbit); }
975 this->setstate(__err);
980 // 27.6.1.2.3 Character extraction templates
981 template<typename _CharT, typename _Traits>
982 basic_istream<_CharT, _Traits>&
983 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
985 typedef basic_istream<_CharT, _Traits> __istream_type;
986 typedef typename __istream_type::int_type __int_type;
988 typename __istream_type::sentry __cerb(__in, false);
991 ios_base::iostate __err = ios_base::goodbit;
994 const __int_type __cb = __in.rdbuf()->sbumpc();
995 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
996 __c = _Traits::to_char_type(__cb);
998 __err |= (ios_base::eofbit | ios_base::failbit);
1000 __catch(__cxxabiv1::__forced_unwind&)
1002 __in._M_setstate(ios_base::badbit);
1003 __throw_exception_again;
1006 { __in._M_setstate(ios_base::badbit); }
1008 __in.setstate(__err);
1013 template<typename _CharT, typename _Traits>
1015 __istream_extract(basic_istream<_CharT, _Traits>& __in, _CharT* __s,
1018 typedef basic_istream<_CharT, _Traits> __istream_type;
1019 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1020 typedef typename _Traits::int_type int_type;
1021 typedef _CharT char_type;
1022 typedef ctype<_CharT> __ctype_type;
1024 streamsize __extracted = 0;
1025 ios_base::iostate __err = ios_base::goodbit;
1026 typename __istream_type::sentry __cerb(__in, false);
1031 // Figure out how many characters to extract.
1032 streamsize __width = __in.width();
1033 if (0 < __width && __width < __num)
1036 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1038 const int_type __eof = _Traits::eof();
1039 __streambuf_type* __sb = __in.rdbuf();
1040 int_type __c = __sb->sgetc();
1042 while (__extracted < __num - 1
1043 && !_Traits::eq_int_type(__c, __eof)
1044 && !__ct.is(ctype_base::space,
1045 _Traits::to_char_type(__c)))
1047 *__s++ = _Traits::to_char_type(__c);
1049 __c = __sb->snextc();
1052 if (__extracted < __num - 1
1053 && _Traits::eq_int_type(__c, __eof))
1054 __err |= ios_base::eofbit;
1056 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1057 // 68. Extractors for char* should store null at end
1061 __catch(__cxxabiv1::__forced_unwind&)
1063 __in._M_setstate(ios_base::badbit);
1064 __throw_exception_again;
1067 { __in._M_setstate(ios_base::badbit); }
1070 __err |= ios_base::failbit;
1072 __in.setstate(__err);
1075 // 27.6.1.4 Standard basic_istream manipulators
1076 template<typename _CharT, typename _Traits>
1077 basic_istream<_CharT, _Traits>&
1078 ws(basic_istream<_CharT, _Traits>& __in)
1080 typedef basic_istream<_CharT, _Traits> __istream_type;
1081 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1082 typedef typename __istream_type::int_type __int_type;
1083 typedef ctype<_CharT> __ctype_type;
1085 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1086 // 451. behavior of std::ws
1087 typename __istream_type::sentry __cerb(__in, true);
1090 ios_base::iostate __err = ios_base::goodbit;
1093 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1094 const __int_type __eof = _Traits::eof();
1095 __streambuf_type* __sb = __in.rdbuf();
1096 __int_type __c = __sb->sgetc();
1100 if (_Traits::eq_int_type(__c, __eof))
1102 __err = ios_base::eofbit;
1105 if (!__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1107 __c = __sb->snextc();
1110 __catch (const __cxxabiv1::__forced_unwind&)
1112 __in._M_setstate(ios_base::badbit);
1113 __throw_exception_again;
1117 __in._M_setstate(ios_base::badbit);
1120 __in.setstate(__err);
1125 // Inhibit implicit instantiations for required instantiations,
1126 // which are defined via explicit instantiations elsewhere.
1127 #if _GLIBCXX_EXTERN_TEMPLATE
1128 #pragma GCC diagnostic push
1129 #pragma GCC diagnostic ignored "-Wc++11-extensions" // extern template
1130 #pragma GCC diagnostic ignored "-Wlong-long"
1131 extern template class basic_istream<char>;
1132 extern template istream& ws(istream&);
1133 extern template istream& operator>>(istream&, char&);
1134 extern template istream& operator>>(istream&, unsigned char&);
1135 extern template istream& operator>>(istream&, signed char&);
1137 extern template istream& istream::_M_extract(unsigned short&);
1138 extern template istream& istream::_M_extract(unsigned int&);
1139 extern template istream& istream::_M_extract(long&);
1140 extern template istream& istream::_M_extract(unsigned long&);
1141 extern template istream& istream::_M_extract(bool&);
1142 #ifdef _GLIBCXX_USE_LONG_LONG
1143 #pragma GCC diagnostic push
1144 #pragma GCC diagnostic ignored "-Wlong-long"
1145 extern template istream& istream::_M_extract(long long&);
1146 extern template istream& istream::_M_extract(unsigned long long&);
1147 #pragma GCC diagnostic pop
1149 extern template istream& istream::_M_extract(float&);
1150 extern template istream& istream::_M_extract(double&);
1151 extern template istream& istream::_M_extract(long double&);
1152 extern template istream& istream::_M_extract(void*&);
1154 extern template class basic_iostream<char>;
1156 #ifdef _GLIBCXX_USE_WCHAR_T
1157 extern template class basic_istream<wchar_t>;
1158 extern template wistream& ws(wistream&);
1159 extern template wistream& operator>>(wistream&, wchar_t&);
1160 extern template void __istream_extract(wistream&, wchar_t*, streamsize);
1162 extern template wistream& wistream::_M_extract(unsigned short&);
1163 extern template wistream& wistream::_M_extract(unsigned int&);
1164 extern template wistream& wistream::_M_extract(long&);
1165 extern template wistream& wistream::_M_extract(unsigned long&);
1166 extern template wistream& wistream::_M_extract(bool&);
1167 #ifdef _GLIBCXX_USE_LONG_LONG
1168 extern template wistream& wistream::_M_extract(long long&);
1169 extern template wistream& wistream::_M_extract(unsigned long long&);
1171 extern template wistream& wistream::_M_extract(float&);
1172 extern template wistream& wistream::_M_extract(double&);
1173 extern template wistream& wistream::_M_extract(long double&);
1174 extern template wistream& wistream::_M_extract(void*&);
1176 extern template class basic_iostream<wchar_t>;
1178 #pragma GCC diagnostic pop
1181 _GLIBCXX_END_NAMESPACE_VERSION
1184 #pragma GCC diagnostic pop