xref: /freebsd-12.1/contrib/libc++/include/istream (revision c19c7afe)
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
17template <class charT, class traits = char_traits<charT> >
18class basic_istream
19    : virtual public basic_ios<charT,traits>
20{
21public:
22    // types (inherited from basic_ios (27.5.4)):
23    typedef charT                          char_type;
24    typedef traits                         traits_type;
25    typedef typename traits_type::int_type int_type;
26    typedef typename traits_type::pos_type pos_type;
27    typedef typename traits_type::off_type off_type;
28
29    // 27.7.1.1.1 Constructor/destructor:
30    explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
31    basic_istream(basic_istream&& rhs);
32    virtual ~basic_istream();
33
34    // 27.7.1.1.2 Assign/swap:
35    basic_istream& operator=(basic_istream&& rhs);
36    void swap(basic_istream& rhs);
37
38    // 27.7.1.1.3 Prefix/suffix:
39    class sentry;
40
41    // 27.7.1.2 Formatted input:
42    basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
43    basic_istream& operator>>(basic_ios<char_type, traits_type>&
44                              (*pf)(basic_ios<char_type, traits_type>&));
45    basic_istream& operator>>(ios_base& (*pf)(ios_base&));
46    basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
47    basic_istream& operator>>(bool& n);
48    basic_istream& operator>>(short& n);
49    basic_istream& operator>>(unsigned short& n);
50    basic_istream& operator>>(int& n);
51    basic_istream& operator>>(unsigned int& n);
52    basic_istream& operator>>(long& n);
53    basic_istream& operator>>(unsigned long& n);
54    basic_istream& operator>>(long long& n);
55    basic_istream& operator>>(unsigned long long& n);
56    basic_istream& operator>>(float& f);
57    basic_istream& operator>>(double& f);
58    basic_istream& operator>>(long double& f);
59    basic_istream& operator>>(void*& p);
60
61    // 27.7.1.3 Unformatted input:
62    streamsize gcount() const;
63    int_type get();
64    basic_istream& get(char_type& c);
65    basic_istream& get(char_type* s, streamsize n);
66    basic_istream& get(char_type* s, streamsize n, char_type delim);
67    basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
68    basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
69
70    basic_istream& getline(char_type* s, streamsize n);
71    basic_istream& getline(char_type* s, streamsize n, char_type delim);
72
73    basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
74    int_type peek();
75    basic_istream& read (char_type* s, streamsize n);
76    streamsize readsome(char_type* s, streamsize n);
77
78    basic_istream& putback(char_type c);
79    basic_istream& unget();
80    int sync();
81
82    pos_type tellg();
83    basic_istream& seekg(pos_type);
84    basic_istream& seekg(off_type, ios_base::seekdir);
85protected:
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:
95template<class charT, class traits>
96  basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
97
98template<class traits>
99  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
100
101template<class traits>
102  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
103
104template<class charT, class traits>
105  basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
106
107template<class traits>
108  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
109
110template<class traits>
111  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
112
113template <class charT, class traits>
114  void
115  swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
116
117typedef basic_istream<char> istream;
118typedef basic_istream<wchar_t> wistream;
119
120template <class charT, class traits = char_traits<charT> >
121class basic_iostream :
122    public basic_istream<charT,traits>,
123    public basic_ostream<charT,traits>
124{
125public:
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
143template <class charT, class traits>
144  void
145  swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
146
147typedef basic_iostream<char> iostream;
148typedef basic_iostream<wchar_t> wiostream;
149
150template <class charT, class traits>
151  basic_istream<charT,traits>&
152  ws(basic_istream<charT,traits>& is);
153
154template <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
175template <class _CharT, class _Traits>
176class _LIBCPP_TEMPLATE_VIS basic_istream
177    : virtual public basic_ios<_CharT, _Traits>
178{
179    streamsize __gc_;
180public:
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();
193protected:
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
213public:
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
292template <class _CharT, class _Traits>
293class _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
300public:
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
309template <class _CharT, class _Traits>
310basic_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
338template <class _CharT, class _Traits>
339basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
340    : __gc_(__rhs.__gc_)
341{
342    __rhs.__gc_ = 0;
343    this->move(__rhs);
344}
345
346template <class _CharT, class _Traits>
347basic_istream<_CharT, _Traits>&
348basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
349{
350    swap(__rhs);
351    return *this;
352}
353
354#endif  // _LIBCPP_CXX03_LANG
355
356template <class _CharT, class _Traits>
357basic_istream<_CharT, _Traits>::~basic_istream()
358{
359}
360
361template <class _CharT, class _Traits>
362basic_istream<_CharT, _Traits>&
363basic_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
388template <class _CharT, class _Traits>
389basic_istream<_CharT, _Traits>&
390basic_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
415template <class _CharT, class _Traits>
416basic_istream<_CharT, _Traits>&
417basic_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
442template <class _CharT, class _Traits>
443basic_istream<_CharT, _Traits>&
444basic_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
469template <class _CharT, class _Traits>
470basic_istream<_CharT, _Traits>&
471basic_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
496template <class _CharT, class _Traits>
497basic_istream<_CharT, _Traits>&
498basic_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
523template <class _CharT, class _Traits>
524basic_istream<_CharT, _Traits>&
525basic_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
550template <class _CharT, class _Traits>
551basic_istream<_CharT, _Traits>&
552basic_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
577template <class _CharT, class _Traits>
578basic_istream<_CharT, _Traits>&
579basic_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
604template <class _CharT, class _Traits>
605basic_istream<_CharT, _Traits>&
606basic_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
631template <class _CharT, class _Traits>
632basic_istream<_CharT, _Traits>&
633basic_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
658template <class _CharT, class _Traits>
659basic_istream<_CharT, _Traits>&
660basic_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
698template <class _CharT, class _Traits>
699basic_istream<_CharT, _Traits>&
700basic_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
738template<class _CharT, class _Traits>
739basic_istream<_CharT, _Traits>&
740operator>>(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
786template<class _Traits>
787inline _LIBCPP_INLINE_VISIBILITY
788basic_istream<char, _Traits>&
789operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
790{
791    return __is >> (char*)__s;
792}
793
794template<class _Traits>
795inline _LIBCPP_INLINE_VISIBILITY
796basic_istream<char, _Traits>&
797operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
798{
799    return __is >> (char*)__s;
800}
801
802template<class _CharT, class _Traits>
803basic_istream<_CharT, _Traits>&
804operator>>(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
829template<class _Traits>
830inline _LIBCPP_INLINE_VISIBILITY
831basic_istream<char, _Traits>&
832operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
833{
834    return __is >> (char&)__c;
835}
836
837template<class _Traits>
838inline _LIBCPP_INLINE_VISIBILITY
839basic_istream<char, _Traits>&
840operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
841{
842    return __is >> (char&)__c;
843}
844
845template<class _CharT, class _Traits>
846basic_istream<_CharT, _Traits>&
847basic_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
904template<class _CharT, class _Traits>
905typename basic_istream<_CharT, _Traits>::int_type
906basic_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
933template<class _CharT, class _Traits>
934basic_istream<_CharT, _Traits>&
935basic_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
981template<class _CharT, class _Traits>
982basic_istream<_CharT, _Traits>&
983basic_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
1035template<class _CharT, class _Traits>
1036basic_istream<_CharT, _Traits>&
1037basic_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 (__n > 0)
1073                *__s = char_type();
1074            if (__gc_ == 0)
1075               __err |= ios_base::failbit;
1076            this->setstate(__err);
1077        }
1078#ifndef _LIBCPP_NO_EXCEPTIONS
1079    }
1080    catch (...)
1081    {
1082        this->__set_badbit_and_consider_rethrow();
1083    }
1084#endif  // _LIBCPP_NO_EXCEPTIONS
1085    return *this;
1086}
1087
1088template<class _CharT, class _Traits>
1089basic_istream<_CharT, _Traits>&
1090basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1091{
1092    __gc_ = 0;
1093#ifndef _LIBCPP_NO_EXCEPTIONS
1094    try
1095    {
1096#endif  // _LIBCPP_NO_EXCEPTIONS
1097        sentry __sen(*this, true);
1098        if (__sen)
1099        {
1100            ios_base::iostate __err = ios_base::goodbit;
1101            if (__n == numeric_limits<streamsize>::max())
1102            {
1103                while (true)
1104                {
1105                    typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1106                    if (traits_type::eq_int_type(__i, traits_type::eof()))
1107                    {
1108                       __err |= ios_base::eofbit;
1109                       break;
1110                    }
1111                    ++__gc_;
1112                    if (traits_type::eq_int_type(__i, __dlm))
1113                        break;
1114                }
1115            }
1116            else
1117            {
1118                while (__gc_ < __n)
1119                {
1120                    typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1121                    if (traits_type::eq_int_type(__i, traits_type::eof()))
1122                    {
1123                       __err |= ios_base::eofbit;
1124                       break;
1125                    }
1126                    ++__gc_;
1127                    if (traits_type::eq_int_type(__i, __dlm))
1128                        break;
1129                }
1130            }
1131            this->setstate(__err);
1132        }
1133#ifndef _LIBCPP_NO_EXCEPTIONS
1134    }
1135    catch (...)
1136    {
1137        this->__set_badbit_and_consider_rethrow();
1138    }
1139#endif  // _LIBCPP_NO_EXCEPTIONS
1140    return *this;
1141}
1142
1143template<class _CharT, class _Traits>
1144typename basic_istream<_CharT, _Traits>::int_type
1145basic_istream<_CharT, _Traits>::peek()
1146{
1147    __gc_ = 0;
1148    int_type __r = traits_type::eof();
1149#ifndef _LIBCPP_NO_EXCEPTIONS
1150    try
1151    {
1152#endif  // _LIBCPP_NO_EXCEPTIONS
1153        sentry __sen(*this, true);
1154        if (__sen)
1155        {
1156            __r = this->rdbuf()->sgetc();
1157            if (traits_type::eq_int_type(__r, traits_type::eof()))
1158                this->setstate(ios_base::eofbit);
1159        }
1160#ifndef _LIBCPP_NO_EXCEPTIONS
1161    }
1162    catch (...)
1163    {
1164        this->__set_badbit_and_consider_rethrow();
1165    }
1166#endif  // _LIBCPP_NO_EXCEPTIONS
1167    return __r;
1168}
1169
1170template<class _CharT, class _Traits>
1171basic_istream<_CharT, _Traits>&
1172basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1173{
1174    __gc_ = 0;
1175#ifndef _LIBCPP_NO_EXCEPTIONS
1176    try
1177    {
1178#endif  // _LIBCPP_NO_EXCEPTIONS
1179        sentry __sen(*this, true);
1180        if (__sen)
1181        {
1182            __gc_ = this->rdbuf()->sgetn(__s, __n);
1183            if (__gc_ != __n)
1184                this->setstate(ios_base::failbit | ios_base::eofbit);
1185        }
1186        else
1187            this->setstate(ios_base::failbit);
1188#ifndef _LIBCPP_NO_EXCEPTIONS
1189    }
1190    catch (...)
1191    {
1192        this->__set_badbit_and_consider_rethrow();
1193    }
1194#endif  // _LIBCPP_NO_EXCEPTIONS
1195    return *this;
1196}
1197
1198template<class _CharT, class _Traits>
1199streamsize
1200basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1201{
1202    __gc_ = 0;
1203#ifndef _LIBCPP_NO_EXCEPTIONS
1204    try
1205    {
1206#endif  // _LIBCPP_NO_EXCEPTIONS
1207        sentry __sen(*this, true);
1208        if (__sen)
1209        {
1210            streamsize __c = this->rdbuf()->in_avail();
1211            switch (__c)
1212            {
1213            case -1:
1214                this->setstate(ios_base::eofbit);
1215                break;
1216            case 0:
1217                break;
1218            default:
1219                read(__s, _VSTD::min(__c, __n));
1220                break;
1221            }
1222        }
1223        else
1224            this->setstate(ios_base::failbit);
1225#ifndef _LIBCPP_NO_EXCEPTIONS
1226    }
1227    catch (...)
1228    {
1229        this->__set_badbit_and_consider_rethrow();
1230    }
1231#endif  // _LIBCPP_NO_EXCEPTIONS
1232    return __gc_;
1233}
1234
1235template<class _CharT, class _Traits>
1236basic_istream<_CharT, _Traits>&
1237basic_istream<_CharT, _Traits>::putback(char_type __c)
1238{
1239    __gc_ = 0;
1240#ifndef _LIBCPP_NO_EXCEPTIONS
1241    try
1242    {
1243#endif  // _LIBCPP_NO_EXCEPTIONS
1244        this->clear(this->rdstate() & ~ios_base::eofbit);
1245        sentry __sen(*this, true);
1246        if (__sen)
1247        {
1248            if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1249                this->setstate(ios_base::badbit);
1250        }
1251        else
1252            this->setstate(ios_base::failbit);
1253#ifndef _LIBCPP_NO_EXCEPTIONS
1254    }
1255    catch (...)
1256    {
1257        this->__set_badbit_and_consider_rethrow();
1258    }
1259#endif  // _LIBCPP_NO_EXCEPTIONS
1260    return *this;
1261}
1262
1263template<class _CharT, class _Traits>
1264basic_istream<_CharT, _Traits>&
1265basic_istream<_CharT, _Traits>::unget()
1266{
1267    __gc_ = 0;
1268#ifndef _LIBCPP_NO_EXCEPTIONS
1269    try
1270    {
1271#endif  // _LIBCPP_NO_EXCEPTIONS
1272        this->clear(this->rdstate() & ~ios_base::eofbit);
1273        sentry __sen(*this, true);
1274        if (__sen)
1275        {
1276            if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1277                this->setstate(ios_base::badbit);
1278        }
1279        else
1280            this->setstate(ios_base::failbit);
1281#ifndef _LIBCPP_NO_EXCEPTIONS
1282    }
1283    catch (...)
1284    {
1285        this->__set_badbit_and_consider_rethrow();
1286    }
1287#endif  // _LIBCPP_NO_EXCEPTIONS
1288    return *this;
1289}
1290
1291template<class _CharT, class _Traits>
1292int
1293basic_istream<_CharT, _Traits>::sync()
1294{
1295    int __r = 0;
1296#ifndef _LIBCPP_NO_EXCEPTIONS
1297    try
1298    {
1299#endif  // _LIBCPP_NO_EXCEPTIONS
1300        sentry __sen(*this, true);
1301        if (__sen)
1302        {
1303            if (this->rdbuf() == 0)
1304                return -1;
1305            if (this->rdbuf()->pubsync() == -1)
1306            {
1307                this->setstate(ios_base::badbit);
1308                return -1;
1309            }
1310        }
1311#ifndef _LIBCPP_NO_EXCEPTIONS
1312    }
1313    catch (...)
1314    {
1315        this->__set_badbit_and_consider_rethrow();
1316    }
1317#endif  // _LIBCPP_NO_EXCEPTIONS
1318    return __r;
1319}
1320
1321template<class _CharT, class _Traits>
1322typename basic_istream<_CharT, _Traits>::pos_type
1323basic_istream<_CharT, _Traits>::tellg()
1324{
1325    pos_type __r(-1);
1326#ifndef _LIBCPP_NO_EXCEPTIONS
1327    try
1328    {
1329#endif  // _LIBCPP_NO_EXCEPTIONS
1330        sentry __sen(*this, true);
1331        if (__sen)
1332            __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1333#ifndef _LIBCPP_NO_EXCEPTIONS
1334    }
1335    catch (...)
1336    {
1337        this->__set_badbit_and_consider_rethrow();
1338    }
1339#endif  // _LIBCPP_NO_EXCEPTIONS
1340    return __r;
1341}
1342
1343template<class _CharT, class _Traits>
1344basic_istream<_CharT, _Traits>&
1345basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1346{
1347#ifndef _LIBCPP_NO_EXCEPTIONS
1348    try
1349    {
1350#endif  // _LIBCPP_NO_EXCEPTIONS
1351        this->clear(this->rdstate() & ~ios_base::eofbit);
1352        sentry __sen(*this, true);
1353        if (__sen)
1354        {
1355            if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1356                this->setstate(ios_base::failbit);
1357        }
1358#ifndef _LIBCPP_NO_EXCEPTIONS
1359    }
1360    catch (...)
1361    {
1362        this->__set_badbit_and_consider_rethrow();
1363    }
1364#endif  // _LIBCPP_NO_EXCEPTIONS
1365    return *this;
1366}
1367
1368template<class _CharT, class _Traits>
1369basic_istream<_CharT, _Traits>&
1370basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1371{
1372#ifndef _LIBCPP_NO_EXCEPTIONS
1373    try
1374    {
1375#endif  // _LIBCPP_NO_EXCEPTIONS
1376        this->clear(this->rdstate() & ~ios_base::eofbit);
1377        sentry __sen(*this, true);
1378        if (__sen)
1379        {
1380            if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1381                this->setstate(ios_base::failbit);
1382        }
1383#ifndef _LIBCPP_NO_EXCEPTIONS
1384    }
1385    catch (...)
1386    {
1387        this->__set_badbit_and_consider_rethrow();
1388    }
1389#endif  // _LIBCPP_NO_EXCEPTIONS
1390    return *this;
1391}
1392
1393template <class _CharT, class _Traits>
1394basic_istream<_CharT, _Traits>&
1395ws(basic_istream<_CharT, _Traits>& __is)
1396{
1397#ifndef _LIBCPP_NO_EXCEPTIONS
1398    try
1399    {
1400#endif  // _LIBCPP_NO_EXCEPTIONS
1401        typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1402        if (__sen)
1403        {
1404            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1405            while (true)
1406            {
1407                typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1408                if (_Traits::eq_int_type(__i, _Traits::eof()))
1409                {
1410                   __is.setstate(ios_base::eofbit);
1411                   break;
1412                }
1413                if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1414                    break;
1415                __is.rdbuf()->sbumpc();
1416            }
1417        }
1418#ifndef _LIBCPP_NO_EXCEPTIONS
1419    }
1420    catch (...)
1421    {
1422        __is.__set_badbit_and_consider_rethrow();
1423    }
1424#endif  // _LIBCPP_NO_EXCEPTIONS
1425    return __is;
1426}
1427
1428#ifndef _LIBCPP_CXX03_LANG
1429
1430template <class _CharT, class _Traits, class _Tp>
1431inline _LIBCPP_INLINE_VISIBILITY
1432basic_istream<_CharT, _Traits>&
1433operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
1434{
1435    __is >> _VSTD::forward<_Tp>(__x);
1436    return __is;
1437}
1438
1439#endif  // _LIBCPP_CXX03_LANG
1440
1441template <class _CharT, class _Traits>
1442class _LIBCPP_TEMPLATE_VIS basic_iostream
1443    : public basic_istream<_CharT, _Traits>,
1444      public basic_ostream<_CharT, _Traits>
1445{
1446public:
1447    // types:
1448    typedef _CharT                         char_type;
1449    typedef _Traits                        traits_type;
1450    typedef typename traits_type::int_type int_type;
1451    typedef typename traits_type::pos_type pos_type;
1452    typedef typename traits_type::off_type off_type;
1453
1454    // constructor/destructor
1455    inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1456    explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1457      : basic_istream<_CharT, _Traits>(__sb)
1458    {}
1459
1460    virtual ~basic_iostream();
1461protected:
1462#ifndef _LIBCPP_CXX03_LANG
1463    inline _LIBCPP_INLINE_VISIBILITY
1464    basic_iostream(basic_iostream&& __rhs);
1465
1466    // assign/swap
1467    inline _LIBCPP_INLINE_VISIBILITY
1468    basic_iostream& operator=(basic_iostream&& __rhs);
1469#endif
1470    inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1471    void swap(basic_iostream& __rhs)
1472    { basic_istream<char_type, traits_type>::swap(__rhs); }
1473public:
1474};
1475
1476#ifndef _LIBCPP_CXX03_LANG
1477
1478template <class _CharT, class _Traits>
1479basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1480    : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1481{
1482}
1483
1484template <class _CharT, class _Traits>
1485basic_iostream<_CharT, _Traits>&
1486basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1487{
1488    swap(__rhs);
1489    return *this;
1490}
1491
1492#endif  // _LIBCPP_CXX03_LANG
1493
1494template <class _CharT, class _Traits>
1495basic_iostream<_CharT, _Traits>::~basic_iostream()
1496{
1497}
1498
1499template<class _CharT, class _Traits, class _Allocator>
1500basic_istream<_CharT, _Traits>&
1501operator>>(basic_istream<_CharT, _Traits>& __is,
1502           basic_string<_CharT, _Traits, _Allocator>& __str)
1503{
1504#ifndef _LIBCPP_NO_EXCEPTIONS
1505    try
1506    {
1507#endif  // _LIBCPP_NO_EXCEPTIONS
1508        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1509        if (__sen)
1510        {
1511            __str.clear();
1512            streamsize __n = __is.width();
1513            if (__n <= 0)
1514                __n = __str.max_size();
1515            if (__n <= 0)
1516                __n = numeric_limits<streamsize>::max();
1517            streamsize __c = 0;
1518            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1519            ios_base::iostate __err = ios_base::goodbit;
1520            while (__c < __n)
1521            {
1522                typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1523                if (_Traits::eq_int_type(__i, _Traits::eof()))
1524                {
1525                   __err |= ios_base::eofbit;
1526                   break;
1527                }
1528                _CharT __ch = _Traits::to_char_type(__i);
1529                if (__ct.is(__ct.space, __ch))
1530                    break;
1531                __str.push_back(__ch);
1532                ++__c;
1533                 __is.rdbuf()->sbumpc();
1534            }
1535            __is.width(0);
1536            if (__c == 0)
1537               __err |= ios_base::failbit;
1538            __is.setstate(__err);
1539        }
1540        else
1541            __is.setstate(ios_base::failbit);
1542#ifndef _LIBCPP_NO_EXCEPTIONS
1543    }
1544    catch (...)
1545    {
1546        __is.__set_badbit_and_consider_rethrow();
1547    }
1548#endif  // _LIBCPP_NO_EXCEPTIONS
1549    return __is;
1550}
1551
1552template<class _CharT, class _Traits, class _Allocator>
1553basic_istream<_CharT, _Traits>&
1554getline(basic_istream<_CharT, _Traits>& __is,
1555        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1556{
1557#ifndef _LIBCPP_NO_EXCEPTIONS
1558    try
1559    {
1560#endif  // _LIBCPP_NO_EXCEPTIONS
1561        typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1562        if (__sen)
1563        {
1564            __str.clear();
1565            ios_base::iostate __err = ios_base::goodbit;
1566            streamsize __extr = 0;
1567            while (true)
1568            {
1569                typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1570                if (_Traits::eq_int_type(__i, _Traits::eof()))
1571                {
1572                   __err |= ios_base::eofbit;
1573                   break;
1574                }
1575                ++__extr;
1576                _CharT __ch = _Traits::to_char_type(__i);
1577                if (_Traits::eq(__ch, __dlm))
1578                    break;
1579                __str.push_back(__ch);
1580                if (__str.size() == __str.max_size())
1581                {
1582                    __err |= ios_base::failbit;
1583                    break;
1584                }
1585            }
1586            if (__extr == 0)
1587               __err |= ios_base::failbit;
1588            __is.setstate(__err);
1589        }
1590#ifndef _LIBCPP_NO_EXCEPTIONS
1591    }
1592    catch (...)
1593    {
1594        __is.__set_badbit_and_consider_rethrow();
1595    }
1596#endif  // _LIBCPP_NO_EXCEPTIONS
1597    return __is;
1598}
1599
1600template<class _CharT, class _Traits, class _Allocator>
1601inline _LIBCPP_INLINE_VISIBILITY
1602basic_istream<_CharT, _Traits>&
1603getline(basic_istream<_CharT, _Traits>& __is,
1604        basic_string<_CharT, _Traits, _Allocator>& __str)
1605{
1606    return getline(__is, __str, __is.widen('\n'));
1607}
1608
1609#ifndef _LIBCPP_CXX03_LANG
1610
1611template<class _CharT, class _Traits, class _Allocator>
1612inline _LIBCPP_INLINE_VISIBILITY
1613basic_istream<_CharT, _Traits>&
1614getline(basic_istream<_CharT, _Traits>&& __is,
1615        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1616{
1617    return getline(__is, __str, __dlm);
1618}
1619
1620template<class _CharT, class _Traits, class _Allocator>
1621inline _LIBCPP_INLINE_VISIBILITY
1622basic_istream<_CharT, _Traits>&
1623getline(basic_istream<_CharT, _Traits>&& __is,
1624        basic_string<_CharT, _Traits, _Allocator>& __str)
1625{
1626    return getline(__is, __str, __is.widen('\n'));
1627}
1628
1629#endif  // _LIBCPP_CXX03_LANG
1630
1631template <class _CharT, class _Traits, size_t _Size>
1632basic_istream<_CharT, _Traits>&
1633operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1634{
1635#ifndef _LIBCPP_NO_EXCEPTIONS
1636    try
1637    {
1638#endif  // _LIBCPP_NO_EXCEPTIONS
1639        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1640        if (__sen)
1641        {
1642            basic_string<_CharT, _Traits> __str;
1643            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
1644            size_t __c = 0;
1645            ios_base::iostate __err = ios_base::goodbit;
1646            _CharT __zero = __ct.widen('0');
1647            _CharT __one = __ct.widen('1');
1648            while (__c < _Size)
1649            {
1650                typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1651                if (_Traits::eq_int_type(__i, _Traits::eof()))
1652                {
1653                   __err |= ios_base::eofbit;
1654                   break;
1655                }
1656                _CharT __ch = _Traits::to_char_type(__i);
1657                if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1658                    break;
1659                __str.push_back(__ch);
1660                ++__c;
1661                 __is.rdbuf()->sbumpc();
1662            }
1663            __x = bitset<_Size>(__str);
1664            if (__c == 0)
1665               __err |= ios_base::failbit;
1666            __is.setstate(__err);
1667        }
1668        else
1669            __is.setstate(ios_base::failbit);
1670#ifndef _LIBCPP_NO_EXCEPTIONS
1671    }
1672    catch (...)
1673    {
1674        __is.__set_badbit_and_consider_rethrow();
1675    }
1676#endif  // _LIBCPP_NO_EXCEPTIONS
1677    return __is;
1678}
1679
1680#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
1681_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1682_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1683_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
1684#endif
1685
1686_LIBCPP_END_NAMESPACE_STD
1687
1688_LIBCPP_POP_MACROS
1689
1690#endif  // _LIBCPP_ISTREAM
1691