2 //===--------------------------- istream ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_ISTREAM
12 #define _LIBCPP_ISTREAM
17 template <class charT, class traits = char_traits<charT> >
19 : virtual public basic_ios<charT,traits>
22 // types (inherited from basic_ios (27.5.4)):
23 typedef charT char_type;
24 typedef traits traits_type;
25 typedef typename traits_type::int_type int_type;
26 typedef typename traits_type::pos_type pos_type;
27 typedef typename traits_type::off_type off_type;
29 // 27.7.1.1.1 Constructor/destructor:
30 explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
31 basic_istream(basic_istream&& rhs);
32 virtual ~basic_istream();
34 // 27.7.1.1.2 Assign/swap:
35 basic_istream& operator=(basic_istream&& rhs);
36 void swap(basic_istream& rhs);
38 // 27.7.1.1.3 Prefix/suffix:
41 // 27.7.1.2 Formatted input:
42 basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
43 basic_istream& operator>>(basic_ios<char_type, traits_type>&
44 (*pf)(basic_ios<char_type, traits_type>&));
45 basic_istream& operator>>(ios_base& (*pf)(ios_base&));
46 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
47 basic_istream& operator>>(bool& n);
48 basic_istream& operator>>(short& n);
49 basic_istream& operator>>(unsigned short& n);
50 basic_istream& operator>>(int& n);
51 basic_istream& operator>>(unsigned int& n);
52 basic_istream& operator>>(long& n);
53 basic_istream& operator>>(unsigned long& n);
54 basic_istream& operator>>(long long& n);
55 basic_istream& operator>>(unsigned long long& n);
56 basic_istream& operator>>(float& f);
57 basic_istream& operator>>(double& f);
58 basic_istream& operator>>(long double& f);
59 basic_istream& operator>>(void*& p);
61 // 27.7.1.3 Unformatted input:
62 streamsize gcount() const;
64 basic_istream& get(char_type& c);
65 basic_istream& get(char_type* s, streamsize n);
66 basic_istream& get(char_type* s, streamsize n, char_type delim);
67 basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
68 basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
70 basic_istream& getline(char_type* s, streamsize n);
71 basic_istream& getline(char_type* s, streamsize n, char_type delim);
73 basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
75 basic_istream& read (char_type* s, streamsize n);
76 streamsize readsome(char_type* s, streamsize n);
78 basic_istream& putback(char_type c);
79 basic_istream& unget();
83 basic_istream& seekg(pos_type);
84 basic_istream& seekg(off_type, ios_base::seekdir);
86 basic_istream(const basic_istream& rhs) = delete;
87 basic_istream(basic_istream&& rhs);
88 // 27.7.2.1.2 Assign/swap:
89 basic_istream& operator=(const basic_istream& rhs) = delete;
90 basic_istream& operator=(basic_istream&& rhs);
91 void swap(basic_istream& rhs);
94 // 27.7.1.2.3 character extraction templates:
95 template<class charT, class traits>
96 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
98 template<class traits>
99 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
101 template<class traits>
102 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
104 template<class charT, class traits>
105 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
107 template<class traits>
108 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
110 template<class traits>
111 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
113 template <class charT, class traits>
115 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
117 typedef basic_istream<char> istream;
118 typedef basic_istream<wchar_t> wistream;
120 template <class charT, class traits = char_traits<charT> >
121 class basic_iostream :
122 public basic_istream<charT,traits>,
123 public basic_ostream<charT,traits>
127 typedef charT char_type;
128 typedef traits traits_type;
129 typedef typename traits_type::int_type int_type;
130 typedef typename traits_type::pos_type pos_type;
131 typedef typename traits_type::off_type off_type;
133 // constructor/destructor
134 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
135 basic_iostream(basic_iostream&& rhs);
136 virtual ~basic_iostream();
139 basic_iostream& operator=(basic_iostream&& rhs);
140 void swap(basic_iostream& rhs);
143 template <class charT, class traits>
145 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
147 typedef basic_iostream<char> iostream;
148 typedef basic_iostream<wchar_t> wiostream;
150 template <class charT, class traits>
151 basic_istream<charT,traits>&
152 ws(basic_istream<charT,traits>& is);
154 template <class charT, class traits, class T>
155 basic_istream<charT, traits>&
156 operator>>(basic_istream<charT, traits>&& is, T& x);
165 #include <__undef_min_max>
167 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
168 #pragma GCC system_header
171 _LIBCPP_BEGIN_NAMESPACE_STD
173 template <class _CharT, class _Traits>
174 class _LIBCPP_TYPE_VIS_ONLY basic_istream
175 : virtual public basic_ios<_CharT, _Traits>
179 // types (inherited from basic_ios (27.5.4)):
180 typedef _CharT char_type;
181 typedef _Traits traits_type;
182 typedef typename traits_type::int_type int_type;
183 typedef typename traits_type::pos_type pos_type;
184 typedef typename traits_type::off_type off_type;
186 // 27.7.1.1.1 Constructor/destructor:
187 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb);
188 virtual ~basic_istream();
190 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
191 _LIBCPP_INLINE_VISIBILITY
192 basic_istream(basic_istream&& __rhs);
194 // 27.7.1.1.2 Assign/swap:
195 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
196 _LIBCPP_INLINE_VISIBILITY
197 basic_istream& operator=(basic_istream&& __rhs);
199 void swap(basic_istream& __rhs);
201 #if _LIBCPP_STD_VER > 11
202 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
203 basic_istream (const basic_istream& __rhs) = delete;
204 basic_istream& operator=(const basic_istream& __rhs) = delete;
206 basic_istream (const basic_istream& __rhs); // not defined
207 basic_istream& operator=(const basic_istream& __rhs); // not defined
212 // 27.7.1.1.3 Prefix/suffix:
213 class _LIBCPP_TYPE_VIS_ONLY sentry;
215 // 27.7.1.2 Formatted input:
216 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
217 basic_istream& operator>>(basic_ios<char_type, traits_type>&
218 (*__pf)(basic_ios<char_type, traits_type>&));
219 basic_istream& operator>>(ios_base& (*__pf)(ios_base&));
220 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
221 basic_istream& operator>>(bool& __n);
222 basic_istream& operator>>(short& __n);
223 basic_istream& operator>>(unsigned short& __n);
224 basic_istream& operator>>(int& __n);
225 basic_istream& operator>>(unsigned int& __n);
226 basic_istream& operator>>(long& __n);
227 basic_istream& operator>>(unsigned long& __n);
228 basic_istream& operator>>(long long& __n);
229 basic_istream& operator>>(unsigned long long& __n);
230 basic_istream& operator>>(float& __f);
231 basic_istream& operator>>(double& __f);
232 basic_istream& operator>>(long double& __f);
233 basic_istream& operator>>(void*& __p);
235 // 27.7.1.3 Unformatted input:
236 _LIBCPP_INLINE_VISIBILITY
237 streamsize gcount() const {return __gc_;}
239 basic_istream& get(char_type& __c);
240 basic_istream& get(char_type* __s, streamsize __n);
241 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
242 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
243 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
245 basic_istream& getline(char_type* __s, streamsize __n);
246 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
248 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
250 basic_istream& read (char_type* __s, streamsize __n);
251 streamsize readsome(char_type* __s, streamsize __n);
253 basic_istream& putback(char_type __c);
254 basic_istream& unget();
258 basic_istream& seekg(pos_type __pos);
259 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
262 template <class _CharT, class _Traits>
263 class _LIBCPP_TYPE_VIS_ONLY basic_istream<_CharT, _Traits>::sentry
267 sentry(const sentry&); // = delete;
268 sentry& operator=(const sentry&); // = delete;
271 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
272 // ~sentry() = default;
274 _LIBCPP_INLINE_VISIBILITY
276 operator bool() const {return __ok_;}
279 template <class _CharT, class _Traits>
280 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
288 if (!__noskipws && (__is.flags() & ios_base::skipws))
290 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
291 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
294 for (; __i != __eof; ++__i)
295 if (!__ct.is(__ct.space, *__i))
298 __is.setstate(ios_base::failbit | ios_base::eofbit);
303 __is.setstate(ios_base::failbit);
306 template <class _CharT, class _Traits>
307 inline _LIBCPP_INLINE_VISIBILITY
308 basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
314 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
316 template <class _CharT, class _Traits>
317 inline _LIBCPP_INLINE_VISIBILITY
318 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
325 template <class _CharT, class _Traits>
326 inline _LIBCPP_INLINE_VISIBILITY
327 basic_istream<_CharT, _Traits>&
328 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
334 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
336 template <class _CharT, class _Traits>
337 basic_istream<_CharT, _Traits>::~basic_istream()
341 template <class _CharT, class _Traits>
342 inline _LIBCPP_INLINE_VISIBILITY
344 basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
346 _VSTD::swap(__gc_, __rhs.__gc_);
347 basic_ios<char_type, traits_type>::swap(__rhs);
350 template <class _CharT, class _Traits>
351 basic_istream<_CharT, _Traits>&
352 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
354 #ifndef _LIBCPP_NO_EXCEPTIONS
357 #endif // _LIBCPP_NO_EXCEPTIONS
361 typedef istreambuf_iterator<char_type, traits_type> _Ip;
362 typedef num_get<char_type, _Ip> _Fp;
363 ios_base::iostate __err = ios_base::goodbit;
364 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
365 this->setstate(__err);
367 #ifndef _LIBCPP_NO_EXCEPTIONS
371 this->__set_badbit_and_consider_rethrow();
373 #endif // _LIBCPP_NO_EXCEPTIONS
377 template <class _CharT, class _Traits>
378 basic_istream<_CharT, _Traits>&
379 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
381 #ifndef _LIBCPP_NO_EXCEPTIONS
384 #endif // _LIBCPP_NO_EXCEPTIONS
388 typedef istreambuf_iterator<char_type, traits_type> _Ip;
389 typedef num_get<char_type, _Ip> _Fp;
390 ios_base::iostate __err = ios_base::goodbit;
391 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
392 this->setstate(__err);
394 #ifndef _LIBCPP_NO_EXCEPTIONS
398 this->__set_badbit_and_consider_rethrow();
400 #endif // _LIBCPP_NO_EXCEPTIONS
404 template <class _CharT, class _Traits>
405 basic_istream<_CharT, _Traits>&
406 basic_istream<_CharT, _Traits>::operator>>(long& __n)
408 #ifndef _LIBCPP_NO_EXCEPTIONS
411 #endif // _LIBCPP_NO_EXCEPTIONS
415 typedef istreambuf_iterator<char_type, traits_type> _Ip;
416 typedef num_get<char_type, _Ip> _Fp;
417 ios_base::iostate __err = ios_base::goodbit;
418 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
419 this->setstate(__err);
421 #ifndef _LIBCPP_NO_EXCEPTIONS
425 this->__set_badbit_and_consider_rethrow();
427 #endif // _LIBCPP_NO_EXCEPTIONS
431 template <class _CharT, class _Traits>
432 basic_istream<_CharT, _Traits>&
433 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
435 #ifndef _LIBCPP_NO_EXCEPTIONS
438 #endif // _LIBCPP_NO_EXCEPTIONS
442 typedef istreambuf_iterator<char_type, traits_type> _Ip;
443 typedef num_get<char_type, _Ip> _Fp;
444 ios_base::iostate __err = ios_base::goodbit;
445 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
446 this->setstate(__err);
448 #ifndef _LIBCPP_NO_EXCEPTIONS
452 this->__set_badbit_and_consider_rethrow();
454 #endif // _LIBCPP_NO_EXCEPTIONS
458 template <class _CharT, class _Traits>
459 basic_istream<_CharT, _Traits>&
460 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
462 #ifndef _LIBCPP_NO_EXCEPTIONS
465 #endif // _LIBCPP_NO_EXCEPTIONS
469 typedef istreambuf_iterator<char_type, traits_type> _Ip;
470 typedef num_get<char_type, _Ip> _Fp;
471 ios_base::iostate __err = ios_base::goodbit;
472 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
473 this->setstate(__err);
475 #ifndef _LIBCPP_NO_EXCEPTIONS
479 this->__set_badbit_and_consider_rethrow();
481 #endif // _LIBCPP_NO_EXCEPTIONS
485 template <class _CharT, class _Traits>
486 basic_istream<_CharT, _Traits>&
487 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
489 #ifndef _LIBCPP_NO_EXCEPTIONS
492 #endif // _LIBCPP_NO_EXCEPTIONS
496 typedef istreambuf_iterator<char_type, traits_type> _Ip;
497 typedef num_get<char_type, _Ip> _Fp;
498 ios_base::iostate __err = ios_base::goodbit;
499 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
500 this->setstate(__err);
502 #ifndef _LIBCPP_NO_EXCEPTIONS
506 this->__set_badbit_and_consider_rethrow();
508 #endif // _LIBCPP_NO_EXCEPTIONS
512 template <class _CharT, class _Traits>
513 basic_istream<_CharT, _Traits>&
514 basic_istream<_CharT, _Traits>::operator>>(float& __n)
516 #ifndef _LIBCPP_NO_EXCEPTIONS
519 #endif // _LIBCPP_NO_EXCEPTIONS
523 typedef istreambuf_iterator<char_type, traits_type> _Ip;
524 typedef num_get<char_type, _Ip> _Fp;
525 ios_base::iostate __err = ios_base::goodbit;
526 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
527 this->setstate(__err);
529 #ifndef _LIBCPP_NO_EXCEPTIONS
533 this->__set_badbit_and_consider_rethrow();
535 #endif // _LIBCPP_NO_EXCEPTIONS
539 template <class _CharT, class _Traits>
540 basic_istream<_CharT, _Traits>&
541 basic_istream<_CharT, _Traits>::operator>>(double& __n)
543 #ifndef _LIBCPP_NO_EXCEPTIONS
546 #endif // _LIBCPP_NO_EXCEPTIONS
550 typedef istreambuf_iterator<char_type, traits_type> _Ip;
551 typedef num_get<char_type, _Ip> _Fp;
552 ios_base::iostate __err = ios_base::goodbit;
553 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
554 this->setstate(__err);
556 #ifndef _LIBCPP_NO_EXCEPTIONS
560 this->__set_badbit_and_consider_rethrow();
562 #endif // _LIBCPP_NO_EXCEPTIONS
566 template <class _CharT, class _Traits>
567 basic_istream<_CharT, _Traits>&
568 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
570 #ifndef _LIBCPP_NO_EXCEPTIONS
573 #endif // _LIBCPP_NO_EXCEPTIONS
577 typedef istreambuf_iterator<char_type, traits_type> _Ip;
578 typedef num_get<char_type, _Ip> _Fp;
579 ios_base::iostate __err = ios_base::goodbit;
580 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
581 this->setstate(__err);
583 #ifndef _LIBCPP_NO_EXCEPTIONS
587 this->__set_badbit_and_consider_rethrow();
589 #endif // _LIBCPP_NO_EXCEPTIONS
593 template <class _CharT, class _Traits>
594 basic_istream<_CharT, _Traits>&
595 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
597 #ifndef _LIBCPP_NO_EXCEPTIONS
600 #endif // _LIBCPP_NO_EXCEPTIONS
604 typedef istreambuf_iterator<char_type, traits_type> _Ip;
605 typedef num_get<char_type, _Ip> _Fp;
606 ios_base::iostate __err = ios_base::goodbit;
607 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
608 this->setstate(__err);
610 #ifndef _LIBCPP_NO_EXCEPTIONS
614 this->__set_badbit_and_consider_rethrow();
616 #endif // _LIBCPP_NO_EXCEPTIONS
620 template <class _CharT, class _Traits>
621 basic_istream<_CharT, _Traits>&
622 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
624 #ifndef _LIBCPP_NO_EXCEPTIONS
627 #endif // _LIBCPP_NO_EXCEPTIONS
631 typedef istreambuf_iterator<char_type, traits_type> _Ip;
632 typedef num_get<char_type, _Ip> _Fp;
633 ios_base::iostate __err = ios_base::goodbit;
634 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
635 this->setstate(__err);
637 #ifndef _LIBCPP_NO_EXCEPTIONS
641 this->__set_badbit_and_consider_rethrow();
643 #endif // _LIBCPP_NO_EXCEPTIONS
647 template <class _CharT, class _Traits>
648 basic_istream<_CharT, _Traits>&
649 basic_istream<_CharT, _Traits>::operator>>(short& __n)
651 #ifndef _LIBCPP_NO_EXCEPTIONS
654 #endif // _LIBCPP_NO_EXCEPTIONS
658 typedef istreambuf_iterator<char_type, traits_type> _Ip;
659 typedef num_get<char_type, _Ip> _Fp;
660 ios_base::iostate __err = ios_base::goodbit;
662 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
663 if (__temp < numeric_limits<short>::min())
665 __err |= ios_base::failbit;
666 __n = numeric_limits<short>::min();
668 else if (__temp > numeric_limits<short>::max())
670 __err |= ios_base::failbit;
671 __n = numeric_limits<short>::max();
674 __n = static_cast<short>(__temp);
675 this->setstate(__err);
677 #ifndef _LIBCPP_NO_EXCEPTIONS
681 this->__set_badbit_and_consider_rethrow();
683 #endif // _LIBCPP_NO_EXCEPTIONS
687 template <class _CharT, class _Traits>
688 basic_istream<_CharT, _Traits>&
689 basic_istream<_CharT, _Traits>::operator>>(int& __n)
691 #ifndef _LIBCPP_NO_EXCEPTIONS
694 #endif // _LIBCPP_NO_EXCEPTIONS
698 typedef istreambuf_iterator<char_type, traits_type> _Ip;
699 typedef num_get<char_type, _Ip> _Fp;
700 ios_base::iostate __err = ios_base::goodbit;
702 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
703 if (__temp < numeric_limits<int>::min())
705 __err |= ios_base::failbit;
706 __n = numeric_limits<int>::min();
708 else if (__temp > numeric_limits<int>::max())
710 __err |= ios_base::failbit;
711 __n = numeric_limits<int>::max();
714 __n = static_cast<int>(__temp);
715 this->setstate(__err);
717 #ifndef _LIBCPP_NO_EXCEPTIONS
721 this->__set_badbit_and_consider_rethrow();
723 #endif // _LIBCPP_NO_EXCEPTIONS
727 template <class _CharT, class _Traits>
728 inline _LIBCPP_INLINE_VISIBILITY
729 basic_istream<_CharT, _Traits>&
730 basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
735 template <class _CharT, class _Traits>
736 inline _LIBCPP_INLINE_VISIBILITY
737 basic_istream<_CharT, _Traits>&
738 basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
739 (*__pf)(basic_ios<char_type, traits_type>&))
745 template <class _CharT, class _Traits>
746 inline _LIBCPP_INLINE_VISIBILITY
747 basic_istream<_CharT, _Traits>&
748 basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
754 template<class _CharT, class _Traits>
755 basic_istream<_CharT, _Traits>&
756 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
758 #ifndef _LIBCPP_NO_EXCEPTIONS
761 #endif // _LIBCPP_NO_EXCEPTIONS
762 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
765 streamsize __n = __is.width();
767 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
769 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
770 ios_base::iostate __err = ios_base::goodbit;
773 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
774 if (_Traits::eq_int_type(__i, _Traits::eof()))
776 __err |= ios_base::eofbit;
779 _CharT __ch = _Traits::to_char_type(__i);
780 if (__ct.is(__ct.space, __ch))
784 __is.rdbuf()->sbumpc();
789 __err |= ios_base::failbit;
790 __is.setstate(__err);
792 #ifndef _LIBCPP_NO_EXCEPTIONS
796 __is.__set_badbit_and_consider_rethrow();
798 #endif // _LIBCPP_NO_EXCEPTIONS
802 template<class _Traits>
803 inline _LIBCPP_INLINE_VISIBILITY
804 basic_istream<char, _Traits>&
805 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
807 return __is >> (char*)__s;
810 template<class _Traits>
811 inline _LIBCPP_INLINE_VISIBILITY
812 basic_istream<char, _Traits>&
813 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
815 return __is >> (char*)__s;
818 template<class _CharT, class _Traits>
819 basic_istream<_CharT, _Traits>&
820 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
822 #ifndef _LIBCPP_NO_EXCEPTIONS
825 #endif // _LIBCPP_NO_EXCEPTIONS
826 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
829 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
830 if (_Traits::eq_int_type(__i, _Traits::eof()))
831 __is.setstate(ios_base::eofbit | ios_base::failbit);
833 __c = _Traits::to_char_type(__i);
835 #ifndef _LIBCPP_NO_EXCEPTIONS
839 __is.__set_badbit_and_consider_rethrow();
841 #endif // _LIBCPP_NO_EXCEPTIONS
845 template<class _Traits>
846 inline _LIBCPP_INLINE_VISIBILITY
847 basic_istream<char, _Traits>&
848 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
850 return __is >> (char&)__c;
853 template<class _Traits>
854 inline _LIBCPP_INLINE_VISIBILITY
855 basic_istream<char, _Traits>&
856 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
858 return __is >> (char&)__c;
861 template<class _CharT, class _Traits>
862 basic_istream<_CharT, _Traits>&
863 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
866 #ifndef _LIBCPP_NO_EXCEPTIONS
869 #endif // _LIBCPP_NO_EXCEPTIONS
870 sentry __s(*this, true);
875 #ifndef _LIBCPP_NO_EXCEPTIONS
878 #endif // _LIBCPP_NO_EXCEPTIONS
879 ios_base::iostate __err = ios_base::goodbit;
882 typename traits_type::int_type __i = this->rdbuf()->sgetc();
883 if (traits_type::eq_int_type(__i, _Traits::eof()))
885 __err |= ios_base::eofbit;
888 if (traits_type::eq_int_type(
889 __sb->sputc(traits_type::to_char_type(__i)),
893 this->rdbuf()->sbumpc();
896 __err |= ios_base::failbit;
897 this->setstate(__err);
898 #ifndef _LIBCPP_NO_EXCEPTIONS
903 this->__set_failbit_and_consider_rethrow();
905 #endif // _LIBCPP_NO_EXCEPTIONS
908 this->setstate(ios_base::failbit);
910 #ifndef _LIBCPP_NO_EXCEPTIONS
914 this->__set_badbit_and_consider_rethrow();
916 #endif // _LIBCPP_NO_EXCEPTIONS
920 template<class _CharT, class _Traits>
921 typename basic_istream<_CharT, _Traits>::int_type
922 basic_istream<_CharT, _Traits>::get()
925 int_type __r = traits_type::eof();
926 #ifndef _LIBCPP_NO_EXCEPTIONS
929 #endif // _LIBCPP_NO_EXCEPTIONS
930 sentry __s(*this, true);
933 __r = this->rdbuf()->sbumpc();
934 if (traits_type::eq_int_type(__r, traits_type::eof()))
935 this->setstate(ios_base::failbit | ios_base::eofbit);
939 #ifndef _LIBCPP_NO_EXCEPTIONS
943 this->__set_badbit_and_consider_rethrow();
945 #endif // _LIBCPP_NO_EXCEPTIONS
949 template<class _CharT, class _Traits>
950 inline _LIBCPP_INLINE_VISIBILITY
951 basic_istream<_CharT, _Traits>&
952 basic_istream<_CharT, _Traits>::get(char_type& __c)
954 int_type __ch = get();
955 if (__ch != traits_type::eof())
956 __c = traits_type::to_char_type(__ch);
960 template<class _CharT, class _Traits>
961 basic_istream<_CharT, _Traits>&
962 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
965 #ifndef _LIBCPP_NO_EXCEPTIONS
968 #endif // _LIBCPP_NO_EXCEPTIONS
969 sentry __sen(*this, true);
974 ios_base::iostate __err = ios_base::goodbit;
975 while (__gc_ < __n-1)
977 int_type __i = this->rdbuf()->sgetc();
978 if (traits_type::eq_int_type(__i, traits_type::eof()))
980 __err |= ios_base::eofbit;
983 char_type __ch = traits_type::to_char_type(__i);
984 if (traits_type::eq(__ch, __dlm))
988 this->rdbuf()->sbumpc();
992 __err |= ios_base::failbit;
993 this->setstate(__err);
996 this->setstate(ios_base::failbit);
998 #ifndef _LIBCPP_NO_EXCEPTIONS
1002 this->__set_badbit_and_consider_rethrow();
1004 #endif // _LIBCPP_NO_EXCEPTIONS
1008 template<class _CharT, class _Traits>
1009 inline _LIBCPP_INLINE_VISIBILITY
1010 basic_istream<_CharT, _Traits>&
1011 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1013 return get(__s, __n, this->widen('\n'));
1016 template<class _CharT, class _Traits>
1017 basic_istream<_CharT, _Traits>&
1018 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1022 #ifndef _LIBCPP_NO_EXCEPTIONS
1025 #endif // _LIBCPP_NO_EXCEPTIONS
1026 sentry __sen(*this, true);
1029 ios_base::iostate __err = ios_base::goodbit;
1030 #ifndef _LIBCPP_NO_EXCEPTIONS
1033 #endif // _LIBCPP_NO_EXCEPTIONS
1036 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1037 if (traits_type::eq_int_type(__i, traits_type::eof()))
1039 __err |= ios_base::eofbit;
1042 char_type __ch = traits_type::to_char_type(__i);
1043 if (traits_type::eq(__ch, __dlm))
1045 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
1048 this->rdbuf()->sbumpc();
1050 #ifndef _LIBCPP_NO_EXCEPTIONS
1055 #endif // _LIBCPP_NO_EXCEPTIONS
1057 __err |= ios_base::failbit;
1058 this->setstate(__err);
1060 #ifndef _LIBCPP_NO_EXCEPTIONS
1064 this->__set_badbit_and_consider_rethrow();
1066 #endif // _LIBCPP_NO_EXCEPTIONS
1070 template<class _CharT, class _Traits>
1071 inline _LIBCPP_INLINE_VISIBILITY
1072 basic_istream<_CharT, _Traits>&
1073 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1075 return get(__sb, this->widen('\n'));
1078 template<class _CharT, class _Traits>
1079 basic_istream<_CharT, _Traits>&
1080 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1083 #ifndef _LIBCPP_NO_EXCEPTIONS
1086 #endif // _LIBCPP_NO_EXCEPTIONS
1087 sentry __sen(*this, true);
1090 ios_base::iostate __err = ios_base::goodbit;
1093 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1094 if (traits_type::eq_int_type(__i, traits_type::eof()))
1096 __err |= ios_base::eofbit;
1099 char_type __ch = traits_type::to_char_type(__i);
1100 if (traits_type::eq(__ch, __dlm))
1102 this->rdbuf()->sbumpc();
1108 __err |= ios_base::failbit;
1112 this->rdbuf()->sbumpc();
1118 __err |= ios_base::failbit;
1119 this->setstate(__err);
1121 #ifndef _LIBCPP_NO_EXCEPTIONS
1125 this->__set_badbit_and_consider_rethrow();
1127 #endif // _LIBCPP_NO_EXCEPTIONS
1131 template<class _CharT, class _Traits>
1132 inline _LIBCPP_INLINE_VISIBILITY
1133 basic_istream<_CharT, _Traits>&
1134 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1136 return getline(__s, __n, this->widen('\n'));
1139 template<class _CharT, class _Traits>
1140 basic_istream<_CharT, _Traits>&
1141 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1144 #ifndef _LIBCPP_NO_EXCEPTIONS
1147 #endif // _LIBCPP_NO_EXCEPTIONS
1148 sentry __sen(*this, true);
1151 ios_base::iostate __err = ios_base::goodbit;
1152 if (__n == numeric_limits<streamsize>::max())
1156 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1157 if (traits_type::eq_int_type(__i, traits_type::eof()))
1159 __err |= ios_base::eofbit;
1163 if (traits_type::eq_int_type(__i, __dlm))
1171 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1172 if (traits_type::eq_int_type(__i, traits_type::eof()))
1174 __err |= ios_base::eofbit;
1178 if (traits_type::eq_int_type(__i, __dlm))
1182 this->setstate(__err);
1184 #ifndef _LIBCPP_NO_EXCEPTIONS
1188 this->__set_badbit_and_consider_rethrow();
1190 #endif // _LIBCPP_NO_EXCEPTIONS
1194 template<class _CharT, class _Traits>
1195 typename basic_istream<_CharT, _Traits>::int_type
1196 basic_istream<_CharT, _Traits>::peek()
1199 int_type __r = traits_type::eof();
1200 #ifndef _LIBCPP_NO_EXCEPTIONS
1203 #endif // _LIBCPP_NO_EXCEPTIONS
1204 sentry __sen(*this, true);
1207 __r = this->rdbuf()->sgetc();
1208 if (traits_type::eq_int_type(__r, traits_type::eof()))
1209 this->setstate(ios_base::eofbit);
1211 #ifndef _LIBCPP_NO_EXCEPTIONS
1215 this->__set_badbit_and_consider_rethrow();
1217 #endif // _LIBCPP_NO_EXCEPTIONS
1221 template<class _CharT, class _Traits>
1222 basic_istream<_CharT, _Traits>&
1223 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1226 #ifndef _LIBCPP_NO_EXCEPTIONS
1229 #endif // _LIBCPP_NO_EXCEPTIONS
1230 sentry __sen(*this, true);
1233 __gc_ = this->rdbuf()->sgetn(__s, __n);
1235 this->setstate(ios_base::failbit | ios_base::eofbit);
1238 this->setstate(ios_base::failbit);
1239 #ifndef _LIBCPP_NO_EXCEPTIONS
1243 this->__set_badbit_and_consider_rethrow();
1245 #endif // _LIBCPP_NO_EXCEPTIONS
1249 template<class _CharT, class _Traits>
1251 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1254 streamsize __c = this->rdbuf()->in_avail();
1258 this->setstate(ios_base::eofbit);
1263 read(__s, _VSTD::min(__c, __n));
1269 template<class _CharT, class _Traits>
1270 basic_istream<_CharT, _Traits>&
1271 basic_istream<_CharT, _Traits>::putback(char_type __c)
1274 #ifndef _LIBCPP_NO_EXCEPTIONS
1277 #endif // _LIBCPP_NO_EXCEPTIONS
1278 this->clear(this->rdstate() & ~ios_base::eofbit);
1279 sentry __sen(*this, true);
1282 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1283 this->setstate(ios_base::badbit);
1286 this->setstate(ios_base::failbit);
1287 #ifndef _LIBCPP_NO_EXCEPTIONS
1291 this->__set_badbit_and_consider_rethrow();
1293 #endif // _LIBCPP_NO_EXCEPTIONS
1297 template<class _CharT, class _Traits>
1298 basic_istream<_CharT, _Traits>&
1299 basic_istream<_CharT, _Traits>::unget()
1302 #ifndef _LIBCPP_NO_EXCEPTIONS
1305 #endif // _LIBCPP_NO_EXCEPTIONS
1306 this->clear(this->rdstate() & ~ios_base::eofbit);
1307 sentry __sen(*this, true);
1310 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1311 this->setstate(ios_base::badbit);
1314 this->setstate(ios_base::failbit);
1315 #ifndef _LIBCPP_NO_EXCEPTIONS
1319 this->__set_badbit_and_consider_rethrow();
1321 #endif // _LIBCPP_NO_EXCEPTIONS
1325 template<class _CharT, class _Traits>
1327 basic_istream<_CharT, _Traits>::sync()
1330 #ifndef _LIBCPP_NO_EXCEPTIONS
1333 #endif // _LIBCPP_NO_EXCEPTIONS
1334 sentry __sen(*this, true);
1337 if (this->rdbuf() == 0)
1339 if (this->rdbuf()->pubsync() == -1)
1341 this->setstate(ios_base::badbit);
1345 #ifndef _LIBCPP_NO_EXCEPTIONS
1349 this->__set_badbit_and_consider_rethrow();
1351 #endif // _LIBCPP_NO_EXCEPTIONS
1355 template<class _CharT, class _Traits>
1356 typename basic_istream<_CharT, _Traits>::pos_type
1357 basic_istream<_CharT, _Traits>::tellg()
1360 #ifndef _LIBCPP_NO_EXCEPTIONS
1363 #endif // _LIBCPP_NO_EXCEPTIONS
1364 sentry __sen(*this, true);
1366 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1367 #ifndef _LIBCPP_NO_EXCEPTIONS
1371 this->__set_badbit_and_consider_rethrow();
1373 #endif // _LIBCPP_NO_EXCEPTIONS
1377 template<class _CharT, class _Traits>
1378 basic_istream<_CharT, _Traits>&
1379 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1381 #ifndef _LIBCPP_NO_EXCEPTIONS
1384 #endif // _LIBCPP_NO_EXCEPTIONS
1385 this->clear(this->rdstate() & ~ios_base::eofbit);
1386 sentry __sen(*this, true);
1389 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1390 this->setstate(ios_base::failbit);
1392 #ifndef _LIBCPP_NO_EXCEPTIONS
1396 this->__set_badbit_and_consider_rethrow();
1398 #endif // _LIBCPP_NO_EXCEPTIONS
1402 template<class _CharT, class _Traits>
1403 basic_istream<_CharT, _Traits>&
1404 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1406 #ifndef _LIBCPP_NO_EXCEPTIONS
1409 #endif // _LIBCPP_NO_EXCEPTIONS
1410 sentry __sen(*this, true);
1413 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1414 this->setstate(ios_base::failbit);
1416 #ifndef _LIBCPP_NO_EXCEPTIONS
1420 this->__set_badbit_and_consider_rethrow();
1422 #endif // _LIBCPP_NO_EXCEPTIONS
1426 template <class _CharT, class _Traits>
1427 basic_istream<_CharT, _Traits>&
1428 ws(basic_istream<_CharT, _Traits>& __is)
1430 #ifndef _LIBCPP_NO_EXCEPTIONS
1433 #endif // _LIBCPP_NO_EXCEPTIONS
1434 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1437 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1440 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1441 if (_Traits::eq_int_type(__i, _Traits::eof()))
1443 __is.setstate(ios_base::eofbit);
1446 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1448 __is.rdbuf()->sbumpc();
1451 #ifndef _LIBCPP_NO_EXCEPTIONS
1455 __is.__set_badbit_and_consider_rethrow();
1457 #endif // _LIBCPP_NO_EXCEPTIONS
1461 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1463 template <class _CharT, class _Traits, class _Tp>
1464 inline _LIBCPP_INLINE_VISIBILITY
1465 basic_istream<_CharT, _Traits>&
1466 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1472 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1474 template <class _CharT, class _Traits>
1475 class _LIBCPP_TYPE_VIS_ONLY basic_iostream
1476 : public basic_istream<_CharT, _Traits>,
1477 public basic_ostream<_CharT, _Traits>
1481 typedef _CharT char_type;
1482 typedef _Traits traits_type;
1483 typedef typename traits_type::int_type int_type;
1484 typedef typename traits_type::pos_type pos_type;
1485 typedef typename traits_type::off_type off_type;
1487 // constructor/destructor
1488 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1489 virtual ~basic_iostream();
1491 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1492 _LIBCPP_INLINE_VISIBILITY
1493 basic_iostream(basic_iostream&& __rhs);
1497 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1498 _LIBCPP_INLINE_VISIBILITY
1499 basic_iostream& operator=(basic_iostream&& __rhs);
1501 void swap(basic_iostream& __rhs);
1505 template <class _CharT, class _Traits>
1506 inline _LIBCPP_INLINE_VISIBILITY
1507 basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1508 : basic_istream<_CharT, _Traits>(__sb)
1512 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1514 template <class _CharT, class _Traits>
1515 inline _LIBCPP_INLINE_VISIBILITY
1516 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1517 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1521 template <class _CharT, class _Traits>
1522 inline _LIBCPP_INLINE_VISIBILITY
1523 basic_iostream<_CharT, _Traits>&
1524 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1530 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1532 template <class _CharT, class _Traits>
1533 basic_iostream<_CharT, _Traits>::~basic_iostream()
1537 template <class _CharT, class _Traits>
1538 inline _LIBCPP_INLINE_VISIBILITY
1540 basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1542 basic_istream<char_type, traits_type>::swap(__rhs);
1545 template<class _CharT, class _Traits, class _Allocator>
1546 basic_istream<_CharT, _Traits>&
1547 operator>>(basic_istream<_CharT, _Traits>& __is,
1548 basic_string<_CharT, _Traits, _Allocator>& __str)
1550 #ifndef _LIBCPP_NO_EXCEPTIONS
1553 #endif // _LIBCPP_NO_EXCEPTIONS
1554 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1558 streamsize __n = __is.width();
1560 __n = __str.max_size();
1562 __n = numeric_limits<streamsize>::max();
1564 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1565 ios_base::iostate __err = ios_base::goodbit;
1568 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1569 if (_Traits::eq_int_type(__i, _Traits::eof()))
1571 __err |= ios_base::eofbit;
1574 _CharT __ch = _Traits::to_char_type(__i);
1575 if (__ct.is(__ct.space, __ch))
1577 __str.push_back(__ch);
1579 __is.rdbuf()->sbumpc();
1583 __err |= ios_base::failbit;
1584 __is.setstate(__err);
1587 __is.setstate(ios_base::failbit);
1588 #ifndef _LIBCPP_NO_EXCEPTIONS
1592 __is.__set_badbit_and_consider_rethrow();
1594 #endif // _LIBCPP_NO_EXCEPTIONS
1598 template<class _CharT, class _Traits, class _Allocator>
1599 basic_istream<_CharT, _Traits>&
1600 getline(basic_istream<_CharT, _Traits>& __is,
1601 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1603 #ifndef _LIBCPP_NO_EXCEPTIONS
1606 #endif // _LIBCPP_NO_EXCEPTIONS
1607 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1611 ios_base::iostate __err = ios_base::goodbit;
1612 streamsize __extr = 0;
1615 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1616 if (_Traits::eq_int_type(__i, _Traits::eof()))
1618 __err |= ios_base::eofbit;
1622 _CharT __ch = _Traits::to_char_type(__i);
1623 if (_Traits::eq(__ch, __dlm))
1625 __str.push_back(__ch);
1626 if (__str.size() == __str.max_size())
1628 __err |= ios_base::failbit;
1633 __err |= ios_base::failbit;
1634 __is.setstate(__err);
1636 #ifndef _LIBCPP_NO_EXCEPTIONS
1640 __is.__set_badbit_and_consider_rethrow();
1642 #endif // _LIBCPP_NO_EXCEPTIONS
1646 template<class _CharT, class _Traits, class _Allocator>
1647 inline _LIBCPP_INLINE_VISIBILITY
1648 basic_istream<_CharT, _Traits>&
1649 getline(basic_istream<_CharT, _Traits>& __is,
1650 basic_string<_CharT, _Traits, _Allocator>& __str)
1652 return getline(__is, __str, __is.widen('\n'));
1655 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1657 template<class _CharT, class _Traits, class _Allocator>
1658 inline _LIBCPP_INLINE_VISIBILITY
1659 basic_istream<_CharT, _Traits>&
1660 getline(basic_istream<_CharT, _Traits>&& __is,
1661 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1663 return getline(__is, __str, __dlm);
1666 template<class _CharT, class _Traits, class _Allocator>
1667 inline _LIBCPP_INLINE_VISIBILITY
1668 basic_istream<_CharT, _Traits>&
1669 getline(basic_istream<_CharT, _Traits>&& __is,
1670 basic_string<_CharT, _Traits, _Allocator>& __str)
1672 return getline(__is, __str, __is.widen('\n'));
1675 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1677 template <class _CharT, class _Traits, size_t _Size>
1678 basic_istream<_CharT, _Traits>&
1679 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1681 #ifndef _LIBCPP_NO_EXCEPTIONS
1684 #endif // _LIBCPP_NO_EXCEPTIONS
1685 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1688 basic_string<_CharT, _Traits> __str;
1689 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1691 ios_base::iostate __err = ios_base::goodbit;
1692 _CharT __zero = __ct.widen('0');
1693 _CharT __one = __ct.widen('1');
1696 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1697 if (_Traits::eq_int_type(__i, _Traits::eof()))
1699 __err |= ios_base::eofbit;
1702 _CharT __ch = _Traits::to_char_type(__i);
1703 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1705 __str.push_back(__ch);
1707 __is.rdbuf()->sbumpc();
1709 __x = bitset<_Size>(__str);
1711 __err |= ios_base::failbit;
1712 __is.setstate(__err);
1715 __is.setstate(ios_base::failbit);
1716 #ifndef _LIBCPP_NO_EXCEPTIONS
1720 __is.__set_badbit_and_consider_rethrow();
1722 #endif // _LIBCPP_NO_EXCEPTIONS
1726 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<char>)
1727 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<wchar_t>)
1728 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_iostream<char>)
1730 _LIBCPP_END_NAMESPACE_STD
1732 #endif // _LIBCPP_ISTREAM