2 //===--------------------------- istream ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_ISTREAM
12 #define _LIBCPP_ISTREAM
17 template <class charT, class traits = char_traits<charT> >
19 : virtual public basic_ios<charT,traits>
22 // types (inherited from basic_ios (27.5.4)):
23 typedef charT char_type;
24 typedef traits traits_type;
25 typedef typename traits_type::int_type int_type;
26 typedef typename traits_type::pos_type pos_type;
27 typedef typename traits_type::off_type off_type;
29 // 27.7.1.1.1 Constructor/destructor:
30 explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
31 basic_istream(basic_istream&& rhs);
32 virtual ~basic_istream();
34 // 27.7.1.1.2 Assign/swap:
35 basic_istream& operator=(basic_istream&& rhs);
36 void swap(basic_istream& rhs);
38 // 27.7.1.1.3 Prefix/suffix:
41 // 27.7.1.2 Formatted input:
42 basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
43 basic_istream& operator>>(basic_ios<char_type, traits_type>&
44 (*pf)(basic_ios<char_type, traits_type>&));
45 basic_istream& operator>>(ios_base& (*pf)(ios_base&));
46 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
47 basic_istream& operator>>(bool& n);
48 basic_istream& operator>>(short& n);
49 basic_istream& operator>>(unsigned short& n);
50 basic_istream& operator>>(int& n);
51 basic_istream& operator>>(unsigned int& n);
52 basic_istream& operator>>(long& n);
53 basic_istream& operator>>(unsigned long& n);
54 basic_istream& operator>>(long long& n);
55 basic_istream& operator>>(unsigned long long& n);
56 basic_istream& operator>>(float& f);
57 basic_istream& operator>>(double& f);
58 basic_istream& operator>>(long double& f);
59 basic_istream& operator>>(void*& p);
61 // 27.7.1.3 Unformatted input:
62 streamsize gcount() const;
64 basic_istream& get(char_type& c);
65 basic_istream& get(char_type* s, streamsize n);
66 basic_istream& get(char_type* s, streamsize n, char_type delim);
67 basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
68 basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
70 basic_istream& getline(char_type* s, streamsize n);
71 basic_istream& getline(char_type* s, streamsize n, char_type delim);
73 basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
75 basic_istream& read (char_type* s, streamsize n);
76 streamsize readsome(char_type* s, streamsize n);
78 basic_istream& putback(char_type c);
79 basic_istream& unget();
83 basic_istream& seekg(pos_type);
84 basic_istream& seekg(off_type, ios_base::seekdir);
86 basic_istream(const basic_istream& rhs) = delete;
87 basic_istream(basic_istream&& rhs);
88 // 27.7.2.1.2 Assign/swap:
89 basic_istream& operator=(const basic_istream& rhs) = delete;
90 basic_istream& operator=(basic_istream&& rhs);
91 void swap(basic_istream& rhs);
94 // 27.7.1.2.3 character extraction templates:
95 template<class charT, class traits>
96 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
98 template<class traits>
99 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
101 template<class traits>
102 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
104 template<class charT, class traits>
105 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
107 template<class traits>
108 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
110 template<class traits>
111 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
113 template <class charT, class traits>
115 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
117 typedef basic_istream<char> istream;
118 typedef basic_istream<wchar_t> wistream;
120 template <class charT, class traits = char_traits<charT> >
121 class basic_iostream :
122 public basic_istream<charT,traits>,
123 public basic_ostream<charT,traits>
127 typedef charT char_type;
128 typedef traits traits_type;
129 typedef typename traits_type::int_type int_type;
130 typedef typename traits_type::pos_type pos_type;
131 typedef typename traits_type::off_type off_type;
133 // constructor/destructor
134 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
135 basic_iostream(basic_iostream&& rhs);
136 virtual ~basic_iostream();
139 basic_iostream& operator=(basic_iostream&& rhs);
140 void swap(basic_iostream& rhs);
143 template <class charT, class traits>
145 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
147 typedef basic_iostream<char> iostream;
148 typedef basic_iostream<wchar_t> wiostream;
150 template <class charT, class traits>
151 basic_istream<charT,traits>&
152 ws(basic_istream<charT,traits>& is);
154 template <class charT, class traits, class T>
155 basic_istream<charT, traits>&
156 operator>>(basic_istream<charT, traits>&& is, T& x);
165 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
166 #pragma GCC system_header
170 #include <__undef_macros>
173 _LIBCPP_BEGIN_NAMESPACE_STD
175 template <class _CharT, class _Traits>
176 class _LIBCPP_TEMPLATE_VIS basic_istream
177 : virtual public basic_ios<_CharT, _Traits>
181 // types (inherited from basic_ios (27.5.4)):
182 typedef _CharT char_type;
183 typedef _Traits traits_type;
184 typedef typename traits_type::int_type int_type;
185 typedef typename traits_type::pos_type pos_type;
186 typedef typename traits_type::off_type off_type;
188 // 27.7.1.1.1 Constructor/destructor:
189 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
190 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0)
191 { this->init(__sb); }
192 virtual ~basic_istream();
194 #ifndef _LIBCPP_CXX03_LANG
195 inline _LIBCPP_INLINE_VISIBILITY
196 basic_istream(basic_istream&& __rhs);
198 // 27.7.1.1.2 Assign/swap:
199 inline _LIBCPP_INLINE_VISIBILITY
200 basic_istream& operator=(basic_istream&& __rhs);
203 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
204 void swap(basic_istream& __rhs) {
205 _VSTD::swap(__gc_, __rhs.__gc_);
206 basic_ios<char_type, traits_type>::swap(__rhs);
209 #ifndef _LIBCPP_CXX03_LANG
210 basic_istream (const basic_istream& __rhs) = delete;
211 basic_istream& operator=(const basic_istream& __rhs) = delete;
215 // 27.7.1.1.3 Prefix/suffix:
216 class _LIBCPP_TEMPLATE_VIS sentry;
218 // 27.7.1.2 Formatted input:
219 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
220 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&))
221 { return __pf(*this); }
223 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
224 basic_istream& operator>>(basic_ios<char_type, traits_type>&
225 (*__pf)(basic_ios<char_type, traits_type>&))
226 { __pf(*this); return *this; }
228 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
229 basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
230 { __pf(*this); return *this; }
232 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
233 basic_istream& operator>>(bool& __n);
234 basic_istream& operator>>(short& __n);
235 basic_istream& operator>>(unsigned short& __n);
236 basic_istream& operator>>(int& __n);
237 basic_istream& operator>>(unsigned int& __n);
238 basic_istream& operator>>(long& __n);
239 basic_istream& operator>>(unsigned long& __n);
240 basic_istream& operator>>(long long& __n);
241 basic_istream& operator>>(unsigned long long& __n);
242 basic_istream& operator>>(float& __f);
243 basic_istream& operator>>(double& __f);
244 basic_istream& operator>>(long double& __f);
245 basic_istream& operator>>(void*& __p);
247 // 27.7.1.3 Unformatted input:
248 _LIBCPP_INLINE_VISIBILITY
249 streamsize gcount() const {return __gc_;}
252 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
253 basic_istream& get(char_type& __c) {
254 int_type __ch = get();
255 if (__ch != traits_type::eof())
256 __c = traits_type::to_char_type(__ch);
260 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
261 basic_istream& get(char_type* __s, streamsize __n)
262 { return get(__s, __n, this->widen('\n')); }
264 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
266 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
267 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb)
268 { return get(__sb, this->widen('\n')); }
270 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
272 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
273 basic_istream& getline(char_type* __s, streamsize __n)
274 { return getline(__s, __n, this->widen('\n')); }
276 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
278 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
280 basic_istream& read (char_type* __s, streamsize __n);
281 streamsize readsome(char_type* __s, streamsize __n);
283 basic_istream& putback(char_type __c);
284 basic_istream& unget();
288 basic_istream& seekg(pos_type __pos);
289 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
292 template <class _CharT, class _Traits>
293 class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
297 sentry(const sentry&); // = delete;
298 sentry& operator=(const sentry&); // = delete;
301 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
302 // ~sentry() = default;
304 _LIBCPP_INLINE_VISIBILITY
306 operator bool() const {return __ok_;}
309 template <class _CharT, class _Traits>
310 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
318 if (!__noskipws && (__is.flags() & ios_base::skipws))
320 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
321 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
324 for (; __i != __eof; ++__i)
325 if (!__ct.is(__ct.space, *__i))
328 __is.setstate(ios_base::failbit | ios_base::eofbit);
333 __is.setstate(ios_base::failbit);
336 #ifndef _LIBCPP_CXX03_LANG
338 template <class _CharT, class _Traits>
339 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
346 template <class _CharT, class _Traits>
347 basic_istream<_CharT, _Traits>&
348 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
354 #endif // _LIBCPP_CXX03_LANG
356 template <class _CharT, class _Traits>
357 basic_istream<_CharT, _Traits>::~basic_istream()
361 template <class _Tp, class _CharT, class _Traits>
362 _LIBCPP_INLINE_VISIBILITY
363 basic_istream<_CharT, _Traits>&
364 __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
365 #ifndef _LIBCPP_NO_EXCEPTIONS
368 #endif // _LIBCPP_NO_EXCEPTIONS
369 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
372 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
373 typedef num_get<_CharT, _Ip> _Fp;
374 ios_base::iostate __err = ios_base::goodbit;
375 use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n);
376 __is.setstate(__err);
378 #ifndef _LIBCPP_NO_EXCEPTIONS
382 __is.__set_badbit_and_consider_rethrow();
384 #endif // _LIBCPP_NO_EXCEPTIONS
388 template <class _CharT, class _Traits>
389 basic_istream<_CharT, _Traits>&
390 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
392 return _VSTD::__input_arithmetic<unsigned short>(*this, __n);
395 template <class _CharT, class _Traits>
396 basic_istream<_CharT, _Traits>&
397 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
399 return _VSTD::__input_arithmetic<unsigned int>(*this, __n);
402 template <class _CharT, class _Traits>
403 basic_istream<_CharT, _Traits>&
404 basic_istream<_CharT, _Traits>::operator>>(long& __n)
406 return _VSTD::__input_arithmetic<long>(*this, __n);
409 template <class _CharT, class _Traits>
410 basic_istream<_CharT, _Traits>&
411 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
413 return _VSTD::__input_arithmetic<unsigned long>(*this, __n);
416 template <class _CharT, class _Traits>
417 basic_istream<_CharT, _Traits>&
418 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
420 return _VSTD::__input_arithmetic<long long>(*this, __n);
423 template <class _CharT, class _Traits>
424 basic_istream<_CharT, _Traits>&
425 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
427 return _VSTD::__input_arithmetic<unsigned long long>(*this, __n);
430 template <class _CharT, class _Traits>
431 basic_istream<_CharT, _Traits>&
432 basic_istream<_CharT, _Traits>::operator>>(float& __n)
434 return _VSTD::__input_arithmetic<float>(*this, __n);
437 template <class _CharT, class _Traits>
438 basic_istream<_CharT, _Traits>&
439 basic_istream<_CharT, _Traits>::operator>>(double& __n)
441 return _VSTD::__input_arithmetic<double>(*this, __n);
444 template <class _CharT, class _Traits>
445 basic_istream<_CharT, _Traits>&
446 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
448 return _VSTD::__input_arithmetic<long double>(*this, __n);
451 template <class _CharT, class _Traits>
452 basic_istream<_CharT, _Traits>&
453 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
455 return _VSTD::__input_arithmetic<bool>(*this, __n);
458 template <class _CharT, class _Traits>
459 basic_istream<_CharT, _Traits>&
460 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
462 return _VSTD::__input_arithmetic<void*>(*this, __n);
465 template <class _Tp, class _CharT, class _Traits>
466 _LIBCPP_INLINE_VISIBILITY
467 basic_istream<_CharT, _Traits>&
468 __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
469 #ifndef _LIBCPP_NO_EXCEPTIONS
472 #endif // _LIBCPP_NO_EXCEPTIONS
473 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
476 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
477 typedef num_get<_CharT, _Ip> _Fp;
478 ios_base::iostate __err = ios_base::goodbit;
480 use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp);
481 if (__temp < numeric_limits<_Tp>::min())
483 __err |= ios_base::failbit;
484 __n = numeric_limits<_Tp>::min();
486 else if (__temp > numeric_limits<_Tp>::max())
488 __err |= ios_base::failbit;
489 __n = numeric_limits<_Tp>::max();
492 __n = static_cast<_Tp>(__temp);
493 __is.setstate(__err);
495 #ifndef _LIBCPP_NO_EXCEPTIONS
499 __is.__set_badbit_and_consider_rethrow();
501 #endif // _LIBCPP_NO_EXCEPTIONS
505 template <class _CharT, class _Traits>
506 basic_istream<_CharT, _Traits>&
507 basic_istream<_CharT, _Traits>::operator>>(short& __n)
509 return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n);
512 template <class _CharT, class _Traits>
513 basic_istream<_CharT, _Traits>&
514 basic_istream<_CharT, _Traits>::operator>>(int& __n)
516 return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n);
519 template<class _CharT, class _Traits>
520 basic_istream<_CharT, _Traits>&
521 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
523 #ifndef _LIBCPP_NO_EXCEPTIONS
526 #endif // _LIBCPP_NO_EXCEPTIONS
527 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
530 streamsize __n = __is.width();
532 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
534 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
535 ios_base::iostate __err = ios_base::goodbit;
538 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
539 if (_Traits::eq_int_type(__i, _Traits::eof()))
541 __err |= ios_base::eofbit;
544 _CharT __ch = _Traits::to_char_type(__i);
545 if (__ct.is(__ct.space, __ch))
549 __is.rdbuf()->sbumpc();
554 __err |= ios_base::failbit;
555 __is.setstate(__err);
557 #ifndef _LIBCPP_NO_EXCEPTIONS
561 __is.__set_badbit_and_consider_rethrow();
563 #endif // _LIBCPP_NO_EXCEPTIONS
567 template<class _Traits>
568 inline _LIBCPP_INLINE_VISIBILITY
569 basic_istream<char, _Traits>&
570 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
572 return __is >> (char*)__s;
575 template<class _Traits>
576 inline _LIBCPP_INLINE_VISIBILITY
577 basic_istream<char, _Traits>&
578 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
580 return __is >> (char*)__s;
583 template<class _CharT, class _Traits>
584 basic_istream<_CharT, _Traits>&
585 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
587 #ifndef _LIBCPP_NO_EXCEPTIONS
590 #endif // _LIBCPP_NO_EXCEPTIONS
591 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
594 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
595 if (_Traits::eq_int_type(__i, _Traits::eof()))
596 __is.setstate(ios_base::eofbit | ios_base::failbit);
598 __c = _Traits::to_char_type(__i);
600 #ifndef _LIBCPP_NO_EXCEPTIONS
604 __is.__set_badbit_and_consider_rethrow();
606 #endif // _LIBCPP_NO_EXCEPTIONS
610 template<class _Traits>
611 inline _LIBCPP_INLINE_VISIBILITY
612 basic_istream<char, _Traits>&
613 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
615 return __is >> (char&)__c;
618 template<class _Traits>
619 inline _LIBCPP_INLINE_VISIBILITY
620 basic_istream<char, _Traits>&
621 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
623 return __is >> (char&)__c;
626 template<class _CharT, class _Traits>
627 basic_istream<_CharT, _Traits>&
628 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
631 #ifndef _LIBCPP_NO_EXCEPTIONS
634 #endif // _LIBCPP_NO_EXCEPTIONS
635 sentry __s(*this, true);
640 #ifndef _LIBCPP_NO_EXCEPTIONS
643 #endif // _LIBCPP_NO_EXCEPTIONS
644 ios_base::iostate __err = ios_base::goodbit;
647 typename traits_type::int_type __i = this->rdbuf()->sgetc();
648 if (traits_type::eq_int_type(__i, _Traits::eof()))
650 __err |= ios_base::eofbit;
653 if (traits_type::eq_int_type(
654 __sb->sputc(traits_type::to_char_type(__i)),
658 this->rdbuf()->sbumpc();
661 __err |= ios_base::failbit;
662 this->setstate(__err);
663 #ifndef _LIBCPP_NO_EXCEPTIONS
668 this->__set_failbit_and_consider_rethrow();
670 #endif // _LIBCPP_NO_EXCEPTIONS
673 this->setstate(ios_base::failbit);
675 #ifndef _LIBCPP_NO_EXCEPTIONS
679 this->__set_badbit_and_consider_rethrow();
681 #endif // _LIBCPP_NO_EXCEPTIONS
685 template<class _CharT, class _Traits>
686 typename basic_istream<_CharT, _Traits>::int_type
687 basic_istream<_CharT, _Traits>::get()
690 int_type __r = traits_type::eof();
691 #ifndef _LIBCPP_NO_EXCEPTIONS
694 #endif // _LIBCPP_NO_EXCEPTIONS
695 sentry __s(*this, true);
698 __r = this->rdbuf()->sbumpc();
699 if (traits_type::eq_int_type(__r, traits_type::eof()))
700 this->setstate(ios_base::failbit | ios_base::eofbit);
704 #ifndef _LIBCPP_NO_EXCEPTIONS
708 this->__set_badbit_and_consider_rethrow();
710 #endif // _LIBCPP_NO_EXCEPTIONS
714 template<class _CharT, class _Traits>
715 basic_istream<_CharT, _Traits>&
716 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
719 #ifndef _LIBCPP_NO_EXCEPTIONS
722 #endif // _LIBCPP_NO_EXCEPTIONS
723 sentry __sen(*this, true);
728 ios_base::iostate __err = ios_base::goodbit;
729 while (__gc_ < __n-1)
731 int_type __i = this->rdbuf()->sgetc();
732 if (traits_type::eq_int_type(__i, traits_type::eof()))
734 __err |= ios_base::eofbit;
737 char_type __ch = traits_type::to_char_type(__i);
738 if (traits_type::eq(__ch, __dlm))
742 this->rdbuf()->sbumpc();
745 __err |= ios_base::failbit;
746 this->setstate(__err);
749 this->setstate(ios_base::failbit);
753 #ifndef _LIBCPP_NO_EXCEPTIONS
759 this->__set_badbit_and_consider_rethrow();
761 #endif // _LIBCPP_NO_EXCEPTIONS
765 template<class _CharT, class _Traits>
766 basic_istream<_CharT, _Traits>&
767 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
771 #ifndef _LIBCPP_NO_EXCEPTIONS
774 #endif // _LIBCPP_NO_EXCEPTIONS
775 sentry __sen(*this, true);
778 ios_base::iostate __err = ios_base::goodbit;
779 #ifndef _LIBCPP_NO_EXCEPTIONS
782 #endif // _LIBCPP_NO_EXCEPTIONS
785 typename traits_type::int_type __i = this->rdbuf()->sgetc();
786 if (traits_type::eq_int_type(__i, traits_type::eof()))
788 __err |= ios_base::eofbit;
791 char_type __ch = traits_type::to_char_type(__i);
792 if (traits_type::eq(__ch, __dlm))
794 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
797 this->rdbuf()->sbumpc();
799 #ifndef _LIBCPP_NO_EXCEPTIONS
804 #endif // _LIBCPP_NO_EXCEPTIONS
806 __err |= ios_base::failbit;
807 this->setstate(__err);
809 #ifndef _LIBCPP_NO_EXCEPTIONS
813 this->__set_badbit_and_consider_rethrow();
815 #endif // _LIBCPP_NO_EXCEPTIONS
819 template<class _CharT, class _Traits>
820 basic_istream<_CharT, _Traits>&
821 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
824 #ifndef _LIBCPP_NO_EXCEPTIONS
827 #endif // _LIBCPP_NO_EXCEPTIONS
828 sentry __sen(*this, true);
831 ios_base::iostate __err = ios_base::goodbit;
834 typename traits_type::int_type __i = this->rdbuf()->sgetc();
835 if (traits_type::eq_int_type(__i, traits_type::eof()))
837 __err |= ios_base::eofbit;
840 char_type __ch = traits_type::to_char_type(__i);
841 if (traits_type::eq(__ch, __dlm))
843 this->rdbuf()->sbumpc();
849 __err |= ios_base::failbit;
853 this->rdbuf()->sbumpc();
857 __err |= ios_base::failbit;
858 this->setstate(__err);
862 #ifndef _LIBCPP_NO_EXCEPTIONS
868 this->__set_badbit_and_consider_rethrow();
870 #endif // _LIBCPP_NO_EXCEPTIONS
874 template<class _CharT, class _Traits>
875 basic_istream<_CharT, _Traits>&
876 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
879 #ifndef _LIBCPP_NO_EXCEPTIONS
882 #endif // _LIBCPP_NO_EXCEPTIONS
883 sentry __sen(*this, true);
886 ios_base::iostate __err = ios_base::goodbit;
887 if (__n == numeric_limits<streamsize>::max())
891 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
892 if (traits_type::eq_int_type(__i, traits_type::eof()))
894 __err |= ios_base::eofbit;
898 if (traits_type::eq_int_type(__i, __dlm))
906 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
907 if (traits_type::eq_int_type(__i, traits_type::eof()))
909 __err |= ios_base::eofbit;
913 if (traits_type::eq_int_type(__i, __dlm))
917 this->setstate(__err);
919 #ifndef _LIBCPP_NO_EXCEPTIONS
923 this->__set_badbit_and_consider_rethrow();
925 #endif // _LIBCPP_NO_EXCEPTIONS
929 template<class _CharT, class _Traits>
930 typename basic_istream<_CharT, _Traits>::int_type
931 basic_istream<_CharT, _Traits>::peek()
934 int_type __r = traits_type::eof();
935 #ifndef _LIBCPP_NO_EXCEPTIONS
938 #endif // _LIBCPP_NO_EXCEPTIONS
939 sentry __sen(*this, true);
942 __r = this->rdbuf()->sgetc();
943 if (traits_type::eq_int_type(__r, traits_type::eof()))
944 this->setstate(ios_base::eofbit);
946 #ifndef _LIBCPP_NO_EXCEPTIONS
950 this->__set_badbit_and_consider_rethrow();
952 #endif // _LIBCPP_NO_EXCEPTIONS
956 template<class _CharT, class _Traits>
957 basic_istream<_CharT, _Traits>&
958 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
961 #ifndef _LIBCPP_NO_EXCEPTIONS
964 #endif // _LIBCPP_NO_EXCEPTIONS
965 sentry __sen(*this, true);
968 __gc_ = this->rdbuf()->sgetn(__s, __n);
970 this->setstate(ios_base::failbit | ios_base::eofbit);
973 this->setstate(ios_base::failbit);
974 #ifndef _LIBCPP_NO_EXCEPTIONS
978 this->__set_badbit_and_consider_rethrow();
980 #endif // _LIBCPP_NO_EXCEPTIONS
984 template<class _CharT, class _Traits>
986 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
989 #ifndef _LIBCPP_NO_EXCEPTIONS
992 #endif // _LIBCPP_NO_EXCEPTIONS
993 sentry __sen(*this, true);
996 streamsize __c = this->rdbuf()->in_avail();
1000 this->setstate(ios_base::eofbit);
1005 read(__s, _VSTD::min(__c, __n));
1010 this->setstate(ios_base::failbit);
1011 #ifndef _LIBCPP_NO_EXCEPTIONS
1015 this->__set_badbit_and_consider_rethrow();
1017 #endif // _LIBCPP_NO_EXCEPTIONS
1021 template<class _CharT, class _Traits>
1022 basic_istream<_CharT, _Traits>&
1023 basic_istream<_CharT, _Traits>::putback(char_type __c)
1026 #ifndef _LIBCPP_NO_EXCEPTIONS
1029 #endif // _LIBCPP_NO_EXCEPTIONS
1030 this->clear(this->rdstate() & ~ios_base::eofbit);
1031 sentry __sen(*this, true);
1034 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1035 this->setstate(ios_base::badbit);
1038 this->setstate(ios_base::failbit);
1039 #ifndef _LIBCPP_NO_EXCEPTIONS
1043 this->__set_badbit_and_consider_rethrow();
1045 #endif // _LIBCPP_NO_EXCEPTIONS
1049 template<class _CharT, class _Traits>
1050 basic_istream<_CharT, _Traits>&
1051 basic_istream<_CharT, _Traits>::unget()
1054 #ifndef _LIBCPP_NO_EXCEPTIONS
1057 #endif // _LIBCPP_NO_EXCEPTIONS
1058 this->clear(this->rdstate() & ~ios_base::eofbit);
1059 sentry __sen(*this, true);
1062 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1063 this->setstate(ios_base::badbit);
1066 this->setstate(ios_base::failbit);
1067 #ifndef _LIBCPP_NO_EXCEPTIONS
1071 this->__set_badbit_and_consider_rethrow();
1073 #endif // _LIBCPP_NO_EXCEPTIONS
1077 template<class _CharT, class _Traits>
1079 basic_istream<_CharT, _Traits>::sync()
1082 #ifndef _LIBCPP_NO_EXCEPTIONS
1085 #endif // _LIBCPP_NO_EXCEPTIONS
1086 sentry __sen(*this, true);
1089 if (this->rdbuf() == 0)
1091 if (this->rdbuf()->pubsync() == -1)
1093 this->setstate(ios_base::badbit);
1097 #ifndef _LIBCPP_NO_EXCEPTIONS
1101 this->__set_badbit_and_consider_rethrow();
1103 #endif // _LIBCPP_NO_EXCEPTIONS
1107 template<class _CharT, class _Traits>
1108 typename basic_istream<_CharT, _Traits>::pos_type
1109 basic_istream<_CharT, _Traits>::tellg()
1112 #ifndef _LIBCPP_NO_EXCEPTIONS
1115 #endif // _LIBCPP_NO_EXCEPTIONS
1116 sentry __sen(*this, true);
1118 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1119 #ifndef _LIBCPP_NO_EXCEPTIONS
1123 this->__set_badbit_and_consider_rethrow();
1125 #endif // _LIBCPP_NO_EXCEPTIONS
1129 template<class _CharT, class _Traits>
1130 basic_istream<_CharT, _Traits>&
1131 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1133 #ifndef _LIBCPP_NO_EXCEPTIONS
1136 #endif // _LIBCPP_NO_EXCEPTIONS
1137 this->clear(this->rdstate() & ~ios_base::eofbit);
1138 sentry __sen(*this, true);
1141 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1142 this->setstate(ios_base::failbit);
1144 #ifndef _LIBCPP_NO_EXCEPTIONS
1148 this->__set_badbit_and_consider_rethrow();
1150 #endif // _LIBCPP_NO_EXCEPTIONS
1154 template<class _CharT, class _Traits>
1155 basic_istream<_CharT, _Traits>&
1156 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1158 #ifndef _LIBCPP_NO_EXCEPTIONS
1161 #endif // _LIBCPP_NO_EXCEPTIONS
1162 this->clear(this->rdstate() & ~ios_base::eofbit);
1163 sentry __sen(*this, true);
1166 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1167 this->setstate(ios_base::failbit);
1169 #ifndef _LIBCPP_NO_EXCEPTIONS
1173 this->__set_badbit_and_consider_rethrow();
1175 #endif // _LIBCPP_NO_EXCEPTIONS
1179 template <class _CharT, class _Traits>
1180 basic_istream<_CharT, _Traits>&
1181 ws(basic_istream<_CharT, _Traits>& __is)
1183 #ifndef _LIBCPP_NO_EXCEPTIONS
1186 #endif // _LIBCPP_NO_EXCEPTIONS
1187 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1190 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1193 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1194 if (_Traits::eq_int_type(__i, _Traits::eof()))
1196 __is.setstate(ios_base::eofbit);
1199 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1201 __is.rdbuf()->sbumpc();
1204 #ifndef _LIBCPP_NO_EXCEPTIONS
1208 __is.__set_badbit_and_consider_rethrow();
1210 #endif // _LIBCPP_NO_EXCEPTIONS
1214 #ifndef _LIBCPP_CXX03_LANG
1216 template <class _CharT, class _Traits, class _Tp>
1217 inline _LIBCPP_INLINE_VISIBILITY
1218 basic_istream<_CharT, _Traits>&
1219 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
1221 __is >> _VSTD::forward<_Tp>(__x);
1225 #endif // _LIBCPP_CXX03_LANG
1227 template <class _CharT, class _Traits>
1228 class _LIBCPP_TEMPLATE_VIS basic_iostream
1229 : public basic_istream<_CharT, _Traits>,
1230 public basic_ostream<_CharT, _Traits>
1234 typedef _CharT char_type;
1235 typedef _Traits traits_type;
1236 typedef typename traits_type::int_type int_type;
1237 typedef typename traits_type::pos_type pos_type;
1238 typedef typename traits_type::off_type off_type;
1240 // constructor/destructor
1241 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1242 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1243 : basic_istream<_CharT, _Traits>(__sb)
1246 virtual ~basic_iostream();
1248 #ifndef _LIBCPP_CXX03_LANG
1249 inline _LIBCPP_INLINE_VISIBILITY
1250 basic_iostream(basic_iostream&& __rhs);
1253 inline _LIBCPP_INLINE_VISIBILITY
1254 basic_iostream& operator=(basic_iostream&& __rhs);
1256 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1257 void swap(basic_iostream& __rhs)
1258 { basic_istream<char_type, traits_type>::swap(__rhs); }
1262 #ifndef _LIBCPP_CXX03_LANG
1264 template <class _CharT, class _Traits>
1265 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1266 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1270 template <class _CharT, class _Traits>
1271 basic_iostream<_CharT, _Traits>&
1272 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1278 #endif // _LIBCPP_CXX03_LANG
1280 template <class _CharT, class _Traits>
1281 basic_iostream<_CharT, _Traits>::~basic_iostream()
1285 template<class _CharT, class _Traits, class _Allocator>
1286 basic_istream<_CharT, _Traits>&
1287 operator>>(basic_istream<_CharT, _Traits>& __is,
1288 basic_string<_CharT, _Traits, _Allocator>& __str)
1290 #ifndef _LIBCPP_NO_EXCEPTIONS
1293 #endif // _LIBCPP_NO_EXCEPTIONS
1294 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1298 streamsize __n = __is.width();
1300 __n = __str.max_size();
1302 __n = numeric_limits<streamsize>::max();
1304 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1305 ios_base::iostate __err = ios_base::goodbit;
1308 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1309 if (_Traits::eq_int_type(__i, _Traits::eof()))
1311 __err |= ios_base::eofbit;
1314 _CharT __ch = _Traits::to_char_type(__i);
1315 if (__ct.is(__ct.space, __ch))
1317 __str.push_back(__ch);
1319 __is.rdbuf()->sbumpc();
1323 __err |= ios_base::failbit;
1324 __is.setstate(__err);
1327 __is.setstate(ios_base::failbit);
1328 #ifndef _LIBCPP_NO_EXCEPTIONS
1332 __is.__set_badbit_and_consider_rethrow();
1334 #endif // _LIBCPP_NO_EXCEPTIONS
1338 template<class _CharT, class _Traits, class _Allocator>
1339 basic_istream<_CharT, _Traits>&
1340 getline(basic_istream<_CharT, _Traits>& __is,
1341 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1343 #ifndef _LIBCPP_NO_EXCEPTIONS
1346 #endif // _LIBCPP_NO_EXCEPTIONS
1347 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1351 ios_base::iostate __err = ios_base::goodbit;
1352 streamsize __extr = 0;
1355 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1356 if (_Traits::eq_int_type(__i, _Traits::eof()))
1358 __err |= ios_base::eofbit;
1362 _CharT __ch = _Traits::to_char_type(__i);
1363 if (_Traits::eq(__ch, __dlm))
1365 __str.push_back(__ch);
1366 if (__str.size() == __str.max_size())
1368 __err |= ios_base::failbit;
1373 __err |= ios_base::failbit;
1374 __is.setstate(__err);
1376 #ifndef _LIBCPP_NO_EXCEPTIONS
1380 __is.__set_badbit_and_consider_rethrow();
1382 #endif // _LIBCPP_NO_EXCEPTIONS
1386 template<class _CharT, class _Traits, class _Allocator>
1387 inline _LIBCPP_INLINE_VISIBILITY
1388 basic_istream<_CharT, _Traits>&
1389 getline(basic_istream<_CharT, _Traits>& __is,
1390 basic_string<_CharT, _Traits, _Allocator>& __str)
1392 return getline(__is, __str, __is.widen('\n'));
1395 #ifndef _LIBCPP_CXX03_LANG
1397 template<class _CharT, class _Traits, class _Allocator>
1398 inline _LIBCPP_INLINE_VISIBILITY
1399 basic_istream<_CharT, _Traits>&
1400 getline(basic_istream<_CharT, _Traits>&& __is,
1401 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1403 return getline(__is, __str, __dlm);
1406 template<class _CharT, class _Traits, class _Allocator>
1407 inline _LIBCPP_INLINE_VISIBILITY
1408 basic_istream<_CharT, _Traits>&
1409 getline(basic_istream<_CharT, _Traits>&& __is,
1410 basic_string<_CharT, _Traits, _Allocator>& __str)
1412 return getline(__is, __str, __is.widen('\n'));
1415 #endif // _LIBCPP_CXX03_LANG
1417 template <class _CharT, class _Traits, size_t _Size>
1418 basic_istream<_CharT, _Traits>&
1419 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1421 #ifndef _LIBCPP_NO_EXCEPTIONS
1424 #endif // _LIBCPP_NO_EXCEPTIONS
1425 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1428 basic_string<_CharT, _Traits> __str;
1429 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1431 ios_base::iostate __err = ios_base::goodbit;
1432 _CharT __zero = __ct.widen('0');
1433 _CharT __one = __ct.widen('1');
1436 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1437 if (_Traits::eq_int_type(__i, _Traits::eof()))
1439 __err |= ios_base::eofbit;
1442 _CharT __ch = _Traits::to_char_type(__i);
1443 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1445 __str.push_back(__ch);
1447 __is.rdbuf()->sbumpc();
1449 __x = bitset<_Size>(__str);
1451 __err |= ios_base::failbit;
1452 __is.setstate(__err);
1455 __is.setstate(ios_base::failbit);
1456 #ifndef _LIBCPP_NO_EXCEPTIONS
1460 __is.__set_badbit_and_consider_rethrow();
1462 #endif // _LIBCPP_NO_EXCEPTIONS
1466 #ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
1467 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1468 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1469 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
1472 _LIBCPP_END_NAMESPACE_STD
1476 #endif // _LIBCPP_ISTREAM