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