1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997-2023 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 const __num_get_type& __ng = __check_facet(this->_M_num_get);
106 __ng.get(*this, 0, *this, __err, __v);
108 __catch(__cxxabiv1::__forced_unwind&)
110 this->_M_setstate(ios_base::badbit);
111 __throw_exception_again;
114 { this->_M_setstate(ios_base::badbit); }
116 this->setstate(__err);
121 template<typename _CharT, typename _Traits>
122 basic_istream<_CharT, _Traits>&
123 basic_istream<_CharT, _Traits>::
124 operator>>(short& __n)
126 // _GLIBCXX_RESOLVE_LIB_DEFECTS
127 // 118. basic_istream uses nonexistent num_get member functions.
128 sentry __cerb(*this, false);
131 ios_base::iostate __err = ios_base::goodbit;
135 const __num_get_type& __ng = __check_facet(this->_M_num_get);
136 __ng.get(*this, 0, *this, __err, __l);
138 // _GLIBCXX_RESOLVE_LIB_DEFECTS
139 // 696. istream::operator>>(int&) broken.
140 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
142 __err |= ios_base::failbit;
143 __n = __gnu_cxx::__numeric_traits<short>::__min;
145 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
147 __err |= ios_base::failbit;
148 __n = __gnu_cxx::__numeric_traits<short>::__max;
153 __catch(__cxxabiv1::__forced_unwind&)
155 this->_M_setstate(ios_base::badbit);
156 __throw_exception_again;
159 { this->_M_setstate(ios_base::badbit); }
161 this->setstate(__err);
166 template<typename _CharT, typename _Traits>
167 basic_istream<_CharT, _Traits>&
168 basic_istream<_CharT, _Traits>::
171 // _GLIBCXX_RESOLVE_LIB_DEFECTS
172 // 118. basic_istream uses nonexistent num_get member functions.
173 sentry __cerb(*this, false);
176 ios_base::iostate __err = ios_base::goodbit;
180 const __num_get_type& __ng = __check_facet(this->_M_num_get);
181 __ng.get(*this, 0, *this, __err, __l);
183 // _GLIBCXX_RESOLVE_LIB_DEFECTS
184 // 696. istream::operator>>(int&) broken.
185 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
187 __err |= ios_base::failbit;
188 __n = __gnu_cxx::__numeric_traits<int>::__min;
190 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
192 __err |= ios_base::failbit;
193 __n = __gnu_cxx::__numeric_traits<int>::__max;
198 __catch(__cxxabiv1::__forced_unwind&)
200 this->_M_setstate(ios_base::badbit);
201 __throw_exception_again;
204 { this->_M_setstate(ios_base::badbit); }
206 this->setstate(__err);
211 template<typename _CharT, typename _Traits>
212 basic_istream<_CharT, _Traits>&
213 basic_istream<_CharT, _Traits>::
214 operator>>(__streambuf_type* __sbout)
216 ios_base::iostate __err = ios_base::goodbit;
217 sentry __cerb(*this, false);
218 if (__cerb && __sbout)
223 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
224 __err |= ios_base::failbit;
226 __err |= ios_base::eofbit;
228 __catch(__cxxabiv1::__forced_unwind&)
230 this->_M_setstate(ios_base::failbit);
231 __throw_exception_again;
234 { this->_M_setstate(ios_base::failbit); }
237 __err |= ios_base::failbit;
239 this->setstate(__err);
243 template<typename _CharT, typename _Traits>
244 typename basic_istream<_CharT, _Traits>::int_type
245 basic_istream<_CharT, _Traits>::
248 const int_type __eof = traits_type::eof();
249 int_type __c = __eof;
251 ios_base::iostate __err = ios_base::goodbit;
252 sentry __cerb(*this, true);
257 __c = this->rdbuf()->sbumpc();
258 // 27.6.1.1 paragraph 3
259 if (!traits_type::eq_int_type(__c, __eof))
262 __err |= ios_base::eofbit;
264 __catch(__cxxabiv1::__forced_unwind&)
266 this->_M_setstate(ios_base::badbit);
267 __throw_exception_again;
270 { this->_M_setstate(ios_base::badbit); }
273 __err |= ios_base::failbit;
275 this->setstate(__err);
279 template<typename _CharT, typename _Traits>
280 basic_istream<_CharT, _Traits>&
281 basic_istream<_CharT, _Traits>::
285 ios_base::iostate __err = ios_base::goodbit;
286 sentry __cerb(*this, true);
291 const int_type __cb = this->rdbuf()->sbumpc();
292 // 27.6.1.1 paragraph 3
293 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
296 __c = traits_type::to_char_type(__cb);
299 __err |= ios_base::eofbit;
301 __catch(__cxxabiv1::__forced_unwind&)
303 this->_M_setstate(ios_base::badbit);
304 __throw_exception_again;
307 { this->_M_setstate(ios_base::badbit); }
310 __err |= ios_base::failbit;
312 this->setstate(__err);
316 template<typename _CharT, typename _Traits>
317 basic_istream<_CharT, _Traits>&
318 basic_istream<_CharT, _Traits>::
319 get(char_type* __s, streamsize __n, char_type __delim)
322 ios_base::iostate __err = ios_base::goodbit;
323 sentry __cerb(*this, true);
328 const int_type __idelim = traits_type::to_int_type(__delim);
329 const int_type __eof = traits_type::eof();
330 __streambuf_type* __sb = this->rdbuf();
331 int_type __c = __sb->sgetc();
333 while (_M_gcount + 1 < __n
334 && !traits_type::eq_int_type(__c, __eof)
335 && !traits_type::eq_int_type(__c, __idelim))
337 *__s++ = traits_type::to_char_type(__c);
339 __c = __sb->snextc();
341 if (traits_type::eq_int_type(__c, __eof))
342 __err |= ios_base::eofbit;
344 __catch(__cxxabiv1::__forced_unwind&)
346 this->_M_setstate(ios_base::badbit);
347 __throw_exception_again;
350 { this->_M_setstate(ios_base::badbit); }
352 // _GLIBCXX_RESOLVE_LIB_DEFECTS
353 // 243. get and getline when sentry reports failure.
357 __err |= ios_base::failbit;
359 this->setstate(__err);
363 template<typename _CharT, typename _Traits>
364 basic_istream<_CharT, _Traits>&
365 basic_istream<_CharT, _Traits>::
366 get(__streambuf_type& __sb, char_type __delim)
369 ios_base::iostate __err = ios_base::goodbit;
370 sentry __cerb(*this, true);
375 const int_type __idelim = traits_type::to_int_type(__delim);
376 const int_type __eof = traits_type::eof();
377 __streambuf_type* __this_sb = this->rdbuf();
378 int_type __c = __this_sb->sgetc();
379 char_type __c2 = traits_type::to_char_type(__c);
380 unsigned long long __gcount = 0;
382 while (!traits_type::eq_int_type(__c, __eof)
383 && !traits_type::eq_int_type(__c, __idelim)
384 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
387 __c = __this_sb->snextc();
388 __c2 = traits_type::to_char_type(__c);
390 if (traits_type::eq_int_type(__c, __eof))
391 __err |= ios_base::eofbit;
392 // _GLIBCXX_RESOLVE_LIB_DEFECTS
393 // 3464. istream::gcount() can overflow
394 if (__gcount <= __gnu_cxx::__numeric_traits<streamsize>::__max)
395 _M_gcount = __gcount;
397 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
399 __catch(__cxxabiv1::__forced_unwind&)
401 this->_M_setstate(ios_base::badbit);
402 __throw_exception_again;
405 { this->_M_setstate(ios_base::badbit); }
408 __err |= ios_base::failbit;
410 this->setstate(__err);
414 template<typename _CharT, typename _Traits>
415 basic_istream<_CharT, _Traits>&
416 basic_istream<_CharT, _Traits>::
417 getline(char_type* __s, streamsize __n, char_type __delim)
420 ios_base::iostate __err = ios_base::goodbit;
421 sentry __cerb(*this, true);
426 const int_type __idelim = traits_type::to_int_type(__delim);
427 const int_type __eof = traits_type::eof();
428 __streambuf_type* __sb = this->rdbuf();
429 int_type __c = __sb->sgetc();
431 while (_M_gcount + 1 < __n
432 && !traits_type::eq_int_type(__c, __eof)
433 && !traits_type::eq_int_type(__c, __idelim))
435 *__s++ = traits_type::to_char_type(__c);
436 __c = __sb->snextc();
439 if (traits_type::eq_int_type(__c, __eof))
440 __err |= ios_base::eofbit;
443 if (traits_type::eq_int_type(__c, __idelim))
449 __err |= ios_base::failbit;
452 __catch(__cxxabiv1::__forced_unwind&)
454 this->_M_setstate(ios_base::badbit);
455 __throw_exception_again;
458 { this->_M_setstate(ios_base::badbit); }
460 // _GLIBCXX_RESOLVE_LIB_DEFECTS
461 // 243. get and getline when sentry reports failure.
465 __err |= ios_base::failbit;
467 this->setstate(__err);
471 // We provide three overloads, since the first two are much simpler
472 // than the general case. Also, the latter two can thus adopt the
473 // same "batchy" strategy used by getline above.
474 template<typename _CharT, typename _Traits>
475 basic_istream<_CharT, _Traits>&
476 basic_istream<_CharT, _Traits>::
480 sentry __cerb(*this, true);
483 ios_base::iostate __err = ios_base::goodbit;
486 const int_type __eof = traits_type::eof();
487 __streambuf_type* __sb = this->rdbuf();
489 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
490 __err |= ios_base::eofbit;
494 __catch(__cxxabiv1::__forced_unwind&)
496 this->_M_setstate(ios_base::badbit);
497 __throw_exception_again;
500 { this->_M_setstate(ios_base::badbit); }
502 this->setstate(__err);
507 template<typename _CharT, typename _Traits>
508 basic_istream<_CharT, _Traits>&
509 basic_istream<_CharT, _Traits>::
510 ignore(streamsize __n)
513 sentry __cerb(*this, true);
514 if (__cerb && __n > 0)
516 ios_base::iostate __err = ios_base::goodbit;
519 const int_type __eof = traits_type::eof();
520 __streambuf_type* __sb = this->rdbuf();
521 int_type __c = __sb->sgetc();
523 // N.B. On LFS-enabled platforms streamsize is still 32 bits
524 // wide: if we want to implement the standard mandated behavior
525 // for n == max() (see 27.6.1.3/24) we are at risk of signed
526 // integer overflow: thus these contortions. Also note that,
527 // by definition, when more than 2G chars are actually ignored,
528 // _M_gcount (the return value of gcount, that is) cannot be
529 // really correct, being unavoidably too small.
530 bool __large_ignore = false;
533 while (_M_gcount < __n
534 && !traits_type::eq_int_type(__c, __eof))
537 __c = __sb->snextc();
539 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
540 && !traits_type::eq_int_type(__c, __eof))
543 __gnu_cxx::__numeric_traits<streamsize>::__min;
544 __large_ignore = true;
550 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
553 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
555 if (traits_type::eq_int_type(__c, __eof))
556 __err |= ios_base::eofbit;
558 else if (_M_gcount < __n)
560 if (traits_type::eq_int_type(__c, __eof))
561 __err |= ios_base::eofbit;
564 __catch(__cxxabiv1::__forced_unwind&)
566 this->_M_setstate(ios_base::badbit);
567 __throw_exception_again;
570 { this->_M_setstate(ios_base::badbit); }
572 this->setstate(__err);
577 template<typename _CharT, typename _Traits>
578 basic_istream<_CharT, _Traits>&
579 basic_istream<_CharT, _Traits>::
580 ignore(streamsize __n, int_type __delim)
583 sentry __cerb(*this, true);
584 if (__cerb && __n > 0)
586 ios_base::iostate __err = ios_base::goodbit;
589 const int_type __eof = traits_type::eof();
590 __streambuf_type* __sb = this->rdbuf();
591 int_type __c = __sb->sgetc();
593 // See comment above.
594 bool __large_ignore = false;
597 while (_M_gcount < __n
598 && !traits_type::eq_int_type(__c, __eof)
599 && !traits_type::eq_int_type(__c, __delim))
602 __c = __sb->snextc();
604 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
605 && !traits_type::eq_int_type(__c, __eof)
606 && !traits_type::eq_int_type(__c, __delim))
609 __gnu_cxx::__numeric_traits<streamsize>::__min;
610 __large_ignore = true;
616 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max)
619 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
621 if (traits_type::eq_int_type(__c, __eof))
622 __err |= ios_base::eofbit;
625 if (_M_gcount != __n)
630 else if (_M_gcount < __n) // implies __c == __delim or EOF
632 if (traits_type::eq_int_type(__c, __eof))
633 __err |= ios_base::eofbit;
641 __catch(__cxxabiv1::__forced_unwind&)
643 this->_M_setstate(ios_base::badbit);
644 __throw_exception_again;
647 { this->_M_setstate(ios_base::badbit); }
649 this->setstate(__err);
654 template<typename _CharT, typename _Traits>
655 typename basic_istream<_CharT, _Traits>::int_type
656 basic_istream<_CharT, _Traits>::
659 int_type __c = traits_type::eof();
661 sentry __cerb(*this, true);
664 ios_base::iostate __err = ios_base::goodbit;
667 __c = this->rdbuf()->sgetc();
668 if (traits_type::eq_int_type(__c, traits_type::eof()))
669 __err |= ios_base::eofbit;
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>
685 basic_istream<_CharT, _Traits>&
686 basic_istream<_CharT, _Traits>::
687 read(char_type* __s, streamsize __n)
690 sentry __cerb(*this, true);
693 ios_base::iostate __err = ios_base::goodbit;
696 _M_gcount = this->rdbuf()->sgetn(__s, __n);
697 if (_M_gcount != __n)
698 __err |= (ios_base::eofbit | ios_base::failbit);
700 __catch(__cxxabiv1::__forced_unwind&)
702 this->_M_setstate(ios_base::badbit);
703 __throw_exception_again;
706 { this->_M_setstate(ios_base::badbit); }
708 this->setstate(__err);
713 template<typename _CharT, typename _Traits>
715 basic_istream<_CharT, _Traits>::
716 readsome(char_type* __s, streamsize __n)
719 sentry __cerb(*this, true);
722 ios_base::iostate __err = ios_base::goodbit;
725 // Cannot compare int_type with streamsize generically.
726 const streamsize __num = this->rdbuf()->in_avail();
728 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
729 else if (__num == -1)
730 __err |= ios_base::eofbit;
732 __catch(__cxxabiv1::__forced_unwind&)
734 this->_M_setstate(ios_base::badbit);
735 __throw_exception_again;
738 { this->_M_setstate(ios_base::badbit); }
740 this->setstate(__err);
745 template<typename _CharT, typename _Traits>
746 basic_istream<_CharT, _Traits>&
747 basic_istream<_CharT, _Traits>::
748 putback(char_type __c)
750 // _GLIBCXX_RESOLVE_LIB_DEFECTS
751 // 60. What is a formatted input function?
753 // Clear eofbit per N3168.
754 this->clear(this->rdstate() & ~ios_base::eofbit);
755 sentry __cerb(*this, true);
758 ios_base::iostate __err = ios_base::goodbit;
761 const int_type __eof = traits_type::eof();
762 __streambuf_type* __sb = this->rdbuf();
764 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
765 __err |= ios_base::badbit;
767 __catch(__cxxabiv1::__forced_unwind&)
769 this->_M_setstate(ios_base::badbit);
770 __throw_exception_again;
773 { this->_M_setstate(ios_base::badbit); }
775 this->setstate(__err);
780 template<typename _CharT, typename _Traits>
781 basic_istream<_CharT, _Traits>&
782 basic_istream<_CharT, _Traits>::
785 // _GLIBCXX_RESOLVE_LIB_DEFECTS
786 // 60. What is a formatted input function?
788 // Clear eofbit per N3168.
789 this->clear(this->rdstate() & ~ios_base::eofbit);
790 sentry __cerb(*this, true);
793 ios_base::iostate __err = ios_base::goodbit;
796 const int_type __eof = traits_type::eof();
797 __streambuf_type* __sb = this->rdbuf();
799 || traits_type::eq_int_type(__sb->sungetc(), __eof))
800 __err |= ios_base::badbit;
802 __catch(__cxxabiv1::__forced_unwind&)
804 this->_M_setstate(ios_base::badbit);
805 __throw_exception_again;
808 { this->_M_setstate(ios_base::badbit); }
810 this->setstate(__err);
815 template<typename _CharT, typename _Traits>
817 basic_istream<_CharT, _Traits>::
820 // _GLIBCXX_RESOLVE_LIB_DEFECTS
821 // DR60. Do not change _M_gcount.
823 sentry __cerb(*this, true);
826 ios_base::iostate __err = ios_base::goodbit;
829 __streambuf_type* __sb = this->rdbuf();
832 if (__sb->pubsync() == -1)
833 __err |= ios_base::badbit;
838 __catch(__cxxabiv1::__forced_unwind&)
840 this->_M_setstate(ios_base::badbit);
841 __throw_exception_again;
844 { this->_M_setstate(ios_base::badbit); }
846 this->setstate(__err);
851 template<typename _CharT, typename _Traits>
852 typename basic_istream<_CharT, _Traits>::pos_type
853 basic_istream<_CharT, _Traits>::
856 // _GLIBCXX_RESOLVE_LIB_DEFECTS
857 // DR60. Do not change _M_gcount.
858 pos_type __ret = pos_type(-1);
859 sentry __cerb(*this, true);
865 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
868 __catch(__cxxabiv1::__forced_unwind&)
870 this->_M_setstate(ios_base::badbit);
871 __throw_exception_again;
874 { this->_M_setstate(ios_base::badbit); }
879 template<typename _CharT, typename _Traits>
880 basic_istream<_CharT, _Traits>&
881 basic_istream<_CharT, _Traits>::
882 seekg(pos_type __pos)
884 // _GLIBCXX_RESOLVE_LIB_DEFECTS
885 // DR60. Do not change _M_gcount.
886 // Clear eofbit per N3168.
887 this->clear(this->rdstate() & ~ios_base::eofbit);
888 sentry __cerb(*this, true);
891 ios_base::iostate __err = ios_base::goodbit;
896 // 136. seekp, seekg setting wrong streams?
897 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
900 // 129. Need error indication from seekp() and seekg()
901 if (__p == pos_type(off_type(-1)))
902 __err |= ios_base::failbit;
905 __catch(__cxxabiv1::__forced_unwind&)
907 this->_M_setstate(ios_base::badbit);
908 __throw_exception_again;
911 { this->_M_setstate(ios_base::badbit); }
913 this->setstate(__err);
918 template<typename _CharT, typename _Traits>
919 basic_istream<_CharT, _Traits>&
920 basic_istream<_CharT, _Traits>::
921 seekg(off_type __off, ios_base::seekdir __dir)
923 // _GLIBCXX_RESOLVE_LIB_DEFECTS
924 // DR60. Do not change _M_gcount.
925 // Clear eofbit per N3168.
926 this->clear(this->rdstate() & ~ios_base::eofbit);
927 sentry __cerb(*this, true);
930 ios_base::iostate __err = ios_base::goodbit;
935 // 136. seekp, seekg setting wrong streams?
936 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
939 // 129. Need error indication from seekp() and seekg()
940 if (__p == pos_type(off_type(-1)))
941 __err |= ios_base::failbit;
944 __catch(__cxxabiv1::__forced_unwind&)
946 this->_M_setstate(ios_base::badbit);
947 __throw_exception_again;
950 { this->_M_setstate(ios_base::badbit); }
952 this->setstate(__err);
957 // 27.6.1.2.3 Character extraction templates
958 template<typename _CharT, typename _Traits>
959 basic_istream<_CharT, _Traits>&
960 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
962 typedef basic_istream<_CharT, _Traits> __istream_type;
963 typedef typename __istream_type::int_type __int_type;
965 typename __istream_type::sentry __cerb(__in, false);
968 ios_base::iostate __err = ios_base::goodbit;
971 const __int_type __cb = __in.rdbuf()->sbumpc();
972 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
973 __c = _Traits::to_char_type(__cb);
975 __err |= (ios_base::eofbit | ios_base::failbit);
977 __catch(__cxxabiv1::__forced_unwind&)
979 __in._M_setstate(ios_base::badbit);
980 __throw_exception_again;
983 { __in._M_setstate(ios_base::badbit); }
985 __in.setstate(__err);
990 template<typename _CharT, typename _Traits>
992 __istream_extract(basic_istream<_CharT, _Traits>& __in, _CharT* __s,
995 typedef basic_istream<_CharT, _Traits> __istream_type;
996 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
997 typedef typename _Traits::int_type int_type;
998 typedef _CharT char_type;
999 typedef ctype<_CharT> __ctype_type;
1001 streamsize __extracted = 0;
1002 ios_base::iostate __err = ios_base::goodbit;
1003 typename __istream_type::sentry __cerb(__in, false);
1008 // Figure out how many characters to extract.
1009 streamsize __width = __in.width();
1010 if (0 < __width && __width < __num)
1013 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1015 const int_type __eof = _Traits::eof();
1016 __streambuf_type* __sb = __in.rdbuf();
1017 int_type __c = __sb->sgetc();
1019 while (__extracted < __num - 1
1020 && !_Traits::eq_int_type(__c, __eof)
1021 && !__ct.is(ctype_base::space,
1022 _Traits::to_char_type(__c)))
1024 *__s++ = _Traits::to_char_type(__c);
1026 __c = __sb->snextc();
1029 if (__extracted < __num - 1
1030 && _Traits::eq_int_type(__c, __eof))
1031 __err |= ios_base::eofbit;
1033 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1034 // 68. Extractors for char* should store null at end
1038 __catch(__cxxabiv1::__forced_unwind&)
1040 __in._M_setstate(ios_base::badbit);
1041 __throw_exception_again;
1044 { __in._M_setstate(ios_base::badbit); }
1047 __err |= ios_base::failbit;
1049 __in.setstate(__err);
1052 // 27.6.1.4 Standard basic_istream manipulators
1053 template<typename _CharT, typename _Traits>
1054 basic_istream<_CharT, _Traits>&
1055 ws(basic_istream<_CharT, _Traits>& __in)
1057 typedef basic_istream<_CharT, _Traits> __istream_type;
1058 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1059 typedef typename __istream_type::int_type __int_type;
1060 typedef ctype<_CharT> __ctype_type;
1062 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1063 // 451. behavior of std::ws
1064 typename __istream_type::sentry __cerb(__in, true);
1067 ios_base::iostate __err = ios_base::goodbit;
1070 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1071 const __int_type __eof = _Traits::eof();
1072 __streambuf_type* __sb = __in.rdbuf();
1073 __int_type __c = __sb->sgetc();
1077 if (_Traits::eq_int_type(__c, __eof))
1079 __err = ios_base::eofbit;
1082 if (!__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1084 __c = __sb->snextc();
1087 __catch (const __cxxabiv1::__forced_unwind&)
1089 __in._M_setstate(ios_base::badbit);
1090 __throw_exception_again;
1094 __in._M_setstate(ios_base::badbit);
1097 __in.setstate(__err);
1102 // Inhibit implicit instantiations for required instantiations,
1103 // which are defined via explicit instantiations elsewhere.
1104 #if _GLIBCXX_EXTERN_TEMPLATE
1105 extern template class basic_istream<char>;
1106 extern template istream& ws(istream&);
1107 extern template istream& operator>>(istream&, char&);
1108 extern template istream& operator>>(istream&, unsigned char&);
1109 extern template istream& operator>>(istream&, signed char&);
1111 extern template istream& istream::_M_extract(unsigned short&);
1112 extern template istream& istream::_M_extract(unsigned int&);
1113 extern template istream& istream::_M_extract(long&);
1114 extern template istream& istream::_M_extract(unsigned long&);
1115 extern template istream& istream::_M_extract(bool&);
1116 #ifdef _GLIBCXX_USE_LONG_LONG
1117 extern template istream& istream::_M_extract(long long&);
1118 extern template istream& istream::_M_extract(unsigned long long&);
1120 extern template istream& istream::_M_extract(float&);
1121 extern template istream& istream::_M_extract(double&);
1122 extern template istream& istream::_M_extract(long double&);
1123 extern template istream& istream::_M_extract(void*&);
1125 extern template class basic_iostream<char>;
1127 #ifdef _GLIBCXX_USE_WCHAR_T
1128 extern template class basic_istream<wchar_t>;
1129 extern template wistream& ws(wistream&);
1130 extern template wistream& operator>>(wistream&, wchar_t&);
1131 extern template void __istream_extract(wistream&, wchar_t*, streamsize);
1133 extern template wistream& wistream::_M_extract(unsigned short&);
1134 extern template wistream& wistream::_M_extract(unsigned int&);
1135 extern template wistream& wistream::_M_extract(long&);
1136 extern template wistream& wistream::_M_extract(unsigned long&);
1137 extern template wistream& wistream::_M_extract(bool&);
1138 #ifdef _GLIBCXX_USE_LONG_LONG
1139 extern template wistream& wistream::_M_extract(long long&);
1140 extern template wistream& wistream::_M_extract(unsigned long long&);
1142 extern template wistream& wistream::_M_extract(float&);
1143 extern template wistream& wistream::_M_extract(double&);
1144 extern template wistream& wistream::_M_extract(long double&);
1145 extern template wistream& wistream::_M_extract(void*&);
1147 extern template class basic_iostream<wchar_t>;
1151 _GLIBCXX_END_NAMESPACE_VERSION