blob: c56393acbee1e46789130c9d8e3a1a1d6e082112 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- istream ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ISTREAM
12#define _LIBCPP_ISTREAM
13
14/*
15 istream synopsis
16
17template <class charT, class traits = char_traits<charT> >
18class basic_istream
19 : virtual public basic_ios<charT,traits>
20{
21public:
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;
28
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();
33
34 // 27.7.1.1.2 Assign/swap:
35 basic_istream& operator=(basic_istream&& rhs);
36 void swap(basic_istream& rhs);
37
38 // 27.7.1.1.3 Prefix/suffix:
39 class sentry;
40
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);
60
61 // 27.7.1.3 Unformatted input:
62 streamsize gcount() const;
63 int_type get();
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);
69
70 basic_istream& getline(char_type* s, streamsize n);
71 basic_istream& getline(char_type* s, streamsize n, char_type delim);
72
73 basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
74 int_type peek();
75 basic_istream& read (char_type* s, streamsize n);
76 streamsize readsome(char_type* s, streamsize n);
77
78 basic_istream& putback(char_type c);
79 basic_istream& unget();
80 int sync();
81
82 pos_type tellg();
83 basic_istream& seekg(pos_type);
84 basic_istream& seekg(off_type, ios_base::seekdir);
85};
86
87// 27.7.1.2.3 character extraction templates:
88template<class charT, class traits>
89 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
90
91template<class traits>
92 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
93
94template<class traits>
95 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
96
97template<class charT, class traits>
98 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
99
100template<class traits>
101 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
102
103template<class traits>
104 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
105
106template <class charT, class traits>
107 void
108 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
109
110typedef basic_istream<char> istream;
111typedef basic_istream<wchar_t> wistream;
112
113template <class charT, class traits = char_traits<charT> >
114class basic_iostream :
115 public basic_istream<charT,traits>,
116 public basic_ostream<charT,traits>
117{
118public:
119 // types:
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;
125
126 // constructor/destructor
127 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
128 basic_iostream(basic_iostream&& rhs);
129 virtual ~basic_iostream();
130
131 // assign/swap
132 basic_iostream& operator=(basic_iostream&& rhs);
133 void swap(basic_iostream& rhs);
134};
135
136template <class charT, class traits>
137 void
138 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
139
140typedef basic_iostream<char> iostream;
141typedef basic_iostream<wchar_t> wiostream;
142
143template <class charT, class traits>
144 basic_istream<charT,traits>&
145 ws(basic_istream<charT,traits>& is);
146
147template <class charT, class traits, class T>
148 basic_istream<charT, traits>&
149 operator>>(basic_istream<charT, traits>&& is, T& x);
150
151} // std
152
153*/
154
155#include <__config>
156#include <ostream>
157
158#pragma GCC system_header
159
160_LIBCPP_BEGIN_NAMESPACE_STD
161
162template <class _CharT, class _Traits>
Howard Hinnant68a8e902010-09-22 15:29:08 +0000163class _LIBCPP_VISIBLE basic_istream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164 : virtual public basic_ios<_CharT, _Traits>
165{
166 streamsize __gc_;
167public:
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;
174
175 // 27.7.1.1.1 Constructor/destructor:
176 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb);
177 virtual ~basic_istream();
178protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000179#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181 basic_istream(basic_istream&& __rhs);
182#endif
183
184 // 27.7.1.1.2 Assign/swap:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000185#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187 basic_istream& operator=(basic_istream&& __rhs);
188#endif
189 void swap(basic_istream& __rhs);
190public:
191
192 // 27.7.1.1.3 Prefix/suffix:
193 class sentry;
194
195 // 27.7.1.2 Formatted input:
196 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
197 basic_istream& operator>>(basic_ios<char_type, traits_type>&
198 (*__pf)(basic_ios<char_type, traits_type>&));
199 basic_istream& operator>>(ios_base& (*__pf)(ios_base&));
200 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
201 basic_istream& operator>>(bool& __n);
202 basic_istream& operator>>(short& __n);
203 basic_istream& operator>>(unsigned short& __n);
204 basic_istream& operator>>(int& __n);
205 basic_istream& operator>>(unsigned int& __n);
206 basic_istream& operator>>(long& __n);
207 basic_istream& operator>>(unsigned long& __n);
208 basic_istream& operator>>(long long& __n);
209 basic_istream& operator>>(unsigned long long& __n);
210 basic_istream& operator>>(float& __f);
211 basic_istream& operator>>(double& __f);
212 basic_istream& operator>>(long double& __f);
213 basic_istream& operator>>(void*& __p);
214
215 // 27.7.1.3 Unformatted input:
Howard Hinnant68a8e902010-09-22 15:29:08 +0000216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 streamsize gcount() const {return __gc_;}
218 int_type get();
219 basic_istream& get(char_type& __c);
220 basic_istream& get(char_type* __s, streamsize __n);
221 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
222 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
223 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
224
225 basic_istream& getline(char_type* __s, streamsize __n);
226 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
227
228 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
229 int_type peek();
230 basic_istream& read (char_type* __s, streamsize __n);
231 streamsize readsome(char_type* __s, streamsize __n);
232
233 basic_istream& putback(char_type __c);
234 basic_istream& unget();
235 int sync();
236
237 pos_type tellg();
238 basic_istream& seekg(pos_type __pos);
239 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
240};
241
242template <class _CharT, class _Traits>
Howard Hinnant68a8e902010-09-22 15:29:08 +0000243class _LIBCPP_VISIBLE basic_istream<_CharT, _Traits>::sentry
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244{
245 bool __ok_;
246
247 sentry(const sentry&); // = delete;
248 sentry& operator=(const sentry&); // = delete;
249
250public:
251 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
252// ~sentry() = default;
253
Howard Hinnant68a8e902010-09-22 15:29:08 +0000254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 // explicit
256 operator bool() const {return __ok_;}
257};
258
259template <class _CharT, class _Traits>
260basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
261 bool __noskipws)
262 : __ok_(false)
263{
264 if (__is.good())
265 {
266 if (__is.tie())
267 __is.tie()->flush();
268 if (!__noskipws && (__is.flags() & ios_base::skipws))
269 {
270 typedef istreambuf_iterator<_CharT, _Traits> _I;
271 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
272 _I __i(__is);
273 _I __eof;
274 for (; __i != __eof; ++__i)
275 if (!__ct.is(__ct.space, *__i))
276 break;
277 if (__i == __eof)
278 __is.setstate(ios_base::failbit | ios_base::eofbit);
279 }
280 __ok_ = __is.good();
281 }
282 else
283 __is.setstate(ios_base::failbit);
284}
285
286template <class _CharT, class _Traits>
287inline _LIBCPP_INLINE_VISIBILITY
288basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
289 : __gc_(0)
290{
291 this->init(__sb);
292}
293
Howard Hinnant73d21a42010-09-04 23:28:19 +0000294#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295
296template <class _CharT, class _Traits>
297inline _LIBCPP_INLINE_VISIBILITY
298basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
299 : __gc_(__rhs.__gc_)
300{
301 __rhs.__gc_ = 0;
302 this->move(__rhs);
303}
304
305template <class _CharT, class _Traits>
306inline _LIBCPP_INLINE_VISIBILITY
307basic_istream<_CharT, _Traits>&
308basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
309{
310 swap(__rhs);
311 return *this;
312}
313
Howard Hinnant73d21a42010-09-04 23:28:19 +0000314#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315
316template <class _CharT, class _Traits>
317basic_istream<_CharT, _Traits>::~basic_istream()
318{
319}
320
321template <class _CharT, class _Traits>
322inline _LIBCPP_INLINE_VISIBILITY
323void
324basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
325{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000326 _VSTD::swap(__gc_, __rhs.__gc_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 basic_ios<char_type, traits_type>::swap(__rhs);
328}
329
330template <class _CharT, class _Traits>
331basic_istream<_CharT, _Traits>&
332basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
333{
334#ifndef _LIBCPP_NO_EXCEPTIONS
335 try
336 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000337#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338 sentry __s(*this);
339 if (__s)
340 {
341 typedef istreambuf_iterator<char_type, traits_type> _I;
342 typedef num_get<char_type, _I> _F;
343 ios_base::iostate __err = ios_base::goodbit;
344 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
345 this->setstate(__err);
346 }
347#ifndef _LIBCPP_NO_EXCEPTIONS
348 }
349 catch (...)
350 {
351 this->__set_badbit_and_consider_rethrow();
352 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000353#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 return *this;
355}
356
357template <class _CharT, class _Traits>
358basic_istream<_CharT, _Traits>&
359basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
360{
361#ifndef _LIBCPP_NO_EXCEPTIONS
362 try
363 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000364#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 sentry __s(*this);
366 if (__s)
367 {
368 typedef istreambuf_iterator<char_type, traits_type> _I;
369 typedef num_get<char_type, _I> _F;
370 ios_base::iostate __err = ios_base::goodbit;
371 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
372 this->setstate(__err);
373 }
374#ifndef _LIBCPP_NO_EXCEPTIONS
375 }
376 catch (...)
377 {
378 this->__set_badbit_and_consider_rethrow();
379 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000380#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 return *this;
382}
383
384template <class _CharT, class _Traits>
385basic_istream<_CharT, _Traits>&
386basic_istream<_CharT, _Traits>::operator>>(long& __n)
387{
388#ifndef _LIBCPP_NO_EXCEPTIONS
389 try
390 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000391#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 sentry __s(*this);
393 if (__s)
394 {
395 typedef istreambuf_iterator<char_type, traits_type> _I;
396 typedef num_get<char_type, _I> _F;
397 ios_base::iostate __err = ios_base::goodbit;
398 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
399 this->setstate(__err);
400 }
401#ifndef _LIBCPP_NO_EXCEPTIONS
402 }
403 catch (...)
404 {
405 this->__set_badbit_and_consider_rethrow();
406 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000407#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 return *this;
409}
410
411template <class _CharT, class _Traits>
412basic_istream<_CharT, _Traits>&
413basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
414{
415#ifndef _LIBCPP_NO_EXCEPTIONS
416 try
417 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000418#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 sentry __s(*this);
420 if (__s)
421 {
422 typedef istreambuf_iterator<char_type, traits_type> _I;
423 typedef num_get<char_type, _I> _F;
424 ios_base::iostate __err = ios_base::goodbit;
425 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
426 this->setstate(__err);
427 }
428#ifndef _LIBCPP_NO_EXCEPTIONS
429 }
430 catch (...)
431 {
432 this->__set_badbit_and_consider_rethrow();
433 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000434#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 return *this;
436}
437
438template <class _CharT, class _Traits>
439basic_istream<_CharT, _Traits>&
440basic_istream<_CharT, _Traits>::operator>>(long long& __n)
441{
442#ifndef _LIBCPP_NO_EXCEPTIONS
443 try
444 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000445#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 sentry __s(*this);
447 if (__s)
448 {
449 typedef istreambuf_iterator<char_type, traits_type> _I;
450 typedef num_get<char_type, _I> _F;
451 ios_base::iostate __err = ios_base::goodbit;
452 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
453 this->setstate(__err);
454 }
455#ifndef _LIBCPP_NO_EXCEPTIONS
456 }
457 catch (...)
458 {
459 this->__set_badbit_and_consider_rethrow();
460 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000461#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 return *this;
463}
464
465template <class _CharT, class _Traits>
466basic_istream<_CharT, _Traits>&
467basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
468{
469#ifndef _LIBCPP_NO_EXCEPTIONS
470 try
471 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000472#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473 sentry __s(*this);
474 if (__s)
475 {
476 typedef istreambuf_iterator<char_type, traits_type> _I;
477 typedef num_get<char_type, _I> _F;
478 ios_base::iostate __err = ios_base::goodbit;
479 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
480 this->setstate(__err);
481 }
482#ifndef _LIBCPP_NO_EXCEPTIONS
483 }
484 catch (...)
485 {
486 this->__set_badbit_and_consider_rethrow();
487 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000488#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 return *this;
490}
491
492template <class _CharT, class _Traits>
493basic_istream<_CharT, _Traits>&
494basic_istream<_CharT, _Traits>::operator>>(float& __n)
495{
496#ifndef _LIBCPP_NO_EXCEPTIONS
497 try
498 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000499#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 sentry __s(*this);
501 if (__s)
502 {
503 typedef istreambuf_iterator<char_type, traits_type> _I;
504 typedef num_get<char_type, _I> _F;
505 ios_base::iostate __err = ios_base::goodbit;
506 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
507 this->setstate(__err);
508 }
509#ifndef _LIBCPP_NO_EXCEPTIONS
510 }
511 catch (...)
512 {
513 this->__set_badbit_and_consider_rethrow();
514 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000515#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516 return *this;
517}
518
519template <class _CharT, class _Traits>
520basic_istream<_CharT, _Traits>&
521basic_istream<_CharT, _Traits>::operator>>(double& __n)
522{
523#ifndef _LIBCPP_NO_EXCEPTIONS
524 try
525 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000526#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 sentry __s(*this);
528 if (__s)
529 {
530 typedef istreambuf_iterator<char_type, traits_type> _I;
531 typedef num_get<char_type, _I> _F;
532 ios_base::iostate __err = ios_base::goodbit;
533 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
534 this->setstate(__err);
535 }
536#ifndef _LIBCPP_NO_EXCEPTIONS
537 }
538 catch (...)
539 {
540 this->__set_badbit_and_consider_rethrow();
541 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000542#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 return *this;
544}
545
546template <class _CharT, class _Traits>
547basic_istream<_CharT, _Traits>&
548basic_istream<_CharT, _Traits>::operator>>(long double& __n)
549{
550#ifndef _LIBCPP_NO_EXCEPTIONS
551 try
552 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 sentry __s(*this);
555 if (__s)
556 {
557 typedef istreambuf_iterator<char_type, traits_type> _I;
558 typedef num_get<char_type, _I> _F;
559 ios_base::iostate __err = ios_base::goodbit;
560 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
561 this->setstate(__err);
562 }
563#ifndef _LIBCPP_NO_EXCEPTIONS
564 }
565 catch (...)
566 {
567 this->__set_badbit_and_consider_rethrow();
568 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000569#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 return *this;
571}
572
573template <class _CharT, class _Traits>
574basic_istream<_CharT, _Traits>&
575basic_istream<_CharT, _Traits>::operator>>(bool& __n)
576{
577#ifndef _LIBCPP_NO_EXCEPTIONS
578 try
579 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000580#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581 sentry __s(*this);
582 if (__s)
583 {
584 typedef istreambuf_iterator<char_type, traits_type> _I;
585 typedef num_get<char_type, _I> _F;
586 ios_base::iostate __err = ios_base::goodbit;
587 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
588 this->setstate(__err);
589 }
590#ifndef _LIBCPP_NO_EXCEPTIONS
591 }
592 catch (...)
593 {
594 this->__set_badbit_and_consider_rethrow();
595 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000596#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597 return *this;
598}
599
600template <class _CharT, class _Traits>
601basic_istream<_CharT, _Traits>&
602basic_istream<_CharT, _Traits>::operator>>(void*& __n)
603{
604#ifndef _LIBCPP_NO_EXCEPTIONS
605 try
606 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000607#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 sentry __s(*this);
609 if (__s)
610 {
611 typedef istreambuf_iterator<char_type, traits_type> _I;
612 typedef num_get<char_type, _I> _F;
613 ios_base::iostate __err = ios_base::goodbit;
614 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
615 this->setstate(__err);
616 }
617#ifndef _LIBCPP_NO_EXCEPTIONS
618 }
619 catch (...)
620 {
621 this->__set_badbit_and_consider_rethrow();
622 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000623#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 return *this;
625}
626
627template <class _CharT, class _Traits>
628basic_istream<_CharT, _Traits>&
629basic_istream<_CharT, _Traits>::operator>>(short& __n)
630{
631#ifndef _LIBCPP_NO_EXCEPTIONS
632 try
633 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000634#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 sentry __s(*this);
636 if (__s)
637 {
638 typedef istreambuf_iterator<char_type, traits_type> _I;
639 typedef num_get<char_type, _I> _F;
640 ios_base::iostate __err = ios_base::goodbit;
641 long __temp;
642 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
643 if (__temp < numeric_limits<short>::min())
644 {
645 __err |= ios_base::failbit;
646 __n = numeric_limits<short>::min();
647 }
648 else if (__temp > numeric_limits<short>::max())
649 {
650 __err |= ios_base::failbit;
651 __n = numeric_limits<short>::max();
652 }
653 else
654 __n = static_cast<short>(__temp);
655 this->setstate(__err);
656 }
657#ifndef _LIBCPP_NO_EXCEPTIONS
658 }
659 catch (...)
660 {
661 this->__set_badbit_and_consider_rethrow();
662 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000663#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664 return *this;
665}
666
667template <class _CharT, class _Traits>
668basic_istream<_CharT, _Traits>&
669basic_istream<_CharT, _Traits>::operator>>(int& __n)
670{
671#ifndef _LIBCPP_NO_EXCEPTIONS
672 try
673 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000674#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 sentry __s(*this);
676 if (__s)
677 {
678 typedef istreambuf_iterator<char_type, traits_type> _I;
679 typedef num_get<char_type, _I> _F;
680 ios_base::iostate __err = ios_base::goodbit;
681 long __temp;
682 use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
683 if (__temp < numeric_limits<int>::min())
684 {
685 __err |= ios_base::failbit;
686 __n = numeric_limits<int>::min();
687 }
688 else if (__temp > numeric_limits<int>::max())
689 {
690 __err |= ios_base::failbit;
691 __n = numeric_limits<int>::max();
692 }
693 else
694 __n = static_cast<int>(__temp);
695 this->setstate(__err);
696 }
697#ifndef _LIBCPP_NO_EXCEPTIONS
698 }
699 catch (...)
700 {
701 this->__set_badbit_and_consider_rethrow();
702 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000703#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 return *this;
705}
706
707template <class _CharT, class _Traits>
708inline _LIBCPP_INLINE_VISIBILITY
709basic_istream<_CharT, _Traits>&
710basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
711{
712 return __pf(*this);
713}
714
715template <class _CharT, class _Traits>
716inline _LIBCPP_INLINE_VISIBILITY
717basic_istream<_CharT, _Traits>&
718basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
719 (*__pf)(basic_ios<char_type, traits_type>&))
720{
721 __pf(*this);
722 return *this;
723}
724
725template <class _CharT, class _Traits>
726inline _LIBCPP_INLINE_VISIBILITY
727basic_istream<_CharT, _Traits>&
728basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
729{
730 __pf(*this);
731 return *this;
732}
733
734template<class _CharT, class _Traits>
735basic_istream<_CharT, _Traits>&
736operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
737{
738#ifndef _LIBCPP_NO_EXCEPTIONS
739 try
740 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000741#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
743 if (__sen)
744 {
745 typedef istreambuf_iterator<_CharT, _Traits> _I;
746 streamsize __n = __is.width();
747 if (__n == 0)
748 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
749 streamsize __c = 0;
750 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
751 _I __i(__is);
752 _I __eof;
753 for (; __i != __eof && __c < __n-1; ++__i, ++__s, ++__c)
754 {
755 _CharT __ch = *__i;
756 if (__ct.is(__ct.space, __ch))
757 break;
758 *__s = __ch;
759 }
760 *__s = _CharT();
761 __is.width(0);
762 ios_base::iostate __err = ios_base::goodbit;
763 if (__i == __eof)
764 __err |= ios_base::eofbit;
765 if (__c == 0)
766 __err |= ios_base::failbit;
767 __is.setstate(__err);
768 }
769#ifndef _LIBCPP_NO_EXCEPTIONS
770 }
771 catch (...)
772 {
773 __is.__set_badbit_and_consider_rethrow();
774 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 return __is;
777}
778
779template<class _Traits>
780inline _LIBCPP_INLINE_VISIBILITY
781basic_istream<char, _Traits>&
782operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
783{
784 return __is >> (char*)__s;
785}
786
787template<class _Traits>
788inline _LIBCPP_INLINE_VISIBILITY
789basic_istream<char, _Traits>&
790operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
791{
792 return __is >> (char*)__s;
793}
794
795template<class _CharT, class _Traits>
796basic_istream<_CharT, _Traits>&
797operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
798{
799#ifndef _LIBCPP_NO_EXCEPTIONS
800 try
801 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000802#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
804 if (__sen)
805 {
Howard Hinnantdf85e572011-02-27 18:02:02 +0000806#if 1
807 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
808 if (_Traits::eq_int_type(__i, _Traits::eof()))
809 __is.setstate(ios_base::eofbit | ios_base::failbit);
810 else
811 __c = _Traits::to_char_type(__i);
812#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813 typedef istreambuf_iterator<_CharT, _Traits> _I;
814 _I __i(__is);
815 _I __eof;
816 if (__i != __eof)
817 {
818 __c = *__i;
819 if (++__i == __eof)
820 __is.setstate(ios_base::eofbit);
821 }
822 else
823 __is.setstate(ios_base::eofbit | ios_base::failbit);
Howard Hinnantdf85e572011-02-27 18:02:02 +0000824#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825 }
826#ifndef _LIBCPP_NO_EXCEPTIONS
827 }
828 catch (...)
829 {
830 __is.__set_badbit_and_consider_rethrow();
831 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000832#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833 return __is;
834}
835
836template<class _Traits>
837inline _LIBCPP_INLINE_VISIBILITY
838basic_istream<char, _Traits>&
839operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
840{
841 return __is >> (char&)__c;
842}
843
844template<class _Traits>
845inline _LIBCPP_INLINE_VISIBILITY
846basic_istream<char, _Traits>&
847operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
848{
849 return __is >> (char&)__c;
850}
851
852template<class _CharT, class _Traits>
853basic_istream<_CharT, _Traits>&
854basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
855{
856 __gc_ = 0;
857#ifndef _LIBCPP_NO_EXCEPTIONS
858 try
859 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000860#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 sentry __s(*this, true);
862 if (__s)
863 {
864 streamsize __c = 0;
865 if (__sb)
866 {
867#ifndef _LIBCPP_NO_EXCEPTIONS
868 try
869 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000870#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 typedef istreambuf_iterator<char_type, traits_type> _I;
872 typedef ostreambuf_iterator<char_type, traits_type> _O;
873 _I __i(*this);
874 _I __eof;
875 _O __o(__sb);
876 for (; __i != __eof; ++__i, ++__o, ++__c)
877 {
878 *__o = *__i;
879 if (__o.failed())
880 break;
881 }
882 ios_base::iostate __err = ios_base::goodbit;
883 if (__i == __eof)
884 __err |= ios_base::eofbit;
885 if (__c == 0)
886 __err |= ios_base::failbit;
887 this->setstate(__err);
888#ifndef _LIBCPP_NO_EXCEPTIONS
889 }
890 catch (...)
891 {
892 if (__c == 0)
893 this->__set_failbit_and_consider_rethrow();
894 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000895#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 }
897 else
898 this->setstate(ios_base::failbit);
899 __gc_ = __c;
900 }
901#ifndef _LIBCPP_NO_EXCEPTIONS
902 }
903 catch (...)
904 {
905 this->__set_badbit_and_consider_rethrow();
906 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000907#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 return *this;
909}
910
911template<class _CharT, class _Traits>
912typename basic_istream<_CharT, _Traits>::int_type
913basic_istream<_CharT, _Traits>::get()
914{
915 __gc_ = 0;
916 int_type __r = traits_type::eof();
917#ifndef _LIBCPP_NO_EXCEPTIONS
918 try
919 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000920#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921 sentry __s(*this, true);
922 if (__s)
923 {
924 streamsize __c = 0;
925 typedef istreambuf_iterator<char_type, traits_type> _I;
926 _I __i(*this);
927 _I __eof;
928 ios_base::iostate __err = ios_base::goodbit;
929 if (__i != __eof)
930 {
931 __r = traits_type::to_int_type(*__i);
932 ++__c;
933 if (++__i == __eof)
934 __err |= ios_base::eofbit;
935 }
936 else
937 __err |= ios_base::failbit | ios_base::eofbit;
938 this->setstate(__err);
939 __gc_ = __c;
940 }
941#ifndef _LIBCPP_NO_EXCEPTIONS
942 }
943 catch (...)
944 {
945 this->__set_badbit_and_consider_rethrow();
946 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000947#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948 return __r;
949}
950
951template<class _CharT, class _Traits>
952inline _LIBCPP_INLINE_VISIBILITY
953basic_istream<_CharT, _Traits>&
954basic_istream<_CharT, _Traits>::get(char_type& __c)
955{
956 int_type __ch = get();
957 if (__ch != traits_type::eof())
958 __c = traits_type::to_char_type(__ch);
959 return *this;
960}
961
962template<class _CharT, class _Traits>
963basic_istream<_CharT, _Traits>&
964basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
965{
966 __gc_ = 0;
967#ifndef _LIBCPP_NO_EXCEPTIONS
968 try
969 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000970#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 sentry __sen(*this, true);
972 if (__sen)
973 {
974 streamsize __c = 0;
975 if (__n > 0)
976 {
977 typedef istreambuf_iterator<char_type, traits_type> _I;
978 _I __i(*this);
979 _I __eof;
980 for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c)
981 {
982 char_type __ch = *__i;
983 if (traits_type::eq(__ch, __dlm))
984 break;
985 *__s = __ch;
986 }
987 *__s = char_type();
988 ios_base::iostate __err = ios_base::goodbit;
989 if (__i == __eof)
990 __err |= ios_base::eofbit;
991 if (__c == 0)
992 __err |= ios_base::failbit;
993 this->setstate(__err);
994 }
995 else
996 this->setstate(ios_base::failbit);
997 __gc_ = __c;
998 }
999#ifndef _LIBCPP_NO_EXCEPTIONS
1000 }
1001 catch (...)
1002 {
1003 this->__set_badbit_and_consider_rethrow();
1004 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001005#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006 return *this;
1007}
1008
1009template<class _CharT, class _Traits>
1010inline _LIBCPP_INLINE_VISIBILITY
1011basic_istream<_CharT, _Traits>&
1012basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1013{
1014 return get(__s, __n, this->widen('\n'));
1015}
1016
1017template<class _CharT, class _Traits>
1018basic_istream<_CharT, _Traits>&
1019basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1020 char_type __dlm)
1021{
1022 __gc_ = 0;
1023#ifndef _LIBCPP_NO_EXCEPTIONS
1024 try
1025 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001026#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 sentry __sen(*this, true);
1028 if (__sen)
1029 {
1030 streamsize __c = 0;
1031 ios_base::iostate __err = ios_base::goodbit;
1032#ifndef _LIBCPP_NO_EXCEPTIONS
1033 try
1034 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001035#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 typedef istreambuf_iterator<char_type, traits_type> _I;
1037 typedef ostreambuf_iterator<char_type, traits_type> _O;
1038 _I __i(*this);
1039 _I __eof;
1040 _O __o(&__sb);
1041 for (; __i != __eof; ++__i, ++__o, ++__c)
1042 {
1043 char_type __ch = *__i;
1044 if (traits_type::eq(__ch, __dlm))
1045 break;
1046 *__o = __ch;
1047 if (__o.failed())
1048 break;
1049 }
1050 if (__i == __eof)
1051 __err |= ios_base::eofbit;
1052#ifndef _LIBCPP_NO_EXCEPTIONS
1053 }
1054 catch (...)
1055 {
1056 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001057#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 if (__c == 0)
1059 __err |= ios_base::failbit;
1060 this->setstate(__err);
1061 __gc_ = __c;
1062 }
1063#ifndef _LIBCPP_NO_EXCEPTIONS
1064 }
1065 catch (...)
1066 {
1067 this->__set_badbit_and_consider_rethrow();
1068 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001069#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070 return *this;
1071}
1072
1073template<class _CharT, class _Traits>
1074inline _LIBCPP_INLINE_VISIBILITY
1075basic_istream<_CharT, _Traits>&
1076basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1077{
1078 return get(__sb, this->widen('\n'));
1079}
1080
1081template<class _CharT, class _Traits>
1082basic_istream<_CharT, _Traits>&
1083basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1084{
1085 __gc_ = 0;
1086#ifndef _LIBCPP_NO_EXCEPTIONS
1087 try
1088 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001089#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090 sentry __sen(*this, true);
1091 if (__sen)
1092 {
1093 streamsize __c = 0;
1094 typedef istreambuf_iterator<char_type, traits_type> _I;
1095 _I __i(*this);
1096 _I __eof;
1097 for (; __i != __eof; ++__s, --__n)
1098 {
1099 char_type __ch = *__i;
1100 ++__i;
1101 ++__c;
1102 if (traits_type::eq(__ch, __dlm))
1103 break;
1104 if (__n < 2)
1105 {
1106 this->setstate(ios_base::failbit);
1107 break;
1108 }
1109 *__s = __ch;
1110 }
1111 if (__n)
1112 *__s = char_type();
1113 ios_base::iostate __err = ios_base::goodbit;
1114 if (__i == __eof)
1115 __err |= ios_base::eofbit;
1116 if (__c == 0)
1117 __err |= ios_base::failbit;
1118 this->setstate(__err);
1119 __gc_ = __c;
1120 }
1121#ifndef _LIBCPP_NO_EXCEPTIONS
1122 }
1123 catch (...)
1124 {
1125 this->__set_badbit_and_consider_rethrow();
1126 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001127#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 return *this;
1129}
1130
1131template<class _CharT, class _Traits>
1132inline _LIBCPP_INLINE_VISIBILITY
1133basic_istream<_CharT, _Traits>&
1134basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1135{
1136 return getline(__s, __n, this->widen('\n'));
1137}
1138
1139template<class _CharT, class _Traits>
1140basic_istream<_CharT, _Traits>&
1141basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1142{
1143 __gc_ = 0;
1144#ifndef _LIBCPP_NO_EXCEPTIONS
1145 try
1146 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001147#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 sentry __sen(*this, true);
1149 if (__sen)
1150 {
1151 streamsize __c = 0;
1152 typedef istreambuf_iterator<char_type, traits_type> _I;
1153 _I __i(*this);
1154 _I __eof;
1155 if (__n != numeric_limits<streamsize>::max())
1156 {
1157 for (; __n > 0 && __i != __eof; --__n)
1158 {
1159 char_type __ch = *__i;
1160 ++__i;
1161 ++__c;
1162 if (traits_type::eq(__ch, __dlm))
1163 break;
1164 }
1165 }
1166 else
1167 {
1168 while (__i != __eof)
1169 {
1170 char_type __ch = *__i;
1171 ++__i;
1172 ++__c;
1173 if (traits_type::eq(__ch, __dlm))
1174 break;
1175 }
1176 }
1177 if (__i == __eof)
1178 this->setstate(ios_base::eofbit);
1179 __gc_ = __c;
1180 }
1181#ifndef _LIBCPP_NO_EXCEPTIONS
1182 }
1183 catch (...)
1184 {
1185 this->__set_badbit_and_consider_rethrow();
1186 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001187#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188 return *this;
1189}
1190
1191template<class _CharT, class _Traits>
1192typename basic_istream<_CharT, _Traits>::int_type
1193basic_istream<_CharT, _Traits>::peek()
1194{
1195 __gc_ = 0;
1196 int_type __r = traits_type::eof();
1197#ifndef _LIBCPP_NO_EXCEPTIONS
1198 try
1199 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001200#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 sentry __sen(*this, true);
1202 if (__sen)
1203 __r = this->rdbuf()->sgetc();
1204#ifndef _LIBCPP_NO_EXCEPTIONS
1205 }
1206 catch (...)
1207 {
1208 this->__set_badbit_and_consider_rethrow();
1209 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001210#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211 return __r;
1212}
1213
1214template<class _CharT, class _Traits>
1215basic_istream<_CharT, _Traits>&
1216basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1217{
1218 __gc_ = 0;
1219#ifndef _LIBCPP_NO_EXCEPTIONS
1220 try
1221 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001222#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 sentry __sen(*this, true);
1224 if (__sen)
1225 {
1226 streamsize __c = 0;
1227 typedef istreambuf_iterator<char_type, traits_type> _I;
1228 _I __i(*this);
1229 _I __eof;
1230 for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n)
1231 *__s = *__i;
1232 if (__i == __eof)
1233 {
1234 ios_base::iostate __err = ios_base::eofbit;
1235 if (__n > 0)
1236 __err |= ios_base::failbit;
1237 this->setstate(__err);
1238 }
1239 __gc_ = __c;
1240 }
1241 else
1242 this->setstate(ios_base::failbit);
1243#ifndef _LIBCPP_NO_EXCEPTIONS
1244 }
1245 catch (...)
1246 {
1247 this->__set_badbit_and_consider_rethrow();
1248 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001249#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 return *this;
1251}
1252
1253template<class _CharT, class _Traits>
1254streamsize
1255basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1256{
1257 __gc_ = 0;
1258 streamsize __c = 0;
1259#ifndef _LIBCPP_NO_EXCEPTIONS
1260 try
1261 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001262#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 sentry __sen(*this, true);
1264 if (__sen)
1265 {
1266 typedef istreambuf_iterator<char_type, traits_type> _I;
1267 _I __i(*this);
1268 _I __eof;
1269 __c = this->rdbuf()->in_avail();
1270 switch (__c)
1271 {
1272 case -1:
1273 __i = __eof;
1274 break;
1275 case 0:
1276 break;
1277 default:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001278 __c = _VSTD::min(__c, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i)
1280 *__s = *__i;
1281 }
1282 if (__i == __eof)
1283 this->setstate(ios_base::eofbit);
1284 __gc_ = __c;
1285 }
1286 else
1287 this->setstate(ios_base::failbit);
1288#ifndef _LIBCPP_NO_EXCEPTIONS
1289 }
1290 catch (...)
1291 {
1292 this->__set_badbit_and_consider_rethrow();
1293 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001294#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295 return __c;
1296}
1297
1298template<class _CharT, class _Traits>
1299basic_istream<_CharT, _Traits>&
1300basic_istream<_CharT, _Traits>::putback(char_type __c)
1301{
1302 __gc_ = 0;
1303#ifndef _LIBCPP_NO_EXCEPTIONS
1304 try
1305 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001306#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307 sentry __sen(*this, true);
1308 if (__sen)
1309 {
1310 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1311 this->setstate(ios_base::badbit);
1312 }
1313 else
1314 this->setstate(ios_base::failbit);
1315#ifndef _LIBCPP_NO_EXCEPTIONS
1316 }
1317 catch (...)
1318 {
1319 this->__set_badbit_and_consider_rethrow();
1320 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001321#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322 return *this;
1323}
1324
1325template<class _CharT, class _Traits>
1326basic_istream<_CharT, _Traits>&
1327basic_istream<_CharT, _Traits>::unget()
1328{
1329 __gc_ = 0;
1330#ifndef _LIBCPP_NO_EXCEPTIONS
1331 try
1332 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001333#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 sentry __sen(*this, true);
1335 if (__sen)
1336 {
1337 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1338 this->setstate(ios_base::badbit);
1339 }
1340 else
1341 this->setstate(ios_base::failbit);
1342#ifndef _LIBCPP_NO_EXCEPTIONS
1343 }
1344 catch (...)
1345 {
1346 this->__set_badbit_and_consider_rethrow();
1347 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001348#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349 return *this;
1350}
1351
1352template<class _CharT, class _Traits>
1353int
1354basic_istream<_CharT, _Traits>::sync()
1355{
1356 int __r = 0;
1357#ifndef _LIBCPP_NO_EXCEPTIONS
1358 try
1359 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001360#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 sentry __sen(*this, true);
1362 if (__sen)
1363 {
1364 if (this->rdbuf() == 0)
1365 return -1;
1366 if (this->rdbuf()->pubsync() == -1)
1367 {
1368 this->setstate(ios_base::badbit);
1369 return -1;
1370 }
1371 }
1372#ifndef _LIBCPP_NO_EXCEPTIONS
1373 }
1374 catch (...)
1375 {
1376 this->__set_badbit_and_consider_rethrow();
1377 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001378#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 return __r;
1380}
1381
1382template<class _CharT, class _Traits>
1383typename basic_istream<_CharT, _Traits>::pos_type
1384basic_istream<_CharT, _Traits>::tellg()
1385{
1386 pos_type __r(-1);
1387#ifndef _LIBCPP_NO_EXCEPTIONS
1388 try
1389 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001390#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391 sentry __sen(*this, true);
1392 if (__sen)
1393 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1394#ifndef _LIBCPP_NO_EXCEPTIONS
1395 }
1396 catch (...)
1397 {
1398 this->__set_badbit_and_consider_rethrow();
1399 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001400#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 return __r;
1402}
1403
1404template<class _CharT, class _Traits>
1405basic_istream<_CharT, _Traits>&
1406basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1407{
1408#ifndef _LIBCPP_NO_EXCEPTIONS
1409 try
1410 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001411#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412 sentry __sen(*this, true);
1413 if (__sen)
1414 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1415 this->setstate(ios_base::failbit);
1416#ifndef _LIBCPP_NO_EXCEPTIONS
1417 }
1418 catch (...)
1419 {
1420 this->__set_badbit_and_consider_rethrow();
1421 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 return *this;
1424}
1425
1426template<class _CharT, class _Traits>
1427basic_istream<_CharT, _Traits>&
1428basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1429{
1430#ifndef _LIBCPP_NO_EXCEPTIONS
1431 try
1432 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001433#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434 sentry __sen(*this, true);
1435 if (__sen)
1436 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
1437#ifndef _LIBCPP_NO_EXCEPTIONS
1438 }
1439 catch (...)
1440 {
1441 this->__set_badbit_and_consider_rethrow();
1442 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001443#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 return *this;
1445}
1446
1447template <class _CharT, class _Traits>
1448basic_istream<_CharT, _Traits>&
1449ws(basic_istream<_CharT, _Traits>& __is)
1450{
1451#ifndef _LIBCPP_NO_EXCEPTIONS
1452 try
1453 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001454#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1456 if (__sen)
1457 {
1458 typedef istreambuf_iterator<_CharT, _Traits> _I;
1459 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1460 _I __i(__is);
1461 _I __eof;
1462 for (; __i != __eof; ++__i)
1463 if (!__ct.is(__ct.space, *__i))
1464 break;
1465 if (__i == __eof)
1466 __is.setstate(ios_base::failbit | ios_base::eofbit);
1467 }
1468#ifndef _LIBCPP_NO_EXCEPTIONS
1469 }
1470 catch (...)
1471 {
1472 __is.__set_badbit_and_consider_rethrow();
1473 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001474#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 return __is;
1476}
1477
Howard Hinnant73d21a42010-09-04 23:28:19 +00001478#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479
1480template <class _CharT, class _Traits, class _Tp>
1481inline _LIBCPP_INLINE_VISIBILITY
1482basic_istream<_CharT, _Traits>&
1483operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1484{
1485 __is >> __x;
1486 return __is;
1487}
1488
Howard Hinnant73d21a42010-09-04 23:28:19 +00001489#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490
1491template <class _CharT, class _Traits>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001492class _LIBCPP_VISIBLE basic_iostream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 : public basic_istream<_CharT, _Traits>,
1494 public basic_ostream<_CharT, _Traits>
1495{
1496public:
1497 // types:
1498 typedef _CharT char_type;
1499 typedef _Traits traits_type;
1500 typedef typename traits_type::int_type int_type;
1501 typedef typename traits_type::pos_type pos_type;
1502 typedef typename traits_type::off_type off_type;
1503
1504 // constructor/destructor
1505 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1506 virtual ~basic_iostream();
1507protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001508#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +00001509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001510 basic_iostream(basic_iostream&& __rhs);
1511#endif
1512
1513 // assign/swap
Howard Hinnant73d21a42010-09-04 23:28:19 +00001514#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +00001515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516 basic_iostream& operator=(basic_iostream&& __rhs);
1517#endif
1518 void swap(basic_iostream& __rhs);
1519public:
1520};
1521
1522template <class _CharT, class _Traits>
1523inline _LIBCPP_INLINE_VISIBILITY
1524basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1525 : basic_istream<_CharT, _Traits>(__sb)
1526{
1527}
1528
Howard Hinnant73d21a42010-09-04 23:28:19 +00001529#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530
1531template <class _CharT, class _Traits>
1532inline _LIBCPP_INLINE_VISIBILITY
1533basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001534 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535{
1536}
1537
1538template <class _CharT, class _Traits>
1539inline _LIBCPP_INLINE_VISIBILITY
1540basic_iostream<_CharT, _Traits>&
1541basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1542{
1543 swap(__rhs);
1544 return *this;
1545}
1546
Howard Hinnant73d21a42010-09-04 23:28:19 +00001547#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548
1549template <class _CharT, class _Traits>
1550basic_iostream<_CharT, _Traits>::~basic_iostream()
1551{
1552}
1553
1554template <class _CharT, class _Traits>
1555inline _LIBCPP_INLINE_VISIBILITY
1556void
1557basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1558{
1559 basic_istream<char_type, traits_type>::swap(__rhs);
1560}
1561
1562template<class _CharT, class _Traits, class _Allocator>
1563basic_istream<_CharT, _Traits>&
1564operator>>(basic_istream<_CharT, _Traits>& __is,
1565 basic_string<_CharT, _Traits, _Allocator>& __str)
1566{
1567#ifndef _LIBCPP_NO_EXCEPTIONS
1568 try
1569 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001570#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1572 if (__sen)
1573 {
1574 __str.clear();
1575 typedef istreambuf_iterator<_CharT, _Traits> _I;
1576 streamsize __n = __is.width();
1577 if (__n == 0)
1578 __n = __str.max_size();
1579 if (__n < 0)
1580 __n = numeric_limits<streamsize>::max();
1581 streamsize __c = 0;
1582 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1583 _I __i(__is);
1584 _I __eof;
1585 for (; __i != __eof && __c < __n; ++__i, ++__c)
1586 {
1587 _CharT __ch = *__i;
1588 if (__ct.is(__ct.space, __ch))
1589 break;
1590 __str.push_back(__ch);
1591 }
1592 __is.width(0);
1593 ios_base::iostate __err = ios_base::goodbit;
1594 if (__i == __eof)
1595 __err |= ios_base::eofbit;
1596 if (__c == 0)
1597 __err |= ios_base::failbit;
1598 __is.setstate(__err);
1599 }
1600 else
1601 __is.setstate(ios_base::failbit);
1602#ifndef _LIBCPP_NO_EXCEPTIONS
1603 }
1604 catch (...)
1605 {
1606 __is.__set_badbit_and_consider_rethrow();
1607 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001608#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 return __is;
1610}
1611
1612template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +00001613basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614getline(basic_istream<_CharT, _Traits>& __is,
1615 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1616{
1617#ifndef _LIBCPP_NO_EXCEPTIONS
1618 try
1619 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001620#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1622 if (__sen)
1623 {
1624 __str.clear();
1625 streamsize __c = 0;
1626 typedef istreambuf_iterator<_CharT, _Traits> _I;
1627 _I __i(__is);
1628 _I __eof;
1629 streamsize __n = __str.max_size();
1630 if (__n < 0)
1631 __n = numeric_limits<streamsize>::max();
1632 for (; __i != __eof;)
1633 {
1634 _CharT __ch = *__i;
1635 ++__i;
1636 ++__c;
1637 if (_Traits::eq(__ch, __dlm))
1638 break;
1639 if (__c == __n)
1640 {
1641 __is.setstate(ios_base::failbit);
1642 break;
1643 }
1644 __str.push_back(__ch);
1645 }
1646 ios_base::iostate __err = ios_base::goodbit;
1647 if (__i == __eof)
1648 __err |= ios_base::eofbit;
1649 if (__c == 0)
1650 __err |= ios_base::failbit;
1651 __is.setstate(__err);
1652 }
1653#ifndef _LIBCPP_NO_EXCEPTIONS
1654 }
1655 catch (...)
1656 {
1657 __is.__set_badbit_and_consider_rethrow();
1658 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001659#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660 return __is;
1661}
1662
1663template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001665basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666getline(basic_istream<_CharT, _Traits>& __is,
1667 basic_string<_CharT, _Traits, _Allocator>& __str)
1668{
1669 return getline(__is, __str, __is.widen('\n'));
1670}
1671
Howard Hinnant73d21a42010-09-04 23:28:19 +00001672#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673
1674template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001676basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001677getline(basic_istream<_CharT, _Traits>&& __is,
1678 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1679{
1680 return getline(__is, __str, __dlm);
1681}
1682
1683template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001685basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686getline(basic_istream<_CharT, _Traits>&& __is,
1687 basic_string<_CharT, _Traits, _Allocator>& __str)
1688{
1689 return getline(__is, __str, __is.widen('\n'));
1690}
1691
Howard Hinnant73d21a42010-09-04 23:28:19 +00001692#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001693
1694template <class _CharT, class _Traits, size_t _Size>
1695basic_istream<_CharT, _Traits>&
1696operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1697{
1698#ifndef _LIBCPP_NO_EXCEPTIONS
1699 try
1700 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001701#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1703 if (__sen)
1704 {
1705 basic_string<_CharT, _Traits> __str;
1706 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1707 typedef istreambuf_iterator<_CharT, _Traits> _I;
1708 streamsize __c = 0;
1709 _CharT __zero = __ct.widen('0');
1710 _CharT __one = __ct.widen('1');
1711 _I __i(__is);
1712 _I __eof;
1713 for (; __i != __eof && __c < _Size; ++__i, ++__c)
1714 {
1715 _CharT __ch = *__i;
1716 if (__ch != __zero && __ch != __one)
1717 break;
1718 __str.push_back(__ch);
1719 }
1720 __is.width(0);
1721 __x = bitset<_Size>(__str);
1722 ios_base::iostate __err = ios_base::goodbit;
1723 if (__i == __eof)
1724 __err |= ios_base::eofbit;
1725 if (__c == 0)
1726 __err |= ios_base::failbit;
1727 __is.setstate(__err);
1728 }
1729 else
1730 __is.setstate(ios_base::failbit);
1731#ifndef _LIBCPP_NO_EXCEPTIONS
1732 }
1733 catch (...)
1734 {
1735 __is.__set_badbit_and_consider_rethrow();
1736 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001737#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 return __is;
1739}
1740
1741extern template class basic_istream<char>;
1742extern template class basic_istream<wchar_t>;
1743extern template class basic_iostream<char>;
1744
1745_LIBCPP_END_NAMESPACE_STD
1746
1747#endif // _LIBCPP_ISTREAM