2 //===--------------------------- istream ----------------------------------===//
4 // ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. 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>
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();
180 basic_istream(basic_istream&& __rhs);
183 // 27.7.1.1.2 Assign/swap:
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 streamsize gcount() const {return __gc_;}
216 basic_istream& get(char_type& __c);
217 basic_istream& get(char_type* __s, streamsize __n);
218 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
219 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
220 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
222 basic_istream& getline(char_type* __s, streamsize __n);
223 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
225 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
227 basic_istream& read (char_type* __s, streamsize __n);
228 streamsize readsome(char_type* __s, streamsize __n);
230 basic_istream& putback(char_type __c);
231 basic_istream& unget();
235 basic_istream& seekg(pos_type __pos);
236 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
239 template <class _CharT, class _Traits>
240 class basic_istream<_CharT, _Traits>::sentry
244 sentry(const sentry&); // = delete;
245 sentry& operator=(const sentry&); // = delete;
248 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
249 // ~sentry() = default;
252 operator bool() const {return __ok_;}
255 template <class _CharT, class _Traits>
256 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
264 if (!__noskipws && (__is.flags() & ios_base::skipws))
266 typedef istreambuf_iterator<_CharT, _Traits> _I;
267 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
270 for (; __i != __eof; ++__i)
271 if (!__ct.is(__ct.space, *__i))
274 __is.setstate(ios_base::failbit | ios_base::eofbit);
279 __is.setstate(ios_base::failbit);
282 template <class _CharT, class _Traits>
283 inline _LIBCPP_INLINE_VISIBILITY
284 basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
292 template <class _CharT, class _Traits>
293 inline _LIBCPP_INLINE_VISIBILITY
294 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
301 template <class _CharT, class _Traits>
302 inline _LIBCPP_INLINE_VISIBILITY
303 basic_istream<_CharT, _Traits>&
304 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
312 template <class _CharT, class _Traits>
313 basic_istream<_CharT, _Traits>::~basic_istream()
317 template <class _CharT, class _Traits>
318 inline _LIBCPP_INLINE_VISIBILITY
320 basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
322 _STD::swap(__gc_, __rhs.__gc_);
323 basic_ios<char_type, traits_type>::swap(__rhs);
326 template <class _CharT, class _Traits>
327 basic_istream<_CharT, _Traits>&
328 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
330 #ifndef _LIBCPP_NO_EXCEPTIONS
337 typedef istreambuf_iterator<char_type, traits_type> _I;
338 typedef num_get<char_type, _I> _F;
339 ios_base::iostate __err = ios_base::goodbit;
340 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
341 this->setstate(__err);
343 #ifndef _LIBCPP_NO_EXCEPTIONS
347 this->__set_badbit_and_consider_rethrow();
353 template <class _CharT, class _Traits>
354 basic_istream<_CharT, _Traits>&
355 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
357 #ifndef _LIBCPP_NO_EXCEPTIONS
364 typedef istreambuf_iterator<char_type, traits_type> _I;
365 typedef num_get<char_type, _I> _F;
366 ios_base::iostate __err = ios_base::goodbit;
367 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
368 this->setstate(__err);
370 #ifndef _LIBCPP_NO_EXCEPTIONS
374 this->__set_badbit_and_consider_rethrow();
380 template <class _CharT, class _Traits>
381 basic_istream<_CharT, _Traits>&
382 basic_istream<_CharT, _Traits>::operator>>(long& __n)
384 #ifndef _LIBCPP_NO_EXCEPTIONS
391 typedef istreambuf_iterator<char_type, traits_type> _I;
392 typedef num_get<char_type, _I> _F;
393 ios_base::iostate __err = ios_base::goodbit;
394 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
395 this->setstate(__err);
397 #ifndef _LIBCPP_NO_EXCEPTIONS
401 this->__set_badbit_and_consider_rethrow();
407 template <class _CharT, class _Traits>
408 basic_istream<_CharT, _Traits>&
409 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
411 #ifndef _LIBCPP_NO_EXCEPTIONS
418 typedef istreambuf_iterator<char_type, traits_type> _I;
419 typedef num_get<char_type, _I> _F;
420 ios_base::iostate __err = ios_base::goodbit;
421 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
422 this->setstate(__err);
424 #ifndef _LIBCPP_NO_EXCEPTIONS
428 this->__set_badbit_and_consider_rethrow();
434 template <class _CharT, class _Traits>
435 basic_istream<_CharT, _Traits>&
436 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
438 #ifndef _LIBCPP_NO_EXCEPTIONS
445 typedef istreambuf_iterator<char_type, traits_type> _I;
446 typedef num_get<char_type, _I> _F;
447 ios_base::iostate __err = ios_base::goodbit;
448 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
449 this->setstate(__err);
451 #ifndef _LIBCPP_NO_EXCEPTIONS
455 this->__set_badbit_and_consider_rethrow();
461 template <class _CharT, class _Traits>
462 basic_istream<_CharT, _Traits>&
463 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
465 #ifndef _LIBCPP_NO_EXCEPTIONS
472 typedef istreambuf_iterator<char_type, traits_type> _I;
473 typedef num_get<char_type, _I> _F;
474 ios_base::iostate __err = ios_base::goodbit;
475 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
476 this->setstate(__err);
478 #ifndef _LIBCPP_NO_EXCEPTIONS
482 this->__set_badbit_and_consider_rethrow();
488 template <class _CharT, class _Traits>
489 basic_istream<_CharT, _Traits>&
490 basic_istream<_CharT, _Traits>::operator>>(float& __n)
492 #ifndef _LIBCPP_NO_EXCEPTIONS
499 typedef istreambuf_iterator<char_type, traits_type> _I;
500 typedef num_get<char_type, _I> _F;
501 ios_base::iostate __err = ios_base::goodbit;
502 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
503 this->setstate(__err);
505 #ifndef _LIBCPP_NO_EXCEPTIONS
509 this->__set_badbit_and_consider_rethrow();
515 template <class _CharT, class _Traits>
516 basic_istream<_CharT, _Traits>&
517 basic_istream<_CharT, _Traits>::operator>>(double& __n)
519 #ifndef _LIBCPP_NO_EXCEPTIONS
526 typedef istreambuf_iterator<char_type, traits_type> _I;
527 typedef num_get<char_type, _I> _F;
528 ios_base::iostate __err = ios_base::goodbit;
529 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
530 this->setstate(__err);
532 #ifndef _LIBCPP_NO_EXCEPTIONS
536 this->__set_badbit_and_consider_rethrow();
542 template <class _CharT, class _Traits>
543 basic_istream<_CharT, _Traits>&
544 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
546 #ifndef _LIBCPP_NO_EXCEPTIONS
553 typedef istreambuf_iterator<char_type, traits_type> _I;
554 typedef num_get<char_type, _I> _F;
555 ios_base::iostate __err = ios_base::goodbit;
556 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
557 this->setstate(__err);
559 #ifndef _LIBCPP_NO_EXCEPTIONS
563 this->__set_badbit_and_consider_rethrow();
569 template <class _CharT, class _Traits>
570 basic_istream<_CharT, _Traits>&
571 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
573 #ifndef _LIBCPP_NO_EXCEPTIONS
580 typedef istreambuf_iterator<char_type, traits_type> _I;
581 typedef num_get<char_type, _I> _F;
582 ios_base::iostate __err = ios_base::goodbit;
583 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
584 this->setstate(__err);
586 #ifndef _LIBCPP_NO_EXCEPTIONS
590 this->__set_badbit_and_consider_rethrow();
596 template <class _CharT, class _Traits>
597 basic_istream<_CharT, _Traits>&
598 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
600 #ifndef _LIBCPP_NO_EXCEPTIONS
607 typedef istreambuf_iterator<char_type, traits_type> _I;
608 typedef num_get<char_type, _I> _F;
609 ios_base::iostate __err = ios_base::goodbit;
610 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
611 this->setstate(__err);
613 #ifndef _LIBCPP_NO_EXCEPTIONS
617 this->__set_badbit_and_consider_rethrow();
623 template <class _CharT, class _Traits>
624 basic_istream<_CharT, _Traits>&
625 basic_istream<_CharT, _Traits>::operator>>(short& __n)
627 #ifndef _LIBCPP_NO_EXCEPTIONS
634 typedef istreambuf_iterator<char_type, traits_type> _I;
635 typedef num_get<char_type, _I> _F;
636 ios_base::iostate __err = ios_base::goodbit;
638 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
639 if (__temp < numeric_limits<short>::min())
641 __err |= ios_base::failbit;
642 __n = numeric_limits<short>::min();
644 else if (__temp > numeric_limits<short>::max())
646 __err |= ios_base::failbit;
647 __n = numeric_limits<short>::max();
650 __n = static_cast<short>(__temp);
651 this->setstate(__err);
653 #ifndef _LIBCPP_NO_EXCEPTIONS
657 this->__set_badbit_and_consider_rethrow();
663 template <class _CharT, class _Traits>
664 basic_istream<_CharT, _Traits>&
665 basic_istream<_CharT, _Traits>::operator>>(int& __n)
667 #ifndef _LIBCPP_NO_EXCEPTIONS
674 typedef istreambuf_iterator<char_type, traits_type> _I;
675 typedef num_get<char_type, _I> _F;
676 ios_base::iostate __err = ios_base::goodbit;
678 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
679 if (__temp < numeric_limits<int>::min())
681 __err |= ios_base::failbit;
682 __n = numeric_limits<int>::min();
684 else if (__temp > numeric_limits<int>::max())
686 __err |= ios_base::failbit;
687 __n = numeric_limits<int>::max();
690 __n = static_cast<int>(__temp);
691 this->setstate(__err);
693 #ifndef _LIBCPP_NO_EXCEPTIONS
697 this->__set_badbit_and_consider_rethrow();
703 template <class _CharT, class _Traits>
704 inline _LIBCPP_INLINE_VISIBILITY
705 basic_istream<_CharT, _Traits>&
706 basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
711 template <class _CharT, class _Traits>
712 inline _LIBCPP_INLINE_VISIBILITY
713 basic_istream<_CharT, _Traits>&
714 basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
715 (*__pf)(basic_ios<char_type, traits_type>&))
721 template <class _CharT, class _Traits>
722 inline _LIBCPP_INLINE_VISIBILITY
723 basic_istream<_CharT, _Traits>&
724 basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
730 template<class _CharT, class _Traits>
731 basic_istream<_CharT, _Traits>&
732 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
734 #ifndef _LIBCPP_NO_EXCEPTIONS
738 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
741 typedef istreambuf_iterator<_CharT, _Traits> _I;
742 streamsize __n = __is.width();
744 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
746 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
749 for (; __i != __eof && __c < __n-1; ++__i, ++__s, ++__c)
752 if (__ct.is(__ct.space, __ch))
758 ios_base::iostate __err = ios_base::goodbit;
760 __err |= ios_base::eofbit;
762 __err |= ios_base::failbit;
763 __is.setstate(__err);
765 #ifndef _LIBCPP_NO_EXCEPTIONS
769 __is.__set_badbit_and_consider_rethrow();
775 template<class _Traits>
776 inline _LIBCPP_INLINE_VISIBILITY
777 basic_istream<char, _Traits>&
778 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
780 return __is >> (char*)__s;
783 template<class _Traits>
784 inline _LIBCPP_INLINE_VISIBILITY
785 basic_istream<char, _Traits>&
786 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
788 return __is >> (char*)__s;
791 template<class _CharT, class _Traits>
792 basic_istream<_CharT, _Traits>&
793 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
795 #ifndef _LIBCPP_NO_EXCEPTIONS
799 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
802 typedef istreambuf_iterator<_CharT, _Traits> _I;
809 __is.setstate(ios_base::eofbit);
812 __is.setstate(ios_base::eofbit | ios_base::failbit);
814 #ifndef _LIBCPP_NO_EXCEPTIONS
818 __is.__set_badbit_and_consider_rethrow();
824 template<class _Traits>
825 inline _LIBCPP_INLINE_VISIBILITY
826 basic_istream<char, _Traits>&
827 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
829 return __is >> (char&)__c;
832 template<class _Traits>
833 inline _LIBCPP_INLINE_VISIBILITY
834 basic_istream<char, _Traits>&
835 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
837 return __is >> (char&)__c;
840 template<class _CharT, class _Traits>
841 basic_istream<_CharT, _Traits>&
842 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
845 #ifndef _LIBCPP_NO_EXCEPTIONS
849 sentry __s(*this, true);
855 #ifndef _LIBCPP_NO_EXCEPTIONS
859 typedef istreambuf_iterator<char_type, traits_type> _I;
860 typedef ostreambuf_iterator<char_type, traits_type> _O;
864 for (; __i != __eof; ++__i, ++__o, ++__c)
870 ios_base::iostate __err = ios_base::goodbit;
872 __err |= ios_base::eofbit;
874 __err |= ios_base::failbit;
875 this->setstate(__err);
876 #ifndef _LIBCPP_NO_EXCEPTIONS
881 this->__set_failbit_and_consider_rethrow();
886 this->setstate(ios_base::failbit);
889 #ifndef _LIBCPP_NO_EXCEPTIONS
893 this->__set_badbit_and_consider_rethrow();
899 template<class _CharT, class _Traits>
900 typename basic_istream<_CharT, _Traits>::int_type
901 basic_istream<_CharT, _Traits>::get()
904 int_type __r = traits_type::eof();
905 #ifndef _LIBCPP_NO_EXCEPTIONS
909 sentry __s(*this, true);
913 typedef istreambuf_iterator<char_type, traits_type> _I;
916 ios_base::iostate __err = ios_base::goodbit;
919 __r = traits_type::to_int_type(*__i);
922 __err |= ios_base::eofbit;
925 __err |= ios_base::failbit | ios_base::eofbit;
926 this->setstate(__err);
929 #ifndef _LIBCPP_NO_EXCEPTIONS
933 this->__set_badbit_and_consider_rethrow();
939 template<class _CharT, class _Traits>
940 inline _LIBCPP_INLINE_VISIBILITY
941 basic_istream<_CharT, _Traits>&
942 basic_istream<_CharT, _Traits>::get(char_type& __c)
944 int_type __ch = get();
945 if (__ch != traits_type::eof())
946 __c = traits_type::to_char_type(__ch);
950 template<class _CharT, class _Traits>
951 basic_istream<_CharT, _Traits>&
952 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
955 #ifndef _LIBCPP_NO_EXCEPTIONS
959 sentry __sen(*this, true);
965 typedef istreambuf_iterator<char_type, traits_type> _I;
968 for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c)
970 char_type __ch = *__i;
971 if (traits_type::eq(__ch, __dlm))
976 ios_base::iostate __err = ios_base::goodbit;
978 __err |= ios_base::eofbit;
980 __err |= ios_base::failbit;
981 this->setstate(__err);
984 this->setstate(ios_base::failbit);
987 #ifndef _LIBCPP_NO_EXCEPTIONS
991 this->__set_badbit_and_consider_rethrow();
997 template<class _CharT, class _Traits>
998 inline _LIBCPP_INLINE_VISIBILITY
999 basic_istream<_CharT, _Traits>&
1000 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1002 return get(__s, __n, this->widen('\n'));
1005 template<class _CharT, class _Traits>
1006 basic_istream<_CharT, _Traits>&
1007 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1011 #ifndef _LIBCPP_NO_EXCEPTIONS
1015 sentry __sen(*this, true);
1019 ios_base::iostate __err = ios_base::goodbit;
1020 #ifndef _LIBCPP_NO_EXCEPTIONS
1024 typedef istreambuf_iterator<char_type, traits_type> _I;
1025 typedef ostreambuf_iterator<char_type, traits_type> _O;
1029 for (; __i != __eof; ++__i, ++__o, ++__c)
1031 char_type __ch = *__i;
1032 if (traits_type::eq(__ch, __dlm))
1039 __err |= ios_base::eofbit;
1040 #ifndef _LIBCPP_NO_EXCEPTIONS
1047 __err |= ios_base::failbit;
1048 this->setstate(__err);
1051 #ifndef _LIBCPP_NO_EXCEPTIONS
1055 this->__set_badbit_and_consider_rethrow();
1061 template<class _CharT, class _Traits>
1062 inline _LIBCPP_INLINE_VISIBILITY
1063 basic_istream<_CharT, _Traits>&
1064 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1066 return get(__sb, this->widen('\n'));
1069 template<class _CharT, class _Traits>
1070 basic_istream<_CharT, _Traits>&
1071 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1074 #ifndef _LIBCPP_NO_EXCEPTIONS
1078 sentry __sen(*this, true);
1082 typedef istreambuf_iterator<char_type, traits_type> _I;
1085 for (; __i != __eof; ++__s, --__n)
1087 char_type __ch = *__i;
1090 if (traits_type::eq(__ch, __dlm))
1094 this->setstate(ios_base::failbit);
1101 ios_base::iostate __err = ios_base::goodbit;
1103 __err |= ios_base::eofbit;
1105 __err |= ios_base::failbit;
1106 this->setstate(__err);
1109 #ifndef _LIBCPP_NO_EXCEPTIONS
1113 this->__set_badbit_and_consider_rethrow();
1119 template<class _CharT, class _Traits>
1120 inline _LIBCPP_INLINE_VISIBILITY
1121 basic_istream<_CharT, _Traits>&
1122 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1124 return getline(__s, __n, this->widen('\n'));
1127 template<class _CharT, class _Traits>
1128 basic_istream<_CharT, _Traits>&
1129 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1132 #ifndef _LIBCPP_NO_EXCEPTIONS
1136 sentry __sen(*this, true);
1140 typedef istreambuf_iterator<char_type, traits_type> _I;
1143 if (__n != numeric_limits<streamsize>::max())
1145 for (; __n > 0 && __i != __eof; --__n)
1147 char_type __ch = *__i;
1150 if (traits_type::eq(__ch, __dlm))
1156 while (__i != __eof)
1158 char_type __ch = *__i;
1161 if (traits_type::eq(__ch, __dlm))
1166 this->setstate(ios_base::eofbit);
1169 #ifndef _LIBCPP_NO_EXCEPTIONS
1173 this->__set_badbit_and_consider_rethrow();
1179 template<class _CharT, class _Traits>
1180 typename basic_istream<_CharT, _Traits>::int_type
1181 basic_istream<_CharT, _Traits>::peek()
1184 int_type __r = traits_type::eof();
1185 #ifndef _LIBCPP_NO_EXCEPTIONS
1189 sentry __sen(*this, true);
1191 __r = this->rdbuf()->sgetc();
1192 #ifndef _LIBCPP_NO_EXCEPTIONS
1196 this->__set_badbit_and_consider_rethrow();
1202 template<class _CharT, class _Traits>
1203 basic_istream<_CharT, _Traits>&
1204 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1207 #ifndef _LIBCPP_NO_EXCEPTIONS
1211 sentry __sen(*this, true);
1215 typedef istreambuf_iterator<char_type, traits_type> _I;
1218 for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n)
1222 ios_base::iostate __err = ios_base::eofbit;
1224 __err |= ios_base::failbit;
1225 this->setstate(__err);
1230 this->setstate(ios_base::failbit);
1231 #ifndef _LIBCPP_NO_EXCEPTIONS
1235 this->__set_badbit_and_consider_rethrow();
1241 template<class _CharT, class _Traits>
1243 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1247 #ifndef _LIBCPP_NO_EXCEPTIONS
1251 sentry __sen(*this, true);
1254 typedef istreambuf_iterator<char_type, traits_type> _I;
1257 __c = this->rdbuf()->in_avail();
1266 __c = min(__c, __n);
1267 for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i)
1271 this->setstate(ios_base::eofbit);
1275 this->setstate(ios_base::failbit);
1276 #ifndef _LIBCPP_NO_EXCEPTIONS
1280 this->__set_badbit_and_consider_rethrow();
1286 template<class _CharT, class _Traits>
1287 basic_istream<_CharT, _Traits>&
1288 basic_istream<_CharT, _Traits>::putback(char_type __c)
1291 #ifndef _LIBCPP_NO_EXCEPTIONS
1295 sentry __sen(*this, true);
1298 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1299 this->setstate(ios_base::badbit);
1302 this->setstate(ios_base::failbit);
1303 #ifndef _LIBCPP_NO_EXCEPTIONS
1307 this->__set_badbit_and_consider_rethrow();
1313 template<class _CharT, class _Traits>
1314 basic_istream<_CharT, _Traits>&
1315 basic_istream<_CharT, _Traits>::unget()
1318 #ifndef _LIBCPP_NO_EXCEPTIONS
1322 sentry __sen(*this, true);
1325 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1326 this->setstate(ios_base::badbit);
1329 this->setstate(ios_base::failbit);
1330 #ifndef _LIBCPP_NO_EXCEPTIONS
1334 this->__set_badbit_and_consider_rethrow();
1340 template<class _CharT, class _Traits>
1342 basic_istream<_CharT, _Traits>::sync()
1345 #ifndef _LIBCPP_NO_EXCEPTIONS
1349 sentry __sen(*this, true);
1352 if (this->rdbuf() == 0)
1354 if (this->rdbuf()->pubsync() == -1)
1356 this->setstate(ios_base::badbit);
1360 #ifndef _LIBCPP_NO_EXCEPTIONS
1364 this->__set_badbit_and_consider_rethrow();
1370 template<class _CharT, class _Traits>
1371 typename basic_istream<_CharT, _Traits>::pos_type
1372 basic_istream<_CharT, _Traits>::tellg()
1375 #ifndef _LIBCPP_NO_EXCEPTIONS
1379 sentry __sen(*this, true);
1381 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1382 #ifndef _LIBCPP_NO_EXCEPTIONS
1386 this->__set_badbit_and_consider_rethrow();
1392 template<class _CharT, class _Traits>
1393 basic_istream<_CharT, _Traits>&
1394 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1396 #ifndef _LIBCPP_NO_EXCEPTIONS
1400 sentry __sen(*this, true);
1402 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1403 this->setstate(ios_base::failbit);
1404 #ifndef _LIBCPP_NO_EXCEPTIONS
1408 this->__set_badbit_and_consider_rethrow();
1414 template<class _CharT, class _Traits>
1415 basic_istream<_CharT, _Traits>&
1416 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1418 #ifndef _LIBCPP_NO_EXCEPTIONS
1422 sentry __sen(*this, true);
1424 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
1425 #ifndef _LIBCPP_NO_EXCEPTIONS
1429 this->__set_badbit_and_consider_rethrow();
1435 template <class _CharT, class _Traits>
1436 basic_istream<_CharT, _Traits>&
1437 ws(basic_istream<_CharT, _Traits>& __is)
1439 #ifndef _LIBCPP_NO_EXCEPTIONS
1443 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1446 typedef istreambuf_iterator<_CharT, _Traits> _I;
1447 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1450 for (; __i != __eof; ++__i)
1451 if (!__ct.is(__ct.space, *__i))
1454 __is.setstate(ios_base::failbit | ios_base::eofbit);
1456 #ifndef _LIBCPP_NO_EXCEPTIONS
1460 __is.__set_badbit_and_consider_rethrow();
1468 template <class _CharT, class _Traits, class _Tp>
1469 inline _LIBCPP_INLINE_VISIBILITY
1470 basic_istream<_CharT, _Traits>&
1471 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1479 template <class _CharT, class _Traits>
1480 class basic_iostream
1481 : public basic_istream<_CharT, _Traits>,
1482 public basic_ostream<_CharT, _Traits>
1486 typedef _CharT char_type;
1487 typedef _Traits traits_type;
1488 typedef typename traits_type::int_type int_type;
1489 typedef typename traits_type::pos_type pos_type;
1490 typedef typename traits_type::off_type off_type;
1492 // constructor/destructor
1493 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1494 virtual ~basic_iostream();
1497 basic_iostream(basic_iostream&& __rhs);
1502 basic_iostream& operator=(basic_iostream&& __rhs);
1504 void swap(basic_iostream& __rhs);
1508 template <class _CharT, class _Traits>
1509 inline _LIBCPP_INLINE_VISIBILITY
1510 basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1511 : basic_istream<_CharT, _Traits>(__sb)
1517 template <class _CharT, class _Traits>
1518 inline _LIBCPP_INLINE_VISIBILITY
1519 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1520 : basic_istream<_CharT, _Traits>(_STD::move(__rhs))
1524 template <class _CharT, class _Traits>
1525 inline _LIBCPP_INLINE_VISIBILITY
1526 basic_iostream<_CharT, _Traits>&
1527 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1535 template <class _CharT, class _Traits>
1536 basic_iostream<_CharT, _Traits>::~basic_iostream()
1540 template <class _CharT, class _Traits>
1541 inline _LIBCPP_INLINE_VISIBILITY
1543 basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1545 basic_istream<char_type, traits_type>::swap(__rhs);
1548 template<class _CharT, class _Traits, class _Allocator>
1549 basic_istream<_CharT, _Traits>&
1550 operator>>(basic_istream<_CharT, _Traits>& __is,
1551 basic_string<_CharT, _Traits, _Allocator>& __str)
1553 #ifndef _LIBCPP_NO_EXCEPTIONS
1557 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1561 typedef istreambuf_iterator<_CharT, _Traits> _I;
1562 streamsize __n = __is.width();
1564 __n = __str.max_size();
1566 __n = numeric_limits<streamsize>::max();
1568 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1571 for (; __i != __eof && __c < __n; ++__i, ++__c)
1574 if (__ct.is(__ct.space, __ch))
1576 __str.push_back(__ch);
1579 ios_base::iostate __err = ios_base::goodbit;
1581 __err |= ios_base::eofbit;
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();
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
1607 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1612 typedef istreambuf_iterator<_CharT, _Traits> _I;
1615 streamsize __n = __str.max_size();
1617 __n = numeric_limits<streamsize>::max();
1618 for (; __i != __eof;)
1623 if (_Traits::eq(__ch, __dlm))
1627 __is.setstate(ios_base::failbit);
1630 __str.push_back(__ch);
1632 ios_base::iostate __err = ios_base::goodbit;
1634 __err |= ios_base::eofbit;
1636 __err |= ios_base::failbit;
1637 __is.setstate(__err);
1639 #ifndef _LIBCPP_NO_EXCEPTIONS
1643 __is.__set_badbit_and_consider_rethrow();
1649 template<class _CharT, class _Traits, class _Allocator>
1651 basic_istream<_CharT, _Traits>&
1652 getline(basic_istream<_CharT, _Traits>& __is,
1653 basic_string<_CharT, _Traits, _Allocator>& __str)
1655 return getline(__is, __str, __is.widen('\n'));
1660 template<class _CharT, class _Traits, class _Allocator>
1662 basic_istream<_CharT, _Traits>&
1663 getline(basic_istream<_CharT, _Traits>&& __is,
1664 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1666 return getline(__is, __str, __dlm);
1669 template<class _CharT, class _Traits, class _Allocator>
1671 basic_istream<_CharT, _Traits>&
1672 getline(basic_istream<_CharT, _Traits>&& __is,
1673 basic_string<_CharT, _Traits, _Allocator>& __str)
1675 return getline(__is, __str, __is.widen('\n'));
1680 template <class _CharT, class _Traits, size_t _Size>
1681 basic_istream<_CharT, _Traits>&
1682 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1684 #ifndef _LIBCPP_NO_EXCEPTIONS
1688 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1691 basic_string<_CharT, _Traits> __str;
1692 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1693 typedef istreambuf_iterator<_CharT, _Traits> _I;
1695 _CharT __zero = __ct.widen('0');
1696 _CharT __one = __ct.widen('1');
1699 for (; __i != __eof && __c < _Size; ++__i, ++__c)
1702 if (__ch != __zero && __ch != __one)
1704 __str.push_back(__ch);
1707 __x = bitset<_Size>(__str);
1708 ios_base::iostate __err = ios_base::goodbit;
1710 __err |= ios_base::eofbit;
1712 __err |= ios_base::failbit;
1713 __is.setstate(__err);
1716 __is.setstate(ios_base::failbit);
1717 #ifndef _LIBCPP_NO_EXCEPTIONS
1721 __is.__set_badbit_and_consider_rethrow();
1727 extern template class basic_istream<char>;
1728 extern template class basic_istream<wchar_t>;
1729 extern template class basic_iostream<char>;
1731 _LIBCPP_END_NAMESPACE_STD
1733 #endif // _LIBCPP_ISTREAM