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>
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);
804 typedef istreambuf_iterator<_CharT, _Traits> _I;
811 __is.setstate(ios_base::eofbit);
814 __is.setstate(ios_base::eofbit | ios_base::failbit);
816 #ifndef _LIBCPP_NO_EXCEPTIONS
820 __is.__set_badbit_and_consider_rethrow();
822 #endif // _LIBCPP_NO_EXCEPTIONS
826 template<class _Traits>
827 inline _LIBCPP_INLINE_VISIBILITY
828 basic_istream<char, _Traits>&
829 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
831 return __is >> (char&)__c;
834 template<class _Traits>
835 inline _LIBCPP_INLINE_VISIBILITY
836 basic_istream<char, _Traits>&
837 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
839 return __is >> (char&)__c;
842 template<class _CharT, class _Traits>
843 basic_istream<_CharT, _Traits>&
844 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
847 #ifndef _LIBCPP_NO_EXCEPTIONS
850 #endif // _LIBCPP_NO_EXCEPTIONS
851 sentry __s(*this, true);
857 #ifndef _LIBCPP_NO_EXCEPTIONS
860 #endif // _LIBCPP_NO_EXCEPTIONS
861 typedef istreambuf_iterator<char_type, traits_type> _I;
862 typedef ostreambuf_iterator<char_type, traits_type> _O;
866 for (; __i != __eof; ++__i, ++__o, ++__c)
872 ios_base::iostate __err = ios_base::goodbit;
874 __err |= ios_base::eofbit;
876 __err |= ios_base::failbit;
877 this->setstate(__err);
878 #ifndef _LIBCPP_NO_EXCEPTIONS
883 this->__set_failbit_and_consider_rethrow();
885 #endif // _LIBCPP_NO_EXCEPTIONS
888 this->setstate(ios_base::failbit);
891 #ifndef _LIBCPP_NO_EXCEPTIONS
895 this->__set_badbit_and_consider_rethrow();
897 #endif // _LIBCPP_NO_EXCEPTIONS
901 template<class _CharT, class _Traits>
902 typename basic_istream<_CharT, _Traits>::int_type
903 basic_istream<_CharT, _Traits>::get()
906 int_type __r = traits_type::eof();
907 #ifndef _LIBCPP_NO_EXCEPTIONS
910 #endif // _LIBCPP_NO_EXCEPTIONS
911 sentry __s(*this, true);
915 typedef istreambuf_iterator<char_type, traits_type> _I;
918 ios_base::iostate __err = ios_base::goodbit;
921 __r = traits_type::to_int_type(*__i);
924 __err |= ios_base::eofbit;
927 __err |= ios_base::failbit | ios_base::eofbit;
928 this->setstate(__err);
931 #ifndef _LIBCPP_NO_EXCEPTIONS
935 this->__set_badbit_and_consider_rethrow();
937 #endif // _LIBCPP_NO_EXCEPTIONS
941 template<class _CharT, class _Traits>
942 inline _LIBCPP_INLINE_VISIBILITY
943 basic_istream<_CharT, _Traits>&
944 basic_istream<_CharT, _Traits>::get(char_type& __c)
946 int_type __ch = get();
947 if (__ch != traits_type::eof())
948 __c = traits_type::to_char_type(__ch);
952 template<class _CharT, class _Traits>
953 basic_istream<_CharT, _Traits>&
954 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
957 #ifndef _LIBCPP_NO_EXCEPTIONS
960 #endif // _LIBCPP_NO_EXCEPTIONS
961 sentry __sen(*this, true);
967 typedef istreambuf_iterator<char_type, traits_type> _I;
970 for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c)
972 char_type __ch = *__i;
973 if (traits_type::eq(__ch, __dlm))
978 ios_base::iostate __err = ios_base::goodbit;
980 __err |= ios_base::eofbit;
982 __err |= ios_base::failbit;
983 this->setstate(__err);
986 this->setstate(ios_base::failbit);
989 #ifndef _LIBCPP_NO_EXCEPTIONS
993 this->__set_badbit_and_consider_rethrow();
995 #endif // _LIBCPP_NO_EXCEPTIONS
999 template<class _CharT, class _Traits>
1000 inline _LIBCPP_INLINE_VISIBILITY
1001 basic_istream<_CharT, _Traits>&
1002 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1004 return get(__s, __n, this->widen('\n'));
1007 template<class _CharT, class _Traits>
1008 basic_istream<_CharT, _Traits>&
1009 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1013 #ifndef _LIBCPP_NO_EXCEPTIONS
1016 #endif // _LIBCPP_NO_EXCEPTIONS
1017 sentry __sen(*this, true);
1021 ios_base::iostate __err = ios_base::goodbit;
1022 #ifndef _LIBCPP_NO_EXCEPTIONS
1025 #endif // _LIBCPP_NO_EXCEPTIONS
1026 typedef istreambuf_iterator<char_type, traits_type> _I;
1027 typedef ostreambuf_iterator<char_type, traits_type> _O;
1031 for (; __i != __eof; ++__i, ++__o, ++__c)
1033 char_type __ch = *__i;
1034 if (traits_type::eq(__ch, __dlm))
1041 __err |= ios_base::eofbit;
1042 #ifndef _LIBCPP_NO_EXCEPTIONS
1047 #endif // _LIBCPP_NO_EXCEPTIONS
1049 __err |= ios_base::failbit;
1050 this->setstate(__err);
1053 #ifndef _LIBCPP_NO_EXCEPTIONS
1057 this->__set_badbit_and_consider_rethrow();
1059 #endif // _LIBCPP_NO_EXCEPTIONS
1063 template<class _CharT, class _Traits>
1064 inline _LIBCPP_INLINE_VISIBILITY
1065 basic_istream<_CharT, _Traits>&
1066 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1068 return get(__sb, this->widen('\n'));
1071 template<class _CharT, class _Traits>
1072 basic_istream<_CharT, _Traits>&
1073 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1076 #ifndef _LIBCPP_NO_EXCEPTIONS
1079 #endif // _LIBCPP_NO_EXCEPTIONS
1080 sentry __sen(*this, true);
1084 typedef istreambuf_iterator<char_type, traits_type> _I;
1087 for (; __i != __eof; ++__s, --__n)
1089 char_type __ch = *__i;
1092 if (traits_type::eq(__ch, __dlm))
1096 this->setstate(ios_base::failbit);
1103 ios_base::iostate __err = ios_base::goodbit;
1105 __err |= ios_base::eofbit;
1107 __err |= ios_base::failbit;
1108 this->setstate(__err);
1111 #ifndef _LIBCPP_NO_EXCEPTIONS
1115 this->__set_badbit_and_consider_rethrow();
1117 #endif // _LIBCPP_NO_EXCEPTIONS
1121 template<class _CharT, class _Traits>
1122 inline _LIBCPP_INLINE_VISIBILITY
1123 basic_istream<_CharT, _Traits>&
1124 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1126 return getline(__s, __n, this->widen('\n'));
1129 template<class _CharT, class _Traits>
1130 basic_istream<_CharT, _Traits>&
1131 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1134 #ifndef _LIBCPP_NO_EXCEPTIONS
1137 #endif // _LIBCPP_NO_EXCEPTIONS
1138 sentry __sen(*this, true);
1142 typedef istreambuf_iterator<char_type, traits_type> _I;
1145 if (__n != numeric_limits<streamsize>::max())
1147 for (; __n > 0 && __i != __eof; --__n)
1149 char_type __ch = *__i;
1152 if (traits_type::eq(__ch, __dlm))
1158 while (__i != __eof)
1160 char_type __ch = *__i;
1163 if (traits_type::eq(__ch, __dlm))
1168 this->setstate(ios_base::eofbit);
1171 #ifndef _LIBCPP_NO_EXCEPTIONS
1175 this->__set_badbit_and_consider_rethrow();
1177 #endif // _LIBCPP_NO_EXCEPTIONS
1181 template<class _CharT, class _Traits>
1182 typename basic_istream<_CharT, _Traits>::int_type
1183 basic_istream<_CharT, _Traits>::peek()
1186 int_type __r = traits_type::eof();
1187 #ifndef _LIBCPP_NO_EXCEPTIONS
1190 #endif // _LIBCPP_NO_EXCEPTIONS
1191 sentry __sen(*this, true);
1193 __r = this->rdbuf()->sgetc();
1194 #ifndef _LIBCPP_NO_EXCEPTIONS
1198 this->__set_badbit_and_consider_rethrow();
1200 #endif // _LIBCPP_NO_EXCEPTIONS
1204 template<class _CharT, class _Traits>
1205 basic_istream<_CharT, _Traits>&
1206 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1209 #ifndef _LIBCPP_NO_EXCEPTIONS
1212 #endif // _LIBCPP_NO_EXCEPTIONS
1213 sentry __sen(*this, true);
1217 typedef istreambuf_iterator<char_type, traits_type> _I;
1220 for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n)
1224 ios_base::iostate __err = ios_base::eofbit;
1226 __err |= ios_base::failbit;
1227 this->setstate(__err);
1232 this->setstate(ios_base::failbit);
1233 #ifndef _LIBCPP_NO_EXCEPTIONS
1237 this->__set_badbit_and_consider_rethrow();
1239 #endif // _LIBCPP_NO_EXCEPTIONS
1243 template<class _CharT, class _Traits>
1245 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1249 #ifndef _LIBCPP_NO_EXCEPTIONS
1252 #endif // _LIBCPP_NO_EXCEPTIONS
1253 sentry __sen(*this, true);
1256 typedef istreambuf_iterator<char_type, traits_type> _I;
1259 __c = this->rdbuf()->in_avail();
1268 __c = min(__c, __n);
1269 for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i)
1273 this->setstate(ios_base::eofbit);
1277 this->setstate(ios_base::failbit);
1278 #ifndef _LIBCPP_NO_EXCEPTIONS
1282 this->__set_badbit_and_consider_rethrow();
1284 #endif // _LIBCPP_NO_EXCEPTIONS
1288 template<class _CharT, class _Traits>
1289 basic_istream<_CharT, _Traits>&
1290 basic_istream<_CharT, _Traits>::putback(char_type __c)
1293 #ifndef _LIBCPP_NO_EXCEPTIONS
1296 #endif // _LIBCPP_NO_EXCEPTIONS
1297 sentry __sen(*this, true);
1300 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1301 this->setstate(ios_base::badbit);
1304 this->setstate(ios_base::failbit);
1305 #ifndef _LIBCPP_NO_EXCEPTIONS
1309 this->__set_badbit_and_consider_rethrow();
1311 #endif // _LIBCPP_NO_EXCEPTIONS
1315 template<class _CharT, class _Traits>
1316 basic_istream<_CharT, _Traits>&
1317 basic_istream<_CharT, _Traits>::unget()
1320 #ifndef _LIBCPP_NO_EXCEPTIONS
1323 #endif // _LIBCPP_NO_EXCEPTIONS
1324 sentry __sen(*this, true);
1327 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1328 this->setstate(ios_base::badbit);
1331 this->setstate(ios_base::failbit);
1332 #ifndef _LIBCPP_NO_EXCEPTIONS
1336 this->__set_badbit_and_consider_rethrow();
1338 #endif // _LIBCPP_NO_EXCEPTIONS
1342 template<class _CharT, class _Traits>
1344 basic_istream<_CharT, _Traits>::sync()
1347 #ifndef _LIBCPP_NO_EXCEPTIONS
1350 #endif // _LIBCPP_NO_EXCEPTIONS
1351 sentry __sen(*this, true);
1354 if (this->rdbuf() == 0)
1356 if (this->rdbuf()->pubsync() == -1)
1358 this->setstate(ios_base::badbit);
1362 #ifndef _LIBCPP_NO_EXCEPTIONS
1366 this->__set_badbit_and_consider_rethrow();
1368 #endif // _LIBCPP_NO_EXCEPTIONS
1372 template<class _CharT, class _Traits>
1373 typename basic_istream<_CharT, _Traits>::pos_type
1374 basic_istream<_CharT, _Traits>::tellg()
1377 #ifndef _LIBCPP_NO_EXCEPTIONS
1380 #endif // _LIBCPP_NO_EXCEPTIONS
1381 sentry __sen(*this, true);
1383 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1384 #ifndef _LIBCPP_NO_EXCEPTIONS
1388 this->__set_badbit_and_consider_rethrow();
1390 #endif // _LIBCPP_NO_EXCEPTIONS
1394 template<class _CharT, class _Traits>
1395 basic_istream<_CharT, _Traits>&
1396 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1398 #ifndef _LIBCPP_NO_EXCEPTIONS
1401 #endif // _LIBCPP_NO_EXCEPTIONS
1402 sentry __sen(*this, true);
1404 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1405 this->setstate(ios_base::failbit);
1406 #ifndef _LIBCPP_NO_EXCEPTIONS
1410 this->__set_badbit_and_consider_rethrow();
1412 #endif // _LIBCPP_NO_EXCEPTIONS
1416 template<class _CharT, class _Traits>
1417 basic_istream<_CharT, _Traits>&
1418 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1420 #ifndef _LIBCPP_NO_EXCEPTIONS
1423 #endif // _LIBCPP_NO_EXCEPTIONS
1424 sentry __sen(*this, true);
1426 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
1427 #ifndef _LIBCPP_NO_EXCEPTIONS
1431 this->__set_badbit_and_consider_rethrow();
1433 #endif // _LIBCPP_NO_EXCEPTIONS
1437 template <class _CharT, class _Traits>
1438 basic_istream<_CharT, _Traits>&
1439 ws(basic_istream<_CharT, _Traits>& __is)
1441 #ifndef _LIBCPP_NO_EXCEPTIONS
1444 #endif // _LIBCPP_NO_EXCEPTIONS
1445 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1448 typedef istreambuf_iterator<_CharT, _Traits> _I;
1449 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1452 for (; __i != __eof; ++__i)
1453 if (!__ct.is(__ct.space, *__i))
1456 __is.setstate(ios_base::failbit | ios_base::eofbit);
1458 #ifndef _LIBCPP_NO_EXCEPTIONS
1462 __is.__set_badbit_and_consider_rethrow();
1464 #endif // _LIBCPP_NO_EXCEPTIONS
1468 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1470 template <class _CharT, class _Traits, class _Tp>
1471 inline _LIBCPP_INLINE_VISIBILITY
1472 basic_istream<_CharT, _Traits>&
1473 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1479 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1481 template <class _CharT, class _Traits>
1482 class _LIBCPP_VISIBLE basic_iostream
1483 : public basic_istream<_CharT, _Traits>,
1484 public basic_ostream<_CharT, _Traits>
1488 typedef _CharT char_type;
1489 typedef _Traits traits_type;
1490 typedef typename traits_type::int_type int_type;
1491 typedef typename traits_type::pos_type pos_type;
1492 typedef typename traits_type::off_type off_type;
1494 // constructor/destructor
1495 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1496 virtual ~basic_iostream();
1498 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1499 basic_iostream(basic_iostream&& __rhs);
1503 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1504 basic_iostream& operator=(basic_iostream&& __rhs);
1506 void swap(basic_iostream& __rhs);
1510 template <class _CharT, class _Traits>
1511 inline _LIBCPP_INLINE_VISIBILITY
1512 basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1513 : basic_istream<_CharT, _Traits>(__sb)
1517 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1519 template <class _CharT, class _Traits>
1520 inline _LIBCPP_INLINE_VISIBILITY
1521 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1522 : basic_istream<_CharT, _Traits>(_STD::move(__rhs))
1526 template <class _CharT, class _Traits>
1527 inline _LIBCPP_INLINE_VISIBILITY
1528 basic_iostream<_CharT, _Traits>&
1529 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1535 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1537 template <class _CharT, class _Traits>
1538 basic_iostream<_CharT, _Traits>::~basic_iostream()
1542 template <class _CharT, class _Traits>
1543 inline _LIBCPP_INLINE_VISIBILITY
1545 basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1547 basic_istream<char_type, traits_type>::swap(__rhs);
1550 template<class _CharT, class _Traits, class _Allocator>
1551 basic_istream<_CharT, _Traits>&
1552 operator>>(basic_istream<_CharT, _Traits>& __is,
1553 basic_string<_CharT, _Traits, _Allocator>& __str)
1555 #ifndef _LIBCPP_NO_EXCEPTIONS
1558 #endif // _LIBCPP_NO_EXCEPTIONS
1559 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1563 typedef istreambuf_iterator<_CharT, _Traits> _I;
1564 streamsize __n = __is.width();
1566 __n = __str.max_size();
1568 __n = numeric_limits<streamsize>::max();
1570 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1573 for (; __i != __eof && __c < __n; ++__i, ++__c)
1576 if (__ct.is(__ct.space, __ch))
1578 __str.push_back(__ch);
1581 ios_base::iostate __err = ios_base::goodbit;
1583 __err |= ios_base::eofbit;
1585 __err |= ios_base::failbit;
1586 __is.setstate(__err);
1589 __is.setstate(ios_base::failbit);
1590 #ifndef _LIBCPP_NO_EXCEPTIONS
1594 __is.__set_badbit_and_consider_rethrow();
1596 #endif // _LIBCPP_NO_EXCEPTIONS
1600 template<class _CharT, class _Traits, class _Allocator>
1601 basic_istream<_CharT, _Traits>&
1602 getline(basic_istream<_CharT, _Traits>& __is,
1603 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1605 #ifndef _LIBCPP_NO_EXCEPTIONS
1608 #endif // _LIBCPP_NO_EXCEPTIONS
1609 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1614 typedef istreambuf_iterator<_CharT, _Traits> _I;
1617 streamsize __n = __str.max_size();
1619 __n = numeric_limits<streamsize>::max();
1620 for (; __i != __eof;)
1625 if (_Traits::eq(__ch, __dlm))
1629 __is.setstate(ios_base::failbit);
1632 __str.push_back(__ch);
1634 ios_base::iostate __err = ios_base::goodbit;
1636 __err |= ios_base::eofbit;
1638 __err |= ios_base::failbit;
1639 __is.setstate(__err);
1641 #ifndef _LIBCPP_NO_EXCEPTIONS
1645 __is.__set_badbit_and_consider_rethrow();
1647 #endif // _LIBCPP_NO_EXCEPTIONS
1651 template<class _CharT, class _Traits, class _Allocator>
1652 inline _LIBCPP_INLINE_VISIBILITY
1653 basic_istream<_CharT, _Traits>&
1654 getline(basic_istream<_CharT, _Traits>& __is,
1655 basic_string<_CharT, _Traits, _Allocator>& __str)
1657 return getline(__is, __str, __is.widen('\n'));
1660 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1662 template<class _CharT, class _Traits, class _Allocator>
1663 inline _LIBCPP_INLINE_VISIBILITY
1664 basic_istream<_CharT, _Traits>&
1665 getline(basic_istream<_CharT, _Traits>&& __is,
1666 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1668 return getline(__is, __str, __dlm);
1671 template<class _CharT, class _Traits, class _Allocator>
1672 inline _LIBCPP_INLINE_VISIBILITY
1673 basic_istream<_CharT, _Traits>&
1674 getline(basic_istream<_CharT, _Traits>&& __is,
1675 basic_string<_CharT, _Traits, _Allocator>& __str)
1677 return getline(__is, __str, __is.widen('\n'));
1680 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1682 template <class _CharT, class _Traits, size_t _Size>
1683 basic_istream<_CharT, _Traits>&
1684 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1686 #ifndef _LIBCPP_NO_EXCEPTIONS
1689 #endif // _LIBCPP_NO_EXCEPTIONS
1690 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1693 basic_string<_CharT, _Traits> __str;
1694 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1695 typedef istreambuf_iterator<_CharT, _Traits> _I;
1697 _CharT __zero = __ct.widen('0');
1698 _CharT __one = __ct.widen('1');
1701 for (; __i != __eof && __c < _Size; ++__i, ++__c)
1704 if (__ch != __zero && __ch != __one)
1706 __str.push_back(__ch);
1709 __x = bitset<_Size>(__str);
1710 ios_base::iostate __err = ios_base::goodbit;
1712 __err |= ios_base::eofbit;
1714 __err |= ios_base::failbit;
1715 __is.setstate(__err);
1718 __is.setstate(ios_base::failbit);
1719 #ifndef _LIBCPP_NO_EXCEPTIONS
1723 __is.__set_badbit_and_consider_rethrow();
1725 #endif // _LIBCPP_NO_EXCEPTIONS
1729 extern template class basic_istream<char>;
1730 extern template class basic_istream<wchar_t>;
1731 extern template class basic_iostream<char>;
1733 _LIBCPP_END_NAMESPACE_STD
1735 #endif // _LIBCPP_ISTREAM