Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / istream
blobd9c1a79cdd54e6ad34ddd72e96d8fb739cf70e43
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_ISTREAM
11 #define _LIBCPP_ISTREAM
14     istream synopsis
16 template <class charT, class traits = char_traits<charT> >
17 class basic_istream
18     : virtual public basic_ios<charT,traits>
20 public:
21     // types (inherited from basic_ios (27.5.4)):
22     typedef charT                          char_type;
23     typedef traits                         traits_type;
24     typedef typename traits_type::int_type int_type;
25     typedef typename traits_type::pos_type pos_type;
26     typedef typename traits_type::off_type off_type;
28     // 27.7.1.1.1 Constructor/destructor:
29     explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
30     basic_istream(basic_istream&& rhs);
31     virtual ~basic_istream();
33     // 27.7.1.1.2 Assign/swap:
34     basic_istream& operator=(basic_istream&& rhs);
35     void swap(basic_istream& rhs);
37     // 27.7.1.1.3 Prefix/suffix:
38     class sentry;
40     // 27.7.1.2 Formatted input:
41     basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
42     basic_istream& operator>>(basic_ios<char_type, traits_type>&
43                               (*pf)(basic_ios<char_type, traits_type>&));
44     basic_istream& operator>>(ios_base& (*pf)(ios_base&));
45     basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
46     basic_istream& operator>>(bool& n);
47     basic_istream& operator>>(short& n);
48     basic_istream& operator>>(unsigned short& n);
49     basic_istream& operator>>(int& n);
50     basic_istream& operator>>(unsigned int& n);
51     basic_istream& operator>>(long& n);
52     basic_istream& operator>>(unsigned long& n);
53     basic_istream& operator>>(long long& n);
54     basic_istream& operator>>(unsigned long long& n);
55     basic_istream& operator>>(float& f);
56     basic_istream& operator>>(double& f);
57     basic_istream& operator>>(long double& f);
58     basic_istream& operator>>(void*& p);
60     // 27.7.1.3 Unformatted input:
61     streamsize gcount() const;
62     int_type get();
63     basic_istream& get(char_type& c);
64     basic_istream& get(char_type* s, streamsize n);
65     basic_istream& get(char_type* s, streamsize n, char_type delim);
66     basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
67     basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
69     basic_istream& getline(char_type* s, streamsize n);
70     basic_istream& getline(char_type* s, streamsize n, char_type delim);
72     basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
73     int_type peek();
74     basic_istream& read (char_type* s, streamsize n);
75     streamsize readsome(char_type* s, streamsize n);
77     basic_istream& putback(char_type c);
78     basic_istream& unget();
79     int sync();
81     pos_type tellg();
82     basic_istream& seekg(pos_type);
83     basic_istream& seekg(off_type, ios_base::seekdir);
84 protected:
85     basic_istream(const basic_istream& rhs) = delete;
86     basic_istream(basic_istream&& rhs);
87     // 27.7.2.1.2 Assign/swap:
88     basic_istream& operator=(const basic_istream& rhs) = delete;
89     basic_istream& operator=(basic_istream&& rhs);
90     void swap(basic_istream& rhs);
93 // 27.7.1.2.3 character extraction templates:
94 template<class charT, class traits>
95   basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
97 template<class traits>
98   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
100 template<class traits>
101   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
103 template<class charT, class traits>
104   basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
106 template<class traits>
107   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
109 template<class traits>
110   basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
112 template <class charT, class traits>
113   void
114   swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
116 typedef basic_istream<char> istream;
117 typedef basic_istream<wchar_t> wistream;
119 template <class charT, class traits = char_traits<charT> >
120 class basic_iostream :
121     public basic_istream<charT,traits>,
122     public basic_ostream<charT,traits>
124 public:
125     // types:
126     typedef charT                          char_type;
127     typedef traits                         traits_type;
128     typedef typename traits_type::int_type int_type;
129     typedef typename traits_type::pos_type pos_type;
130     typedef typename traits_type::off_type off_type;
132     // constructor/destructor
133     explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
134     basic_iostream(basic_iostream&& rhs);
135     virtual ~basic_iostream();
137     // assign/swap
138     basic_iostream& operator=(basic_iostream&& rhs);
139     void swap(basic_iostream& rhs);
142 template <class charT, class traits>
143   void
144   swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
146 typedef basic_iostream<char> iostream;
147 typedef basic_iostream<wchar_t> wiostream;
149 template <class charT, class traits>
150   basic_istream<charT,traits>&
151   ws(basic_istream<charT,traits>& is);
153 // rvalue stream extraction
154 template <class Stream, class T>
155   Stream&& operator>>(Stream&& is, T&& x);
157 }  // std
161 #include <__assert> // all public C++ headers provide the assertion handler
162 #include <__config>
163 #include <__fwd/istream.h>
164 #include <__iterator/istreambuf_iterator.h>
165 #include <__type_traits/conjunction.h>
166 #include <__type_traits/enable_if.h>
167 #include <__type_traits/is_base_of.h>
168 #include <__utility/declval.h>
169 #include <__utility/forward.h>
170 #include <ostream>
171 #include <version>
173 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
174 #  pragma GCC system_header
175 #endif
177 _LIBCPP_PUSH_MACROS
178 #include <__undef_macros>
181 _LIBCPP_BEGIN_NAMESPACE_STD
183 template <class _CharT, class _Traits>
184 class _LIBCPP_TEMPLATE_VIS basic_istream
185     : virtual public basic_ios<_CharT, _Traits>
187     streamsize __gc_;
189     _LIBCPP_HIDE_FROM_ABI void __inc_gcount() {
190       if (__gc_ < numeric_limits<streamsize>::max())
191         ++__gc_;
192     }
193 public:
194     // types (inherited from basic_ios (27.5.4)):
195     typedef _CharT                         char_type;
196     typedef _Traits                        traits_type;
197     typedef typename traits_type::int_type int_type;
198     typedef typename traits_type::pos_type pos_type;
199     typedef typename traits_type::off_type off_type;
201     // 27.7.1.1.1 Constructor/destructor:
202     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
203     explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0)
204     { this->init(__sb); }
205     ~basic_istream() override;
206 protected:
207     inline _LIBCPP_INLINE_VISIBILITY
208     basic_istream(basic_istream&& __rhs);
210     // 27.7.1.1.2 Assign/swap:
211     inline _LIBCPP_INLINE_VISIBILITY
212     basic_istream& operator=(basic_istream&& __rhs);
214     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
215     void swap(basic_istream& __rhs) {
216       _VSTD::swap(__gc_, __rhs.__gc_);
217       basic_ios<char_type, traits_type>::swap(__rhs);
218     }
220     basic_istream           (const basic_istream& __rhs) = delete;
221     basic_istream& operator=(const basic_istream& __rhs) = delete;
222 public:
224     // 27.7.1.1.3 Prefix/suffix:
225     class _LIBCPP_TEMPLATE_VIS sentry;
227     // 27.7.1.2 Formatted input:
228     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
229     basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&))
230     { return __pf(*this); }
232     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
233     basic_istream& operator>>(basic_ios<char_type, traits_type>&
234                               (*__pf)(basic_ios<char_type, traits_type>&))
235     { __pf(*this); return *this; }
237     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
238     basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
239     { __pf(*this); return *this; }
241     basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
242     basic_istream& operator>>(bool& __n);
243     basic_istream& operator>>(short& __n);
244     basic_istream& operator>>(unsigned short& __n);
245     basic_istream& operator>>(int& __n);
246     basic_istream& operator>>(unsigned int& __n);
247     basic_istream& operator>>(long& __n);
248     basic_istream& operator>>(unsigned long& __n);
249     basic_istream& operator>>(long long& __n);
250     basic_istream& operator>>(unsigned long long& __n);
251     basic_istream& operator>>(float& __f);
252     basic_istream& operator>>(double& __f);
253     basic_istream& operator>>(long double& __f);
254     basic_istream& operator>>(void*& __p);
256     // 27.7.1.3 Unformatted input:
257     _LIBCPP_INLINE_VISIBILITY
258     streamsize gcount() const {return __gc_;}
259     int_type get();
261     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
262     basic_istream& get(char_type& __c) {
263       int_type __ch = get();
264       if (__ch != traits_type::eof())
265         __c = traits_type::to_char_type(__ch);
266       return *this;
267     }
269     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
270     basic_istream& get(char_type* __s, streamsize __n)
271     { return get(__s, __n, this->widen('\n')); }
273     basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
275     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
276     basic_istream& get(basic_streambuf<char_type, traits_type>& __sb)
277     { return get(__sb, this->widen('\n')); }
279     basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
281     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
282     basic_istream& getline(char_type* __s, streamsize __n)
283     { return getline(__s, __n, this->widen('\n')); }
285     basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
287     basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
288     int_type peek();
289     basic_istream& read (char_type* __s, streamsize __n);
290     streamsize readsome(char_type* __s, streamsize __n);
292     basic_istream& putback(char_type __c);
293     basic_istream& unget();
294     int sync();
296     pos_type tellg();
297     basic_istream& seekg(pos_type __pos);
298     basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
301 template <class _CharT, class _Traits>
302 class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
304     bool __ok_;
306 public:
307     explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
308 //    ~sentry() = default;
310     _LIBCPP_INLINE_VISIBILITY
311     explicit operator bool() const {return __ok_;}
313     sentry(const sentry&) = delete;
314     sentry& operator=(const sentry&) = delete;
317 template <class _CharT, class _Traits>
318 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
319                                                bool __noskipws)
320     : __ok_(false)
322     if (__is.good())
323     {
324         if (__is.tie())
325             __is.tie()->flush();
326         if (!__noskipws && (__is.flags() & ios_base::skipws))
327         {
328             typedef istreambuf_iterator<_CharT, _Traits> _Ip;
329             const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
330             _Ip __i(__is);
331             _Ip __eof;
332             for (; __i != __eof; ++__i)
333                 if (!__ct.is(__ct.space, *__i))
334                     break;
335             if (__i == __eof)
336                 __is.setstate(ios_base::failbit | ios_base::eofbit);
337         }
338         __ok_ = __is.good();
339     }
340     else
341         __is.setstate(ios_base::failbit);
344 template <class _CharT, class _Traits>
345 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
346     : __gc_(__rhs.__gc_)
348     __rhs.__gc_ = 0;
349     this->move(__rhs);
352 template <class _CharT, class _Traits>
353 basic_istream<_CharT, _Traits>&
354 basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
356     swap(__rhs);
357     return *this;
360 template <class _CharT, class _Traits>
361 basic_istream<_CharT, _Traits>::~basic_istream()
365 template <class _Tp, class _CharT, class _Traits>
366 _LIBCPP_INLINE_VISIBILITY
367 basic_istream<_CharT, _Traits>&
368 __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
369     ios_base::iostate __state = ios_base::goodbit;
370     typename basic_istream<_CharT, _Traits>::sentry __s(__is);
371     if (__s)
372     {
373 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
374         try
375         {
376 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
377             typedef istreambuf_iterator<_CharT, _Traits> _Ip;
378             typedef num_get<_CharT, _Ip> _Fp;
379             std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);
380 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
381         }
382         catch (...)
383         {
384             __state |= ios_base::badbit;
385             __is.__setstate_nothrow(__state);
386             if (__is.exceptions() & ios_base::badbit)
387             {
388                 throw;
389             }
390         }
391 #endif
392         __is.setstate(__state);
393     }
394     return __is;
397 template <class _CharT, class _Traits>
398 basic_istream<_CharT, _Traits>&
399 basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
401     return _VSTD::__input_arithmetic<unsigned short>(*this, __n);
404 template <class _CharT, class _Traits>
405 basic_istream<_CharT, _Traits>&
406 basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
408     return _VSTD::__input_arithmetic<unsigned int>(*this, __n);
411 template <class _CharT, class _Traits>
412 basic_istream<_CharT, _Traits>&
413 basic_istream<_CharT, _Traits>::operator>>(long& __n)
415     return _VSTD::__input_arithmetic<long>(*this, __n);
418 template <class _CharT, class _Traits>
419 basic_istream<_CharT, _Traits>&
420 basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
422     return _VSTD::__input_arithmetic<unsigned long>(*this, __n);
425 template <class _CharT, class _Traits>
426 basic_istream<_CharT, _Traits>&
427 basic_istream<_CharT, _Traits>::operator>>(long long& __n)
429     return _VSTD::__input_arithmetic<long long>(*this, __n);
432 template <class _CharT, class _Traits>
433 basic_istream<_CharT, _Traits>&
434 basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
436     return _VSTD::__input_arithmetic<unsigned long long>(*this, __n);
439 template <class _CharT, class _Traits>
440 basic_istream<_CharT, _Traits>&
441 basic_istream<_CharT, _Traits>::operator>>(float& __n)
443     return _VSTD::__input_arithmetic<float>(*this, __n);
446 template <class _CharT, class _Traits>
447 basic_istream<_CharT, _Traits>&
448 basic_istream<_CharT, _Traits>::operator>>(double& __n)
450     return _VSTD::__input_arithmetic<double>(*this, __n);
453 template <class _CharT, class _Traits>
454 basic_istream<_CharT, _Traits>&
455 basic_istream<_CharT, _Traits>::operator>>(long double& __n)
457     return _VSTD::__input_arithmetic<long double>(*this, __n);
460 template <class _CharT, class _Traits>
461 basic_istream<_CharT, _Traits>&
462 basic_istream<_CharT, _Traits>::operator>>(bool& __n)
464     return _VSTD::__input_arithmetic<bool>(*this, __n);
467 template <class _CharT, class _Traits>
468 basic_istream<_CharT, _Traits>&
469 basic_istream<_CharT, _Traits>::operator>>(void*& __n)
471     return _VSTD::__input_arithmetic<void*>(*this, __n);
474 template <class _Tp, class _CharT, class _Traits>
475 _LIBCPP_INLINE_VISIBILITY
476 basic_istream<_CharT, _Traits>&
477 __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
478     ios_base::iostate __state = ios_base::goodbit;
479     typename basic_istream<_CharT, _Traits>::sentry __s(__is);
480     if (__s)
481     {
482 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
483         try
484         {
485 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
486             typedef istreambuf_iterator<_CharT, _Traits> _Ip;
487             typedef num_get<_CharT, _Ip> _Fp;
488             long __temp;
489             std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp);
490             if (__temp < numeric_limits<_Tp>::min())
491             {
492                 __state |= ios_base::failbit;
493                 __n = numeric_limits<_Tp>::min();
494             }
495             else if (__temp > numeric_limits<_Tp>::max())
496             {
497                 __state |= ios_base::failbit;
498                 __n = numeric_limits<_Tp>::max();
499             }
500             else
501             {
502                 __n = static_cast<_Tp>(__temp);
503             }
504 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
505         }
506         catch (...)
507         {
508             __state |= ios_base::badbit;
509             __is.__setstate_nothrow(__state);
510             if (__is.exceptions() & ios_base::badbit)
511             {
512                 throw;
513             }
514         }
515 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
516         __is.setstate(__state);
517     }
518     return __is;
521 template <class _CharT, class _Traits>
522 basic_istream<_CharT, _Traits>&
523 basic_istream<_CharT, _Traits>::operator>>(short& __n)
525     return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n);
528 template <class _CharT, class _Traits>
529 basic_istream<_CharT, _Traits>&
530 basic_istream<_CharT, _Traits>::operator>>(int& __n)
532     return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n);
535 template<class _CharT, class _Traits>
536 _LIBCPP_INLINE_VISIBILITY
537 basic_istream<_CharT, _Traits>&
538 __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
540     ios_base::iostate __state = ios_base::goodbit;
541     typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
542     if (__sen)
543     {
544 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
545         try
546         {
547 #endif
548             _CharT* __s = __p;
549             const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
550             while (__s != __p + (__n-1))
551             {
552                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
553                 if (_Traits::eq_int_type(__i, _Traits::eof()))
554                 {
555                    __state |= ios_base::eofbit;
556                    break;
557                 }
558                 _CharT __ch = _Traits::to_char_type(__i);
559                 if (__ct.is(__ct.space, __ch))
560                     break;
561                 *__s++ = __ch;
562                  __is.rdbuf()->sbumpc();
563             }
564             *__s = _CharT();
565             __is.width(0);
566             if (__s == __p)
567                __state |= ios_base::failbit;
568 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
569         }
570         catch (...)
571         {
572             __state |= ios_base::badbit;
573             __is.__setstate_nothrow(__state);
574             if (__is.exceptions() & ios_base::badbit)
575             {
576                 throw;
577             }
578         }
579 #endif
580         __is.setstate(__state);
581     }
582     return __is;
585 #if _LIBCPP_STD_VER >= 20
587 template<class _CharT, class _Traits, size_t _Np>
588 inline _LIBCPP_INLINE_VISIBILITY
589 basic_istream<_CharT, _Traits>&
590 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np])
592     size_t __n = _Np;
593     if (__is.width() > 0)
594         __n = _VSTD::min(size_t(__is.width()), _Np);
595     return _VSTD::__input_c_string(__is, __buf, __n);
598 template<class _Traits, size_t _Np>
599 inline _LIBCPP_INLINE_VISIBILITY
600 basic_istream<char, _Traits>&
601 operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np])
603     return __is >> (char(&)[_Np])__buf;
606 template<class _Traits, size_t _Np>
607 inline _LIBCPP_INLINE_VISIBILITY
608 basic_istream<char, _Traits>&
609 operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np])
611     return __is >> (char(&)[_Np])__buf;
614 #else
616 template<class _CharT, class _Traits>
617 inline _LIBCPP_INLINE_VISIBILITY
618 basic_istream<_CharT, _Traits>&
619 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
621     streamsize __n = __is.width();
622     if (__n <= 0)
623         __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
624     return _VSTD::__input_c_string(__is, __s, size_t(__n));
627 template<class _Traits>
628 inline _LIBCPP_INLINE_VISIBILITY
629 basic_istream<char, _Traits>&
630 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
632     return __is >> (char*)__s;
635 template<class _Traits>
636 inline _LIBCPP_INLINE_VISIBILITY
637 basic_istream<char, _Traits>&
638 operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
640     return __is >> (char*)__s;
643 #endif // _LIBCPP_STD_VER >= 20
645 template<class _CharT, class _Traits>
646 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
647 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
649     ios_base::iostate __state = ios_base::goodbit;
650     typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
651     if (__sen)
652     {
653 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
654         try
655         {
656 #endif
657             typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
658             if (_Traits::eq_int_type(__i, _Traits::eof()))
659                 __state |= ios_base::eofbit | ios_base::failbit;
660             else
661                 __c = _Traits::to_char_type(__i);
662 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
663         }
664         catch (...)
665         {
666             __state |= ios_base::badbit;
667             __is.__setstate_nothrow(__state);
668             if (__is.exceptions() & ios_base::badbit)
669             {
670                 throw;
671             }
672         }
673 #endif
674         __is.setstate(__state);
675     }
676     return __is;
679 template<class _Traits>
680 inline _LIBCPP_INLINE_VISIBILITY
681 basic_istream<char, _Traits>&
682 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
684     return __is >> (char&)__c;
687 template<class _Traits>
688 inline _LIBCPP_INLINE_VISIBILITY
689 basic_istream<char, _Traits>&
690 operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
692     return __is >> (char&)__c;
695 template<class _CharT, class _Traits>
696 basic_istream<_CharT, _Traits>&
697 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
699     ios_base::iostate __state = ios_base::goodbit;
700     __gc_ = 0;
701     sentry __s(*this, true);
702     if (__s)
703     {
704         if (__sb)
705         {
706 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
707             try
708             {
709 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
710                 while (true)
711                 {
712                     typename traits_type::int_type __i = this->rdbuf()->sgetc();
713                     if (traits_type::eq_int_type(__i, _Traits::eof()))
714                     {
715                        __state |= ios_base::eofbit;
716                        break;
717                     }
718                     if (traits_type::eq_int_type(
719                             __sb->sputc(traits_type::to_char_type(__i)),
720                             traits_type::eof()))
721                         break;
722                     __inc_gcount();
723                     this->rdbuf()->sbumpc();
724                 }
725                 if (__gc_ == 0)
726                    __state |= ios_base::failbit;
727 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
728             }
729             catch (...)
730             {
731                 __state |= ios_base::badbit;
732                 if (__gc_ == 0)
733                     __state |= ios_base::failbit;
735                 this->__setstate_nothrow(__state);
736                 if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit)
737                 {
738                     throw;
739                 }
740             }
741 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
742         }
743         else
744         {
745             __state |= ios_base::failbit;
746         }
747         this->setstate(__state);
748     }
749     return *this;
752 template<class _CharT, class _Traits>
753 typename basic_istream<_CharT, _Traits>::int_type
754 basic_istream<_CharT, _Traits>::get()
756     ios_base::iostate __state = ios_base::goodbit;
757     __gc_ = 0;
758     int_type __r = traits_type::eof();
759     sentry __s(*this, true);
760     if (__s)
761     {
762 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
763         try
764         {
765 #endif
766             __r = this->rdbuf()->sbumpc();
767             if (traits_type::eq_int_type(__r, traits_type::eof()))
768                __state |= ios_base::failbit | ios_base::eofbit;
769             else
770                 __gc_ = 1;
771 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
772         }
773         catch (...)
774         {
775             this->__setstate_nothrow(this->rdstate() | ios_base::badbit);
776             if (this->exceptions() & ios_base::badbit)
777             {
778                 throw;
779             }
780         }
781 #endif
782         this->setstate(__state);
783     }
784     return __r;
787 template<class _CharT, class _Traits>
788 basic_istream<_CharT, _Traits>&
789 basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
791     ios_base::iostate __state = ios_base::goodbit;
792     __gc_ = 0;
793     sentry __sen(*this, true);
794     if (__sen)
795     {
796         if (__n > 0)
797         {
798 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
799             try
800             {
801 #endif
802                 while (__gc_ < __n-1)
803                 {
804                     int_type __i = this->rdbuf()->sgetc();
805                     if (traits_type::eq_int_type(__i, traits_type::eof()))
806                     {
807                        __state |= ios_base::eofbit;
808                        break;
809                     }
810                     char_type __ch = traits_type::to_char_type(__i);
811                     if (traits_type::eq(__ch, __dlm))
812                         break;
813                     *__s++ = __ch;
814                     __inc_gcount();
815                      this->rdbuf()->sbumpc();
816                 }
817                 if (__gc_ == 0)
818                    __state |= ios_base::failbit;
819 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
820             }
821             catch (...)
822             {
823                 __state |= ios_base::badbit;
824                 this->__setstate_nothrow(__state);
825                 if (this->exceptions() & ios_base::badbit)
826                 {
827                     if (__n > 0)
828                         *__s = char_type();
829                     throw;
830                 }
831             }
832 #endif
833         }
834         else
835         {
836             __state |= ios_base::failbit;
837         }
839         if (__n > 0)
840             *__s = char_type();
841         this->setstate(__state);
842     }
843     if (__n > 0)
844         *__s = char_type();
845     return *this;
848 template<class _CharT, class _Traits>
849 basic_istream<_CharT, _Traits>&
850 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
851                                     char_type __dlm)
853     ios_base::iostate __state = ios_base::goodbit;
854     __gc_ = 0;
855     sentry __sen(*this, true);
856     if (__sen)
857     {
858 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
859         try
860         {
861 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
862             while (true)
863             {
864                 typename traits_type::int_type __i = this->rdbuf()->sgetc();
865                 if (traits_type::eq_int_type(__i, traits_type::eof()))
866                 {
867                    __state |= ios_base::eofbit;
868                    break;
869                 }
870                 char_type __ch = traits_type::to_char_type(__i);
871                 if (traits_type::eq(__ch, __dlm))
872                     break;
873                 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
874                     break;
875                 __inc_gcount();
876                 this->rdbuf()->sbumpc();
877             }
878 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
879         }
880         catch (...)
881         {
882             __state |= ios_base::badbit;
883             // according to the spec, exceptions here are caught but not rethrown
884         }
885 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
886         if (__gc_ == 0)
887            __state |= ios_base::failbit;
888         this->setstate(__state);
889     }
890     return *this;
893 template<class _CharT, class _Traits>
894 basic_istream<_CharT, _Traits>&
895 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
897     ios_base::iostate __state = ios_base::goodbit;
898     __gc_ = 0;
899     sentry __sen(*this, true);
900     if (__sen)
901     {
902 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
903         try
904         {
905 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
906             while (true)
907             {
908                 typename traits_type::int_type __i = this->rdbuf()->sgetc();
909                 if (traits_type::eq_int_type(__i, traits_type::eof()))
910                 {
911                    __state |= ios_base::eofbit;
912                    break;
913                 }
914                 char_type __ch = traits_type::to_char_type(__i);
915                 if (traits_type::eq(__ch, __dlm))
916                 {
917                     this->rdbuf()->sbumpc();
918                     __inc_gcount();
919                     break;
920                 }
921                 if (__gc_ >= __n-1)
922                 {
923                     __state |= ios_base::failbit;
924                     break;
925                 }
926                 *__s++ = __ch;
927                 this->rdbuf()->sbumpc();
928                 __inc_gcount();
929             }
930 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
931         }
932         catch (...)
933         {
934             __state |= ios_base::badbit;
935             this->__setstate_nothrow(__state);
936             if (this->exceptions() & ios_base::badbit)
937             {
938                 if (__n > 0)
939                     *__s = char_type();
940                 if (__gc_ == 0)
941                     __state |= ios_base::failbit;
942                 throw;
943             }
944         }
945 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
946     }
947     if (__n > 0)
948         *__s = char_type();
949     if (__gc_ == 0)
950         __state |= ios_base::failbit;
951     this->setstate(__state);
952     return *this;
955 template<class _CharT, class _Traits>
956 basic_istream<_CharT, _Traits>&
957 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
959     ios_base::iostate __state = ios_base::goodbit;
960     __gc_ = 0;
961     sentry __sen(*this, true);
962     if (__sen)
963     {
964 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
965         try
966         {
967 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
968             if (__n == numeric_limits<streamsize>::max())
969             {
970                 while (true)
971                 {
972                     typename traits_type::int_type __i = this->rdbuf()->sbumpc();
973                     if (traits_type::eq_int_type(__i, traits_type::eof()))
974                     {
975                        __state |= ios_base::eofbit;
976                        break;
977                     }
978                     __inc_gcount();
979                     if (traits_type::eq_int_type(__i, __dlm))
980                         break;
981                 }
982             }
983             else
984             {
985                 while (__gc_ < __n)
986                 {
987                     typename traits_type::int_type __i = this->rdbuf()->sbumpc();
988                     if (traits_type::eq_int_type(__i, traits_type::eof()))
989                     {
990                        __state |= ios_base::eofbit;
991                        break;
992                     }
993                     __inc_gcount();
994                     if (traits_type::eq_int_type(__i, __dlm))
995                         break;
996                 }
997             }
998 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
999         }
1000         catch (...)
1001         {
1002             __state |= ios_base::badbit;
1003             this->__setstate_nothrow(__state);
1004             if (this->exceptions() & ios_base::badbit)
1005             {
1006                 throw;
1007             }
1008         }
1009 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1010         this->setstate(__state);
1011     }
1012     return *this;
1015 template<class _CharT, class _Traits>
1016 typename basic_istream<_CharT, _Traits>::int_type
1017 basic_istream<_CharT, _Traits>::peek()
1019     ios_base::iostate __state = ios_base::goodbit;
1020     __gc_ = 0;
1021     int_type __r = traits_type::eof();
1022     sentry __sen(*this, true);
1023     if (__sen)
1024     {
1025 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1026         try
1027         {
1028 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1029             __r = this->rdbuf()->sgetc();
1030             if (traits_type::eq_int_type(__r, traits_type::eof()))
1031                 __state |= ios_base::eofbit;
1032 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1033         }
1034         catch (...)
1035         {
1036             __state |= ios_base::badbit;
1037             this->__setstate_nothrow(__state);
1038             if (this->exceptions() & ios_base::badbit)
1039             {
1040                 throw;
1041             }
1042         }
1043 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1044         this->setstate(__state);
1045     }
1046     return __r;
1049 template<class _CharT, class _Traits>
1050 basic_istream<_CharT, _Traits>&
1051 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1053     ios_base::iostate __state = ios_base::goodbit;
1054     __gc_ = 0;
1055     sentry __sen(*this, true);
1056     if (__sen)
1057     {
1058 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1059         try
1060         {
1061 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1062             __gc_ = this->rdbuf()->sgetn(__s, __n);
1063             if (__gc_ != __n)
1064                 __state |= ios_base::failbit | ios_base::eofbit;
1065 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1066         }
1067         catch (...)
1068         {
1069             __state |= ios_base::badbit;
1070             this->__setstate_nothrow(__state);
1071             if (this->exceptions() & ios_base::badbit)
1072             {
1073                 throw;
1074             }
1075         }
1076 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1077     }
1078     else
1079     {
1080         __state |= ios_base::failbit;
1081     }
1082     this->setstate(__state);
1083     return *this;
1086 template<class _CharT, class _Traits>
1087 streamsize
1088 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1090     ios_base::iostate __state = ios_base::goodbit;
1091     __gc_ = 0;
1092     sentry __sen(*this, true);
1093     if (__sen)
1094     {
1095 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1096         try
1097         {
1098 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1099             streamsize __c = this->rdbuf()->in_avail();
1100             switch (__c)
1101             {
1102             case -1:
1103                 __state |= ios_base::eofbit;
1104                 break;
1105             case 0:
1106                 break;
1107             default:
1108                 __n = _VSTD::min(__c, __n);
1109                 __gc_ = this->rdbuf()->sgetn(__s, __n);
1110                 if (__gc_ != __n)
1111                     __state |= ios_base::failbit | ios_base::eofbit;
1112                 break;
1113             }
1114 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1115         }
1116         catch (...)
1117         {
1118             __state |= ios_base::badbit;
1119             this->__setstate_nothrow(__state);
1120             if (this->exceptions() & ios_base::badbit)
1121             {
1122                 throw;
1123             }
1124         }
1125 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1126     }
1127     else
1128     {
1129         __state |= ios_base::failbit;
1130     }
1131     this->setstate(__state);
1132     return __gc_;
1135 template<class _CharT, class _Traits>
1136 basic_istream<_CharT, _Traits>&
1137 basic_istream<_CharT, _Traits>::putback(char_type __c)
1139     ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1140     __gc_ = 0;
1141     this->clear(__state);
1142     sentry __sen(*this, true);
1143     if (__sen)
1144     {
1145 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1146         try
1147         {
1148 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1149             if (this->rdbuf() == nullptr || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1150                 __state |= ios_base::badbit;
1151 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1152         }
1153         catch (...)
1154         {
1155             __state |= ios_base::badbit;
1156             this->__setstate_nothrow(__state);
1157             if (this->exceptions() & ios_base::badbit)
1158             {
1159                 throw;
1160             }
1161         }
1162 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1163     }
1164     else
1165     {
1166         __state |= ios_base::failbit;
1167     }
1168     this->setstate(__state);
1169     return *this;
1172 template<class _CharT, class _Traits>
1173 basic_istream<_CharT, _Traits>&
1174 basic_istream<_CharT, _Traits>::unget()
1176     ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1177     __gc_ = 0;
1178     this->clear(__state);
1179     sentry __sen(*this, true);
1180     if (__sen)
1181     {
1182 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1183         try
1184         {
1185 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1186             if (this->rdbuf() == nullptr || this->rdbuf()->sungetc() == traits_type::eof())
1187                 __state |= ios_base::badbit;
1188 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1189         }
1190         catch (...)
1191         {
1192             __state |= ios_base::badbit;
1193             this->__setstate_nothrow(__state);
1194             if (this->exceptions() & ios_base::badbit)
1195             {
1196                 throw;
1197             }
1198         }
1199 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1200     }
1201     else
1202     {
1203         __state |= ios_base::failbit;
1204     }
1205     this->setstate(__state);
1206     return *this;
1209 template<class _CharT, class _Traits>
1211 basic_istream<_CharT, _Traits>::sync()
1213     ios_base::iostate __state = ios_base::goodbit;
1214     int __r = 0;
1215     sentry __sen(*this, true);
1216     if (__sen)
1217     {
1218 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1219         try
1220         {
1221 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1222             if (this->rdbuf() == nullptr)
1223                 return -1;
1224             if (this->rdbuf()->pubsync() == -1)
1225             {
1226                 __state |= ios_base::badbit;
1227                 return -1;
1228             }
1229 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1230         }
1231         catch (...)
1232         {
1233             __state |= ios_base::badbit;
1234             this->__setstate_nothrow(__state);
1235             if (this->exceptions() & ios_base::badbit)
1236             {
1237                 throw;
1238             }
1239         }
1240 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1241         this->setstate(__state);
1242     }
1243     return __r;
1246 template<class _CharT, class _Traits>
1247 typename basic_istream<_CharT, _Traits>::pos_type
1248 basic_istream<_CharT, _Traits>::tellg()
1250     ios_base::iostate __state = ios_base::goodbit;
1251     pos_type __r(-1);
1252     sentry __sen(*this, true);
1253     if (__sen)
1254     {
1255 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1256         try
1257         {
1258 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1259         __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1260 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1261         }
1262         catch (...)
1263         {
1264             __state |= ios_base::badbit;
1265             this->__setstate_nothrow(__state);
1266             if (this->exceptions() & ios_base::badbit)
1267             {
1268                 throw;
1269             }
1270         }
1271 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1272         this->setstate(__state);
1273     }
1274     return __r;
1277 template<class _CharT, class _Traits>
1278 basic_istream<_CharT, _Traits>&
1279 basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1281     ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1282     this->clear(__state);
1283     sentry __sen(*this, true);
1284     if (__sen)
1285     {
1286 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1287         try
1288         {
1289 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1290             if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1291                 __state |= ios_base::failbit;
1292 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1293         }
1294         catch (...)
1295         {
1296             __state |= ios_base::badbit;
1297             this->__setstate_nothrow(__state);
1298             if (this->exceptions() & ios_base::badbit)
1299             {
1300                 throw;
1301             }
1302         }
1303 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1304         this->setstate(__state);
1305     }
1306     return *this;
1309 template<class _CharT, class _Traits>
1310 basic_istream<_CharT, _Traits>&
1311 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1313     ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1314     this->clear(__state);
1315     sentry __sen(*this, true);
1316     if (__sen)
1317     {
1318 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1319         try
1320         {
1321 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1322             if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1323                 __state |= ios_base::failbit;
1324 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1325         }
1326         catch (...)
1327         {
1328             __state |= ios_base::badbit;
1329             this->__setstate_nothrow(__state);
1330             if (this->exceptions() & ios_base::badbit)
1331             {
1332                 throw;
1333             }
1334         }
1335 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1336         this->setstate(__state);
1337     }
1338     return *this;
1341 template <class _CharT, class _Traits>
1342 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1343 ws(basic_istream<_CharT, _Traits>& __is)
1345     ios_base::iostate __state = ios_base::goodbit;
1346     typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1347     if (__sen)
1348     {
1349 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1350         try
1351         {
1352 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1353             const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1354             while (true)
1355             {
1356                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1357                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1358                 {
1359                    __state |= ios_base::eofbit;
1360                    break;
1361                 }
1362                 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1363                     break;
1364                 __is.rdbuf()->sbumpc();
1365             }
1366 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1367         }
1368         catch (...)
1369         {
1370             __state |= ios_base::badbit;
1371             __is.__setstate_nothrow(__state);
1372             if (__is.exceptions() & ios_base::badbit)
1373             {
1374                 throw;
1375             }
1376         }
1377 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
1378         __is.setstate(__state);
1379     }
1380     return __is;
1383 template <class _Stream, class _Tp, class = void>
1384 struct __is_istreamable : false_type { };
1386 template <class _Stream, class _Tp>
1387 struct __is_istreamable<_Stream, _Tp, decltype(
1388     std::declval<_Stream>() >> std::declval<_Tp>(), void()
1389 )> : true_type { };
1391 template <class _Stream, class _Tp, __enable_if_t<
1392     _And<is_base_of<ios_base, _Stream>, __is_istreamable<_Stream&, _Tp&&> >::value, int> = 0>
1393 _LIBCPP_INLINE_VISIBILITY
1394 _Stream&& operator>>(_Stream&& __is, _Tp&& __x)
1396     __is >> _VSTD::forward<_Tp>(__x);
1397     return _VSTD::move(__is);
1400 template <class _CharT, class _Traits>
1401 class _LIBCPP_TEMPLATE_VIS basic_iostream
1402     : public basic_istream<_CharT, _Traits>,
1403       public basic_ostream<_CharT, _Traits>
1405 public:
1406     // types:
1407     typedef _CharT                         char_type;
1408     typedef _Traits                        traits_type;
1409     typedef typename traits_type::int_type int_type;
1410     typedef typename traits_type::pos_type pos_type;
1411     typedef typename traits_type::off_type off_type;
1413     // constructor/destructor
1414     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
1415     explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1416       : basic_istream<_CharT, _Traits>(__sb)
1417     {}
1419     ~basic_iostream() override;
1420 protected:
1421     inline _LIBCPP_INLINE_VISIBILITY
1422     basic_iostream(basic_iostream&& __rhs);
1424     // assign/swap
1425     inline _LIBCPP_INLINE_VISIBILITY
1426     basic_iostream& operator=(basic_iostream&& __rhs);
1428     inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
1429     void swap(basic_iostream& __rhs)
1430     { basic_istream<char_type, traits_type>::swap(__rhs); }
1433 template <class _CharT, class _Traits>
1434 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1435     : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
1439 template <class _CharT, class _Traits>
1440 basic_iostream<_CharT, _Traits>&
1441 basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1443     swap(__rhs);
1444     return *this;
1447 template <class _CharT, class _Traits>
1448 basic_iostream<_CharT, _Traits>::~basic_iostream()
1452 template<class _CharT, class _Traits, class _Allocator>
1453 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1454 operator>>(basic_istream<_CharT, _Traits>& __is,
1455            basic_string<_CharT, _Traits, _Allocator>& __str)
1457     ios_base::iostate __state = ios_base::goodbit;
1458     typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1459     if (__sen)
1460     {
1461 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1462         try
1463         {
1464 #endif
1465             __str.clear();
1466             streamsize __n = __is.width();
1467             if (__n <= 0)
1468                 __n = __str.max_size();
1469             if (__n <= 0)
1470                 __n = numeric_limits<streamsize>::max();
1471             streamsize __c = 0;
1472             const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1473             while (__c < __n)
1474             {
1475                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1476                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1477                 {
1478                    __state |= ios_base::eofbit;
1479                    break;
1480                 }
1481                 _CharT __ch = _Traits::to_char_type(__i);
1482                 if (__ct.is(__ct.space, __ch))
1483                     break;
1484                 __str.push_back(__ch);
1485                 ++__c;
1486                  __is.rdbuf()->sbumpc();
1487             }
1488             __is.width(0);
1489             if (__c == 0)
1490                __state |= ios_base::failbit;
1491 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1492         }
1493         catch (...)
1494         {
1495             __state |= ios_base::badbit;
1496             __is.__setstate_nothrow(__state);
1497             if (__is.exceptions() & ios_base::badbit)
1498             {
1499                 throw;
1500             }
1501         }
1502 #endif
1503         __is.setstate(__state);
1504     }
1505     return __is;
1508 template<class _CharT, class _Traits, class _Allocator>
1509 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1510 getline(basic_istream<_CharT, _Traits>& __is,
1511         basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1513     ios_base::iostate __state = ios_base::goodbit;
1514     typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1515     if (__sen)
1516     {
1517 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1518         try
1519         {
1520 #endif
1521             __str.clear();
1522             streamsize __extr = 0;
1523             while (true)
1524             {
1525                 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1526                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1527                 {
1528                    __state |= ios_base::eofbit;
1529                    break;
1530                 }
1531                 ++__extr;
1532                 _CharT __ch = _Traits::to_char_type(__i);
1533                 if (_Traits::eq(__ch, __dlm))
1534                     break;
1535                 __str.push_back(__ch);
1536                 if (__str.size() == __str.max_size())
1537                 {
1538                     __state |= ios_base::failbit;
1539                     break;
1540                 }
1541             }
1542             if (__extr == 0)
1543                __state |= ios_base::failbit;
1544 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1545         }
1546         catch (...)
1547         {
1548             __state |= ios_base::badbit;
1549             __is.__setstate_nothrow(__state);
1550             if (__is.exceptions() & ios_base::badbit)
1551             {
1552                 throw;
1553             }
1554         }
1555 #endif
1556         __is.setstate(__state);
1557     }
1558     return __is;
1561 template<class _CharT, class _Traits, class _Allocator>
1562 inline _LIBCPP_INLINE_VISIBILITY
1563 basic_istream<_CharT, _Traits>&
1564 getline(basic_istream<_CharT, _Traits>& __is,
1565         basic_string<_CharT, _Traits, _Allocator>& __str)
1567     return std::getline(__is, __str, __is.widen('\n'));
1570 template<class _CharT, class _Traits, class _Allocator>
1571 inline _LIBCPP_INLINE_VISIBILITY
1572 basic_istream<_CharT, _Traits>&
1573 getline(basic_istream<_CharT, _Traits>&& __is,
1574         basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1576     return std::getline(__is, __str, __dlm);
1579 template<class _CharT, class _Traits, class _Allocator>
1580 inline _LIBCPP_INLINE_VISIBILITY
1581 basic_istream<_CharT, _Traits>&
1582 getline(basic_istream<_CharT, _Traits>&& __is,
1583         basic_string<_CharT, _Traits, _Allocator>& __str)
1585     return std::getline(__is, __str, __is.widen('\n'));
1588 template <class _CharT, class _Traits, size_t _Size>
1589 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1590 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1592     ios_base::iostate __state = ios_base::goodbit;
1593     typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1594     if (__sen)
1595     {
1596 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1597         try
1598         {
1599 #endif
1600             basic_string<_CharT, _Traits> __str;
1601             const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1602             size_t __c = 0;
1603             _CharT __zero = __ct.widen('0');
1604             _CharT __one = __ct.widen('1');
1605             while (__c != _Size)
1606             {
1607                 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1608                 if (_Traits::eq_int_type(__i, _Traits::eof()))
1609                 {
1610                    __state |= ios_base::eofbit;
1611                    break;
1612                 }
1613                 _CharT __ch = _Traits::to_char_type(__i);
1614                 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1615                     break;
1616                 __str.push_back(__ch);
1617                 ++__c;
1618                  __is.rdbuf()->sbumpc();
1619             }
1620             __x = bitset<_Size>(__str);
1621             if (_Size > 0 && __c == 0)
1622                __state |= ios_base::failbit;
1623 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1624         }
1625         catch (...)
1626         {
1627             __state |= ios_base::badbit;
1628             __is.__setstate_nothrow(__state);
1629             if (__is.exceptions() & ios_base::badbit)
1630             {
1631                 throw;
1632             }
1633         }
1634 #endif
1635         __is.setstate(__state);
1636     }
1637     return __is;
1640 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>;
1641 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1642 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>;
1643 #endif
1644 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>;
1646 _LIBCPP_END_NAMESPACE_STD
1648 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1649 #  include <concepts>
1650 #  include <iosfwd>
1651 #  include <type_traits>
1652 #endif
1654 _LIBCPP_POP_MACROS
1656 #endif // _LIBCPP_ISTREAM