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