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);
166 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
167 #pragma GCC system_header
171 #include <__undef_macros>
174 _LIBCPP_BEGIN_NAMESPACE_STD
176 template <class _CharT, class _Traits>
177 class _LIBCPP_TEMPLATE_VIS basic_istream
178 : virtual public basic_ios<_CharT, _Traits>
182 // types (inherited from basic_ios (27.5.4)):
183 typedef _CharT char_type;
184 typedef _Traits traits_type;
185 typedef typename traits_type::int_type int_type;
186 typedef typename traits_type::pos_type pos_type;
187 typedef typename traits_type::off_type off_type;
189 // 27.7.1.1.1 Constructor/destructor:
190 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
191 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0)
192 { this->init(__sb); }
193 virtual ~basic_istream();
195 #ifndef _LIBCPP_CXX03_LANG
196 inline _LIBCPP_INLINE_VISIBILITY
197 basic_istream(basic_istream&& __rhs);
199 // 27.7.1.1.2 Assign/swap:
200 inline _LIBCPP_INLINE_VISIBILITY
201 basic_istream& operator=(basic_istream&& __rhs);
204 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
205 void swap(basic_istream& __rhs) {
206 _VSTD::swap(__gc_, __rhs.__gc_);
207 basic_ios<char_type, traits_type>::swap(__rhs);
210 #ifndef _LIBCPP_CXX03_LANG
211 basic_istream (const basic_istream& __rhs) = delete;
212 basic_istream& operator=(const basic_istream& __rhs) = delete;
216 // 27.7.1.1.3 Prefix/suffix:
217 class _LIBCPP_TEMPLATE_VIS sentry;
219 // 27.7.1.2 Formatted input:
220 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
221 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&))
222 { return __pf(*this); }
224 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
225 basic_istream& operator>>(basic_ios<char_type, traits_type>&
226 (*__pf)(basic_ios<char_type, traits_type>&))
227 { __pf(*this); return *this; }
229 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
230 basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
231 { __pf(*this); return *this; }
233 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
234 basic_istream& operator>>(bool& __n);
235 basic_istream& operator>>(short& __n);
236 basic_istream& operator>>(unsigned short& __n);
237 basic_istream& operator>>(int& __n);
238 basic_istream& operator>>(unsigned int& __n);
239 basic_istream& operator>>(long& __n);
240 basic_istream& operator>>(unsigned long& __n);
241 basic_istream& operator>>(long long& __n);
242 basic_istream& operator>>(unsigned long long& __n);
243 basic_istream& operator>>(float& __f);
244 basic_istream& operator>>(double& __f);
245 basic_istream& operator>>(long double& __f);
246 basic_istream& operator>>(void*& __p);
248 // 27.7.1.3 Unformatted input:
249 _LIBCPP_INLINE_VISIBILITY
250 streamsize gcount() const {return __gc_;}
253 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
254 basic_istream& get(char_type& __c) {
255 int_type __ch = get();
256 if (__ch != traits_type::eof())
257 __c = traits_type::to_char_type(__ch);
261 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
262 basic_istream& get(char_type* __s, streamsize __n)
263 { return get(__s, __n, this->widen('\n')); }
265 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
267 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
268 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb)
269 { return get(__sb, this->widen('\n')); }
271 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
273 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
274 basic_istream& getline(char_type* __s, streamsize __n)
275 { return getline(__s, __n, this->widen('\n')); }
277 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
279 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
281 basic_istream& read (char_type* __s, streamsize __n);
282 streamsize readsome(char_type* __s, streamsize __n);
284 basic_istream& putback(char_type __c);
285 basic_istream& unget();
289 basic_istream& seekg(pos_type __pos);
290 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
293 template <class _CharT, class _Traits>
294 class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
298 sentry(const sentry&); // = delete;
299 sentry& operator=(const sentry&); // = delete;
302 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
303 // ~sentry() = default;
305 _LIBCPP_INLINE_VISIBILITY
307 operator bool() const {return __ok_;}
310 template <class _CharT, class _Traits>
311 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
319 if (!__noskipws && (__is.flags() & ios_base::skipws))
321 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
322 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
325 for (; __i != __eof; ++__i)
326 if (!__ct.is(__ct.space, *__i))
329 __is.setstate(ios_base::failbit | ios_base::eofbit);
334 __is.setstate(ios_base::failbit);
337 #ifndef _LIBCPP_CXX03_LANG
339 template <class _CharT, class _Traits>
340 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
347 template <class _CharT, class _Traits>
348 basic_istream<_CharT, _Traits>&
349 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
355 #endif // _LIBCPP_CXX03_LANG
357 template <class _CharT, class _Traits>
358 basic_istream<_CharT, _Traits>::~basic_istream()
362 template <class _Tp, class _CharT, class _Traits>
363 _LIBCPP_INLINE_VISIBILITY
364 basic_istream<_CharT, _Traits>&
365 __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
366 #ifndef _LIBCPP_NO_EXCEPTIONS
369 #endif // _LIBCPP_NO_EXCEPTIONS
370 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
373 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
374 typedef num_get<_CharT, _Ip> _Fp;
375 ios_base::iostate __err = ios_base::goodbit;
376 use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n);
377 __is.setstate(__err);
379 #ifndef _LIBCPP_NO_EXCEPTIONS
383 __is.__set_badbit_and_consider_rethrow();
385 #endif // _LIBCPP_NO_EXCEPTIONS
389 template <class _CharT, class _Traits>
390 basic_istream<_CharT, _Traits>&
391 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
393 return _VSTD::__input_arithmetic<unsigned short>(*this, __n);
396 template <class _CharT, class _Traits>
397 basic_istream<_CharT, _Traits>&
398 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
400 return _VSTD::__input_arithmetic<unsigned int>(*this, __n);
403 template <class _CharT, class _Traits>
404 basic_istream<_CharT, _Traits>&
405 basic_istream<_CharT, _Traits>::operator>>(long& __n)
407 return _VSTD::__input_arithmetic<long>(*this, __n);
410 template <class _CharT, class _Traits>
411 basic_istream<_CharT, _Traits>&
412 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
414 return _VSTD::__input_arithmetic<unsigned long>(*this, __n);
417 template <class _CharT, class _Traits>
418 basic_istream<_CharT, _Traits>&
419 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
421 return _VSTD::__input_arithmetic<long long>(*this, __n);
424 template <class _CharT, class _Traits>
425 basic_istream<_CharT, _Traits>&
426 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
428 return _VSTD::__input_arithmetic<unsigned long long>(*this, __n);
431 template <class _CharT, class _Traits>
432 basic_istream<_CharT, _Traits>&
433 basic_istream<_CharT, _Traits>::operator>>(float& __n)
435 return _VSTD::__input_arithmetic<float>(*this, __n);
438 template <class _CharT, class _Traits>
439 basic_istream<_CharT, _Traits>&
440 basic_istream<_CharT, _Traits>::operator>>(double& __n)
442 return _VSTD::__input_arithmetic<double>(*this, __n);
445 template <class _CharT, class _Traits>
446 basic_istream<_CharT, _Traits>&
447 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
449 return _VSTD::__input_arithmetic<long double>(*this, __n);
452 template <class _CharT, class _Traits>
453 basic_istream<_CharT, _Traits>&
454 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
456 return _VSTD::__input_arithmetic<bool>(*this, __n);
459 template <class _CharT, class _Traits>
460 basic_istream<_CharT, _Traits>&
461 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
463 return _VSTD::__input_arithmetic<void*>(*this, __n);
466 template <class _Tp, class _CharT, class _Traits>
467 _LIBCPP_INLINE_VISIBILITY
468 basic_istream<_CharT, _Traits>&
469 __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
470 #ifndef _LIBCPP_NO_EXCEPTIONS
473 #endif // _LIBCPP_NO_EXCEPTIONS
474 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
477 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
478 typedef num_get<_CharT, _Ip> _Fp;
479 ios_base::iostate __err = ios_base::goodbit;
481 use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp);
482 if (__temp < numeric_limits<_Tp>::min())
484 __err |= ios_base::failbit;
485 __n = numeric_limits<_Tp>::min();
487 else if (__temp > numeric_limits<_Tp>::max())
489 __err |= ios_base::failbit;
490 __n = numeric_limits<_Tp>::max();
493 __n = static_cast<_Tp>(__temp);
494 __is.setstate(__err);
496 #ifndef _LIBCPP_NO_EXCEPTIONS
500 __is.__set_badbit_and_consider_rethrow();
502 #endif // _LIBCPP_NO_EXCEPTIONS
506 template <class _CharT, class _Traits>
507 basic_istream<_CharT, _Traits>&
508 basic_istream<_CharT, _Traits>::operator>>(short& __n)
510 return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n);
513 template <class _CharT, class _Traits>
514 basic_istream<_CharT, _Traits>&
515 basic_istream<_CharT, _Traits>::operator>>(int& __n)
517 return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n);
520 template<class _CharT, class _Traits>
521 _LIBCPP_INLINE_VISIBILITY
522 basic_istream<_CharT, _Traits>&
523 __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
525 #ifndef _LIBCPP_NO_EXCEPTIONS
528 #endif // _LIBCPP_NO_EXCEPTIONS
529 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
533 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
534 ios_base::iostate __err = ios_base::goodbit;
535 while (__s != __p + (__n-1))
537 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
538 if (_Traits::eq_int_type(__i, _Traits::eof()))
540 __err |= ios_base::eofbit;
543 _CharT __ch = _Traits::to_char_type(__i);
544 if (__ct.is(__ct.space, __ch))
547 __is.rdbuf()->sbumpc();
552 __err |= ios_base::failbit;
553 __is.setstate(__err);
555 #ifndef _LIBCPP_NO_EXCEPTIONS
559 __is.__set_badbit_and_consider_rethrow();
561 #endif // _LIBCPP_NO_EXCEPTIONS
565 #if _LIBCPP_STD_VER > 17
567 template<class _CharT, class _Traits, size_t _Np>
568 inline _LIBCPP_INLINE_VISIBILITY
569 basic_istream<_CharT, _Traits>&
570 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np])
573 if (__is.width() > 0)
574 __n = _VSTD::min(size_t(__is.width()), _Np);
575 return _VSTD::__input_c_string(__is, __buf, __n);
578 template<class _Traits, size_t _Np>
579 inline _LIBCPP_INLINE_VISIBILITY
580 basic_istream<char, _Traits>&
581 operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np])
583 return __is >> (char(&)[_Np])__buf;
586 template<class _Traits, size_t _Np>
587 inline _LIBCPP_INLINE_VISIBILITY
588 basic_istream<char, _Traits>&
589 operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np])
591 return __is >> (char(&)[_Np])__buf;
596 template<class _CharT, class _Traits>
597 inline _LIBCPP_INLINE_VISIBILITY
598 basic_istream<_CharT, _Traits>&
599 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
601 streamsize __n = __is.width();
603 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
604 return _VSTD::__input_c_string(__is, __s, size_t(__n));
607 template<class _Traits>
608 inline _LIBCPP_INLINE_VISIBILITY
609 basic_istream<char, _Traits>&
610 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
612 return __is >> (char*)__s;
615 template<class _Traits>
616 inline _LIBCPP_INLINE_VISIBILITY
617 basic_istream<char, _Traits>&
618 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
620 return __is >> (char*)__s;
623 #endif // _LIBCPP_STD_VER > 17
625 template<class _CharT, class _Traits>
626 basic_istream<_CharT, _Traits>&
627 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
629 #ifndef _LIBCPP_NO_EXCEPTIONS
632 #endif // _LIBCPP_NO_EXCEPTIONS
633 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
636 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
637 if (_Traits::eq_int_type(__i, _Traits::eof()))
638 __is.setstate(ios_base::eofbit | ios_base::failbit);
640 __c = _Traits::to_char_type(__i);
642 #ifndef _LIBCPP_NO_EXCEPTIONS
646 __is.__set_badbit_and_consider_rethrow();
648 #endif // _LIBCPP_NO_EXCEPTIONS
652 template<class _Traits>
653 inline _LIBCPP_INLINE_VISIBILITY
654 basic_istream<char, _Traits>&
655 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
657 return __is >> (char&)__c;
660 template<class _Traits>
661 inline _LIBCPP_INLINE_VISIBILITY
662 basic_istream<char, _Traits>&
663 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
665 return __is >> (char&)__c;
668 template<class _CharT, class _Traits>
669 basic_istream<_CharT, _Traits>&
670 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
673 #ifndef _LIBCPP_NO_EXCEPTIONS
676 #endif // _LIBCPP_NO_EXCEPTIONS
677 sentry __s(*this, true);
682 #ifndef _LIBCPP_NO_EXCEPTIONS
685 #endif // _LIBCPP_NO_EXCEPTIONS
686 ios_base::iostate __err = ios_base::goodbit;
689 typename traits_type::int_type __i = this->rdbuf()->sgetc();
690 if (traits_type::eq_int_type(__i, _Traits::eof()))
692 __err |= ios_base::eofbit;
695 if (traits_type::eq_int_type(
696 __sb->sputc(traits_type::to_char_type(__i)),
700 this->rdbuf()->sbumpc();
703 __err |= ios_base::failbit;
704 this->setstate(__err);
705 #ifndef _LIBCPP_NO_EXCEPTIONS
710 this->__set_failbit_and_consider_rethrow();
712 #endif // _LIBCPP_NO_EXCEPTIONS
715 this->setstate(ios_base::failbit);
717 #ifndef _LIBCPP_NO_EXCEPTIONS
721 this->__set_badbit_and_consider_rethrow();
723 #endif // _LIBCPP_NO_EXCEPTIONS
727 template<class _CharT, class _Traits>
728 typename basic_istream<_CharT, _Traits>::int_type
729 basic_istream<_CharT, _Traits>::get()
732 int_type __r = traits_type::eof();
733 #ifndef _LIBCPP_NO_EXCEPTIONS
736 #endif // _LIBCPP_NO_EXCEPTIONS
737 sentry __s(*this, true);
740 __r = this->rdbuf()->sbumpc();
741 if (traits_type::eq_int_type(__r, traits_type::eof()))
742 this->setstate(ios_base::failbit | ios_base::eofbit);
746 #ifndef _LIBCPP_NO_EXCEPTIONS
750 this->__set_badbit_and_consider_rethrow();
752 #endif // _LIBCPP_NO_EXCEPTIONS
756 template<class _CharT, class _Traits>
757 basic_istream<_CharT, _Traits>&
758 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
761 #ifndef _LIBCPP_NO_EXCEPTIONS
764 #endif // _LIBCPP_NO_EXCEPTIONS
765 sentry __sen(*this, true);
770 ios_base::iostate __err = ios_base::goodbit;
771 while (__gc_ < __n-1)
773 int_type __i = this->rdbuf()->sgetc();
774 if (traits_type::eq_int_type(__i, traits_type::eof()))
776 __err |= ios_base::eofbit;
779 char_type __ch = traits_type::to_char_type(__i);
780 if (traits_type::eq(__ch, __dlm))
784 this->rdbuf()->sbumpc();
787 __err |= ios_base::failbit;
788 this->setstate(__err);
791 this->setstate(ios_base::failbit);
795 #ifndef _LIBCPP_NO_EXCEPTIONS
801 this->__set_badbit_and_consider_rethrow();
803 #endif // _LIBCPP_NO_EXCEPTIONS
807 template<class _CharT, class _Traits>
808 basic_istream<_CharT, _Traits>&
809 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
813 #ifndef _LIBCPP_NO_EXCEPTIONS
816 #endif // _LIBCPP_NO_EXCEPTIONS
817 sentry __sen(*this, true);
820 ios_base::iostate __err = ios_base::goodbit;
821 #ifndef _LIBCPP_NO_EXCEPTIONS
824 #endif // _LIBCPP_NO_EXCEPTIONS
827 typename traits_type::int_type __i = this->rdbuf()->sgetc();
828 if (traits_type::eq_int_type(__i, traits_type::eof()))
830 __err |= ios_base::eofbit;
833 char_type __ch = traits_type::to_char_type(__i);
834 if (traits_type::eq(__ch, __dlm))
836 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
839 this->rdbuf()->sbumpc();
841 #ifndef _LIBCPP_NO_EXCEPTIONS
846 #endif // _LIBCPP_NO_EXCEPTIONS
848 __err |= ios_base::failbit;
849 this->setstate(__err);
851 #ifndef _LIBCPP_NO_EXCEPTIONS
855 this->__set_badbit_and_consider_rethrow();
857 #endif // _LIBCPP_NO_EXCEPTIONS
861 template<class _CharT, class _Traits>
862 basic_istream<_CharT, _Traits>&
863 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
866 #ifndef _LIBCPP_NO_EXCEPTIONS
869 #endif // _LIBCPP_NO_EXCEPTIONS
870 sentry __sen(*this, true);
873 ios_base::iostate __err = ios_base::goodbit;
876 typename traits_type::int_type __i = this->rdbuf()->sgetc();
877 if (traits_type::eq_int_type(__i, traits_type::eof()))
879 __err |= ios_base::eofbit;
882 char_type __ch = traits_type::to_char_type(__i);
883 if (traits_type::eq(__ch, __dlm))
885 this->rdbuf()->sbumpc();
891 __err |= ios_base::failbit;
895 this->rdbuf()->sbumpc();
899 __err |= ios_base::failbit;
900 this->setstate(__err);
904 #ifndef _LIBCPP_NO_EXCEPTIONS
910 this->__set_badbit_and_consider_rethrow();
912 #endif // _LIBCPP_NO_EXCEPTIONS
916 template<class _CharT, class _Traits>
917 basic_istream<_CharT, _Traits>&
918 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
921 #ifndef _LIBCPP_NO_EXCEPTIONS
924 #endif // _LIBCPP_NO_EXCEPTIONS
925 sentry __sen(*this, true);
928 ios_base::iostate __err = ios_base::goodbit;
929 if (__n == numeric_limits<streamsize>::max())
933 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
934 if (traits_type::eq_int_type(__i, traits_type::eof()))
936 __err |= ios_base::eofbit;
940 if (traits_type::eq_int_type(__i, __dlm))
948 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
949 if (traits_type::eq_int_type(__i, traits_type::eof()))
951 __err |= ios_base::eofbit;
955 if (traits_type::eq_int_type(__i, __dlm))
959 this->setstate(__err);
961 #ifndef _LIBCPP_NO_EXCEPTIONS
965 this->__set_badbit_and_consider_rethrow();
967 #endif // _LIBCPP_NO_EXCEPTIONS
971 template<class _CharT, class _Traits>
972 typename basic_istream<_CharT, _Traits>::int_type
973 basic_istream<_CharT, _Traits>::peek()
976 int_type __r = traits_type::eof();
977 #ifndef _LIBCPP_NO_EXCEPTIONS
980 #endif // _LIBCPP_NO_EXCEPTIONS
981 sentry __sen(*this, true);
984 __r = this->rdbuf()->sgetc();
985 if (traits_type::eq_int_type(__r, traits_type::eof()))
986 this->setstate(ios_base::eofbit);
988 #ifndef _LIBCPP_NO_EXCEPTIONS
992 this->__set_badbit_and_consider_rethrow();
994 #endif // _LIBCPP_NO_EXCEPTIONS
998 template<class _CharT, class _Traits>
999 basic_istream<_CharT, _Traits>&
1000 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1003 #ifndef _LIBCPP_NO_EXCEPTIONS
1006 #endif // _LIBCPP_NO_EXCEPTIONS
1007 sentry __sen(*this, true);
1010 __gc_ = this->rdbuf()->sgetn(__s, __n);
1012 this->setstate(ios_base::failbit | ios_base::eofbit);
1015 this->setstate(ios_base::failbit);
1016 #ifndef _LIBCPP_NO_EXCEPTIONS
1020 this->__set_badbit_and_consider_rethrow();
1022 #endif // _LIBCPP_NO_EXCEPTIONS
1026 template<class _CharT, class _Traits>
1028 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1031 #ifndef _LIBCPP_NO_EXCEPTIONS
1034 #endif // _LIBCPP_NO_EXCEPTIONS
1035 sentry __sen(*this, true);
1038 streamsize __c = this->rdbuf()->in_avail();
1042 this->setstate(ios_base::eofbit);
1047 read(__s, _VSTD::min(__c, __n));
1052 this->setstate(ios_base::failbit);
1053 #ifndef _LIBCPP_NO_EXCEPTIONS
1057 this->__set_badbit_and_consider_rethrow();
1059 #endif // _LIBCPP_NO_EXCEPTIONS
1063 template<class _CharT, class _Traits>
1064 basic_istream<_CharT, _Traits>&
1065 basic_istream<_CharT, _Traits>::putback(char_type __c)
1068 #ifndef _LIBCPP_NO_EXCEPTIONS
1071 #endif // _LIBCPP_NO_EXCEPTIONS
1072 this->clear(this->rdstate() & ~ios_base::eofbit);
1073 sentry __sen(*this, true);
1076 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1077 this->setstate(ios_base::badbit);
1080 this->setstate(ios_base::failbit);
1081 #ifndef _LIBCPP_NO_EXCEPTIONS
1085 this->__set_badbit_and_consider_rethrow();
1087 #endif // _LIBCPP_NO_EXCEPTIONS
1091 template<class _CharT, class _Traits>
1092 basic_istream<_CharT, _Traits>&
1093 basic_istream<_CharT, _Traits>::unget()
1096 #ifndef _LIBCPP_NO_EXCEPTIONS
1099 #endif // _LIBCPP_NO_EXCEPTIONS
1100 this->clear(this->rdstate() & ~ios_base::eofbit);
1101 sentry __sen(*this, true);
1104 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1105 this->setstate(ios_base::badbit);
1108 this->setstate(ios_base::failbit);
1109 #ifndef _LIBCPP_NO_EXCEPTIONS
1113 this->__set_badbit_and_consider_rethrow();
1115 #endif // _LIBCPP_NO_EXCEPTIONS
1119 template<class _CharT, class _Traits>
1121 basic_istream<_CharT, _Traits>::sync()
1124 #ifndef _LIBCPP_NO_EXCEPTIONS
1127 #endif // _LIBCPP_NO_EXCEPTIONS
1128 sentry __sen(*this, true);
1131 if (this->rdbuf() == 0)
1133 if (this->rdbuf()->pubsync() == -1)
1135 this->setstate(ios_base::badbit);
1139 #ifndef _LIBCPP_NO_EXCEPTIONS
1143 this->__set_badbit_and_consider_rethrow();
1145 #endif // _LIBCPP_NO_EXCEPTIONS
1149 template<class _CharT, class _Traits>
1150 typename basic_istream<_CharT, _Traits>::pos_type
1151 basic_istream<_CharT, _Traits>::tellg()
1154 #ifndef _LIBCPP_NO_EXCEPTIONS
1157 #endif // _LIBCPP_NO_EXCEPTIONS
1158 sentry __sen(*this, true);
1160 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1161 #ifndef _LIBCPP_NO_EXCEPTIONS
1165 this->__set_badbit_and_consider_rethrow();
1167 #endif // _LIBCPP_NO_EXCEPTIONS
1171 template<class _CharT, class _Traits>
1172 basic_istream<_CharT, _Traits>&
1173 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1175 #ifndef _LIBCPP_NO_EXCEPTIONS
1178 #endif // _LIBCPP_NO_EXCEPTIONS
1179 this->clear(this->rdstate() & ~ios_base::eofbit);
1180 sentry __sen(*this, true);
1183 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1184 this->setstate(ios_base::failbit);
1186 #ifndef _LIBCPP_NO_EXCEPTIONS
1190 this->__set_badbit_and_consider_rethrow();
1192 #endif // _LIBCPP_NO_EXCEPTIONS
1196 template<class _CharT, class _Traits>
1197 basic_istream<_CharT, _Traits>&
1198 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1200 #ifndef _LIBCPP_NO_EXCEPTIONS
1203 #endif // _LIBCPP_NO_EXCEPTIONS
1204 this->clear(this->rdstate() & ~ios_base::eofbit);
1205 sentry __sen(*this, true);
1208 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1209 this->setstate(ios_base::failbit);
1211 #ifndef _LIBCPP_NO_EXCEPTIONS
1215 this->__set_badbit_and_consider_rethrow();
1217 #endif // _LIBCPP_NO_EXCEPTIONS
1221 template <class _CharT, class _Traits>
1222 basic_istream<_CharT, _Traits>&
1223 ws(basic_istream<_CharT, _Traits>& __is)
1225 #ifndef _LIBCPP_NO_EXCEPTIONS
1228 #endif // _LIBCPP_NO_EXCEPTIONS
1229 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1232 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1235 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1236 if (_Traits::eq_int_type(__i, _Traits::eof()))
1238 __is.setstate(ios_base::eofbit);
1241 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1243 __is.rdbuf()->sbumpc();
1246 #ifndef _LIBCPP_NO_EXCEPTIONS
1250 __is.__set_badbit_and_consider_rethrow();
1252 #endif // _LIBCPP_NO_EXCEPTIONS
1256 #ifndef _LIBCPP_CXX03_LANG
1258 template <class _CharT, class _Traits, class _Tp>
1259 inline _LIBCPP_INLINE_VISIBILITY
1260 basic_istream<_CharT, _Traits>&
1261 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
1263 __is >> _VSTD::forward<_Tp>(__x);
1267 #endif // _LIBCPP_CXX03_LANG
1269 template <class _CharT, class _Traits>
1270 class _LIBCPP_TEMPLATE_VIS basic_iostream
1271 : public basic_istream<_CharT, _Traits>,
1272 public basic_ostream<_CharT, _Traits>
1276 typedef _CharT char_type;
1277 typedef _Traits traits_type;
1278 typedef typename traits_type::int_type int_type;
1279 typedef typename traits_type::pos_type pos_type;
1280 typedef typename traits_type::off_type off_type;
1282 // constructor/destructor
1283 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
1284 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1285 : basic_istream<_CharT, _Traits>(__sb)
1288 virtual ~basic_iostream();
1290 #ifndef _LIBCPP_CXX03_LANG
1291 inline _LIBCPP_INLINE_VISIBILITY
1292 basic_iostream(basic_iostream&& __rhs);
1295 inline _LIBCPP_INLINE_VISIBILITY
1296 basic_iostream& operator=(basic_iostream&& __rhs);
1298 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
1299 void swap(basic_iostream& __rhs)
1300 { basic_istream<char_type, traits_type>::swap(__rhs); }
1304 #ifndef _LIBCPP_CXX03_LANG
1306 template <class _CharT, class _Traits>
1307 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1308 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1312 template <class _CharT, class _Traits>
1313 basic_iostream<_CharT, _Traits>&
1314 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1320 #endif // _LIBCPP_CXX03_LANG
1322 template <class _CharT, class _Traits>
1323 basic_iostream<_CharT, _Traits>::~basic_iostream()
1327 template<class _CharT, class _Traits, class _Allocator>
1328 basic_istream<_CharT, _Traits>&
1329 operator>>(basic_istream<_CharT, _Traits>& __is,
1330 basic_string<_CharT, _Traits, _Allocator>& __str)
1332 #ifndef _LIBCPP_NO_EXCEPTIONS
1335 #endif // _LIBCPP_NO_EXCEPTIONS
1336 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1340 streamsize __n = __is.width();
1342 __n = __str.max_size();
1344 __n = numeric_limits<streamsize>::max();
1346 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1347 ios_base::iostate __err = ios_base::goodbit;
1350 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1351 if (_Traits::eq_int_type(__i, _Traits::eof()))
1353 __err |= ios_base::eofbit;
1356 _CharT __ch = _Traits::to_char_type(__i);
1357 if (__ct.is(__ct.space, __ch))
1359 __str.push_back(__ch);
1361 __is.rdbuf()->sbumpc();
1365 __err |= ios_base::failbit;
1366 __is.setstate(__err);
1369 __is.setstate(ios_base::failbit);
1370 #ifndef _LIBCPP_NO_EXCEPTIONS
1374 __is.__set_badbit_and_consider_rethrow();
1376 #endif // _LIBCPP_NO_EXCEPTIONS
1380 template<class _CharT, class _Traits, class _Allocator>
1381 basic_istream<_CharT, _Traits>&
1382 getline(basic_istream<_CharT, _Traits>& __is,
1383 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1385 #ifndef _LIBCPP_NO_EXCEPTIONS
1388 #endif // _LIBCPP_NO_EXCEPTIONS
1389 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1393 ios_base::iostate __err = ios_base::goodbit;
1394 streamsize __extr = 0;
1397 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1398 if (_Traits::eq_int_type(__i, _Traits::eof()))
1400 __err |= ios_base::eofbit;
1404 _CharT __ch = _Traits::to_char_type(__i);
1405 if (_Traits::eq(__ch, __dlm))
1407 __str.push_back(__ch);
1408 if (__str.size() == __str.max_size())
1410 __err |= ios_base::failbit;
1415 __err |= ios_base::failbit;
1416 __is.setstate(__err);
1418 #ifndef _LIBCPP_NO_EXCEPTIONS
1422 __is.__set_badbit_and_consider_rethrow();
1424 #endif // _LIBCPP_NO_EXCEPTIONS
1428 template<class _CharT, class _Traits, class _Allocator>
1429 inline _LIBCPP_INLINE_VISIBILITY
1430 basic_istream<_CharT, _Traits>&
1431 getline(basic_istream<_CharT, _Traits>& __is,
1432 basic_string<_CharT, _Traits, _Allocator>& __str)
1434 return getline(__is, __str, __is.widen('\n'));
1437 #ifndef _LIBCPP_CXX03_LANG
1439 template<class _CharT, class _Traits, class _Allocator>
1440 inline _LIBCPP_INLINE_VISIBILITY
1441 basic_istream<_CharT, _Traits>&
1442 getline(basic_istream<_CharT, _Traits>&& __is,
1443 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1445 return getline(__is, __str, __dlm);
1448 template<class _CharT, class _Traits, class _Allocator>
1449 inline _LIBCPP_INLINE_VISIBILITY
1450 basic_istream<_CharT, _Traits>&
1451 getline(basic_istream<_CharT, _Traits>&& __is,
1452 basic_string<_CharT, _Traits, _Allocator>& __str)
1454 return getline(__is, __str, __is.widen('\n'));
1457 #endif // _LIBCPP_CXX03_LANG
1459 template <class _CharT, class _Traits, size_t _Size>
1460 basic_istream<_CharT, _Traits>&
1461 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1463 #ifndef _LIBCPP_NO_EXCEPTIONS
1466 #endif // _LIBCPP_NO_EXCEPTIONS
1467 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1470 basic_string<_CharT, _Traits> __str;
1471 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1473 ios_base::iostate __err = ios_base::goodbit;
1474 _CharT __zero = __ct.widen('0');
1475 _CharT __one = __ct.widen('1');
1478 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1479 if (_Traits::eq_int_type(__i, _Traits::eof()))
1481 __err |= ios_base::eofbit;
1484 _CharT __ch = _Traits::to_char_type(__i);
1485 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1487 __str.push_back(__ch);
1489 __is.rdbuf()->sbumpc();
1491 __x = bitset<_Size>(__str);
1493 __err |= ios_base::failbit;
1494 __is.setstate(__err);
1497 __is.setstate(ios_base::failbit);
1498 #ifndef _LIBCPP_NO_EXCEPTIONS
1502 __is.__set_badbit_and_consider_rethrow();
1504 #endif // _LIBCPP_NO_EXCEPTIONS
1508 #ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
1509 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1510 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1511 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
1514 _LIBCPP_END_NAMESPACE_STD
1518 #endif // _LIBCPP_ISTREAM