1428 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_ISTREAM11#define _LIBCPP_ISTREAM12 13/*14 istream synopsis15 16template <class charT, class traits = char_traits<charT> >17class basic_istream18 : virtual public basic_ios<charT,traits>19{20public: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;27 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();32 33 // 27.7.1.1.2 Assign/swap:34 basic_istream& operator=(basic_istream&& rhs);35 void swap(basic_istream& rhs);36 37 // 27.7.1.1.3 Prefix/suffix:38 class sentry;39 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);59 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);68 69 basic_istream& getline(char_type* s, streamsize n);70 basic_istream& getline(char_type* s, streamsize n, char_type delim);71 72 basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());73 basic_istream& ignore(streamsize n, char_type delim); // Since C++26, implemented as a DR74 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 void115 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/destructor134 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);135 basic_iostream(basic_iostream&& rhs);136 virtual ~basic_iostream();137 138 // assign/swap139 basic_iostream& operator=(basic_iostream&& rhs);140 void swap(basic_iostream& rhs);141};142 143template <class charT, class traits>144 void145 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 154// rvalue stream extraction155template <class Stream, class T>156 Stream&& operator>>(Stream&& is, T&& x);157 158} // std159 160*/161 162#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)163# include <__cxx03/istream>164#else165# include <__config>166 167# if _LIBCPP_HAS_LOCALIZATION168 169# include <__fwd/istream.h>170# include <__iterator/istreambuf_iterator.h>171# include <__locale_dir/num.h>172# include <__ostream/basic_ostream.h>173# include <__type_traits/conjunction.h>174# include <__type_traits/enable_if.h>175# include <__type_traits/is_base_of.h>176# include <__type_traits/is_same.h>177# include <__type_traits/make_unsigned.h>178# include <__utility/declval.h>179# include <__utility/forward.h>180# include <bitset>181# include <ios>182# include <streambuf>183# include <version>184 185# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)186# pragma GCC system_header187# endif188 189_LIBCPP_PUSH_MACROS190# include <__undef_macros>191 192_LIBCPP_BEGIN_NAMESPACE_STD193 194template <class _CharT, class _Traits>195class basic_istream : virtual public basic_ios<_CharT, _Traits> {196 streamsize __gc_;197 198 _LIBCPP_HIDE_FROM_ABI void __inc_gcount() {199 if (__gc_ < numeric_limits<streamsize>::max())200 ++__gc_;201 }202 203public:204 // types (inherited from basic_ios (27.5.4)):205 typedef _CharT char_type;206 typedef _Traits traits_type;207 typedef typename traits_type::int_type int_type;208 typedef typename traits_type::pos_type pos_type;209 typedef typename traits_type::off_type off_type;210 211 // 27.7.1.1.1 Constructor/destructor:212 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb)213 : __gc_(0) {214 this->init(__sb);215 }216 ~basic_istream() override;217 218protected:219 inline _LIBCPP_HIDE_FROM_ABI basic_istream(basic_istream&& __rhs);220 221 // 27.7.1.1.2 Assign/swap:222 inline _LIBCPP_HIDE_FROM_ABI basic_istream& operator=(basic_istream&& __rhs);223 224 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_istream& __rhs) {225 std::swap(__gc_, __rhs.__gc_);226 basic_ios<char_type, traits_type>::swap(__rhs);227 }228 229public:230 basic_istream(const basic_istream& __rhs) = delete;231 basic_istream& operator=(const basic_istream& __rhs) = delete;232 233 // 27.7.1.1.3 Prefix/suffix:234 class sentry;235 236 // 27.7.1.2 Formatted input:237 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) {238 return __pf(*this);239 }240 241 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream&242 operator>>(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) {243 __pf(*this);244 return *this;245 }246 247 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) {248 __pf(*this);249 return *this;250 }251 252 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);253 basic_istream& operator>>(bool& __n);254 basic_istream& operator>>(short& __n);255 basic_istream& operator>>(unsigned short& __n);256 basic_istream& operator>>(int& __n);257 basic_istream& operator>>(unsigned int& __n);258 basic_istream& operator>>(long& __n);259 basic_istream& operator>>(unsigned long& __n);260 basic_istream& operator>>(long long& __n);261 basic_istream& operator>>(unsigned long long& __n);262 basic_istream& operator>>(float& __f);263 basic_istream& operator>>(double& __f);264 basic_istream& operator>>(long double& __f);265 basic_istream& operator>>(void*& __p);266 267 // 27.7.1.3 Unformatted input:268 _LIBCPP_HIDE_FROM_ABI streamsize gcount() const { return __gc_; }269 int_type get();270 271 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type& __c) {272 int_type __ch = get();273 if (__ch != traits_type::eof())274 __c = traits_type::to_char_type(__ch);275 return *this;276 }277 278 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type* __s, streamsize __n) {279 return get(__s, __n, this->widen('\n'));280 }281 282 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);283 284 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) {285 return get(__sb, this->widen('\n'));286 }287 288 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);289 290 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& getline(char_type* __s, streamsize __n) {291 return getline(__s, __n, this->widen('\n'));292 }293 294 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);295 296 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());297 template <class _Tp = char_type, __enable_if_t<is_same<_Tp, char>::value, int> = 0>298 _LIBCPP_HIDE_FROM_ABI basic_istream& ignore(streamsize __n, char_type __delim) {299 return ignore(__n, traits_type::to_int_type(__delim));300 }301 int_type peek();302 basic_istream& read(char_type* __s, streamsize __n);303 streamsize readsome(char_type* __s, streamsize __n);304 305 basic_istream& putback(char_type __c);306 basic_istream& unget();307 int sync();308 309 pos_type tellg();310 basic_istream& seekg(pos_type __pos);311 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);312};313 314template <class _CharT, class _Traits>315class basic_istream<_CharT, _Traits>::sentry {316 bool __ok_;317 318public:319 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);320 // ~sentry() = default;321 322 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }323 324 sentry(const sentry&) = delete;325 sentry& operator=(const sentry&) = delete;326};327 328template <class _CharT, class _Traits>329basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws) : __ok_(false) {330 if (__is.good()) {331 if (__is.tie())332 __is.tie()->flush();333 if (!__noskipws && (__is.flags() & ios_base::skipws)) {334 typedef istreambuf_iterator<_CharT, _Traits> _Ip;335 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());336 _Ip __i(__is);337 _Ip __eof;338 for (; __i != __eof; ++__i)339 if (!__ct.is(__ct.space, *__i))340 break;341 if (__i == __eof)342 __is.setstate(ios_base::failbit | ios_base::eofbit);343 }344 __ok_ = __is.good();345 } else346 __is.setstate(ios_base::failbit);347}348 349template <class _CharT, class _Traits>350basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) {351 __rhs.__gc_ = 0;352 this->move(__rhs);353}354 355template <class _CharT, class _Traits>356basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) {357 swap(__rhs);358 return *this;359}360 361template <class _CharT, class _Traits>362basic_istream<_CharT, _Traits>::~basic_istream() {}363 364template <class _Tp, class _CharT, class _Traits>365_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&366__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {367 ios_base::iostate __state = ios_base::goodbit;368 typename basic_istream<_CharT, _Traits>::sentry __s(__is);369 if (__s) {370# if _LIBCPP_HAS_EXCEPTIONS371 try {372# endif // _LIBCPP_HAS_EXCEPTIONS373 typedef istreambuf_iterator<_CharT, _Traits> _Ip;374 typedef num_get<_CharT, _Ip> _Fp;375 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);376# if _LIBCPP_HAS_EXCEPTIONS377 } catch (...) {378 __state |= ios_base::badbit;379 __is.__setstate_nothrow(__state);380 if (__is.exceptions() & ios_base::badbit) {381 throw;382 }383 }384# endif385 __is.setstate(__state);386 }387 return __is;388}389 390template <class _CharT, class _Traits>391basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) {392 return std::__input_arithmetic<unsigned short>(*this, __n);393}394 395template <class _CharT, class _Traits>396basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) {397 return std::__input_arithmetic<unsigned int>(*this, __n);398}399 400template <class _CharT, class _Traits>401basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long& __n) {402 return std::__input_arithmetic<long>(*this, __n);403}404 405template <class _CharT, class _Traits>406basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) {407 return std::__input_arithmetic<unsigned long>(*this, __n);408}409 410template <class _CharT, class _Traits>411basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long long& __n) {412 return std::__input_arithmetic<long long>(*this, __n);413}414 415template <class _CharT, class _Traits>416basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) {417 return std::__input_arithmetic<unsigned long long>(*this, __n);418}419 420template <class _CharT, class _Traits>421basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(float& __n) {422 return std::__input_arithmetic<float>(*this, __n);423}424 425template <class _CharT, class _Traits>426basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(double& __n) {427 return std::__input_arithmetic<double>(*this, __n);428}429 430template <class _CharT, class _Traits>431basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long double& __n) {432 return std::__input_arithmetic<long double>(*this, __n);433}434 435template <class _CharT, class _Traits>436basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(bool& __n) {437 return std::__input_arithmetic<bool>(*this, __n);438}439 440template <class _CharT, class _Traits>441basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) {442 return std::__input_arithmetic<void*>(*this, __n);443}444 445template <class _Tp, class _CharT, class _Traits>446_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&447__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {448 ios_base::iostate __state = ios_base::goodbit;449 typename basic_istream<_CharT, _Traits>::sentry __s(__is);450 if (__s) {451# if _LIBCPP_HAS_EXCEPTIONS452 try {453# endif // _LIBCPP_HAS_EXCEPTIONS454 typedef istreambuf_iterator<_CharT, _Traits> _Ip;455 typedef num_get<_CharT, _Ip> _Fp;456 long __temp;457 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp);458 if (__temp < numeric_limits<_Tp>::min()) {459 __state |= ios_base::failbit;460 __n = numeric_limits<_Tp>::min();461 } else if (__temp > numeric_limits<_Tp>::max()) {462 __state |= ios_base::failbit;463 __n = numeric_limits<_Tp>::max();464 } else {465 __n = static_cast<_Tp>(__temp);466 }467# if _LIBCPP_HAS_EXCEPTIONS468 } catch (...) {469 __state |= ios_base::badbit;470 __is.__setstate_nothrow(__state);471 if (__is.exceptions() & ios_base::badbit) {472 throw;473 }474 }475# endif // _LIBCPP_HAS_EXCEPTIONS476 __is.setstate(__state);477 }478 return __is;479}480 481template <class _CharT, class _Traits>482basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(short& __n) {483 return std::__input_arithmetic_with_numeric_limits<short>(*this, __n);484}485 486template <class _CharT, class _Traits>487basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(int& __n) {488 return std::__input_arithmetic_with_numeric_limits<int>(*this, __n);489}490 491template <class _CharT, class _Traits>492_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&493__input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) {494 ios_base::iostate __state = ios_base::goodbit;495 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);496 if (__sen) {497# if _LIBCPP_HAS_EXCEPTIONS498 try {499# endif500 _CharT* __s = __p;501 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());502 while (__s != __p + (__n - 1)) {503 typename _Traits::int_type __i = __is.rdbuf()->sgetc();504 if (_Traits::eq_int_type(__i, _Traits::eof())) {505 __state |= ios_base::eofbit;506 break;507 }508 _CharT __ch = _Traits::to_char_type(__i);509 if (__ct.is(__ct.space, __ch))510 break;511 *__s++ = __ch;512 __is.rdbuf()->sbumpc();513 }514 *__s = _CharT();515 __is.width(0);516 if (__s == __p)517 __state |= ios_base::failbit;518# if _LIBCPP_HAS_EXCEPTIONS519 } catch (...) {520 __state |= ios_base::badbit;521 __is.__setstate_nothrow(__state);522 if (__is.exceptions() & ios_base::badbit) {523 throw;524 }525 }526# endif527 __is.setstate(__state);528 }529 return __is;530}531 532# if _LIBCPP_STD_VER >= 20533 534template <class _CharT, class _Traits, size_t _Np>535inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&536operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np]) {537 size_t __n = _Np;538 if (__is.width() > 0)539 __n = std::min(size_t(__is.width()), _Np);540 return std::__input_c_string(__is, __buf, __n);541}542 543template <class _Traits, size_t _Np>544inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&545operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np]) {546 return __is >> (char(&)[_Np])__buf;547}548 549template <class _Traits, size_t _Np>550inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&551operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np]) {552 return __is >> (char(&)[_Np])__buf;553}554 555# else556 557template <class _CharT, class _Traits>558inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&559operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) {560 streamsize __n = __is.width();561 if (__n <= 0)562 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;563 return std::__input_c_string(__is, __s, size_t(__n));564}565 566template <class _Traits>567inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&568operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) {569 return __is >> (char*)__s;570}571 572template <class _Traits>573inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&574operator>>(basic_istream<char, _Traits>& __is, signed char* __s) {575 return __is >> (char*)__s;576}577 578# endif // _LIBCPP_STD_VER >= 20579 580template <class _CharT, class _Traits>581_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) {582 ios_base::iostate __state = ios_base::goodbit;583 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);584 if (__sen) {585# if _LIBCPP_HAS_EXCEPTIONS586 try {587# endif588 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();589 if (_Traits::eq_int_type(__i, _Traits::eof()))590 __state |= ios_base::eofbit | ios_base::failbit;591 else592 __c = _Traits::to_char_type(__i);593# if _LIBCPP_HAS_EXCEPTIONS594 } catch (...) {595 __state |= ios_base::badbit;596 __is.__setstate_nothrow(__state);597 if (__is.exceptions() & ios_base::badbit) {598 throw;599 }600 }601# endif602 __is.setstate(__state);603 }604 return __is;605}606 607template <class _Traits>608inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&609operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) {610 return __is >> (char&)__c;611}612 613template <class _Traits>614inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&615operator>>(basic_istream<char, _Traits>& __is, signed char& __c) {616 return __is >> (char&)__c;617}618 619template <class _CharT, class _Traits>620basic_istream<_CharT, _Traits>&621basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) {622 ios_base::iostate __state = ios_base::goodbit;623 __gc_ = 0;624 sentry __s(*this, true);625 if (__s) {626 if (__sb) {627# if _LIBCPP_HAS_EXCEPTIONS628 try {629# endif // _LIBCPP_HAS_EXCEPTIONS630 while (true) {631 typename traits_type::int_type __i = this->rdbuf()->sgetc();632 if (traits_type::eq_int_type(__i, _Traits::eof())) {633 __state |= ios_base::eofbit;634 break;635 }636 if (traits_type::eq_int_type(__sb->sputc(traits_type::to_char_type(__i)), traits_type::eof()))637 break;638 __inc_gcount();639 this->rdbuf()->sbumpc();640 }641 if (__gc_ == 0)642 __state |= ios_base::failbit;643# if _LIBCPP_HAS_EXCEPTIONS644 } catch (...) {645 __state |= ios_base::badbit;646 if (__gc_ == 0)647 __state |= ios_base::failbit;648 649 this->__setstate_nothrow(__state);650 if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit) {651 throw;652 }653 }654# endif // _LIBCPP_HAS_EXCEPTIONS655 } else {656 __state |= ios_base::failbit;657 }658 this->setstate(__state);659 }660 return *this;661}662 663template <class _CharT, class _Traits>664typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get() {665 ios_base::iostate __state = ios_base::goodbit;666 __gc_ = 0;667 int_type __r = traits_type::eof();668 sentry __s(*this, true);669 if (__s) {670# if _LIBCPP_HAS_EXCEPTIONS671 try {672# endif673 __r = this->rdbuf()->sbumpc();674 if (traits_type::eq_int_type(__r, traits_type::eof()))675 __state |= ios_base::failbit | ios_base::eofbit;676 else677 __gc_ = 1;678# if _LIBCPP_HAS_EXCEPTIONS679 } catch (...) {680 this->__setstate_nothrow(this->rdstate() | ios_base::badbit);681 if (this->exceptions() & ios_base::badbit) {682 throw;683 }684 }685# endif686 this->setstate(__state);687 }688 return __r;689}690 691template <class _CharT, class _Traits>692basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) {693 ios_base::iostate __state = ios_base::goodbit;694 __gc_ = 0;695 sentry __sen(*this, true);696 if (__sen) {697 if (__n > 0) {698# if _LIBCPP_HAS_EXCEPTIONS699 try {700# endif701 while (__gc_ < __n - 1) {702 int_type __i = this->rdbuf()->sgetc();703 if (traits_type::eq_int_type(__i, traits_type::eof())) {704 __state |= ios_base::eofbit;705 break;706 }707 char_type __ch = traits_type::to_char_type(__i);708 if (traits_type::eq(__ch, __dlm))709 break;710 *__s++ = __ch;711 __inc_gcount();712 this->rdbuf()->sbumpc();713 }714 if (__gc_ == 0)715 __state |= ios_base::failbit;716# if _LIBCPP_HAS_EXCEPTIONS717 } catch (...) {718 __state |= ios_base::badbit;719 this->__setstate_nothrow(__state);720 if (this->exceptions() & ios_base::badbit) {721 if (__n > 0)722 *__s = char_type();723 throw;724 }725 }726# endif727 } else {728 __state |= ios_base::failbit;729 }730 731 if (__n > 0)732 *__s = char_type();733 this->setstate(__state);734 }735 if (__n > 0)736 *__s = char_type();737 return *this;738}739 740template <class _CharT, class _Traits>741basic_istream<_CharT, _Traits>&742basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm) {743 ios_base::iostate __state = ios_base::goodbit;744 __gc_ = 0;745 sentry __sen(*this, true);746 if (__sen) {747# if _LIBCPP_HAS_EXCEPTIONS748 try {749# endif // _LIBCPP_HAS_EXCEPTIONS750 while (true) {751 typename traits_type::int_type __i = this->rdbuf()->sgetc();752 if (traits_type::eq_int_type(__i, traits_type::eof())) {753 __state |= ios_base::eofbit;754 break;755 }756 char_type __ch = traits_type::to_char_type(__i);757 if (traits_type::eq(__ch, __dlm))758 break;759 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))760 break;761 __inc_gcount();762 this->rdbuf()->sbumpc();763 }764# if _LIBCPP_HAS_EXCEPTIONS765 } catch (...) {766 __state |= ios_base::badbit;767 // according to the spec, exceptions here are caught but not rethrown768 }769# endif // _LIBCPP_HAS_EXCEPTIONS770 if (__gc_ == 0)771 __state |= ios_base::failbit;772 this->setstate(__state);773 }774 return *this;775}776 777template <class _CharT, class _Traits>778basic_istream<_CharT, _Traits>&779basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) {780 ios_base::iostate __state = ios_base::goodbit;781 __gc_ = 0;782 sentry __sen(*this, true);783 if (__sen) {784# if _LIBCPP_HAS_EXCEPTIONS785 try {786# endif // _LIBCPP_HAS_EXCEPTIONS787 while (true) {788 typename traits_type::int_type __i = this->rdbuf()->sgetc();789 if (traits_type::eq_int_type(__i, traits_type::eof())) {790 __state |= ios_base::eofbit;791 break;792 }793 char_type __ch = traits_type::to_char_type(__i);794 if (traits_type::eq(__ch, __dlm)) {795 this->rdbuf()->sbumpc();796 __inc_gcount();797 break;798 }799 if (__gc_ >= __n - 1) {800 __state |= ios_base::failbit;801 break;802 }803 *__s++ = __ch;804 this->rdbuf()->sbumpc();805 __inc_gcount();806 }807# if _LIBCPP_HAS_EXCEPTIONS808 } catch (...) {809 __state |= ios_base::badbit;810 this->__setstate_nothrow(__state);811 if (this->exceptions() & ios_base::badbit) {812 if (__n > 0)813 *__s = char_type();814 if (__gc_ == 0)815 __state |= ios_base::failbit;816 throw;817 }818 }819# endif // _LIBCPP_HAS_EXCEPTIONS820 }821 if (__n > 0)822 *__s = char_type();823 if (__gc_ == 0)824 __state |= ios_base::failbit;825 this->setstate(__state);826 return *this;827}828 829template <class _CharT, class _Traits>830basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) {831 ios_base::iostate __state = ios_base::goodbit;832 __gc_ = 0;833 sentry __sen(*this, true);834 if (__sen) {835# if _LIBCPP_HAS_EXCEPTIONS836 try {837# endif // _LIBCPP_HAS_EXCEPTIONS838 if (__n == numeric_limits<streamsize>::max()) {839 while (true) {840 typename traits_type::int_type __i = this->rdbuf()->sbumpc();841 if (traits_type::eq_int_type(__i, traits_type::eof())) {842 __state |= ios_base::eofbit;843 break;844 }845 __inc_gcount();846 if (traits_type::eq_int_type(__i, __dlm))847 break;848 }849 } else {850 while (__gc_ < __n) {851 typename traits_type::int_type __i = this->rdbuf()->sbumpc();852 if (traits_type::eq_int_type(__i, traits_type::eof())) {853 __state |= ios_base::eofbit;854 break;855 }856 __inc_gcount();857 if (traits_type::eq_int_type(__i, __dlm))858 break;859 }860 }861# if _LIBCPP_HAS_EXCEPTIONS862 } catch (...) {863 __state |= ios_base::badbit;864 this->__setstate_nothrow(__state);865 if (this->exceptions() & ios_base::badbit) {866 throw;867 }868 }869# endif // _LIBCPP_HAS_EXCEPTIONS870 this->setstate(__state);871 }872 return *this;873}874 875template <class _CharT, class _Traits>876typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek() {877 ios_base::iostate __state = ios_base::goodbit;878 __gc_ = 0;879 int_type __r = traits_type::eof();880 sentry __sen(*this, true);881 if (__sen) {882# if _LIBCPP_HAS_EXCEPTIONS883 try {884# endif // _LIBCPP_HAS_EXCEPTIONS885 __r = this->rdbuf()->sgetc();886 if (traits_type::eq_int_type(__r, traits_type::eof()))887 __state |= ios_base::eofbit;888# if _LIBCPP_HAS_EXCEPTIONS889 } catch (...) {890 __state |= ios_base::badbit;891 this->__setstate_nothrow(__state);892 if (this->exceptions() & ios_base::badbit) {893 throw;894 }895 }896# endif // _LIBCPP_HAS_EXCEPTIONS897 this->setstate(__state);898 }899 return __r;900}901 902template <class _CharT, class _Traits>903basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) {904 ios_base::iostate __state = ios_base::goodbit;905 __gc_ = 0;906 sentry __sen(*this, true);907 if (__sen) {908# if _LIBCPP_HAS_EXCEPTIONS909 try {910# endif // _LIBCPP_HAS_EXCEPTIONS911 __gc_ = this->rdbuf()->sgetn(__s, __n);912 if (__gc_ != __n)913 __state |= ios_base::failbit | ios_base::eofbit;914# if _LIBCPP_HAS_EXCEPTIONS915 } catch (...) {916 __state |= ios_base::badbit;917 this->__setstate_nothrow(__state);918 if (this->exceptions() & ios_base::badbit) {919 throw;920 }921 }922# endif // _LIBCPP_HAS_EXCEPTIONS923 } else {924 __state |= ios_base::failbit;925 }926 this->setstate(__state);927 return *this;928}929 930template <class _CharT, class _Traits>931streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) {932 ios_base::iostate __state = ios_base::goodbit;933 __gc_ = 0;934 sentry __sen(*this, true);935 if (__sen) {936# if _LIBCPP_HAS_EXCEPTIONS937 try {938# endif // _LIBCPP_HAS_EXCEPTIONS939 streamsize __c = this->rdbuf()->in_avail();940 switch (__c) {941 case -1:942 __state |= ios_base::eofbit;943 break;944 case 0:945 break;946 default:947 __n = std::min(__c, __n);948 __gc_ = this->rdbuf()->sgetn(__s, __n);949 if (__gc_ != __n)950 __state |= ios_base::failbit | ios_base::eofbit;951 break;952 }953# if _LIBCPP_HAS_EXCEPTIONS954 } catch (...) {955 __state |= ios_base::badbit;956 this->__setstate_nothrow(__state);957 if (this->exceptions() & ios_base::badbit) {958 throw;959 }960 }961# endif // _LIBCPP_HAS_EXCEPTIONS962 } else {963 __state |= ios_base::failbit;964 }965 this->setstate(__state);966 return __gc_;967}968 969template <class _CharT, class _Traits>970basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_type __c) {971 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;972 __gc_ = 0;973 this->clear(__state);974 sentry __sen(*this, true);975 if (__sen) {976# if _LIBCPP_HAS_EXCEPTIONS977 try {978# endif // _LIBCPP_HAS_EXCEPTIONS979 if (this->rdbuf() == nullptr || this->rdbuf()->sputbackc(__c) == traits_type::eof())980 __state |= ios_base::badbit;981# if _LIBCPP_HAS_EXCEPTIONS982 } catch (...) {983 __state |= ios_base::badbit;984 this->__setstate_nothrow(__state);985 if (this->exceptions() & ios_base::badbit) {986 throw;987 }988 }989# endif // _LIBCPP_HAS_EXCEPTIONS990 } else {991 __state |= ios_base::failbit;992 }993 this->setstate(__state);994 return *this;995}996 997template <class _CharT, class _Traits>998basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {999 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;1000 __gc_ = 0;1001 this->clear(__state);1002 sentry __sen(*this, true);1003 if (__sen) {1004# if _LIBCPP_HAS_EXCEPTIONS1005 try {1006# endif // _LIBCPP_HAS_EXCEPTIONS1007 if (this->rdbuf() == nullptr || this->rdbuf()->sungetc() == traits_type::eof())1008 __state |= ios_base::badbit;1009# if _LIBCPP_HAS_EXCEPTIONS1010 } catch (...) {1011 __state |= ios_base::badbit;1012 this->__setstate_nothrow(__state);1013 if (this->exceptions() & ios_base::badbit) {1014 throw;1015 }1016 }1017# endif // _LIBCPP_HAS_EXCEPTIONS1018 } else {1019 __state |= ios_base::failbit;1020 }1021 this->setstate(__state);1022 return *this;1023}1024 1025template <class _CharT, class _Traits>1026int basic_istream<_CharT, _Traits>::sync() {1027 ios_base::iostate __state = ios_base::goodbit;1028 sentry __sen(*this, true);1029 if (this->rdbuf() == nullptr)1030 return -1;1031 1032 int __r = 0;1033 if (__sen) {1034# if _LIBCPP_HAS_EXCEPTIONS1035 try {1036# endif // _LIBCPP_HAS_EXCEPTIONS1037 if (this->rdbuf()->pubsync() == -1) {1038 __state |= ios_base::badbit;1039 __r = -1;1040 }1041# if _LIBCPP_HAS_EXCEPTIONS1042 } catch (...) {1043 __state |= ios_base::badbit;1044 this->__setstate_nothrow(__state);1045 if (this->exceptions() & ios_base::badbit) {1046 throw;1047 }1048 }1049# endif // _LIBCPP_HAS_EXCEPTIONS1050 this->setstate(__state);1051 }1052 return __r;1053}1054 1055template <class _CharT, class _Traits>1056typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>::tellg() {1057 ios_base::iostate __state = ios_base::goodbit;1058 pos_type __r(-1);1059 sentry __sen(*this, true);1060 if (__sen) {1061# if _LIBCPP_HAS_EXCEPTIONS1062 try {1063# endif // _LIBCPP_HAS_EXCEPTIONS1064 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);1065# if _LIBCPP_HAS_EXCEPTIONS1066 } catch (...) {1067 __state |= ios_base::badbit;1068 this->__setstate_nothrow(__state);1069 if (this->exceptions() & ios_base::badbit) {1070 throw;1071 }1072 }1073# endif // _LIBCPP_HAS_EXCEPTIONS1074 this->setstate(__state);1075 }1076 return __r;1077}1078 1079template <class _CharT, class _Traits>1080basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {1081 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;1082 this->clear(__state);1083 sentry __sen(*this, true);1084 if (__sen) {1085# if _LIBCPP_HAS_EXCEPTIONS1086 try {1087# endif // _LIBCPP_HAS_EXCEPTIONS1088 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))1089 __state |= ios_base::failbit;1090# if _LIBCPP_HAS_EXCEPTIONS1091 } catch (...) {1092 __state |= ios_base::badbit;1093 this->__setstate_nothrow(__state);1094 if (this->exceptions() & ios_base::badbit) {1095 throw;1096 }1097 }1098# endif // _LIBCPP_HAS_EXCEPTIONS1099 this->setstate(__state);1100 }1101 return *this;1102}1103 1104template <class _CharT, class _Traits>1105basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) {1106 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;1107 this->clear(__state);1108 sentry __sen(*this, true);1109 if (__sen) {1110# if _LIBCPP_HAS_EXCEPTIONS1111 try {1112# endif // _LIBCPP_HAS_EXCEPTIONS1113 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))1114 __state |= ios_base::failbit;1115# if _LIBCPP_HAS_EXCEPTIONS1116 } catch (...) {1117 __state |= ios_base::badbit;1118 this->__setstate_nothrow(__state);1119 if (this->exceptions() & ios_base::badbit) {1120 throw;1121 }1122 }1123# endif // _LIBCPP_HAS_EXCEPTIONS1124 this->setstate(__state);1125 }1126 return *this;1127}1128 1129template <class _CharT, class _Traits>1130_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _Traits>& __is) {1131 ios_base::iostate __state = ios_base::goodbit;1132 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);1133 if (__sen) {1134# if _LIBCPP_HAS_EXCEPTIONS1135 try {1136# endif // _LIBCPP_HAS_EXCEPTIONS1137 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());1138 while (true) {1139 typename _Traits::int_type __i = __is.rdbuf()->sgetc();1140 if (_Traits::eq_int_type(__i, _Traits::eof())) {1141 __state |= ios_base::eofbit;1142 break;1143 }1144 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))1145 break;1146 __is.rdbuf()->sbumpc();1147 }1148# if _LIBCPP_HAS_EXCEPTIONS1149 } catch (...) {1150 __state |= ios_base::badbit;1151 __is.__setstate_nothrow(__state);1152 if (__is.exceptions() & ios_base::badbit) {1153 throw;1154 }1155 }1156# endif // _LIBCPP_HAS_EXCEPTIONS1157 __is.setstate(__state);1158 }1159 return __is;1160}1161 1162template <class _Stream, class _Tp, class = void>1163struct __is_istreamable : false_type {};1164 1165template <class _Stream, class _Tp>1166struct __is_istreamable<_Stream, _Tp, decltype(std::declval<_Stream>() >> std::declval<_Tp>(), void())> : true_type {};1167 1168template <class _Stream,1169 class _Tp,1170 __enable_if_t< _And<is_base_of<ios_base, _Stream>, __is_istreamable<_Stream&, _Tp&&> >::value, int> = 0>1171_LIBCPP_HIDE_FROM_ABI _Stream&& operator>>(_Stream&& __is, _Tp&& __x) {1172 __is >> std::forward<_Tp>(__x);1173 return std::move(__is);1174}1175 1176template <class _CharT, class _Traits>1177class basic_iostream : public basic_istream<_CharT, _Traits>, public basic_ostream<_CharT, _Traits> {1178public:1179 // types:1180 typedef _CharT char_type;1181 typedef _Traits traits_type;1182 typedef typename traits_type::int_type int_type;1183 typedef typename traits_type::pos_type pos_type;1184 typedef typename traits_type::off_type off_type;1185 1186 // constructor/destructor1187 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)1188 : basic_istream<_CharT, _Traits>(__sb) {}1189 1190 ~basic_iostream() override;1191 1192protected:1193 inline _LIBCPP_HIDE_FROM_ABI basic_iostream(basic_iostream&& __rhs);1194 1195 // assign/swap1196 inline _LIBCPP_HIDE_FROM_ABI basic_iostream& operator=(basic_iostream&& __rhs);1197 1198 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_iostream& __rhs) {1199 basic_istream<char_type, traits_type>::swap(__rhs);1200 }1201};1202 1203template <class _CharT, class _Traits>1204basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)1205 : basic_istream<_CharT, _Traits>(std::move(__rhs)) {}1206 1207template <class _CharT, class _Traits>1208basic_iostream<_CharT, _Traits>& basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) {1209 swap(__rhs);1210 return *this;1211}1212 1213template <class _CharT, class _Traits>1214basic_iostream<_CharT, _Traits>::~basic_iostream() {}1215 1216template <class _CharT, class _Traits, class _Allocator>1217_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1218operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {1219 ios_base::iostate __state = ios_base::goodbit;1220 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);1221 if (__sen) {1222# if _LIBCPP_HAS_EXCEPTIONS1223 try {1224# endif1225 __str.clear();1226 using _Size = typename basic_string<_CharT, _Traits, _Allocator>::size_type;1227 streamsize const __width = __is.width();1228 _Size const __max_size = __str.max_size();1229 _Size __n;1230 if (__width <= 0) {1231 __n = __max_size;1232 } else {1233 __n = std::__to_unsigned_like(__width) < __max_size ? static_cast<_Size>(__width) : __max_size;1234 }1235 1236 _Size __c = 0;1237 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());1238 while (__c < __n) {1239 typename _Traits::int_type __i = __is.rdbuf()->sgetc();1240 if (_Traits::eq_int_type(__i, _Traits::eof())) {1241 __state |= ios_base::eofbit;1242 break;1243 }1244 _CharT __ch = _Traits::to_char_type(__i);1245 if (__ct.is(__ct.space, __ch))1246 break;1247 __str.push_back(__ch);1248 ++__c;1249 __is.rdbuf()->sbumpc();1250 }1251 __is.width(0);1252 if (__c == 0)1253 __state |= ios_base::failbit;1254# if _LIBCPP_HAS_EXCEPTIONS1255 } catch (...) {1256 __state |= ios_base::badbit;1257 __is.__setstate_nothrow(__state);1258 if (__is.exceptions() & ios_base::badbit) {1259 throw;1260 }1261 }1262# endif1263 __is.setstate(__state);1264 }1265 return __is;1266}1267 1268template <class _CharT, class _Traits, class _Allocator>1269_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1270getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) {1271 ios_base::iostate __state = ios_base::goodbit;1272 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);1273 if (!__sen)1274 return __is;1275# if _LIBCPP_HAS_EXCEPTIONS1276 try {1277# endif1278 __str.clear();1279 1280 auto& __buffer = *__is.rdbuf();1281 1282 auto __next = __buffer.sgetc();1283 for (; !_Traits::eq_int_type(__next, _Traits::eof()); __next = __buffer.sgetc()) {1284 const auto* __first = __buffer.gptr();1285 const auto* __last = __buffer.egptr();1286 _CharT __1buf;1287 1288 if (__first == __last) {1289 __1buf = __next;1290 __first = std::addressof(__1buf);1291 __last = std::addressof(__1buf) + 1;1292 }1293 1294 auto __bump_stream = [&](ptrdiff_t __diff) {1295 if (__first == std::addressof(__1buf)) {1296 _LIBCPP_ASSERT_INTERNAL(__diff == 0 || __diff == 1, "trying to bump stream further than buffer size");1297 if (__diff != 0)1298 __buffer.sbumpc();1299 } else {1300 __buffer.__gbump_ptrdiff(__diff);1301 }1302 };1303 1304 const auto* const __match = _Traits::find(__first, __last - __first, __dlm);1305 if (__match)1306 __last = __match;1307 1308 if (auto __cap = __str.max_size() - __str.size(); __cap > static_cast<size_t>(__last - __first)) {1309 __str.append(__first, __last);1310 __bump_stream(__last - __first);1311 1312 if (__match) {1313 __bump_stream(1); // Remove the matched character1314 break;1315 }1316 } else {1317 __str.append(__first, __cap);1318 __bump_stream(__cap);1319 __state |= ios_base::failbit;1320 break;1321 }1322 }1323 1324 if (_Traits::eq_int_type(__next, _Traits::eof()))1325 __state |= ios_base::eofbit | (__str.empty() ? ios_base::failbit : ios_base::goodbit);1326 1327# if _LIBCPP_HAS_EXCEPTIONS1328 } catch (...) {1329 __state |= ios_base::badbit;1330 __is.__setstate_nothrow(__state);1331 if (__is.exceptions() & ios_base::badbit) {1332 throw;1333 }1334 }1335# endif1336 __is.setstate(__state);1337 return __is;1338}1339 1340template <class _CharT, class _Traits, class _Allocator>1341inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1342getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {1343 return std::getline(__is, __str, __is.widen('\n'));1344}1345 1346template <class _CharT, class _Traits, class _Allocator>1347inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1348getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) {1349 return std::getline(__is, __str, __dlm);1350}1351 1352template <class _CharT, class _Traits, class _Allocator>1353inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1354getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {1355 return std::getline(__is, __str, __is.widen('\n'));1356}1357 1358template <class _CharT, class _Traits, size_t _Size>1359_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&1360operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) {1361 ios_base::iostate __state = ios_base::goodbit;1362 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);1363 if (__sen) {1364# if _LIBCPP_HAS_EXCEPTIONS1365 try {1366# endif1367 basic_string<_CharT, _Traits> __str;1368 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());1369 size_t __c = 0;1370 _CharT __zero = __ct.widen('0');1371 _CharT __one = __ct.widen('1');1372 while (__c != _Size) {1373 typename _Traits::int_type __i = __is.rdbuf()->sgetc();1374 if (_Traits::eq_int_type(__i, _Traits::eof())) {1375 __state |= ios_base::eofbit;1376 break;1377 }1378 _CharT __ch = _Traits::to_char_type(__i);1379 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))1380 break;1381 __str.push_back(__ch);1382 ++__c;1383 __is.rdbuf()->sbumpc();1384 }1385 __x = bitset<_Size>(__str);1386 if (_Size > 0 && __c == 0)1387 __state |= ios_base::failbit;1388# if _LIBCPP_HAS_EXCEPTIONS1389 } catch (...) {1390 __state |= ios_base::badbit;1391 __is.__setstate_nothrow(__state);1392 if (__is.exceptions() & ios_base::badbit) {1393 throw;1394 }1395 }1396# endif1397 __is.setstate(__state);1398 }1399 return __is;1400}1401 1402extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>;1403# if _LIBCPP_HAS_WIDE_CHARACTERS1404extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>;1405# endif1406extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>;1407 1408_LIBCPP_END_NAMESPACE_STD1409 1410_LIBCPP_POP_MACROS1411 1412# endif // _LIBCPP_HAS_LOCALIZATION1413 1414# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 201415# include <concepts>1416# include <iosfwd>1417# include <ostream>1418# include <type_traits>1419# endif1420 1421# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 231422# include <locale>1423# endif1424 1425#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)1426 1427#endif // _LIBCPP_ISTREAM1428