1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file bits/istream.tcc
28 * This is an internal header file, included by other library headers.
29 * Do not attempt to use it directly. @headername{istream}
33 // ISO C++ 14882: 27.6.1 Input streams
37 #define _ISTREAM_TCC 1
39 #pragma GCC system_header
41 #include <bits/cxxabi_forced.h>
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<typename _CharT, typename _Traits>
48 basic_istream<_CharT, _Traits>::sentry::
49 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
51 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;
76 if (__in.good() && __err == ios_base::goodbit)
80 __err |= ios_base::failbit;
85 template<typename _CharT, typename _Traits>
86 template<typename _ValueT>
87 basic_istream<_CharT, _Traits>&
88 basic_istream<_CharT, _Traits>::
89 _M_extract(_ValueT& __v)
91 sentry __cerb(*this, false);
94 ios_base::iostate __err = ios_base::goodbit;
97 const __num_get_type& __ng = __check_facet(this->_M_num_get);
98 __ng.get(*this, 0, *this, __err, __v);
100 __catch(__cxxabiv1::__forced_unwind&)
102 this->_M_setstate(ios_base::badbit);
103 __throw_exception_again;
106 { this->_M_setstate(ios_base::badbit); }
108 this->setstate(__err);
113 template<typename _CharT, typename _Traits>
114 basic_istream<_CharT, _Traits>&
115 basic_istream<_CharT, _Traits>::
116 operator>>(short& __n)
118 // _GLIBCXX_RESOLVE_LIB_DEFECTS
119 // 118. basic_istream uses nonexistent num_get member functions.
120 sentry __cerb(*this, false);
123 ios_base::iostate __err = ios_base::goodbit;
127 const __num_get_type& __ng = __check_facet(this->_M_num_get);
128 __ng.get(*this, 0, *this, __err, __l);
130 // _GLIBCXX_RESOLVE_LIB_DEFECTS
131 // 696. istream::operator>>(int&) broken.
132 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
134 __err |= ios_base::failbit;
135 __n = __gnu_cxx::__numeric_traits<short>::__min;
137 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
139 __err |= ios_base::failbit;
140 __n = __gnu_cxx::__numeric_traits<short>::__max;
145 __catch(__cxxabiv1::__forced_unwind&)
147 this->_M_setstate(ios_base::badbit);
148 __throw_exception_again;
151 { this->_M_setstate(ios_base::badbit); }
153 this->setstate(__err);
158 template<typename _CharT, typename _Traits>
159 basic_istream<_CharT, _Traits>&
160 basic_istream<_CharT, _Traits>::
163 // _GLIBCXX_RESOLVE_LIB_DEFECTS
164 // 118. basic_istream uses nonexistent num_get member functions.
165 sentry __cerb(*this, false);
168 ios_base::iostate __err = ios_base::goodbit;
172 const __num_get_type& __ng = __check_facet(this->_M_num_get);
173 __ng.get(*this, 0, *this, __err, __l);
175 // _GLIBCXX_RESOLVE_LIB_DEFECTS
176 // 696. istream::operator>>(int&) broken.
177 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
179 __err |= ios_base::failbit;
180 __n = __gnu_cxx::__numeric_traits<int>::__min;
182 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
184 __err |= ios_base::failbit;
185 __n = __gnu_cxx::__numeric_traits<int>::__max;
190 __catch(__cxxabiv1::__forced_unwind&)
192 this->_M_setstate(ios_base::badbit);
193 __throw_exception_again;
196 { this->_M_setstate(ios_base::badbit); }
198 this->setstate(__err);
203 template<typename _CharT, typename _Traits>
204 basic_istream<_CharT, _Traits>&
205 basic_istream<_CharT, _Traits>::
206 operator>>(__streambuf_type* __sbout)
208 ios_base::iostate __err = ios_base::goodbit;
209 sentry __cerb(*this, false);
210 if (__cerb && __sbout)
215 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
216 __err |= ios_base::failbit;
218 __err |= ios_base::eofbit;
220 __catch(__cxxabiv1::__forced_unwind&)
222 this->_M_setstate(ios_base::failbit);
223 __throw_exception_again;
226 { this->_M_setstate(ios_base::failbit); }
229 __err |= ios_base::failbit;
231 this->setstate(__err);
235 template<typename _CharT, typename _Traits>
236 typename basic_istream<_CharT, _Traits>::int_type
237 basic_istream<_CharT, _Traits>::
240 const int_type __eof = traits_type::eof();
241 int_type __c = __eof;
243 ios_base::iostate __err = ios_base::goodbit;
244 sentry __cerb(*this, true);
249 __c = this->rdbuf()->sbumpc();
250 // 27.6.1.1 paragraph 3
251 if (!traits_type::eq_int_type(__c, __eof))
254 __err |= ios_base::eofbit;
256 __catch(__cxxabiv1::__forced_unwind&)
258 this->_M_setstate(ios_base::badbit);
259 __throw_exception_again;
262 { this->_M_setstate(ios_base::badbit); }
265 __err |= ios_base::failbit;
267 this->setstate(__err);
271 template<typename _CharT, typename _Traits>
272 basic_istream<_CharT, _Traits>&
273 basic_istream<_CharT, _Traits>::
277 ios_base::iostate __err = ios_base::goodbit;
278 sentry __cerb(*this, true);
283 const int_type __cb = this->rdbuf()->sbumpc();
284 // 27.6.1.1 paragraph 3
285 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
288 __c = traits_type::to_char_type(__cb);
291 __err |= ios_base::eofbit;
293 __catch(__cxxabiv1::__forced_unwind&)
295 this->_M_setstate(ios_base::badbit);
296 __throw_exception_again;
299 { this->_M_setstate(ios_base::badbit); }
302 __err |= ios_base::failbit;
304 this->setstate(__err);
308 template<typename _CharT, typename _Traits>
309 basic_istream<_CharT, _Traits>&
310 basic_istream<_CharT, _Traits>::
311 get(char_type* __s, streamsize __n, char_type __delim)
314 ios_base::iostate __err = ios_base::goodbit;
315 sentry __cerb(*this, true);
320 const int_type __idelim = traits_type::to_int_type(__delim);
321 const int_type __eof = traits_type::eof();
322 __streambuf_type* __sb = this->rdbuf();
323 int_type __c = __sb->sgetc();
325 while (_M_gcount + 1 < __n
326 && !traits_type::eq_int_type(__c, __eof)
327 && !traits_type::eq_int_type(__c, __idelim))
329 *__s++ = traits_type::to_char_type(__c);
331 __c = __sb->snextc();
333 if (traits_type::eq_int_type(__c, __eof))
334 __err |= ios_base::eofbit;
336 __catch(__cxxabiv1::__forced_unwind&)
338 this->_M_setstate(ios_base::badbit);
339 __throw_exception_again;
342 { this->_M_setstate(ios_base::badbit); }
344 // _GLIBCXX_RESOLVE_LIB_DEFECTS
345 // 243. get and getline when sentry reports failure.
349 __err |= ios_base::failbit;
351 this->setstate(__err);
355 template<typename _CharT, typename _Traits>
356 basic_istream<_CharT, _Traits>&
357 basic_istream<_CharT, _Traits>::
358 get(__streambuf_type& __sb, char_type __delim)
361 ios_base::iostate __err = ios_base::goodbit;
362 sentry __cerb(*this, true);
367 const int_type __idelim = traits_type::to_int_type(__delim);
368 const int_type __eof = traits_type::eof();
369 __streambuf_type* __this_sb = this->rdbuf();
370 int_type __c = __this_sb->sgetc();
371 char_type __c2 = traits_type::to_char_type(__c);
373 while (!traits_type::eq_int_type(__c, __eof)
374 && !traits_type::eq_int_type(__c, __idelim)
375 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
378 __c = __this_sb->snextc();
379 __c2 = traits_type::to_char_type(__c);
381 if (traits_type::eq_int_type(__c, __eof))
382 __err |= ios_base::eofbit;
384 __catch(__cxxabiv1::__forced_unwind&)
386 this->_M_setstate(ios_base::badbit);
387 __throw_exception_again;
390 { this->_M_setstate(ios_base::badbit); }
393 __err |= ios_base::failbit;
395 this->setstate(__err);
399 template<typename _CharT, typename _Traits>
400 basic_istream<_CharT, _Traits>&
401 basic_istream<_CharT, _Traits>::
402 getline(char_type* __s, streamsize __n, char_type __delim)
405 ios_base::iostate __err = ios_base::goodbit;
406 sentry __cerb(*this, true);
411 const int_type __idelim = traits_type::to_int_type(__delim);
412 const int_type __eof = traits_type::eof();
413 __streambuf_type* __sb = this->rdbuf();
414 int_type __c = __sb->sgetc();
416 while (_M_gcount + 1 < __n
417 && !traits_type::eq_int_type(__c, __eof)
418 && !traits_type::eq_int_type(__c, __idelim))
420 *__s++ = traits_type::to_char_type(__c);
421 __c = __sb->snextc();
424 if (traits_type::eq_int_type(__c, __eof))
425 __err |= ios_base::eofbit;
428 if (traits_type::eq_int_type(__c, __idelim))
434 __err |= ios_base::failbit;
437 __catch(__cxxabiv1::__forced_unwind&)
439 this->_M_setstate(ios_base::badbit);
440 __throw_exception_again;
443 { this->_M_setstate(ios_base::badbit); }
445 // _GLIBCXX_RESOLVE_LIB_DEFECTS
446 // 243. get and getline when sentry reports failure.
450 __err |= ios_base::failbit;
452 this->setstate(__err);
456 // We provide three overloads, since the first two are much simpler
457 // than the general case. Also, the latter two can thus adopt the
458 // same "batchy" strategy used by getline above.
459 template<typename _CharT, typename _Traits>
460 basic_istream<_CharT, _Traits>&
461 basic_istream<_CharT, _Traits>::
465 sentry __cerb(*this, true);
468 ios_base::iostate __err = ios_base::goodbit;
471 const int_type __eof = traits_type::eof();
472 __streambuf_type* __sb = this->rdbuf();
474 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
475 __err |= ios_base::eofbit;
479 __catch(__cxxabiv1::__forced_unwind&)
481 this->_M_setstate(ios_base::badbit);
482 __throw_exception_again;
485 { this->_M_setstate(ios_base::badbit); }
487 this->setstate(__err);
492 template<typename _CharT, typename _Traits>
493 basic_istream<_CharT, _Traits>&
494 basic_istream<_CharT, _Traits>::
495 ignore(streamsize __n)
498 sentry __cerb(*this, true);
499 if (__cerb && __n > 0)
501 ios_base::iostate __err = ios_base::goodbit;
504 const int_type __eof = traits_type::eof();
505 __streambuf_type* __sb = this->rdbuf();
506 int_type __c = __sb->sgetc();
508 // N.B. On LFS-enabled platforms streamsize is still 32 bits
509 // wide: if we want to implement the standard mandated behavior
510 // for n == max() (see 27.6.1.3/24) we are at risk of signed
511 // integer overflow: thus these contortions. Also note that,
512 // by definition, when more than 2G chars are actually ignored,
513 // _M_gcount (the return value of gcount, that is) cannot be
514 // really correct, being unavoidably too small.
515 bool __large_ignore = false;
518 while (_M_gcount < __n
519 && !traits_type::eq_int_type(__c, __eof))
522 __c = __sb->snextc();
524 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
525 && !traits_type::eq_int_type(__c, __eof))
528 __gnu_cxx::__numeric_traits<streamsize>::__min;
529 __large_ignore = true;
536 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
538 if (traits_type::eq_int_type(__c, __eof))
539 __err |= ios_base::eofbit;
541 __catch(__cxxabiv1::__forced_unwind&)
543 this->_M_setstate(ios_base::badbit);
544 __throw_exception_again;
547 { this->_M_setstate(ios_base::badbit); }
549 this->setstate(__err);
554 template<typename _CharT, typename _Traits>
555 basic_istream<_CharT, _Traits>&
556 basic_istream<_CharT, _Traits>::
557 ignore(streamsize __n, int_type __delim)
560 sentry __cerb(*this, true);
561 if (__cerb && __n > 0)
563 ios_base::iostate __err = ios_base::goodbit;
566 const int_type __eof = traits_type::eof();
567 __streambuf_type* __sb = this->rdbuf();
568 int_type __c = __sb->sgetc();
570 // See comment above.
571 bool __large_ignore = false;
574 while (_M_gcount < __n
575 && !traits_type::eq_int_type(__c, __eof)
576 && !traits_type::eq_int_type(__c, __delim))
579 __c = __sb->snextc();
581 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
582 && !traits_type::eq_int_type(__c, __eof)
583 && !traits_type::eq_int_type(__c, __delim))
586 __gnu_cxx::__numeric_traits<streamsize>::__min;
587 __large_ignore = true;
594 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
596 if (traits_type::eq_int_type(__c, __eof))
597 __err |= ios_base::eofbit;
598 else if (traits_type::eq_int_type(__c, __delim))
601 < __gnu_cxx::__numeric_traits<streamsize>::__max)
606 __catch(__cxxabiv1::__forced_unwind&)
608 this->_M_setstate(ios_base::badbit);
609 __throw_exception_again;
612 { this->_M_setstate(ios_base::badbit); }
614 this->setstate(__err);
619 template<typename _CharT, typename _Traits>
620 typename basic_istream<_CharT, _Traits>::int_type
621 basic_istream<_CharT, _Traits>::
624 int_type __c = traits_type::eof();
626 sentry __cerb(*this, true);
629 ios_base::iostate __err = ios_base::goodbit;
632 __c = this->rdbuf()->sgetc();
633 if (traits_type::eq_int_type(__c, traits_type::eof()))
634 __err |= ios_base::eofbit;
636 __catch(__cxxabiv1::__forced_unwind&)
638 this->_M_setstate(ios_base::badbit);
639 __throw_exception_again;
642 { this->_M_setstate(ios_base::badbit); }
644 this->setstate(__err);
649 template<typename _CharT, typename _Traits>
650 basic_istream<_CharT, _Traits>&
651 basic_istream<_CharT, _Traits>::
652 read(char_type* __s, streamsize __n)
655 sentry __cerb(*this, true);
658 ios_base::iostate __err = ios_base::goodbit;
661 _M_gcount = this->rdbuf()->sgetn(__s, __n);
662 if (_M_gcount != __n)
663 __err |= (ios_base::eofbit | ios_base::failbit);
665 __catch(__cxxabiv1::__forced_unwind&)
667 this->_M_setstate(ios_base::badbit);
668 __throw_exception_again;
671 { this->_M_setstate(ios_base::badbit); }
673 this->setstate(__err);
678 template<typename _CharT, typename _Traits>
680 basic_istream<_CharT, _Traits>::
681 readsome(char_type* __s, streamsize __n)
684 sentry __cerb(*this, true);
687 ios_base::iostate __err = ios_base::goodbit;
690 // Cannot compare int_type with streamsize generically.
691 const streamsize __num = this->rdbuf()->in_avail();
693 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
694 else if (__num == -1)
695 __err |= ios_base::eofbit;
697 __catch(__cxxabiv1::__forced_unwind&)
699 this->_M_setstate(ios_base::badbit);
700 __throw_exception_again;
703 { this->_M_setstate(ios_base::badbit); }
705 this->setstate(__err);
710 template<typename _CharT, typename _Traits>
711 basic_istream<_CharT, _Traits>&
712 basic_istream<_CharT, _Traits>::
713 putback(char_type __c)
715 // _GLIBCXX_RESOLVE_LIB_DEFECTS
716 // 60. What is a formatted input function?
718 // Clear eofbit per N3168.
719 this->clear(this->rdstate() & ~ios_base::eofbit);
720 sentry __cerb(*this, true);
723 ios_base::iostate __err = ios_base::goodbit;
726 const int_type __eof = traits_type::eof();
727 __streambuf_type* __sb = this->rdbuf();
729 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
730 __err |= ios_base::badbit;
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>::
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->sungetc(), __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>
782 basic_istream<_CharT, _Traits>::
785 // _GLIBCXX_RESOLVE_LIB_DEFECTS
786 // DR60. Do not change _M_gcount.
788 sentry __cerb(*this, true);
791 ios_base::iostate __err = ios_base::goodbit;
794 __streambuf_type* __sb = this->rdbuf();
797 if (__sb->pubsync() == -1)
798 __err |= ios_base::badbit;
803 __catch(__cxxabiv1::__forced_unwind&)
805 this->_M_setstate(ios_base::badbit);
806 __throw_exception_again;
809 { this->_M_setstate(ios_base::badbit); }
811 this->setstate(__err);
816 template<typename _CharT, typename _Traits>
817 typename basic_istream<_CharT, _Traits>::pos_type
818 basic_istream<_CharT, _Traits>::
821 // _GLIBCXX_RESOLVE_LIB_DEFECTS
822 // DR60. Do not change _M_gcount.
823 pos_type __ret = pos_type(-1);
824 sentry __cerb(*this, true);
830 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
833 __catch(__cxxabiv1::__forced_unwind&)
835 this->_M_setstate(ios_base::badbit);
836 __throw_exception_again;
839 { this->_M_setstate(ios_base::badbit); }
844 template<typename _CharT, typename _Traits>
845 basic_istream<_CharT, _Traits>&
846 basic_istream<_CharT, _Traits>::
847 seekg(pos_type __pos)
849 // _GLIBCXX_RESOLVE_LIB_DEFECTS
850 // DR60. Do not change _M_gcount.
851 // Clear eofbit per N3168.
852 this->clear(this->rdstate() & ~ios_base::eofbit);
853 sentry __cerb(*this, true);
856 ios_base::iostate __err = ios_base::goodbit;
861 // 136. seekp, seekg setting wrong streams?
862 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
865 // 129. Need error indication from seekp() and seekg()
866 if (__p == pos_type(off_type(-1)))
867 __err |= ios_base::failbit;
870 __catch(__cxxabiv1::__forced_unwind&)
872 this->_M_setstate(ios_base::badbit);
873 __throw_exception_again;
876 { this->_M_setstate(ios_base::badbit); }
878 this->setstate(__err);
883 template<typename _CharT, typename _Traits>
884 basic_istream<_CharT, _Traits>&
885 basic_istream<_CharT, _Traits>::
886 seekg(off_type __off, ios_base::seekdir __dir)
888 // _GLIBCXX_RESOLVE_LIB_DEFECTS
889 // DR60. Do not change _M_gcount.
890 // Clear eofbit per N3168.
891 this->clear(this->rdstate() & ~ios_base::eofbit);
892 sentry __cerb(*this, true);
895 ios_base::iostate __err = ios_base::goodbit;
900 // 136. seekp, seekg setting wrong streams?
901 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
904 // 129. Need error indication from seekp() and seekg()
905 if (__p == pos_type(off_type(-1)))
906 __err |= ios_base::failbit;
909 __catch(__cxxabiv1::__forced_unwind&)
911 this->_M_setstate(ios_base::badbit);
912 __throw_exception_again;
915 { this->_M_setstate(ios_base::badbit); }
917 this->setstate(__err);
922 // 27.6.1.2.3 Character extraction templates
923 template<typename _CharT, typename _Traits>
924 basic_istream<_CharT, _Traits>&
925 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
927 typedef basic_istream<_CharT, _Traits> __istream_type;
928 typedef typename __istream_type::int_type __int_type;
930 typename __istream_type::sentry __cerb(__in, false);
933 ios_base::iostate __err = ios_base::goodbit;
936 const __int_type __cb = __in.rdbuf()->sbumpc();
937 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
938 __c = _Traits::to_char_type(__cb);
940 __err |= (ios_base::eofbit | ios_base::failbit);
942 __catch(__cxxabiv1::__forced_unwind&)
944 __in._M_setstate(ios_base::badbit);
945 __throw_exception_again;
948 { __in._M_setstate(ios_base::badbit); }
950 __in.setstate(__err);
955 template<typename _CharT, typename _Traits>
956 basic_istream<_CharT, _Traits>&
957 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
959 typedef basic_istream<_CharT, _Traits> __istream_type;
960 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
961 typedef typename _Traits::int_type int_type;
962 typedef _CharT char_type;
963 typedef ctype<_CharT> __ctype_type;
965 streamsize __extracted = 0;
966 ios_base::iostate __err = ios_base::goodbit;
967 typename __istream_type::sentry __cerb(__in, false);
972 // Figure out how many characters to extract.
973 streamsize __num = __in.width();
975 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
977 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
979 const int_type __eof = _Traits::eof();
980 __streambuf_type* __sb = __in.rdbuf();
981 int_type __c = __sb->sgetc();
983 while (__extracted < __num - 1
984 && !_Traits::eq_int_type(__c, __eof)
985 && !__ct.is(ctype_base::space,
986 _Traits::to_char_type(__c)))
988 *__s++ = _Traits::to_char_type(__c);
990 __c = __sb->snextc();
992 if (_Traits::eq_int_type(__c, __eof))
993 __err |= ios_base::eofbit;
995 // _GLIBCXX_RESOLVE_LIB_DEFECTS
996 // 68. Extractors for char* should store null at end
1000 __catch(__cxxabiv1::__forced_unwind&)
1002 __in._M_setstate(ios_base::badbit);
1003 __throw_exception_again;
1006 { __in._M_setstate(ios_base::badbit); }
1009 __err |= ios_base::failbit;
1011 __in.setstate(__err);
1015 // 27.6.1.4 Standard basic_istream manipulators
1016 template<typename _CharT, typename _Traits>
1017 basic_istream<_CharT, _Traits>&
1018 ws(basic_istream<_CharT, _Traits>& __in)
1020 typedef basic_istream<_CharT, _Traits> __istream_type;
1021 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1022 typedef typename __istream_type::int_type __int_type;
1023 typedef ctype<_CharT> __ctype_type;
1025 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1026 const __int_type __eof = _Traits::eof();
1027 __streambuf_type* __sb = __in.rdbuf();
1028 __int_type __c = __sb->sgetc();
1030 while (!_Traits::eq_int_type(__c, __eof)
1031 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1032 __c = __sb->snextc();
1034 if (_Traits::eq_int_type(__c, __eof))
1035 __in.setstate(ios_base::eofbit);
1039 // Inhibit implicit instantiations for required instantiations,
1040 // which are defined via explicit instantiations elsewhere.
1041 #if _GLIBCXX_EXTERN_TEMPLATE
1042 extern template class basic_istream<char>;
1043 extern template istream& ws(istream&);
1044 extern template istream& operator>>(istream&, char&);
1045 extern template istream& operator>>(istream&, char*);
1046 extern template istream& operator>>(istream&, unsigned char&);
1047 extern template istream& operator>>(istream&, signed char&);
1048 extern template istream& operator>>(istream&, unsigned char*);
1049 extern template istream& operator>>(istream&, signed char*);
1051 extern template istream& istream::_M_extract(unsigned short&);
1052 extern template istream& istream::_M_extract(unsigned int&);
1053 extern template istream& istream::_M_extract(long&);
1054 extern template istream& istream::_M_extract(unsigned long&);
1055 extern template istream& istream::_M_extract(bool&);
1056 #ifdef _GLIBCXX_USE_LONG_LONG
1057 extern template istream& istream::_M_extract(long long&);
1058 extern template istream& istream::_M_extract(unsigned long long&);
1060 extern template istream& istream::_M_extract(float&);
1061 extern template istream& istream::_M_extract(double&);
1062 extern template istream& istream::_M_extract(long double&);
1063 extern template istream& istream::_M_extract(void*&);
1065 extern template class basic_iostream<char>;
1067 #ifdef _GLIBCXX_USE_WCHAR_T
1068 extern template class basic_istream<wchar_t>;
1069 extern template wistream& ws(wistream&);
1070 extern template wistream& operator>>(wistream&, wchar_t&);
1071 extern template wistream& operator>>(wistream&, wchar_t*);
1073 extern template wistream& wistream::_M_extract(unsigned short&);
1074 extern template wistream& wistream::_M_extract(unsigned int&);
1075 extern template wistream& wistream::_M_extract(long&);
1076 extern template wistream& wistream::_M_extract(unsigned long&);
1077 extern template wistream& wistream::_M_extract(bool&);
1078 #ifdef _GLIBCXX_USE_LONG_LONG
1079 extern template wistream& wistream::_M_extract(long long&);
1080 extern template wistream& wistream::_M_extract(unsigned long long&);
1082 extern template wistream& wistream::_M_extract(float&);
1083 extern template wistream& wistream::_M_extract(double&);
1084 extern template wistream& wistream::_M_extract(long double&);
1085 extern template wistream& wistream::_M_extract(void*&);
1087 extern template class basic_iostream<wchar_t>;
1091 _GLIBCXX_END_NAMESPACE_VERSION