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);
87 // 27.7.1.2.3 character extraction templates:
88 template<class charT, class traits>
89 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
91 template<class traits>
92 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
94 template<class traits>
95 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
97 template<class charT, class traits>
98 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
100 template<class traits>
101 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
103 template<class traits>
104 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
106 template <class charT, class traits>
108 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
110 typedef basic_istream<char> istream;
111 typedef basic_istream<wchar_t> wistream;
113 template <class charT, class traits = char_traits<charT> >
114 class basic_iostream :
115 public basic_istream<charT,traits>,
116 public basic_ostream<charT,traits>
120 typedef charT char_type;
121 typedef traits traits_type;
122 typedef typename traits_type::int_type int_type;
123 typedef typename traits_type::pos_type pos_type;
124 typedef typename traits_type::off_type off_type;
126 // constructor/destructor
127 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
128 basic_iostream(basic_iostream&& rhs);
129 virtual ~basic_iostream();
132 basic_iostream& operator=(basic_iostream&& rhs);
133 void swap(basic_iostream& rhs);
136 template <class charT, class traits>
138 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
140 typedef basic_iostream<char> iostream;
141 typedef basic_iostream<wchar_t> wiostream;
143 template <class charT, class traits>
144 basic_istream<charT,traits>&
145 ws(basic_istream<charT,traits>& is);
147 template <class charT, class traits, class T>
148 basic_istream<charT, traits>&
149 operator>>(basic_istream<charT, traits>&& is, T& x);
158 #pragma GCC system_header
160 _LIBCPP_BEGIN_NAMESPACE_STD
162 template <class _CharT, class _Traits>
163 class _LIBCPP_VISIBLE basic_istream
164 : virtual public basic_ios<_CharT, _Traits>
168 // types (inherited from basic_ios (27.5.4)):
169 typedef _CharT char_type;
170 typedef _Traits traits_type;
171 typedef typename traits_type::int_type int_type;
172 typedef typename traits_type::pos_type pos_type;
173 typedef typename traits_type::off_type off_type;
175 // 27.7.1.1.1 Constructor/destructor:
176 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb);
177 virtual ~basic_istream();
179 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
180 basic_istream(basic_istream&& __rhs);
183 // 27.7.1.1.2 Assign/swap:
184 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
185 basic_istream& operator=(basic_istream&& __rhs);
187 void swap(basic_istream& __rhs);
190 // 27.7.1.1.3 Prefix/suffix:
193 // 27.7.1.2 Formatted input:
194 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
195 basic_istream& operator>>(basic_ios<char_type, traits_type>&
196 (*__pf)(basic_ios<char_type, traits_type>&));
197 basic_istream& operator>>(ios_base& (*__pf)(ios_base&));
198 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
199 basic_istream& operator>>(bool& __n);
200 basic_istream& operator>>(short& __n);
201 basic_istream& operator>>(unsigned short& __n);
202 basic_istream& operator>>(int& __n);
203 basic_istream& operator>>(unsigned int& __n);
204 basic_istream& operator>>(long& __n);
205 basic_istream& operator>>(unsigned long& __n);
206 basic_istream& operator>>(long long& __n);
207 basic_istream& operator>>(unsigned long long& __n);
208 basic_istream& operator>>(float& __f);
209 basic_istream& operator>>(double& __f);
210 basic_istream& operator>>(long double& __f);
211 basic_istream& operator>>(void*& __p);
213 // 27.7.1.3 Unformatted input:
214 _LIBCPP_INLINE_VISIBILITY
215 streamsize gcount() const {return __gc_;}
217 basic_istream& get(char_type& __c);
218 basic_istream& get(char_type* __s, streamsize __n);
219 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
220 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
221 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
223 basic_istream& getline(char_type* __s, streamsize __n);
224 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
226 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
228 basic_istream& read (char_type* __s, streamsize __n);
229 streamsize readsome(char_type* __s, streamsize __n);
231 basic_istream& putback(char_type __c);
232 basic_istream& unget();
236 basic_istream& seekg(pos_type __pos);
237 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
240 template <class _CharT, class _Traits>
241 class _LIBCPP_VISIBLE basic_istream<_CharT, _Traits>::sentry
245 sentry(const sentry&); // = delete;
246 sentry& operator=(const sentry&); // = delete;
249 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
250 // ~sentry() = default;
252 _LIBCPP_INLINE_VISIBILITY
254 operator bool() const {return __ok_;}
257 template <class _CharT, class _Traits>
258 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
266 if (!__noskipws && (__is.flags() & ios_base::skipws))
268 typedef istreambuf_iterator<_CharT, _Traits> _I;
269 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
272 for (; __i != __eof; ++__i)
273 if (!__ct.is(__ct.space, *__i))
276 __is.setstate(ios_base::failbit | ios_base::eofbit);
281 __is.setstate(ios_base::failbit);
284 template <class _CharT, class _Traits>
285 inline _LIBCPP_INLINE_VISIBILITY
286 basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
292 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
294 template <class _CharT, class _Traits>
295 inline _LIBCPP_INLINE_VISIBILITY
296 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
303 template <class _CharT, class _Traits>
304 inline _LIBCPP_INLINE_VISIBILITY
305 basic_istream<_CharT, _Traits>&
306 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
312 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
314 template <class _CharT, class _Traits>
315 basic_istream<_CharT, _Traits>::~basic_istream()
319 template <class _CharT, class _Traits>
320 inline _LIBCPP_INLINE_VISIBILITY
322 basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
324 _STD::swap(__gc_, __rhs.__gc_);
325 basic_ios<char_type, traits_type>::swap(__rhs);
328 template <class _CharT, class _Traits>
329 basic_istream<_CharT, _Traits>&
330 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
332 #ifndef _LIBCPP_NO_EXCEPTIONS
335 #endif // _LIBCPP_NO_EXCEPTIONS
339 typedef istreambuf_iterator<char_type, traits_type> _I;
340 typedef num_get<char_type, _I> _F;
341 ios_base::iostate __err = ios_base::goodbit;
342 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
343 this->setstate(__err);
345 #ifndef _LIBCPP_NO_EXCEPTIONS
349 this->__set_badbit_and_consider_rethrow();
351 #endif // _LIBCPP_NO_EXCEPTIONS
355 template <class _CharT, class _Traits>
356 basic_istream<_CharT, _Traits>&
357 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
359 #ifndef _LIBCPP_NO_EXCEPTIONS
362 #endif // _LIBCPP_NO_EXCEPTIONS
366 typedef istreambuf_iterator<char_type, traits_type> _I;
367 typedef num_get<char_type, _I> _F;
368 ios_base::iostate __err = ios_base::goodbit;
369 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
370 this->setstate(__err);
372 #ifndef _LIBCPP_NO_EXCEPTIONS
376 this->__set_badbit_and_consider_rethrow();
378 #endif // _LIBCPP_NO_EXCEPTIONS
382 template <class _CharT, class _Traits>
383 basic_istream<_CharT, _Traits>&
384 basic_istream<_CharT, _Traits>::operator>>(long& __n)
386 #ifndef _LIBCPP_NO_EXCEPTIONS
389 #endif // _LIBCPP_NO_EXCEPTIONS
393 typedef istreambuf_iterator<char_type, traits_type> _I;
394 typedef num_get<char_type, _I> _F;
395 ios_base::iostate __err = ios_base::goodbit;
396 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
397 this->setstate(__err);
399 #ifndef _LIBCPP_NO_EXCEPTIONS
403 this->__set_badbit_and_consider_rethrow();
405 #endif // _LIBCPP_NO_EXCEPTIONS
409 template <class _CharT, class _Traits>
410 basic_istream<_CharT, _Traits>&
411 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
413 #ifndef _LIBCPP_NO_EXCEPTIONS
416 #endif // _LIBCPP_NO_EXCEPTIONS
420 typedef istreambuf_iterator<char_type, traits_type> _I;
421 typedef num_get<char_type, _I> _F;
422 ios_base::iostate __err = ios_base::goodbit;
423 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
424 this->setstate(__err);
426 #ifndef _LIBCPP_NO_EXCEPTIONS
430 this->__set_badbit_and_consider_rethrow();
432 #endif // _LIBCPP_NO_EXCEPTIONS
436 template <class _CharT, class _Traits>
437 basic_istream<_CharT, _Traits>&
438 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
440 #ifndef _LIBCPP_NO_EXCEPTIONS
443 #endif // _LIBCPP_NO_EXCEPTIONS
447 typedef istreambuf_iterator<char_type, traits_type> _I;
448 typedef num_get<char_type, _I> _F;
449 ios_base::iostate __err = ios_base::goodbit;
450 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
451 this->setstate(__err);
453 #ifndef _LIBCPP_NO_EXCEPTIONS
457 this->__set_badbit_and_consider_rethrow();
459 #endif // _LIBCPP_NO_EXCEPTIONS
463 template <class _CharT, class _Traits>
464 basic_istream<_CharT, _Traits>&
465 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
467 #ifndef _LIBCPP_NO_EXCEPTIONS
470 #endif // _LIBCPP_NO_EXCEPTIONS
474 typedef istreambuf_iterator<char_type, traits_type> _I;
475 typedef num_get<char_type, _I> _F;
476 ios_base::iostate __err = ios_base::goodbit;
477 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
478 this->setstate(__err);
480 #ifndef _LIBCPP_NO_EXCEPTIONS
484 this->__set_badbit_and_consider_rethrow();
486 #endif // _LIBCPP_NO_EXCEPTIONS
490 template <class _CharT, class _Traits>
491 basic_istream<_CharT, _Traits>&
492 basic_istream<_CharT, _Traits>::operator>>(float& __n)
494 #ifndef _LIBCPP_NO_EXCEPTIONS
497 #endif // _LIBCPP_NO_EXCEPTIONS
501 typedef istreambuf_iterator<char_type, traits_type> _I;
502 typedef num_get<char_type, _I> _F;
503 ios_base::iostate __err = ios_base::goodbit;
504 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
505 this->setstate(__err);
507 #ifndef _LIBCPP_NO_EXCEPTIONS
511 this->__set_badbit_and_consider_rethrow();
513 #endif // _LIBCPP_NO_EXCEPTIONS
517 template <class _CharT, class _Traits>
518 basic_istream<_CharT, _Traits>&
519 basic_istream<_CharT, _Traits>::operator>>(double& __n)
521 #ifndef _LIBCPP_NO_EXCEPTIONS
524 #endif // _LIBCPP_NO_EXCEPTIONS
528 typedef istreambuf_iterator<char_type, traits_type> _I;
529 typedef num_get<char_type, _I> _F;
530 ios_base::iostate __err = ios_base::goodbit;
531 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
532 this->setstate(__err);
534 #ifndef _LIBCPP_NO_EXCEPTIONS
538 this->__set_badbit_and_consider_rethrow();
540 #endif // _LIBCPP_NO_EXCEPTIONS
544 template <class _CharT, class _Traits>
545 basic_istream<_CharT, _Traits>&
546 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
548 #ifndef _LIBCPP_NO_EXCEPTIONS
551 #endif // _LIBCPP_NO_EXCEPTIONS
555 typedef istreambuf_iterator<char_type, traits_type> _I;
556 typedef num_get<char_type, _I> _F;
557 ios_base::iostate __err = ios_base::goodbit;
558 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
559 this->setstate(__err);
561 #ifndef _LIBCPP_NO_EXCEPTIONS
565 this->__set_badbit_and_consider_rethrow();
567 #endif // _LIBCPP_NO_EXCEPTIONS
571 template <class _CharT, class _Traits>
572 basic_istream<_CharT, _Traits>&
573 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
575 #ifndef _LIBCPP_NO_EXCEPTIONS
578 #endif // _LIBCPP_NO_EXCEPTIONS
582 typedef istreambuf_iterator<char_type, traits_type> _I;
583 typedef num_get<char_type, _I> _F;
584 ios_base::iostate __err = ios_base::goodbit;
585 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
586 this->setstate(__err);
588 #ifndef _LIBCPP_NO_EXCEPTIONS
592 this->__set_badbit_and_consider_rethrow();
594 #endif // _LIBCPP_NO_EXCEPTIONS
598 template <class _CharT, class _Traits>
599 basic_istream<_CharT, _Traits>&
600 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
602 #ifndef _LIBCPP_NO_EXCEPTIONS
605 #endif // _LIBCPP_NO_EXCEPTIONS
609 typedef istreambuf_iterator<char_type, traits_type> _I;
610 typedef num_get<char_type, _I> _F;
611 ios_base::iostate __err = ios_base::goodbit;
612 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
613 this->setstate(__err);
615 #ifndef _LIBCPP_NO_EXCEPTIONS
619 this->__set_badbit_and_consider_rethrow();
621 #endif // _LIBCPP_NO_EXCEPTIONS
625 template <class _CharT, class _Traits>
626 basic_istream<_CharT, _Traits>&
627 basic_istream<_CharT, _Traits>::operator>>(short& __n)
629 #ifndef _LIBCPP_NO_EXCEPTIONS
632 #endif // _LIBCPP_NO_EXCEPTIONS
636 typedef istreambuf_iterator<char_type, traits_type> _I;
637 typedef num_get<char_type, _I> _F;
638 ios_base::iostate __err = ios_base::goodbit;
640 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
641 if (__temp < numeric_limits<short>::min())
643 __err |= ios_base::failbit;
644 __n = numeric_limits<short>::min();
646 else if (__temp > numeric_limits<short>::max())
648 __err |= ios_base::failbit;
649 __n = numeric_limits<short>::max();
652 __n = static_cast<short>(__temp);
653 this->setstate(__err);
655 #ifndef _LIBCPP_NO_EXCEPTIONS
659 this->__set_badbit_and_consider_rethrow();
661 #endif // _LIBCPP_NO_EXCEPTIONS
665 template <class _CharT, class _Traits>
666 basic_istream<_CharT, _Traits>&
667 basic_istream<_CharT, _Traits>::operator>>(int& __n)
669 #ifndef _LIBCPP_NO_EXCEPTIONS
672 #endif // _LIBCPP_NO_EXCEPTIONS
676 typedef istreambuf_iterator<char_type, traits_type> _I;
677 typedef num_get<char_type, _I> _F;
678 ios_base::iostate __err = ios_base::goodbit;
680 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
681 if (__temp < numeric_limits<int>::min())
683 __err |= ios_base::failbit;
684 __n = numeric_limits<int>::min();
686 else if (__temp > numeric_limits<int>::max())
688 __err |= ios_base::failbit;
689 __n = numeric_limits<int>::max();
692 __n = static_cast<int>(__temp);
693 this->setstate(__err);
695 #ifndef _LIBCPP_NO_EXCEPTIONS
699 this->__set_badbit_and_consider_rethrow();
701 #endif // _LIBCPP_NO_EXCEPTIONS
705 template <class _CharT, class _Traits>
706 inline _LIBCPP_INLINE_VISIBILITY
707 basic_istream<_CharT, _Traits>&
708 basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
713 template <class _CharT, class _Traits>
714 inline _LIBCPP_INLINE_VISIBILITY
715 basic_istream<_CharT, _Traits>&
716 basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
717 (*__pf)(basic_ios<char_type, traits_type>&))
723 template <class _CharT, class _Traits>
724 inline _LIBCPP_INLINE_VISIBILITY
725 basic_istream<_CharT, _Traits>&
726 basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
732 template<class _CharT, class _Traits>
733 basic_istream<_CharT, _Traits>&
734 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
736 #ifndef _LIBCPP_NO_EXCEPTIONS
739 #endif // _LIBCPP_NO_EXCEPTIONS
740 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
743 typedef istreambuf_iterator<_CharT, _Traits> _I;
744 streamsize __n = __is.width();
746 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
748 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
751 for (; __i != __eof && __c < __n-1; ++__i, ++__s, ++__c)
754 if (__ct.is(__ct.space, __ch))
760 ios_base::iostate __err = ios_base::goodbit;
762 __err |= ios_base::eofbit;
764 __err |= ios_base::failbit;
765 __is.setstate(__err);
767 #ifndef _LIBCPP_NO_EXCEPTIONS
771 __is.__set_badbit_and_consider_rethrow();
773 #endif // _LIBCPP_NO_EXCEPTIONS
777 template<class _Traits>
778 inline _LIBCPP_INLINE_VISIBILITY
779 basic_istream<char, _Traits>&
780 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
782 return __is >> (char*)__s;
785 template<class _Traits>
786 inline _LIBCPP_INLINE_VISIBILITY
787 basic_istream<char, _Traits>&
788 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
790 return __is >> (char*)__s;
793 template<class _CharT, class _Traits>
794 basic_istream<_CharT, _Traits>&
795 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
797 #ifndef _LIBCPP_NO_EXCEPTIONS
800 #endif // _LIBCPP_NO_EXCEPTIONS
801 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
805 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
806 if (_Traits::eq_int_type(__i, _Traits::eof()))
807 __is.setstate(ios_base::eofbit | ios_base::failbit);
809 __c = _Traits::to_char_type(__i);
811 typedef istreambuf_iterator<_CharT, _Traits> _I;
818 __is.setstate(ios_base::eofbit);
821 __is.setstate(ios_base::eofbit | ios_base::failbit);
824 #ifndef _LIBCPP_NO_EXCEPTIONS
828 __is.__set_badbit_and_consider_rethrow();
830 #endif // _LIBCPP_NO_EXCEPTIONS
834 template<class _Traits>
835 inline _LIBCPP_INLINE_VISIBILITY
836 basic_istream<char, _Traits>&
837 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
839 return __is >> (char&)__c;
842 template<class _Traits>
843 inline _LIBCPP_INLINE_VISIBILITY
844 basic_istream<char, _Traits>&
845 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
847 return __is >> (char&)__c;
850 template<class _CharT, class _Traits>
851 basic_istream<_CharT, _Traits>&
852 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
855 #ifndef _LIBCPP_NO_EXCEPTIONS
858 #endif // _LIBCPP_NO_EXCEPTIONS
859 sentry __s(*this, true);
865 #ifndef _LIBCPP_NO_EXCEPTIONS
868 #endif // _LIBCPP_NO_EXCEPTIONS
869 typedef istreambuf_iterator<char_type, traits_type> _I;
870 typedef ostreambuf_iterator<char_type, traits_type> _O;
874 for (; __i != __eof; ++__i, ++__o, ++__c)
880 ios_base::iostate __err = ios_base::goodbit;
882 __err |= ios_base::eofbit;
884 __err |= ios_base::failbit;
885 this->setstate(__err);
886 #ifndef _LIBCPP_NO_EXCEPTIONS
891 this->__set_failbit_and_consider_rethrow();
893 #endif // _LIBCPP_NO_EXCEPTIONS
896 this->setstate(ios_base::failbit);
899 #ifndef _LIBCPP_NO_EXCEPTIONS
903 this->__set_badbit_and_consider_rethrow();
905 #endif // _LIBCPP_NO_EXCEPTIONS
909 template<class _CharT, class _Traits>
910 typename basic_istream<_CharT, _Traits>::int_type
911 basic_istream<_CharT, _Traits>::get()
914 int_type __r = traits_type::eof();
915 #ifndef _LIBCPP_NO_EXCEPTIONS
918 #endif // _LIBCPP_NO_EXCEPTIONS
919 sentry __s(*this, true);
923 typedef istreambuf_iterator<char_type, traits_type> _I;
926 ios_base::iostate __err = ios_base::goodbit;
929 __r = traits_type::to_int_type(*__i);
932 __err |= ios_base::eofbit;
935 __err |= ios_base::failbit | ios_base::eofbit;
936 this->setstate(__err);
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);
975 typedef istreambuf_iterator<char_type, traits_type> _I;
978 for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c)
980 char_type __ch = *__i;
981 if (traits_type::eq(__ch, __dlm))
986 ios_base::iostate __err = ios_base::goodbit;
988 __err |= ios_base::eofbit;
990 __err |= ios_base::failbit;
991 this->setstate(__err);
994 this->setstate(ios_base::failbit);
997 #ifndef _LIBCPP_NO_EXCEPTIONS
1001 this->__set_badbit_and_consider_rethrow();
1003 #endif // _LIBCPP_NO_EXCEPTIONS
1007 template<class _CharT, class _Traits>
1008 inline _LIBCPP_INLINE_VISIBILITY
1009 basic_istream<_CharT, _Traits>&
1010 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1012 return get(__s, __n, this->widen('\n'));
1015 template<class _CharT, class _Traits>
1016 basic_istream<_CharT, _Traits>&
1017 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1021 #ifndef _LIBCPP_NO_EXCEPTIONS
1024 #endif // _LIBCPP_NO_EXCEPTIONS
1025 sentry __sen(*this, true);
1029 ios_base::iostate __err = ios_base::goodbit;
1030 #ifndef _LIBCPP_NO_EXCEPTIONS
1033 #endif // _LIBCPP_NO_EXCEPTIONS
1034 typedef istreambuf_iterator<char_type, traits_type> _I;
1035 typedef ostreambuf_iterator<char_type, traits_type> _O;
1039 for (; __i != __eof; ++__i, ++__o, ++__c)
1041 char_type __ch = *__i;
1042 if (traits_type::eq(__ch, __dlm))
1049 __err |= ios_base::eofbit;
1050 #ifndef _LIBCPP_NO_EXCEPTIONS
1055 #endif // _LIBCPP_NO_EXCEPTIONS
1057 __err |= ios_base::failbit;
1058 this->setstate(__err);
1061 #ifndef _LIBCPP_NO_EXCEPTIONS
1065 this->__set_badbit_and_consider_rethrow();
1067 #endif // _LIBCPP_NO_EXCEPTIONS
1071 template<class _CharT, class _Traits>
1072 inline _LIBCPP_INLINE_VISIBILITY
1073 basic_istream<_CharT, _Traits>&
1074 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1076 return get(__sb, this->widen('\n'));
1079 template<class _CharT, class _Traits>
1080 basic_istream<_CharT, _Traits>&
1081 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1084 #ifndef _LIBCPP_NO_EXCEPTIONS
1087 #endif // _LIBCPP_NO_EXCEPTIONS
1088 sentry __sen(*this, true);
1092 typedef istreambuf_iterator<char_type, traits_type> _I;
1095 for (; __i != __eof; ++__s, --__n)
1097 char_type __ch = *__i;
1100 if (traits_type::eq(__ch, __dlm))
1104 this->setstate(ios_base::failbit);
1111 ios_base::iostate __err = ios_base::goodbit;
1113 __err |= ios_base::eofbit;
1115 __err |= ios_base::failbit;
1116 this->setstate(__err);
1119 #ifndef _LIBCPP_NO_EXCEPTIONS
1123 this->__set_badbit_and_consider_rethrow();
1125 #endif // _LIBCPP_NO_EXCEPTIONS
1129 template<class _CharT, class _Traits>
1130 inline _LIBCPP_INLINE_VISIBILITY
1131 basic_istream<_CharT, _Traits>&
1132 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1134 return getline(__s, __n, this->widen('\n'));
1137 template<class _CharT, class _Traits>
1138 basic_istream<_CharT, _Traits>&
1139 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1142 #ifndef _LIBCPP_NO_EXCEPTIONS
1145 #endif // _LIBCPP_NO_EXCEPTIONS
1146 sentry __sen(*this, true);
1150 typedef istreambuf_iterator<char_type, traits_type> _I;
1153 if (__n != numeric_limits<streamsize>::max())
1155 for (; __n > 0 && __i != __eof; --__n)
1157 char_type __ch = *__i;
1160 if (traits_type::eq(__ch, __dlm))
1166 while (__i != __eof)
1168 char_type __ch = *__i;
1171 if (traits_type::eq(__ch, __dlm))
1176 this->setstate(ios_base::eofbit);
1179 #ifndef _LIBCPP_NO_EXCEPTIONS
1183 this->__set_badbit_and_consider_rethrow();
1185 #endif // _LIBCPP_NO_EXCEPTIONS
1189 template<class _CharT, class _Traits>
1190 typename basic_istream<_CharT, _Traits>::int_type
1191 basic_istream<_CharT, _Traits>::peek()
1194 int_type __r = traits_type::eof();
1195 #ifndef _LIBCPP_NO_EXCEPTIONS
1198 #endif // _LIBCPP_NO_EXCEPTIONS
1199 sentry __sen(*this, true);
1201 __r = this->rdbuf()->sgetc();
1202 #ifndef _LIBCPP_NO_EXCEPTIONS
1206 this->__set_badbit_and_consider_rethrow();
1208 #endif // _LIBCPP_NO_EXCEPTIONS
1212 template<class _CharT, class _Traits>
1213 basic_istream<_CharT, _Traits>&
1214 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1217 #ifndef _LIBCPP_NO_EXCEPTIONS
1220 #endif // _LIBCPP_NO_EXCEPTIONS
1221 sentry __sen(*this, true);
1225 typedef istreambuf_iterator<char_type, traits_type> _I;
1228 for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n)
1232 ios_base::iostate __err = ios_base::eofbit;
1234 __err |= ios_base::failbit;
1235 this->setstate(__err);
1240 this->setstate(ios_base::failbit);
1241 #ifndef _LIBCPP_NO_EXCEPTIONS
1245 this->__set_badbit_and_consider_rethrow();
1247 #endif // _LIBCPP_NO_EXCEPTIONS
1251 template<class _CharT, class _Traits>
1253 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1257 #ifndef _LIBCPP_NO_EXCEPTIONS
1260 #endif // _LIBCPP_NO_EXCEPTIONS
1261 sentry __sen(*this, true);
1264 typedef istreambuf_iterator<char_type, traits_type> _I;
1267 __c = this->rdbuf()->in_avail();
1276 __c = _STD::min(__c, __n);
1277 for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i)
1281 this->setstate(ios_base::eofbit);
1285 this->setstate(ios_base::failbit);
1286 #ifndef _LIBCPP_NO_EXCEPTIONS
1290 this->__set_badbit_and_consider_rethrow();
1292 #endif // _LIBCPP_NO_EXCEPTIONS
1296 template<class _CharT, class _Traits>
1297 basic_istream<_CharT, _Traits>&
1298 basic_istream<_CharT, _Traits>::putback(char_type __c)
1301 #ifndef _LIBCPP_NO_EXCEPTIONS
1304 #endif // _LIBCPP_NO_EXCEPTIONS
1305 sentry __sen(*this, true);
1308 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1309 this->setstate(ios_base::badbit);
1312 this->setstate(ios_base::failbit);
1313 #ifndef _LIBCPP_NO_EXCEPTIONS
1317 this->__set_badbit_and_consider_rethrow();
1319 #endif // _LIBCPP_NO_EXCEPTIONS
1323 template<class _CharT, class _Traits>
1324 basic_istream<_CharT, _Traits>&
1325 basic_istream<_CharT, _Traits>::unget()
1328 #ifndef _LIBCPP_NO_EXCEPTIONS
1331 #endif // _LIBCPP_NO_EXCEPTIONS
1332 sentry __sen(*this, true);
1335 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1336 this->setstate(ios_base::badbit);
1339 this->setstate(ios_base::failbit);
1340 #ifndef _LIBCPP_NO_EXCEPTIONS
1344 this->__set_badbit_and_consider_rethrow();
1346 #endif // _LIBCPP_NO_EXCEPTIONS
1350 template<class _CharT, class _Traits>
1352 basic_istream<_CharT, _Traits>::sync()
1355 #ifndef _LIBCPP_NO_EXCEPTIONS
1358 #endif // _LIBCPP_NO_EXCEPTIONS
1359 sentry __sen(*this, true);
1362 if (this->rdbuf() == 0)
1364 if (this->rdbuf()->pubsync() == -1)
1366 this->setstate(ios_base::badbit);
1370 #ifndef _LIBCPP_NO_EXCEPTIONS
1374 this->__set_badbit_and_consider_rethrow();
1376 #endif // _LIBCPP_NO_EXCEPTIONS
1380 template<class _CharT, class _Traits>
1381 typename basic_istream<_CharT, _Traits>::pos_type
1382 basic_istream<_CharT, _Traits>::tellg()
1385 #ifndef _LIBCPP_NO_EXCEPTIONS
1388 #endif // _LIBCPP_NO_EXCEPTIONS
1389 sentry __sen(*this, true);
1391 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
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(pos_type __pos)
1406 #ifndef _LIBCPP_NO_EXCEPTIONS
1409 #endif // _LIBCPP_NO_EXCEPTIONS
1410 sentry __sen(*this, true);
1412 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1413 this->setstate(ios_base::failbit);
1414 #ifndef _LIBCPP_NO_EXCEPTIONS
1418 this->__set_badbit_and_consider_rethrow();
1420 #endif // _LIBCPP_NO_EXCEPTIONS
1424 template<class _CharT, class _Traits>
1425 basic_istream<_CharT, _Traits>&
1426 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1428 #ifndef _LIBCPP_NO_EXCEPTIONS
1431 #endif // _LIBCPP_NO_EXCEPTIONS
1432 sentry __sen(*this, true);
1434 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
1435 #ifndef _LIBCPP_NO_EXCEPTIONS
1439 this->__set_badbit_and_consider_rethrow();
1441 #endif // _LIBCPP_NO_EXCEPTIONS
1445 template <class _CharT, class _Traits>
1446 basic_istream<_CharT, _Traits>&
1447 ws(basic_istream<_CharT, _Traits>& __is)
1449 #ifndef _LIBCPP_NO_EXCEPTIONS
1452 #endif // _LIBCPP_NO_EXCEPTIONS
1453 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1456 typedef istreambuf_iterator<_CharT, _Traits> _I;
1457 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1460 for (; __i != __eof; ++__i)
1461 if (!__ct.is(__ct.space, *__i))
1464 __is.setstate(ios_base::failbit | ios_base::eofbit);
1466 #ifndef _LIBCPP_NO_EXCEPTIONS
1470 __is.__set_badbit_and_consider_rethrow();
1472 #endif // _LIBCPP_NO_EXCEPTIONS
1476 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1478 template <class _CharT, class _Traits, class _Tp>
1479 inline _LIBCPP_INLINE_VISIBILITY
1480 basic_istream<_CharT, _Traits>&
1481 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1487 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1489 template <class _CharT, class _Traits>
1490 class _LIBCPP_VISIBLE basic_iostream
1491 : public basic_istream<_CharT, _Traits>,
1492 public basic_ostream<_CharT, _Traits>
1496 typedef _CharT char_type;
1497 typedef _Traits traits_type;
1498 typedef typename traits_type::int_type int_type;
1499 typedef typename traits_type::pos_type pos_type;
1500 typedef typename traits_type::off_type off_type;
1502 // constructor/destructor
1503 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1504 virtual ~basic_iostream();
1506 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1507 basic_iostream(basic_iostream&& __rhs);
1511 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1512 basic_iostream& operator=(basic_iostream&& __rhs);
1514 void swap(basic_iostream& __rhs);
1518 template <class _CharT, class _Traits>
1519 inline _LIBCPP_INLINE_VISIBILITY
1520 basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1521 : basic_istream<_CharT, _Traits>(__sb)
1525 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1527 template <class _CharT, class _Traits>
1528 inline _LIBCPP_INLINE_VISIBILITY
1529 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1530 : basic_istream<_CharT, _Traits>(_STD::move(__rhs))
1534 template <class _CharT, class _Traits>
1535 inline _LIBCPP_INLINE_VISIBILITY
1536 basic_iostream<_CharT, _Traits>&
1537 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1543 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1545 template <class _CharT, class _Traits>
1546 basic_iostream<_CharT, _Traits>::~basic_iostream()
1550 template <class _CharT, class _Traits>
1551 inline _LIBCPP_INLINE_VISIBILITY
1553 basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1555 basic_istream<char_type, traits_type>::swap(__rhs);
1558 template<class _CharT, class _Traits, class _Allocator>
1559 basic_istream<_CharT, _Traits>&
1560 operator>>(basic_istream<_CharT, _Traits>& __is,
1561 basic_string<_CharT, _Traits, _Allocator>& __str)
1563 #ifndef _LIBCPP_NO_EXCEPTIONS
1566 #endif // _LIBCPP_NO_EXCEPTIONS
1567 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1571 typedef istreambuf_iterator<_CharT, _Traits> _I;
1572 streamsize __n = __is.width();
1574 __n = __str.max_size();
1576 __n = numeric_limits<streamsize>::max();
1578 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1581 for (; __i != __eof && __c < __n; ++__i, ++__c)
1584 if (__ct.is(__ct.space, __ch))
1586 __str.push_back(__ch);
1589 ios_base::iostate __err = ios_base::goodbit;
1591 __err |= ios_base::eofbit;
1593 __err |= ios_base::failbit;
1594 __is.setstate(__err);
1597 __is.setstate(ios_base::failbit);
1598 #ifndef _LIBCPP_NO_EXCEPTIONS
1602 __is.__set_badbit_and_consider_rethrow();
1604 #endif // _LIBCPP_NO_EXCEPTIONS
1608 template<class _CharT, class _Traits, class _Allocator>
1609 basic_istream<_CharT, _Traits>&
1610 getline(basic_istream<_CharT, _Traits>& __is,
1611 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1613 #ifndef _LIBCPP_NO_EXCEPTIONS
1616 #endif // _LIBCPP_NO_EXCEPTIONS
1617 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1622 typedef istreambuf_iterator<_CharT, _Traits> _I;
1625 streamsize __n = __str.max_size();
1627 __n = numeric_limits<streamsize>::max();
1628 for (; __i != __eof;)
1633 if (_Traits::eq(__ch, __dlm))
1637 __is.setstate(ios_base::failbit);
1640 __str.push_back(__ch);
1642 ios_base::iostate __err = ios_base::goodbit;
1644 __err |= ios_base::eofbit;
1646 __err |= ios_base::failbit;
1647 __is.setstate(__err);
1649 #ifndef _LIBCPP_NO_EXCEPTIONS
1653 __is.__set_badbit_and_consider_rethrow();
1655 #endif // _LIBCPP_NO_EXCEPTIONS
1659 template<class _CharT, class _Traits, class _Allocator>
1660 inline _LIBCPP_INLINE_VISIBILITY
1661 basic_istream<_CharT, _Traits>&
1662 getline(basic_istream<_CharT, _Traits>& __is,
1663 basic_string<_CharT, _Traits, _Allocator>& __str)
1665 return getline(__is, __str, __is.widen('\n'));
1668 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1670 template<class _CharT, class _Traits, class _Allocator>
1671 inline _LIBCPP_INLINE_VISIBILITY
1672 basic_istream<_CharT, _Traits>&
1673 getline(basic_istream<_CharT, _Traits>&& __is,
1674 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1676 return getline(__is, __str, __dlm);
1679 template<class _CharT, class _Traits, class _Allocator>
1680 inline _LIBCPP_INLINE_VISIBILITY
1681 basic_istream<_CharT, _Traits>&
1682 getline(basic_istream<_CharT, _Traits>&& __is,
1683 basic_string<_CharT, _Traits, _Allocator>& __str)
1685 return getline(__is, __str, __is.widen('\n'));
1688 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1690 template <class _CharT, class _Traits, size_t _Size>
1691 basic_istream<_CharT, _Traits>&
1692 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1694 #ifndef _LIBCPP_NO_EXCEPTIONS
1697 #endif // _LIBCPP_NO_EXCEPTIONS
1698 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1701 basic_string<_CharT, _Traits> __str;
1702 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1703 typedef istreambuf_iterator<_CharT, _Traits> _I;
1705 _CharT __zero = __ct.widen('0');
1706 _CharT __one = __ct.widen('1');
1709 for (; __i != __eof && __c < _Size; ++__i, ++__c)
1712 if (__ch != __zero && __ch != __one)
1714 __str.push_back(__ch);
1717 __x = bitset<_Size>(__str);
1718 ios_base::iostate __err = ios_base::goodbit;
1720 __err |= ios_base::eofbit;
1722 __err |= ios_base::failbit;
1723 __is.setstate(__err);
1726 __is.setstate(ios_base::failbit);
1727 #ifndef _LIBCPP_NO_EXCEPTIONS
1731 __is.__set_badbit_and_consider_rethrow();
1733 #endif // _LIBCPP_NO_EXCEPTIONS
1737 extern template class basic_istream<char>;
1738 extern template class basic_istream<wchar_t>;
1739 extern template class basic_iostream<char>;
1741 _LIBCPP_END_NAMESPACE_STD
1743 #endif // _LIBCPP_ISTREAM