]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/istream
Update OpenSSL to 1.1.1.
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / istream
1 // -*- C++ -*-
2 //===--------------------------- istream ----------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _LIBCPP_ISTREAM
12 #define _LIBCPP_ISTREAM
13
14 /*
15     istream synopsis
16
17 template <class charT, class traits = char_traits<charT> >
18 class basic_istream
19     : virtual public basic_ios<charT,traits>
20 {
21 public:
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 protected:
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);
92 };
93
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&);
97
98 template<class traits>
99   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
100
101 template<class traits>
102   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
103
104 template<class charT, class traits>
105   basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
106
107 template<class traits>
108   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
109
110 template<class traits>
111   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
112
113 template <class charT, class traits>
114   void
115   swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
116
117 typedef basic_istream<char> istream;
118 typedef basic_istream<wchar_t> wistream;
119
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>
124 {
125 public:
126     // types:
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;
132
133     // constructor/destructor
134     explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
135     basic_iostream(basic_iostream&& rhs);
136     virtual ~basic_iostream();
137
138     // assign/swap
139     basic_iostream& operator=(basic_iostream&& rhs);
140     void swap(basic_iostream& rhs);
141 };
142
143 template <class charT, class traits>
144   void
145   swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
146
147 typedef basic_iostream<char> iostream;
148 typedef basic_iostream<wchar_t> wiostream;
149
150 template <class charT, class traits>
151   basic_istream<charT,traits>&
152   ws(basic_istream<charT,traits>& is);
153
154 template <class charT, class traits, class T>
155   basic_istream<charT, traits>&
156   operator>>(basic_istream<charT, traits>&& is, T& x);
157
158 }  // std
159
160 */
161
162 #include <__config>
163 #include <ostream>
164
165 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
166 #pragma GCC system_header
167 #endif
168
169 _LIBCPP_PUSH_MACROS
170 #include <__undef_macros>
171
172
173 _LIBCPP_BEGIN_NAMESPACE_STD
174
175 template <class _CharT, class _Traits>
176 class _LIBCPP_TEMPLATE_VIS basic_istream
177     : virtual public basic_ios<_CharT, _Traits>
178 {
179     streamsize __gc_;
180 public:
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;
187
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();
193 protected:
194 #ifndef _LIBCPP_CXX03_LANG
195     inline _LIBCPP_INLINE_VISIBILITY
196     basic_istream(basic_istream&& __rhs);
197
198     // 27.7.1.1.2 Assign/swap:
199     inline _LIBCPP_INLINE_VISIBILITY
200     basic_istream& operator=(basic_istream&& __rhs);
201 #endif
202
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);
207     }
208
209 #ifndef _LIBCPP_CXX03_LANG
210     basic_istream           (const basic_istream& __rhs) = delete;
211     basic_istream& operator=(const basic_istream& __rhs) = delete;
212 #endif
213 public:
214
215     // 27.7.1.1.3 Prefix/suffix:
216     class _LIBCPP_TEMPLATE_VIS sentry;
217
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); }
222
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; }
227
228     inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
229     basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
230     { __pf(*this); return *this; }
231
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);
246
247     // 27.7.1.3 Unformatted input:
248     _LIBCPP_INLINE_VISIBILITY
249     streamsize gcount() const {return __gc_;}
250     int_type get();
251
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);
257       return *this;
258     }
259
260     inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
261     basic_istream& get(char_type* __s, streamsize __n)
262     { return get(__s, __n, this->widen('\n')); }
263
264     basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
265
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')); }
269
270     basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
271
272     inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
273     basic_istream& getline(char_type* __s, streamsize __n)
274     { return getline(__s, __n, this->widen('\n')); }
275
276     basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
277
278     basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
279     int_type peek();
280     basic_istream& read (char_type* __s, streamsize __n);
281     streamsize readsome(char_type* __s, streamsize __n);
282
283     basic_istream& putback(char_type __c);
284     basic_istream& unget();
285     int sync();
286
287     pos_type tellg();
288     basic_istream& seekg(pos_type __pos);
289     basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
290 };
291
292 template <class _CharT, class _Traits>
293 class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
294 {
295     bool __ok_;
296
297     sentry(const sentry&); // = delete;
298     sentry& operator=(const sentry&); // = delete;
299
300 public:
301     explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
302 //    ~sentry() = default;
303
304     _LIBCPP_INLINE_VISIBILITY
305         _LIBCPP_EXPLICIT
306         operator bool() const {return __ok_;}
307 };
308
309 template <class _CharT, class _Traits>
310 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
311                                                bool __noskipws)
312     : __ok_(false)
313 {
314     if (__is.good())
315     {
316         if (__is.tie())
317             __is.tie()->flush();
318         if (!__noskipws && (__is.flags() & ios_base::skipws))
319         {
320             typedef istreambuf_iterator<_CharT, _Traits> _Ip;
321             const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
322             _Ip __i(__is);
323             _Ip __eof;
324             for (; __i != __eof; ++__i)
325                 if (!__ct.is(__ct.space, *__i))
326                     break;
327             if (__i == __eof)
328                 __is.setstate(ios_base::failbit | ios_base::eofbit);
329         }
330         __ok_ = __is.good();
331     }
332     else
333         __is.setstate(ios_base::failbit);
334 }
335
336 #ifndef _LIBCPP_CXX03_LANG
337
338 template <class _CharT, class _Traits>
339 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
340     : __gc_(__rhs.__gc_)
341 {
342     __rhs.__gc_ = 0;
343     this->move(__rhs);
344 }
345
346 template <class _CharT, class _Traits>
347 basic_istream<_CharT, _Traits>&
348 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
349 {
350     swap(__rhs);
351     return *this;
352 }
353
354 #endif  // _LIBCPP_CXX03_LANG
355
356 template <class _CharT, class _Traits>
357 basic_istream<_CharT, _Traits>::~basic_istream()
358 {
359 }
360
361 template <class _CharT, class _Traits>
362 basic_istream<_CharT, _Traits>&
363 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
364 {
365 #ifndef _LIBCPP_NO_EXCEPTIONS
366     try
367     {
368 #endif  // _LIBCPP_NO_EXCEPTIONS
369         sentry __s(*this);
370         if (__s)
371         {
372             typedef istreambuf_iterator<char_type, traits_type> _Ip;
373             typedef num_get<char_type, _Ip> _Fp;
374             ios_base::iostate __err = ios_base::goodbit;
375             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
376             this->setstate(__err);
377         }
378 #ifndef _LIBCPP_NO_EXCEPTIONS
379     }
380     catch (...)
381     {
382         this->__set_badbit_and_consider_rethrow();
383     }
384 #endif  // _LIBCPP_NO_EXCEPTIONS
385     return *this;
386 }
387
388 template <class _CharT, class _Traits>
389 basic_istream<_CharT, _Traits>&
390 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
391 {
392 #ifndef _LIBCPP_NO_EXCEPTIONS
393     try
394     {
395 #endif  // _LIBCPP_NO_EXCEPTIONS
396         sentry __s(*this);
397         if (__s)
398         {
399             typedef istreambuf_iterator<char_type, traits_type> _Ip;
400             typedef num_get<char_type, _Ip> _Fp;
401             ios_base::iostate __err = ios_base::goodbit;
402             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
403             this->setstate(__err);
404         }
405 #ifndef _LIBCPP_NO_EXCEPTIONS
406     }
407     catch (...)
408     {
409         this->__set_badbit_and_consider_rethrow();
410     }
411 #endif  // _LIBCPP_NO_EXCEPTIONS
412     return *this;
413 }
414
415 template <class _CharT, class _Traits>
416 basic_istream<_CharT, _Traits>&
417 basic_istream<_CharT, _Traits>::operator>>(long& __n)
418 {
419 #ifndef _LIBCPP_NO_EXCEPTIONS
420     try
421     {
422 #endif  // _LIBCPP_NO_EXCEPTIONS
423         sentry __s(*this);
424         if (__s)
425         {
426             typedef istreambuf_iterator<char_type, traits_type> _Ip;
427             typedef num_get<char_type, _Ip> _Fp;
428             ios_base::iostate __err = ios_base::goodbit;
429             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
430             this->setstate(__err);
431         }
432 #ifndef _LIBCPP_NO_EXCEPTIONS
433     }
434     catch (...)
435     {
436         this->__set_badbit_and_consider_rethrow();
437     }
438 #endif  // _LIBCPP_NO_EXCEPTIONS
439     return *this;
440 }
441
442 template <class _CharT, class _Traits>
443 basic_istream<_CharT, _Traits>&
444 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
445 {
446 #ifndef _LIBCPP_NO_EXCEPTIONS
447     try
448     {
449 #endif  // _LIBCPP_NO_EXCEPTIONS
450         sentry __s(*this);
451         if (__s)
452         {
453             typedef istreambuf_iterator<char_type, traits_type> _Ip;
454             typedef num_get<char_type, _Ip> _Fp;
455             ios_base::iostate __err = ios_base::goodbit;
456             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
457             this->setstate(__err);
458         }
459 #ifndef _LIBCPP_NO_EXCEPTIONS
460     }
461     catch (...)
462     {
463         this->__set_badbit_and_consider_rethrow();
464     }
465 #endif  // _LIBCPP_NO_EXCEPTIONS
466     return *this;
467 }
468
469 template <class _CharT, class _Traits>
470 basic_istream<_CharT, _Traits>&
471 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
472 {
473 #ifndef _LIBCPP_NO_EXCEPTIONS
474     try
475     {
476 #endif  // _LIBCPP_NO_EXCEPTIONS
477         sentry __s(*this);
478         if (__s)
479         {
480             typedef istreambuf_iterator<char_type, traits_type> _Ip;
481             typedef num_get<char_type, _Ip> _Fp;
482             ios_base::iostate __err = ios_base::goodbit;
483             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
484             this->setstate(__err);
485         }
486 #ifndef _LIBCPP_NO_EXCEPTIONS
487     }
488     catch (...)
489     {
490         this->__set_badbit_and_consider_rethrow();
491     }
492 #endif  // _LIBCPP_NO_EXCEPTIONS
493     return *this;
494 }
495
496 template <class _CharT, class _Traits>
497 basic_istream<_CharT, _Traits>&
498 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
499 {
500 #ifndef _LIBCPP_NO_EXCEPTIONS
501     try
502     {
503 #endif  // _LIBCPP_NO_EXCEPTIONS
504         sentry __s(*this);
505         if (__s)
506         {
507             typedef istreambuf_iterator<char_type, traits_type> _Ip;
508             typedef num_get<char_type, _Ip> _Fp;
509             ios_base::iostate __err = ios_base::goodbit;
510             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
511             this->setstate(__err);
512         }
513 #ifndef _LIBCPP_NO_EXCEPTIONS
514     }
515     catch (...)
516     {
517         this->__set_badbit_and_consider_rethrow();
518     }
519 #endif  // _LIBCPP_NO_EXCEPTIONS
520     return *this;
521 }
522
523 template <class _CharT, class _Traits>
524 basic_istream<_CharT, _Traits>&
525 basic_istream<_CharT, _Traits>::operator>>(float& __n)
526 {
527 #ifndef _LIBCPP_NO_EXCEPTIONS
528     try
529     {
530 #endif  // _LIBCPP_NO_EXCEPTIONS
531         sentry __s(*this);
532         if (__s)
533         {
534             typedef istreambuf_iterator<char_type, traits_type> _Ip;
535             typedef num_get<char_type, _Ip> _Fp;
536             ios_base::iostate __err = ios_base::goodbit;
537             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
538             this->setstate(__err);
539         }
540 #ifndef _LIBCPP_NO_EXCEPTIONS
541     }
542     catch (...)
543     {
544         this->__set_badbit_and_consider_rethrow();
545     }
546 #endif  // _LIBCPP_NO_EXCEPTIONS
547     return *this;
548 }
549
550 template <class _CharT, class _Traits>
551 basic_istream<_CharT, _Traits>&
552 basic_istream<_CharT, _Traits>::operator>>(double& __n)
553 {
554 #ifndef _LIBCPP_NO_EXCEPTIONS
555     try
556     {
557 #endif  // _LIBCPP_NO_EXCEPTIONS
558         sentry __s(*this);
559         if (__s)
560         {
561             typedef istreambuf_iterator<char_type, traits_type> _Ip;
562             typedef num_get<char_type, _Ip> _Fp;
563             ios_base::iostate __err = ios_base::goodbit;
564             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
565             this->setstate(__err);
566         }
567 #ifndef _LIBCPP_NO_EXCEPTIONS
568     }
569     catch (...)
570     {
571         this->__set_badbit_and_consider_rethrow();
572     }
573 #endif  // _LIBCPP_NO_EXCEPTIONS
574     return *this;
575 }
576
577 template <class _CharT, class _Traits>
578 basic_istream<_CharT, _Traits>&
579 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
580 {
581 #ifndef _LIBCPP_NO_EXCEPTIONS
582     try
583     {
584 #endif  // _LIBCPP_NO_EXCEPTIONS
585         sentry __s(*this);
586         if (__s)
587         {
588             typedef istreambuf_iterator<char_type, traits_type> _Ip;
589             typedef num_get<char_type, _Ip> _Fp;
590             ios_base::iostate __err = ios_base::goodbit;
591             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
592             this->setstate(__err);
593         }
594 #ifndef _LIBCPP_NO_EXCEPTIONS
595     }
596     catch (...)
597     {
598         this->__set_badbit_and_consider_rethrow();
599     }
600 #endif  // _LIBCPP_NO_EXCEPTIONS
601     return *this;
602 }
603
604 template <class _CharT, class _Traits>
605 basic_istream<_CharT, _Traits>&
606 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
607 {
608 #ifndef _LIBCPP_NO_EXCEPTIONS
609     try
610     {
611 #endif  // _LIBCPP_NO_EXCEPTIONS
612         sentry __s(*this);
613         if (__s)
614         {
615             typedef istreambuf_iterator<char_type, traits_type> _Ip;
616             typedef num_get<char_type, _Ip> _Fp;
617             ios_base::iostate __err = ios_base::goodbit;
618             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
619             this->setstate(__err);
620         }
621 #ifndef _LIBCPP_NO_EXCEPTIONS
622     }
623     catch (...)
624     {
625         this->__set_badbit_and_consider_rethrow();
626     }
627 #endif  // _LIBCPP_NO_EXCEPTIONS
628     return *this;
629 }
630
631 template <class _CharT, class _Traits>
632 basic_istream<_CharT, _Traits>&
633 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
634 {
635 #ifndef _LIBCPP_NO_EXCEPTIONS
636     try
637     {
638 #endif  // _LIBCPP_NO_EXCEPTIONS
639         sentry __s(*this);
640         if (__s)
641         {
642             typedef istreambuf_iterator<char_type, traits_type> _Ip;
643             typedef num_get<char_type, _Ip> _Fp;
644             ios_base::iostate __err = ios_base::goodbit;
645             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
646             this->setstate(__err);
647         }
648 #ifndef _LIBCPP_NO_EXCEPTIONS
649     }
650     catch (...)
651     {
652         this->__set_badbit_and_consider_rethrow();
653     }
654 #endif  // _LIBCPP_NO_EXCEPTIONS
655     return *this;
656 }
657
658 template <class _CharT, class _Traits>
659 basic_istream<_CharT, _Traits>&
660 basic_istream<_CharT, _Traits>::operator>>(short& __n)
661 {
662 #ifndef _LIBCPP_NO_EXCEPTIONS
663     try
664     {
665 #endif  // _LIBCPP_NO_EXCEPTIONS
666         sentry __s(*this);
667         if (__s)
668         {
669             typedef istreambuf_iterator<char_type, traits_type> _Ip;
670             typedef num_get<char_type, _Ip> _Fp;
671             ios_base::iostate __err = ios_base::goodbit;
672             long __temp;
673             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
674             if (__temp < numeric_limits<short>::min())
675             {
676                 __err |= ios_base::failbit;
677                 __n = numeric_limits<short>::min();
678             }
679             else if (__temp > numeric_limits<short>::max())
680             {
681                 __err |= ios_base::failbit;
682                 __n = numeric_limits<short>::max();
683             }
684             else
685                 __n = static_cast<short>(__temp);
686             this->setstate(__err);
687         }
688 #ifndef _LIBCPP_NO_EXCEPTIONS
689     }
690     catch (...)
691     {
692         this->__set_badbit_and_consider_rethrow();
693     }
694 #endif  // _LIBCPP_NO_EXCEPTIONS
695     return *this;
696 }
697
698 template <class _CharT, class _Traits>
699 basic_istream<_CharT, _Traits>&
700 basic_istream<_CharT, _Traits>::operator>>(int& __n)
701 {
702 #ifndef _LIBCPP_NO_EXCEPTIONS
703     try
704     {
705 #endif  // _LIBCPP_NO_EXCEPTIONS
706         sentry __s(*this);
707         if (__s)
708         {
709             typedef istreambuf_iterator<char_type, traits_type> _Ip;
710             typedef num_get<char_type, _Ip> _Fp;
711             ios_base::iostate __err = ios_base::goodbit;
712             long __temp;
713             use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
714             if (__temp < numeric_limits<int>::min())
715             {
716                 __err |= ios_base::failbit;
717                 __n = numeric_limits<int>::min();
718             }
719             else if (__temp > numeric_limits<int>::max())
720             {
721                 __err |= ios_base::failbit;
722                 __n = numeric_limits<int>::max();
723             }
724             else
725                 __n = static_cast<int>(__temp);
726             this->setstate(__err);
727         }
728 #ifndef _LIBCPP_NO_EXCEPTIONS
729     }
730     catch (...)
731     {
732         this->__set_badbit_and_consider_rethrow();
733     }
734 #endif  // _LIBCPP_NO_EXCEPTIONS
735     return *this;
736 }
737
738 template<class _CharT, class _Traits>
739 basic_istream<_CharT, _Traits>&
740 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
741 {
742 #ifndef _LIBCPP_NO_EXCEPTIONS
743     try
744     {
745 #endif  // _LIBCPP_NO_EXCEPTIONS
746         typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
747         if (__sen)
748         {
749             streamsize __n = __is.width();
750             if (__n <= 0)
751                 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
752             streamsize __c = 0;
753             const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
754             ios_base::iostate __err = ios_base::goodbit;
755             while (__c < __n-1)
756             {
757                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
758                 if (_Traits::eq_int_type(__i, _Traits::eof()))
759                 {
760                    __err |= ios_base::eofbit;
761                    break;
762                 }
763                 _CharT __ch = _Traits::to_char_type(__i);
764                 if (__ct.is(__ct.space, __ch))
765                     break;
766                 *__s++ = __ch;
767                 ++__c;
768                  __is.rdbuf()->sbumpc();
769             }
770             *__s = _CharT();
771             __is.width(0);
772             if (__c == 0)
773                __err |= ios_base::failbit;
774             __is.setstate(__err);
775         }
776 #ifndef _LIBCPP_NO_EXCEPTIONS
777     }
778     catch (...)
779     {
780         __is.__set_badbit_and_consider_rethrow();
781     }
782 #endif  // _LIBCPP_NO_EXCEPTIONS
783     return __is;
784 }
785
786 template<class _Traits>
787 inline _LIBCPP_INLINE_VISIBILITY
788 basic_istream<char, _Traits>&
789 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
790 {
791     return __is >> (char*)__s;
792 }
793
794 template<class _Traits>
795 inline _LIBCPP_INLINE_VISIBILITY
796 basic_istream<char, _Traits>&
797 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
798 {
799     return __is >> (char*)__s;
800 }
801
802 template<class _CharT, class _Traits>
803 basic_istream<_CharT, _Traits>&
804 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
805 {
806 #ifndef _LIBCPP_NO_EXCEPTIONS
807     try
808     {
809 #endif  // _LIBCPP_NO_EXCEPTIONS
810         typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
811         if (__sen)
812         {
813             typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
814             if (_Traits::eq_int_type(__i, _Traits::eof()))
815                 __is.setstate(ios_base::eofbit | ios_base::failbit);
816             else
817                 __c = _Traits::to_char_type(__i);
818         }
819 #ifndef _LIBCPP_NO_EXCEPTIONS
820     }
821     catch (...)
822     {
823         __is.__set_badbit_and_consider_rethrow();
824     }
825 #endif  // _LIBCPP_NO_EXCEPTIONS
826     return __is;
827 }
828
829 template<class _Traits>
830 inline _LIBCPP_INLINE_VISIBILITY
831 basic_istream<char, _Traits>&
832 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
833 {
834     return __is >> (char&)__c;
835 }
836
837 template<class _Traits>
838 inline _LIBCPP_INLINE_VISIBILITY
839 basic_istream<char, _Traits>&
840 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
841 {
842     return __is >> (char&)__c;
843 }
844
845 template<class _CharT, class _Traits>
846 basic_istream<_CharT, _Traits>&
847 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
848 {
849     __gc_ = 0;
850 #ifndef _LIBCPP_NO_EXCEPTIONS
851     try
852     {
853 #endif  // _LIBCPP_NO_EXCEPTIONS
854         sentry __s(*this, true);
855         if (__s)
856         {
857             if (__sb)
858             {
859 #ifndef _LIBCPP_NO_EXCEPTIONS
860                 try
861                 {
862 #endif  // _LIBCPP_NO_EXCEPTIONS
863                     ios_base::iostate __err = ios_base::goodbit;
864                     while (true)
865                     {
866                         typename traits_type::int_type __i = this->rdbuf()->sgetc();
867                         if (traits_type::eq_int_type(__i, _Traits::eof()))
868                         {
869                            __err |= ios_base::eofbit;
870                            break;
871                         }
872                         if (traits_type::eq_int_type(
873                                 __sb->sputc(traits_type::to_char_type(__i)),
874                                 traits_type::eof()))
875                             break;
876                         ++__gc_;
877                         this->rdbuf()->sbumpc();
878                     }
879                     if (__gc_ == 0)
880                        __err |= ios_base::failbit;
881                     this->setstate(__err);
882 #ifndef _LIBCPP_NO_EXCEPTIONS
883                 }
884                 catch (...)
885                 {
886                     if (__gc_ == 0)
887                         this->__set_failbit_and_consider_rethrow();
888                 }
889 #endif  // _LIBCPP_NO_EXCEPTIONS
890             }
891             else
892                 this->setstate(ios_base::failbit);
893         }
894 #ifndef _LIBCPP_NO_EXCEPTIONS
895     }
896     catch (...)
897     {
898         this->__set_badbit_and_consider_rethrow();
899     }
900 #endif  // _LIBCPP_NO_EXCEPTIONS
901     return *this;
902 }
903
904 template<class _CharT, class _Traits>
905 typename basic_istream<_CharT, _Traits>::int_type
906 basic_istream<_CharT, _Traits>::get()
907 {
908     __gc_ = 0;
909     int_type __r = traits_type::eof();
910 #ifndef _LIBCPP_NO_EXCEPTIONS
911     try
912     {
913 #endif  // _LIBCPP_NO_EXCEPTIONS
914         sentry __s(*this, true);
915         if (__s)
916         {
917             __r = this->rdbuf()->sbumpc();
918             if (traits_type::eq_int_type(__r, traits_type::eof()))
919                this->setstate(ios_base::failbit | ios_base::eofbit);
920             else
921                 __gc_ = 1;
922         }
923 #ifndef _LIBCPP_NO_EXCEPTIONS
924     }
925     catch (...)
926     {
927         this->__set_badbit_and_consider_rethrow();
928     }
929 #endif  // _LIBCPP_NO_EXCEPTIONS
930     return __r;
931 }
932
933 template<class _CharT, class _Traits>
934 basic_istream<_CharT, _Traits>&
935 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
936 {
937     __gc_ = 0;
938 #ifndef _LIBCPP_NO_EXCEPTIONS
939     try
940     {
941 #endif  // _LIBCPP_NO_EXCEPTIONS
942         sentry __sen(*this, true);
943         if (__sen)
944         {
945             if (__n > 0)
946             {
947                 ios_base::iostate __err = ios_base::goodbit;
948                 while (__gc_ < __n-1)
949                 {
950                     int_type __i = this->rdbuf()->sgetc();
951                     if (traits_type::eq_int_type(__i, traits_type::eof()))
952                     {
953                        __err |= ios_base::eofbit;
954                        break;
955                     }
956                     char_type __ch = traits_type::to_char_type(__i);
957                     if (traits_type::eq(__ch, __dlm))
958                         break;
959                     *__s++ = __ch;
960                     ++__gc_;
961                      this->rdbuf()->sbumpc();
962                 }
963                 *__s = char_type();
964                 if (__gc_ == 0)
965                    __err |= ios_base::failbit;
966                 this->setstate(__err);
967             }
968             else
969                 this->setstate(ios_base::failbit);
970         }
971 #ifndef _LIBCPP_NO_EXCEPTIONS
972     }
973     catch (...)
974     {
975         this->__set_badbit_and_consider_rethrow();
976     }
977 #endif  // _LIBCPP_NO_EXCEPTIONS
978     return *this;
979 }
980
981 template<class _CharT, class _Traits>
982 basic_istream<_CharT, _Traits>&
983 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
984                                     char_type __dlm)
985 {
986     __gc_ = 0;
987 #ifndef _LIBCPP_NO_EXCEPTIONS
988     try
989     {
990 #endif  // _LIBCPP_NO_EXCEPTIONS
991         sentry __sen(*this, true);
992         if (__sen)
993         {
994             ios_base::iostate __err = ios_base::goodbit;
995 #ifndef _LIBCPP_NO_EXCEPTIONS
996             try
997             {
998 #endif  // _LIBCPP_NO_EXCEPTIONS
999                 while (true)
1000                 {
1001                     typename traits_type::int_type __i = this->rdbuf()->sgetc();
1002                     if (traits_type::eq_int_type(__i, traits_type::eof()))
1003                     {
1004                        __err |= ios_base::eofbit;
1005                        break;
1006                     }
1007                     char_type __ch = traits_type::to_char_type(__i);
1008                     if (traits_type::eq(__ch, __dlm))
1009                         break;
1010                     if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
1011                         break;
1012                     ++__gc_;
1013                     this->rdbuf()->sbumpc();
1014                 }
1015 #ifndef _LIBCPP_NO_EXCEPTIONS
1016             }
1017             catch (...)
1018             {
1019             }
1020 #endif  // _LIBCPP_NO_EXCEPTIONS
1021             if (__gc_ == 0)
1022                __err |= ios_base::failbit;
1023             this->setstate(__err);
1024         }
1025 #ifndef _LIBCPP_NO_EXCEPTIONS
1026     }
1027     catch (...)
1028     {
1029         this->__set_badbit_and_consider_rethrow();
1030     }
1031 #endif  // _LIBCPP_NO_EXCEPTIONS
1032     return *this;
1033 }
1034
1035 template<class _CharT, class _Traits>
1036 basic_istream<_CharT, _Traits>&
1037 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1038 {
1039     __gc_ = 0;
1040 #ifndef _LIBCPP_NO_EXCEPTIONS
1041     try
1042     {
1043 #endif  // _LIBCPP_NO_EXCEPTIONS
1044         sentry __sen(*this, true);
1045         if (__sen)
1046         {
1047             ios_base::iostate __err = ios_base::goodbit;
1048             while (true)
1049             {
1050                 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1051                 if (traits_type::eq_int_type(__i, traits_type::eof()))
1052                 {
1053                    __err |= ios_base::eofbit;
1054                    break;
1055                 }
1056                 char_type __ch = traits_type::to_char_type(__i);
1057                 if (traits_type::eq(__ch, __dlm))
1058                 {
1059                     this->rdbuf()->sbumpc();
1060                     ++__gc_;
1061                     break;
1062                 }
1063                 if (__gc_ >= __n-1)
1064                 {
1065                     __err |= ios_base::failbit;
1066                     break;
1067                 }
1068                 *__s++ = __ch;
1069                 this->rdbuf()->sbumpc();
1070                 ++__gc_;
1071             }
1072             if (__gc_ == 0)
1073                __err |= ios_base::failbit;
1074             this->setstate(__err);
1075         }
1076         if (__n > 0)
1077             *__s = char_type();
1078 #ifndef _LIBCPP_NO_EXCEPTIONS
1079     }
1080     catch (...)
1081     {
1082         if (__n > 0)
1083             *__s = char_type();
1084         this->__set_badbit_and_consider_rethrow();
1085     }
1086 #endif  // _LIBCPP_NO_EXCEPTIONS
1087     return *this;
1088 }
1089
1090 template<class _CharT, class _Traits>
1091 basic_istream<_CharT, _Traits>&
1092 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1093 {
1094     __gc_ = 0;
1095 #ifndef _LIBCPP_NO_EXCEPTIONS
1096     try
1097     {
1098 #endif  // _LIBCPP_NO_EXCEPTIONS
1099         sentry __sen(*this, true);
1100         if (__sen)
1101         {
1102             ios_base::iostate __err = ios_base::goodbit;
1103             if (__n == numeric_limits<streamsize>::max())
1104             {
1105                 while (true)
1106                 {
1107                     typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1108                     if (traits_type::eq_int_type(__i, traits_type::eof()))
1109                     {
1110                        __err |= ios_base::eofbit;
1111                        break;
1112                     }
1113                     ++__gc_;
1114                     if (traits_type::eq_int_type(__i, __dlm))
1115                         break;
1116                 }
1117             }
1118             else
1119             {
1120                 while (__gc_ < __n)
1121                 {
1122                     typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1123                     if (traits_type::eq_int_type(__i, traits_type::eof()))
1124                     {
1125                        __err |= ios_base::eofbit;
1126                        break;
1127                     }
1128                     ++__gc_;
1129                     if (traits_type::eq_int_type(__i, __dlm))
1130                         break;
1131                 }
1132             }
1133             this->setstate(__err);
1134         }
1135 #ifndef _LIBCPP_NO_EXCEPTIONS
1136     }
1137     catch (...)
1138     {
1139         this->__set_badbit_and_consider_rethrow();
1140     }
1141 #endif  // _LIBCPP_NO_EXCEPTIONS
1142     return *this;
1143 }
1144
1145 template<class _CharT, class _Traits>
1146 typename basic_istream<_CharT, _Traits>::int_type
1147 basic_istream<_CharT, _Traits>::peek()
1148 {
1149     __gc_ = 0;
1150     int_type __r = traits_type::eof();
1151 #ifndef _LIBCPP_NO_EXCEPTIONS
1152     try
1153     {
1154 #endif  // _LIBCPP_NO_EXCEPTIONS
1155         sentry __sen(*this, true);
1156         if (__sen)
1157         {
1158             __r = this->rdbuf()->sgetc();
1159             if (traits_type::eq_int_type(__r, traits_type::eof()))
1160                 this->setstate(ios_base::eofbit);
1161         }
1162 #ifndef _LIBCPP_NO_EXCEPTIONS
1163     }
1164     catch (...)
1165     {
1166         this->__set_badbit_and_consider_rethrow();
1167     }
1168 #endif  // _LIBCPP_NO_EXCEPTIONS
1169     return __r;
1170 }
1171
1172 template<class _CharT, class _Traits>
1173 basic_istream<_CharT, _Traits>&
1174 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1175 {
1176     __gc_ = 0;
1177 #ifndef _LIBCPP_NO_EXCEPTIONS
1178     try
1179     {
1180 #endif  // _LIBCPP_NO_EXCEPTIONS
1181         sentry __sen(*this, true);
1182         if (__sen)
1183         {
1184             __gc_ = this->rdbuf()->sgetn(__s, __n);
1185             if (__gc_ != __n)
1186                 this->setstate(ios_base::failbit | ios_base::eofbit);
1187         }
1188         else
1189             this->setstate(ios_base::failbit);
1190 #ifndef _LIBCPP_NO_EXCEPTIONS
1191     }
1192     catch (...)
1193     {
1194         this->__set_badbit_and_consider_rethrow();
1195     }
1196 #endif  // _LIBCPP_NO_EXCEPTIONS
1197     return *this;
1198 }
1199
1200 template<class _CharT, class _Traits>
1201 streamsize
1202 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1203 {
1204     __gc_ = 0;
1205 #ifndef _LIBCPP_NO_EXCEPTIONS
1206     try
1207     {
1208 #endif  // _LIBCPP_NO_EXCEPTIONS
1209         sentry __sen(*this, true);
1210         if (__sen)
1211         {
1212             streamsize __c = this->rdbuf()->in_avail();
1213             switch (__c)
1214             {
1215             case -1:
1216                 this->setstate(ios_base::eofbit);
1217                 break;
1218             case 0:
1219                 break;
1220             default:
1221                 read(__s, _VSTD::min(__c, __n));
1222                 break;
1223             }
1224         }
1225         else
1226             this->setstate(ios_base::failbit);
1227 #ifndef _LIBCPP_NO_EXCEPTIONS
1228     }
1229     catch (...)
1230     {
1231         this->__set_badbit_and_consider_rethrow();
1232     }
1233 #endif  // _LIBCPP_NO_EXCEPTIONS
1234     return __gc_;
1235 }
1236
1237 template<class _CharT, class _Traits>
1238 basic_istream<_CharT, _Traits>&
1239 basic_istream<_CharT, _Traits>::putback(char_type __c)
1240 {
1241     __gc_ = 0;
1242 #ifndef _LIBCPP_NO_EXCEPTIONS
1243     try
1244     {
1245 #endif  // _LIBCPP_NO_EXCEPTIONS
1246         this->clear(this->rdstate() & ~ios_base::eofbit);
1247         sentry __sen(*this, true);
1248         if (__sen)
1249         {
1250             if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1251                 this->setstate(ios_base::badbit);
1252         }
1253         else
1254             this->setstate(ios_base::failbit);
1255 #ifndef _LIBCPP_NO_EXCEPTIONS
1256     }
1257     catch (...)
1258     {
1259         this->__set_badbit_and_consider_rethrow();
1260     }
1261 #endif  // _LIBCPP_NO_EXCEPTIONS
1262     return *this;
1263 }
1264
1265 template<class _CharT, class _Traits>
1266 basic_istream<_CharT, _Traits>&
1267 basic_istream<_CharT, _Traits>::unget()
1268 {
1269     __gc_ = 0;
1270 #ifndef _LIBCPP_NO_EXCEPTIONS
1271     try
1272     {
1273 #endif  // _LIBCPP_NO_EXCEPTIONS
1274         this->clear(this->rdstate() & ~ios_base::eofbit);
1275         sentry __sen(*this, true);
1276         if (__sen)
1277         {
1278             if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1279                 this->setstate(ios_base::badbit);
1280         }
1281         else
1282             this->setstate(ios_base::failbit);
1283 #ifndef _LIBCPP_NO_EXCEPTIONS
1284     }
1285     catch (...)
1286     {
1287         this->__set_badbit_and_consider_rethrow();
1288     }
1289 #endif  // _LIBCPP_NO_EXCEPTIONS
1290     return *this;
1291 }
1292
1293 template<class _CharT, class _Traits>
1294 int
1295 basic_istream<_CharT, _Traits>::sync()
1296 {
1297     int __r = 0;
1298 #ifndef _LIBCPP_NO_EXCEPTIONS
1299     try
1300     {
1301 #endif  // _LIBCPP_NO_EXCEPTIONS
1302         sentry __sen(*this, true);
1303         if (__sen)
1304         {
1305             if (this->rdbuf() == 0)
1306                 return -1;
1307             if (this->rdbuf()->pubsync() == -1)
1308             {
1309                 this->setstate(ios_base::badbit);
1310                 return -1;
1311             }
1312         }
1313 #ifndef _LIBCPP_NO_EXCEPTIONS
1314     }
1315     catch (...)
1316     {
1317         this->__set_badbit_and_consider_rethrow();
1318     }
1319 #endif  // _LIBCPP_NO_EXCEPTIONS
1320     return __r;
1321 }
1322
1323 template<class _CharT, class _Traits>
1324 typename basic_istream<_CharT, _Traits>::pos_type
1325 basic_istream<_CharT, _Traits>::tellg()
1326 {
1327     pos_type __r(-1);
1328 #ifndef _LIBCPP_NO_EXCEPTIONS
1329     try
1330     {
1331 #endif  // _LIBCPP_NO_EXCEPTIONS
1332         sentry __sen(*this, true);
1333         if (__sen)
1334             __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1335 #ifndef _LIBCPP_NO_EXCEPTIONS
1336     }
1337     catch (...)
1338     {
1339         this->__set_badbit_and_consider_rethrow();
1340     }
1341 #endif  // _LIBCPP_NO_EXCEPTIONS
1342     return __r;
1343 }
1344
1345 template<class _CharT, class _Traits>
1346 basic_istream<_CharT, _Traits>&
1347 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1348 {
1349 #ifndef _LIBCPP_NO_EXCEPTIONS
1350     try
1351     {
1352 #endif  // _LIBCPP_NO_EXCEPTIONS
1353         this->clear(this->rdstate() & ~ios_base::eofbit);
1354         sentry __sen(*this, true);
1355         if (__sen)
1356         {
1357             if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1358                 this->setstate(ios_base::failbit);
1359         }
1360 #ifndef _LIBCPP_NO_EXCEPTIONS
1361     }
1362     catch (...)
1363     {
1364         this->__set_badbit_and_consider_rethrow();
1365     }
1366 #endif  // _LIBCPP_NO_EXCEPTIONS
1367     return *this;
1368 }
1369
1370 template<class _CharT, class _Traits>
1371 basic_istream<_CharT, _Traits>&
1372 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1373 {
1374 #ifndef _LIBCPP_NO_EXCEPTIONS
1375     try
1376     {
1377 #endif  // _LIBCPP_NO_EXCEPTIONS
1378         this->clear(this->rdstate() & ~ios_base::eofbit);
1379         sentry __sen(*this, true);
1380         if (__sen)
1381         {
1382             if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1383                 this->setstate(ios_base::failbit);
1384         }
1385 #ifndef _LIBCPP_NO_EXCEPTIONS
1386     }
1387     catch (...)
1388     {
1389         this->__set_badbit_and_consider_rethrow();
1390     }
1391 #endif  // _LIBCPP_NO_EXCEPTIONS
1392     return *this;
1393 }
1394
1395 template <class _CharT, class _Traits>
1396 basic_istream<_CharT, _Traits>&
1397 ws(basic_istream<_CharT, _Traits>& __is)
1398 {
1399 #ifndef _LIBCPP_NO_EXCEPTIONS
1400     try
1401     {
1402 #endif  // _LIBCPP_NO_EXCEPTIONS
1403         typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1404         if (__sen)
1405         {
1406             const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1407             while (true)
1408             {
1409                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1410                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1411                 {
1412                    __is.setstate(ios_base::eofbit);
1413                    break;
1414                 }
1415                 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1416                     break;
1417                 __is.rdbuf()->sbumpc();
1418             }
1419         }
1420 #ifndef _LIBCPP_NO_EXCEPTIONS
1421     }
1422     catch (...)
1423     {
1424         __is.__set_badbit_and_consider_rethrow();
1425     }
1426 #endif  // _LIBCPP_NO_EXCEPTIONS
1427     return __is;
1428 }
1429
1430 #ifndef _LIBCPP_CXX03_LANG
1431
1432 template <class _CharT, class _Traits, class _Tp>
1433 inline _LIBCPP_INLINE_VISIBILITY
1434 basic_istream<_CharT, _Traits>&
1435 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
1436 {
1437     __is >> _VSTD::forward<_Tp>(__x);
1438     return __is;
1439 }
1440
1441 #endif  // _LIBCPP_CXX03_LANG
1442
1443 template <class _CharT, class _Traits>
1444 class _LIBCPP_TEMPLATE_VIS basic_iostream
1445     : public basic_istream<_CharT, _Traits>,
1446       public basic_ostream<_CharT, _Traits>
1447 {
1448 public:
1449     // types:
1450     typedef _CharT                         char_type;
1451     typedef _Traits                        traits_type;
1452     typedef typename traits_type::int_type int_type;
1453     typedef typename traits_type::pos_type pos_type;
1454     typedef typename traits_type::off_type off_type;
1455
1456     // constructor/destructor
1457     inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1458     explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1459       : basic_istream<_CharT, _Traits>(__sb)
1460     {}
1461
1462     virtual ~basic_iostream();
1463 protected:
1464 #ifndef _LIBCPP_CXX03_LANG
1465     inline _LIBCPP_INLINE_VISIBILITY
1466     basic_iostream(basic_iostream&& __rhs);
1467
1468     // assign/swap
1469     inline _LIBCPP_INLINE_VISIBILITY
1470     basic_iostream& operator=(basic_iostream&& __rhs);
1471 #endif
1472     inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1473     void swap(basic_iostream& __rhs)
1474     { basic_istream<char_type, traits_type>::swap(__rhs); }
1475 public:
1476 };
1477
1478 #ifndef _LIBCPP_CXX03_LANG
1479
1480 template <class _CharT, class _Traits>
1481 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1482     : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1483 {
1484 }
1485
1486 template <class _CharT, class _Traits>
1487 basic_iostream<_CharT, _Traits>&
1488 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1489 {
1490     swap(__rhs);
1491     return *this;
1492 }
1493
1494 #endif  // _LIBCPP_CXX03_LANG
1495
1496 template <class _CharT, class _Traits>
1497 basic_iostream<_CharT, _Traits>::~basic_iostream()
1498 {
1499 }
1500
1501 template<class _CharT, class _Traits, class _Allocator>
1502 basic_istream<_CharT, _Traits>&
1503 operator>>(basic_istream<_CharT, _Traits>& __is,
1504            basic_string<_CharT, _Traits, _Allocator>& __str)
1505 {
1506 #ifndef _LIBCPP_NO_EXCEPTIONS
1507     try
1508     {
1509 #endif  // _LIBCPP_NO_EXCEPTIONS
1510         typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1511         if (__sen)
1512         {
1513             __str.clear();
1514             streamsize __n = __is.width();
1515             if (__n <= 0)
1516                 __n = __str.max_size();
1517             if (__n <= 0)
1518                 __n = numeric_limits<streamsize>::max();
1519             streamsize __c = 0;
1520             const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1521             ios_base::iostate __err = ios_base::goodbit;
1522             while (__c < __n)
1523             {
1524                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1525                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1526                 {
1527                    __err |= ios_base::eofbit;
1528                    break;
1529                 }
1530                 _CharT __ch = _Traits::to_char_type(__i);
1531                 if (__ct.is(__ct.space, __ch))
1532                     break;
1533                 __str.push_back(__ch);
1534                 ++__c;
1535                  __is.rdbuf()->sbumpc();
1536             }
1537             __is.width(0);
1538             if (__c == 0)
1539                __err |= ios_base::failbit;
1540             __is.setstate(__err);
1541         }
1542         else
1543             __is.setstate(ios_base::failbit);
1544 #ifndef _LIBCPP_NO_EXCEPTIONS
1545     }
1546     catch (...)
1547     {
1548         __is.__set_badbit_and_consider_rethrow();
1549     }
1550 #endif  // _LIBCPP_NO_EXCEPTIONS
1551     return __is;
1552 }
1553
1554 template<class _CharT, class _Traits, class _Allocator>
1555 basic_istream<_CharT, _Traits>&
1556 getline(basic_istream<_CharT, _Traits>& __is,
1557         basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1558 {
1559 #ifndef _LIBCPP_NO_EXCEPTIONS
1560     try
1561     {
1562 #endif  // _LIBCPP_NO_EXCEPTIONS
1563         typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1564         if (__sen)
1565         {
1566             __str.clear();
1567             ios_base::iostate __err = ios_base::goodbit;
1568             streamsize __extr = 0;
1569             while (true)
1570             {
1571                 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1572                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1573                 {
1574                    __err |= ios_base::eofbit;
1575                    break;
1576                 }
1577                 ++__extr;
1578                 _CharT __ch = _Traits::to_char_type(__i);
1579                 if (_Traits::eq(__ch, __dlm))
1580                     break;
1581                 __str.push_back(__ch);
1582                 if (__str.size() == __str.max_size())
1583                 {
1584                     __err |= ios_base::failbit;
1585                     break;
1586                 }
1587             }
1588             if (__extr == 0)
1589                __err |= ios_base::failbit;
1590             __is.setstate(__err);
1591         }
1592 #ifndef _LIBCPP_NO_EXCEPTIONS
1593     }
1594     catch (...)
1595     {
1596         __is.__set_badbit_and_consider_rethrow();
1597     }
1598 #endif  // _LIBCPP_NO_EXCEPTIONS
1599     return __is;
1600 }
1601
1602 template<class _CharT, class _Traits, class _Allocator>
1603 inline _LIBCPP_INLINE_VISIBILITY
1604 basic_istream<_CharT, _Traits>&
1605 getline(basic_istream<_CharT, _Traits>& __is,
1606         basic_string<_CharT, _Traits, _Allocator>& __str)
1607 {
1608     return getline(__is, __str, __is.widen('\n'));
1609 }
1610
1611 #ifndef _LIBCPP_CXX03_LANG
1612
1613 template<class _CharT, class _Traits, class _Allocator>
1614 inline _LIBCPP_INLINE_VISIBILITY
1615 basic_istream<_CharT, _Traits>&
1616 getline(basic_istream<_CharT, _Traits>&& __is,
1617         basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1618 {
1619     return getline(__is, __str, __dlm);
1620 }
1621
1622 template<class _CharT, class _Traits, class _Allocator>
1623 inline _LIBCPP_INLINE_VISIBILITY
1624 basic_istream<_CharT, _Traits>&
1625 getline(basic_istream<_CharT, _Traits>&& __is,
1626         basic_string<_CharT, _Traits, _Allocator>& __str)
1627 {
1628     return getline(__is, __str, __is.widen('\n'));
1629 }
1630
1631 #endif  // _LIBCPP_CXX03_LANG
1632
1633 template <class _CharT, class _Traits, size_t _Size>
1634 basic_istream<_CharT, _Traits>&
1635 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1636 {
1637 #ifndef _LIBCPP_NO_EXCEPTIONS
1638     try
1639     {
1640 #endif  // _LIBCPP_NO_EXCEPTIONS
1641         typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1642         if (__sen)
1643         {
1644             basic_string<_CharT, _Traits> __str;
1645             const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1646             size_t __c = 0;
1647             ios_base::iostate __err = ios_base::goodbit;
1648             _CharT __zero = __ct.widen('0');
1649             _CharT __one = __ct.widen('1');
1650             while (__c < _Size)
1651             {
1652                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1653                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1654                 {
1655                    __err |= ios_base::eofbit;
1656                    break;
1657                 }
1658                 _CharT __ch = _Traits::to_char_type(__i);
1659                 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1660                     break;
1661                 __str.push_back(__ch);
1662                 ++__c;
1663                  __is.rdbuf()->sbumpc();
1664             }
1665             __x = bitset<_Size>(__str);
1666             if (__c == 0)
1667                __err |= ios_base::failbit;
1668             __is.setstate(__err);
1669         }
1670         else
1671             __is.setstate(ios_base::failbit);
1672 #ifndef _LIBCPP_NO_EXCEPTIONS
1673     }
1674     catch (...)
1675     {
1676         __is.__set_badbit_and_consider_rethrow();
1677     }
1678 #endif  // _LIBCPP_NO_EXCEPTIONS
1679     return __is;
1680 }
1681
1682 #ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
1683 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1684 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1685 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
1686 #endif
1687
1688 _LIBCPP_END_NAMESPACE_STD
1689
1690 _LIBCPP_POP_MACROS
1691
1692 #endif  // _LIBCPP_ISTREAM