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//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP___CXX03_ISTREAM 11#define _LIBCPP___CXX03_ISTREAM 12 13/* 14 istream synopsis 15 16template <class charT, class traits = char_traits<charT> > 17class basic_istream 18 : 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 int_type peek(); 74 basic_istream& read (char_type* s, streamsize n); 75 streamsize readsome(char_type* s, streamsize n); 76 77 basic_istream& putback(char_type c); 78 basic_istream& unget(); 79 int sync(); 80 81 pos_type tellg(); 82 basic_istream& seekg(pos_type); 83 basic_istream& seekg(off_type, ios_base::seekdir); 84protected: 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); 91}; 92 93// 27.7.1.2.3 character extraction templates: 94template<class charT, class traits> 95 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&); 96 97template<class traits> 98 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&); 99 100template<class traits> 101 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&); 102 103template<class charT, class traits> 104 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*); 105 106template<class traits> 107 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*); 108 109template<class traits> 110 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*); 111 112template <class charT, class traits> 113 void 114 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y); 115 116typedef basic_istream<char> istream; 117typedef basic_istream<wchar_t> wistream; 118 119template <class charT, class traits = char_traits<charT> > 120class basic_iostream : 121 public basic_istream<charT,traits>, 122 public basic_ostream<charT,traits> 123{ 124public: 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; 131 132 // constructor/destructor 133 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb); 134 basic_iostream(basic_iostream&& rhs); 135 virtual ~basic_iostream(); 136 137 // assign/swap 138 basic_iostream& operator=(basic_iostream&& rhs); 139 void swap(basic_iostream& rhs); 140}; 141 142template <class charT, class traits> 143 void 144 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y); 145 146typedef basic_iostream<char> iostream; 147typedef basic_iostream<wchar_t> wiostream; 148 149template <class charT, class traits> 150 basic_istream<charT,traits>& 151 ws(basic_istream<charT,traits>& is); 152 153// rvalue stream extraction 154template <class Stream, class T> 155 Stream&& operator>>(Stream&& is, T&& x); 156 157} // std 158 159*/ 160 161#include <__cxx03/__config> 162#include <__cxx03/__fwd/istream.h> 163#include <__cxx03/__iterator/istreambuf_iterator.h> 164#include <__cxx03/__ostream/basic_ostream.h> 165#include <__cxx03/__type_traits/conjunction.h> 166#include <__cxx03/__type_traits/enable_if.h> 167#include <__cxx03/__type_traits/is_base_of.h> 168#include <__cxx03/__utility/declval.h> 169#include <__cxx03/__utility/forward.h> 170#include <__cxx03/bitset> 171#include <__cxx03/ios> 172#include <__cxx03/locale> 173#include <__cxx03/version> 174 175#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 176# pragma GCC system_header 177#endif 178 179_LIBCPP_PUSH_MACROS 180#include <__cxx03/__undef_macros> 181 182_LIBCPP_BEGIN_NAMESPACE_STD 183 184template <class _CharT, class _Traits> 185class _LIBCPP_TEMPLATE_VIS basic_istream : virtual public basic_ios<_CharT, _Traits> { 186 streamsize __gc_; 187 188 _LIBCPP_HIDE_FROM_ABI void __inc_gcount() { 189 if (__gc_ < numeric_limits<streamsize>::max()) 190 ++__gc_; 191 } 192 193public: 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; 200 201 // 27.7.1.1.1 Constructor/destructor: 202 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) 203 : __gc_(0) { 204 this->init(__sb); 205 } 206 ~basic_istream() override; 207 208protected: 209 inline _LIBCPP_HIDE_FROM_ABI basic_istream(basic_istream&& __rhs); 210 211 // 27.7.1.1.2 Assign/swap: 212 inline _LIBCPP_HIDE_FROM_ABI basic_istream& operator=(basic_istream&& __rhs); 213 214 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_istream& __rhs) { 215 std::swap(__gc_, __rhs.__gc_); 216 basic_ios<char_type, traits_type>::swap(__rhs); 217 } 218 219public: 220 basic_istream(const basic_istream& __rhs) = delete; 221 basic_istream& operator=(const basic_istream& __rhs) = delete; 222 223 // 27.7.1.1.3 Prefix/suffix: 224 class _LIBCPP_TEMPLATE_VIS sentry; 225 226 // 27.7.1.2 Formatted input: 227 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) { 228 return __pf(*this); 229 } 230 231 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& 232 operator>>(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) { 233 __pf(*this); 234 return *this; 235 } 236 237 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) { 238 __pf(*this); 239 return *this; 240 } 241 242 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb); 243 basic_istream& operator>>(bool& __n); 244 basic_istream& operator>>(short& __n); 245 basic_istream& operator>>(unsigned short& __n); 246 basic_istream& operator>>(int& __n); 247 basic_istream& operator>>(unsigned int& __n); 248 basic_istream& operator>>(long& __n); 249 basic_istream& operator>>(unsigned long& __n); 250 basic_istream& operator>>(long long& __n); 251 basic_istream& operator>>(unsigned long long& __n); 252 basic_istream& operator>>(float& __f); 253 basic_istream& operator>>(double& __f); 254 basic_istream& operator>>(long double& __f); 255 basic_istream& operator>>(void*& __p); 256 257 // 27.7.1.3 Unformatted input: 258 _LIBCPP_HIDE_FROM_ABI streamsize gcount() const { return __gc_; } 259 int_type get(); 260 261 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type& __c) { 262 int_type __ch = get(); 263 if (__ch != traits_type::eof()) 264 __c = traits_type::to_char_type(__ch); 265 return *this; 266 } 267 268 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type* __s, streamsize __n) { 269 return get(__s, __n, this->widen('\n')); 270 } 271 272 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); 273 274 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) { 275 return get(__sb, this->widen('\n')); 276 } 277 278 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm); 279 280 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& getline(char_type* __s, streamsize __n) { 281 return getline(__s, __n, this->widen('\n')); 282 } 283 284 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); 285 286 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); 287 int_type peek(); 288 basic_istream& read(char_type* __s, streamsize __n); 289 streamsize readsome(char_type* __s, streamsize __n); 290 291 basic_istream& putback(char_type __c); 292 basic_istream& unget(); 293 int sync(); 294 295 pos_type tellg(); 296 basic_istream& seekg(pos_type __pos); 297 basic_istream& seekg(off_type __off, ios_base::seekdir __dir); 298}; 299 300template <class _CharT, class _Traits> 301class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry { 302 bool __ok_; 303 304public: 305 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); 306 // ~sentry() = default; 307 308 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; } 309 310 sentry(const sentry&) = delete; 311 sentry& operator=(const sentry&) = delete; 312}; 313 314template <class _CharT, class _Traits> 315basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws) : __ok_(false) { 316 if (__is.good()) { 317 if (__is.tie()) 318 __is.tie()->flush(); 319 if (!__noskipws && (__is.flags() & ios_base::skipws)) { 320 typedef istreambuf_iterator<_CharT, _Traits> _Ip; 321 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc()); 322 _Ip __i(__is); 323 _Ip __eof; 324 for (; __i != __eof; ++__i) 325 if (!__ct.is(__ct.space, *__i)) 326 break; 327 if (__i == __eof) 328 __is.setstate(ios_base::failbit | ios_base::eofbit); 329 } 330 __ok_ = __is.good(); 331 } else 332 __is.setstate(ios_base::failbit); 333} 334 335template <class _CharT, class _Traits> 336basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) { 337 __rhs.__gc_ = 0; 338 this->move(__rhs); 339} 340 341template <class _CharT, class _Traits> 342basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) { 343 swap(__rhs); 344 return *this; 345} 346 347template <class _CharT, class _Traits> 348basic_istream<_CharT, _Traits>::~basic_istream() {} 349 350template <class _Tp, class _CharT, class _Traits> 351_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 352__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { 353 ios_base::iostate __state = ios_base::goodbit; 354 typename basic_istream<_CharT, _Traits>::sentry __s(__is); 355 if (__s) { 356#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 357 try { 358#endif // _LIBCPP_HAS_NO_EXCEPTIONS 359 typedef istreambuf_iterator<_CharT, _Traits> _Ip; 360 typedef num_get<_CharT, _Ip> _Fp; 361 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n); 362#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 363 } catch (...) { 364 __state |= ios_base::badbit; 365 __is.__setstate_nothrow(__state); 366 if (__is.exceptions() & ios_base::badbit) { 367 throw; 368 } 369 } 370#endif 371 __is.setstate(__state); 372 } 373 return __is; 374} 375 376template <class _CharT, class _Traits> 377basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) { 378 return std::__input_arithmetic<unsigned short>(*this, __n); 379} 380 381template <class _CharT, class _Traits> 382basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) { 383 return std::__input_arithmetic<unsigned int>(*this, __n); 384} 385 386template <class _CharT, class _Traits> 387basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long& __n) { 388 return std::__input_arithmetic<long>(*this, __n); 389} 390 391template <class _CharT, class _Traits> 392basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) { 393 return std::__input_arithmetic<unsigned long>(*this, __n); 394} 395 396template <class _CharT, class _Traits> 397basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long long& __n) { 398 return std::__input_arithmetic<long long>(*this, __n); 399} 400 401template <class _CharT, class _Traits> 402basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) { 403 return std::__input_arithmetic<unsigned long long>(*this, __n); 404} 405 406template <class _CharT, class _Traits> 407basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(float& __n) { 408 return std::__input_arithmetic<float>(*this, __n); 409} 410 411template <class _CharT, class _Traits> 412basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(double& __n) { 413 return std::__input_arithmetic<double>(*this, __n); 414} 415 416template <class _CharT, class _Traits> 417basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long double& __n) { 418 return std::__input_arithmetic<long double>(*this, __n); 419} 420 421template <class _CharT, class _Traits> 422basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(bool& __n) { 423 return std::__input_arithmetic<bool>(*this, __n); 424} 425 426template <class _CharT, class _Traits> 427basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) { 428 return std::__input_arithmetic<void*>(*this, __n); 429} 430 431template <class _Tp, class _CharT, class _Traits> 432_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 433__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { 434 ios_base::iostate __state = ios_base::goodbit; 435 typename basic_istream<_CharT, _Traits>::sentry __s(__is); 436 if (__s) { 437#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 438 try { 439#endif // _LIBCPP_HAS_NO_EXCEPTIONS 440 typedef istreambuf_iterator<_CharT, _Traits> _Ip; 441 typedef num_get<_CharT, _Ip> _Fp; 442 long __temp; 443 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp); 444 if (__temp < numeric_limits<_Tp>::min()) { 445 __state |= ios_base::failbit; 446 __n = numeric_limits<_Tp>::min(); 447 } else if (__temp > numeric_limits<_Tp>::max()) { 448 __state |= ios_base::failbit; 449 __n = numeric_limits<_Tp>::max(); 450 } else { 451 __n = static_cast<_Tp>(__temp); 452 } 453#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 454 } catch (...) { 455 __state |= ios_base::badbit; 456 __is.__setstate_nothrow(__state); 457 if (__is.exceptions() & ios_base::badbit) { 458 throw; 459 } 460 } 461#endif // _LIBCPP_HAS_NO_EXCEPTIONS 462 __is.setstate(__state); 463 } 464 return __is; 465} 466 467template <class _CharT, class _Traits> 468basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(short& __n) { 469 return std::__input_arithmetic_with_numeric_limits<short>(*this, __n); 470} 471 472template <class _CharT, class _Traits> 473basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(int& __n) { 474 return std::__input_arithmetic_with_numeric_limits<int>(*this, __n); 475} 476 477template <class _CharT, class _Traits> 478_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 479__input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) { 480 ios_base::iostate __state = ios_base::goodbit; 481 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 482 if (__sen) { 483#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 484 try { 485#endif 486 _CharT* __s = __p; 487 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc()); 488 while (__s != __p + (__n - 1)) { 489 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 490 if (_Traits::eq_int_type(__i, _Traits::eof())) { 491 __state |= ios_base::eofbit; 492 break; 493 } 494 _CharT __ch = _Traits::to_char_type(__i); 495 if (__ct.is(__ct.space, __ch)) 496 break; 497 *__s++ = __ch; 498 __is.rdbuf()->sbumpc(); 499 } 500 *__s = _CharT(); 501 __is.width(0); 502 if (__s == __p) 503 __state |= ios_base::failbit; 504#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 505 } catch (...) { 506 __state |= ios_base::badbit; 507 __is.__setstate_nothrow(__state); 508 if (__is.exceptions() & ios_base::badbit) { 509 throw; 510 } 511 } 512#endif 513 __is.setstate(__state); 514 } 515 return __is; 516} 517 518template <class _CharT, class _Traits> 519inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 520operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) { 521 streamsize __n = __is.width(); 522 if (__n <= 0) 523 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1; 524 return std::__input_c_string(__is, __s, size_t(__n)); 525} 526 527template <class _Traits> 528inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>& 529operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) { 530 return __is >> (char*)__s; 531} 532 533template <class _Traits> 534inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>& 535operator>>(basic_istream<char, _Traits>& __is, signed char* __s) { 536 return __is >> (char*)__s; 537} 538 539template <class _CharT, class _Traits> 540_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) { 541 ios_base::iostate __state = ios_base::goodbit; 542 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 543 if (__sen) { 544#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 545 try { 546#endif 547 typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); 548 if (_Traits::eq_int_type(__i, _Traits::eof())) 549 __state |= ios_base::eofbit | ios_base::failbit; 550 else 551 __c = _Traits::to_char_type(__i); 552#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 553 } catch (...) { 554 __state |= ios_base::badbit; 555 __is.__setstate_nothrow(__state); 556 if (__is.exceptions() & ios_base::badbit) { 557 throw; 558 } 559 } 560#endif 561 __is.setstate(__state); 562 } 563 return __is; 564} 565 566template <class _Traits> 567inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>& 568operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) { 569 return __is >> (char&)__c; 570} 571 572template <class _Traits> 573inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>& 574operator>>(basic_istream<char, _Traits>& __is, signed char& __c) { 575 return __is >> (char&)__c; 576} 577 578template <class _CharT, class _Traits> 579basic_istream<_CharT, _Traits>& 580basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) { 581 ios_base::iostate __state = ios_base::goodbit; 582 __gc_ = 0; 583 sentry __s(*this, true); 584 if (__s) { 585 if (__sb) { 586#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 587 try { 588#endif // _LIBCPP_HAS_NO_EXCEPTIONS 589 while (true) { 590 typename traits_type::int_type __i = this->rdbuf()->sgetc(); 591 if (traits_type::eq_int_type(__i, _Traits::eof())) { 592 __state |= ios_base::eofbit; 593 break; 594 } 595 if (traits_type::eq_int_type(__sb->sputc(traits_type::to_char_type(__i)), traits_type::eof())) 596 break; 597 __inc_gcount(); 598 this->rdbuf()->sbumpc(); 599 } 600 if (__gc_ == 0) 601 __state |= ios_base::failbit; 602#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 603 } catch (...) { 604 __state |= ios_base::badbit; 605 if (__gc_ == 0) 606 __state |= ios_base::failbit; 607 608 this->__setstate_nothrow(__state); 609 if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit) { 610 throw; 611 } 612 } 613#endif // _LIBCPP_HAS_NO_EXCEPTIONS 614 } else { 615 __state |= ios_base::failbit; 616 } 617 this->setstate(__state); 618 } 619 return *this; 620} 621 622template <class _CharT, class _Traits> 623typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get() { 624 ios_base::iostate __state = ios_base::goodbit; 625 __gc_ = 0; 626 int_type __r = traits_type::eof(); 627 sentry __s(*this, true); 628 if (__s) { 629#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 630 try { 631#endif 632 __r = this->rdbuf()->sbumpc(); 633 if (traits_type::eq_int_type(__r, traits_type::eof())) 634 __state |= ios_base::failbit | ios_base::eofbit; 635 else 636 __gc_ = 1; 637#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 638 } catch (...) { 639 this->__setstate_nothrow(this->rdstate() | ios_base::badbit); 640 if (this->exceptions() & ios_base::badbit) { 641 throw; 642 } 643 } 644#endif 645 this->setstate(__state); 646 } 647 return __r; 648} 649 650template <class _CharT, class _Traits> 651basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) { 652 ios_base::iostate __state = ios_base::goodbit; 653 __gc_ = 0; 654 sentry __sen(*this, true); 655 if (__sen) { 656 if (__n > 0) { 657#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 658 try { 659#endif 660 while (__gc_ < __n - 1) { 661 int_type __i = this->rdbuf()->sgetc(); 662 if (traits_type::eq_int_type(__i, traits_type::eof())) { 663 __state |= ios_base::eofbit; 664 break; 665 } 666 char_type __ch = traits_type::to_char_type(__i); 667 if (traits_type::eq(__ch, __dlm)) 668 break; 669 *__s++ = __ch; 670 __inc_gcount(); 671 this->rdbuf()->sbumpc(); 672 } 673 if (__gc_ == 0) 674 __state |= ios_base::failbit; 675#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 676 } catch (...) { 677 __state |= ios_base::badbit; 678 this->__setstate_nothrow(__state); 679 if (this->exceptions() & ios_base::badbit) { 680 if (__n > 0) 681 *__s = char_type(); 682 throw; 683 } 684 } 685#endif 686 } else { 687 __state |= ios_base::failbit; 688 } 689 690 if (__n > 0) 691 *__s = char_type(); 692 this->setstate(__state); 693 } 694 if (__n > 0) 695 *__s = char_type(); 696 return *this; 697} 698 699template <class _CharT, class _Traits> 700basic_istream<_CharT, _Traits>& 701basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm) { 702 ios_base::iostate __state = ios_base::goodbit; 703 __gc_ = 0; 704 sentry __sen(*this, true); 705 if (__sen) { 706#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 707 try { 708#endif // _LIBCPP_HAS_NO_EXCEPTIONS 709 while (true) { 710 typename traits_type::int_type __i = this->rdbuf()->sgetc(); 711 if (traits_type::eq_int_type(__i, traits_type::eof())) { 712 __state |= ios_base::eofbit; 713 break; 714 } 715 char_type __ch = traits_type::to_char_type(__i); 716 if (traits_type::eq(__ch, __dlm)) 717 break; 718 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) 719 break; 720 __inc_gcount(); 721 this->rdbuf()->sbumpc(); 722 } 723#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 724 } catch (...) { 725 __state |= ios_base::badbit; 726 // according to the spec, exceptions here are caught but not rethrown 727 } 728#endif // _LIBCPP_HAS_NO_EXCEPTIONS 729 if (__gc_ == 0) 730 __state |= ios_base::failbit; 731 this->setstate(__state); 732 } 733 return *this; 734} 735 736template <class _CharT, class _Traits> 737basic_istream<_CharT, _Traits>& 738basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) { 739 ios_base::iostate __state = ios_base::goodbit; 740 __gc_ = 0; 741 sentry __sen(*this, true); 742 if (__sen) { 743#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 744 try { 745#endif // _LIBCPP_HAS_NO_EXCEPTIONS 746 while (true) { 747 typename traits_type::int_type __i = this->rdbuf()->sgetc(); 748 if (traits_type::eq_int_type(__i, traits_type::eof())) { 749 __state |= ios_base::eofbit; 750 break; 751 } 752 char_type __ch = traits_type::to_char_type(__i); 753 if (traits_type::eq(__ch, __dlm)) { 754 this->rdbuf()->sbumpc(); 755 __inc_gcount(); 756 break; 757 } 758 if (__gc_ >= __n - 1) { 759 __state |= ios_base::failbit; 760 break; 761 } 762 *__s++ = __ch; 763 this->rdbuf()->sbumpc(); 764 __inc_gcount(); 765 } 766#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 767 } catch (...) { 768 __state |= ios_base::badbit; 769 this->__setstate_nothrow(__state); 770 if (this->exceptions() & ios_base::badbit) { 771 if (__n > 0) 772 *__s = char_type(); 773 if (__gc_ == 0) 774 __state |= ios_base::failbit; 775 throw; 776 } 777 } 778#endif // _LIBCPP_HAS_NO_EXCEPTIONS 779 } 780 if (__n > 0) 781 *__s = char_type(); 782 if (__gc_ == 0) 783 __state |= ios_base::failbit; 784 this->setstate(__state); 785 return *this; 786} 787 788template <class _CharT, class _Traits> 789basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) { 790 ios_base::iostate __state = ios_base::goodbit; 791 __gc_ = 0; 792 sentry __sen(*this, true); 793 if (__sen) { 794#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 795 try { 796#endif // _LIBCPP_HAS_NO_EXCEPTIONS 797 if (__n == numeric_limits<streamsize>::max()) { 798 while (true) { 799 typename traits_type::int_type __i = this->rdbuf()->sbumpc(); 800 if (traits_type::eq_int_type(__i, traits_type::eof())) { 801 __state |= ios_base::eofbit; 802 break; 803 } 804 __inc_gcount(); 805 if (traits_type::eq_int_type(__i, __dlm)) 806 break; 807 } 808 } else { 809 while (__gc_ < __n) { 810 typename traits_type::int_type __i = this->rdbuf()->sbumpc(); 811 if (traits_type::eq_int_type(__i, traits_type::eof())) { 812 __state |= ios_base::eofbit; 813 break; 814 } 815 __inc_gcount(); 816 if (traits_type::eq_int_type(__i, __dlm)) 817 break; 818 } 819 } 820#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 821 } catch (...) { 822 __state |= ios_base::badbit; 823 this->__setstate_nothrow(__state); 824 if (this->exceptions() & ios_base::badbit) { 825 throw; 826 } 827 } 828#endif // _LIBCPP_HAS_NO_EXCEPTIONS 829 this->setstate(__state); 830 } 831 return *this; 832} 833 834template <class _CharT, class _Traits> 835typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek() { 836 ios_base::iostate __state = ios_base::goodbit; 837 __gc_ = 0; 838 int_type __r = traits_type::eof(); 839 sentry __sen(*this, true); 840 if (__sen) { 841#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 842 try { 843#endif // _LIBCPP_HAS_NO_EXCEPTIONS 844 __r = this->rdbuf()->sgetc(); 845 if (traits_type::eq_int_type(__r, traits_type::eof())) 846 __state |= ios_base::eofbit; 847#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 848 } catch (...) { 849 __state |= ios_base::badbit; 850 this->__setstate_nothrow(__state); 851 if (this->exceptions() & ios_base::badbit) { 852 throw; 853 } 854 } 855#endif // _LIBCPP_HAS_NO_EXCEPTIONS 856 this->setstate(__state); 857 } 858 return __r; 859} 860 861template <class _CharT, class _Traits> 862basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) { 863 ios_base::iostate __state = ios_base::goodbit; 864 __gc_ = 0; 865 sentry __sen(*this, true); 866 if (__sen) { 867#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 868 try { 869#endif // _LIBCPP_HAS_NO_EXCEPTIONS 870 __gc_ = this->rdbuf()->sgetn(__s, __n); 871 if (__gc_ != __n) 872 __state |= ios_base::failbit | ios_base::eofbit; 873#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 874 } catch (...) { 875 __state |= ios_base::badbit; 876 this->__setstate_nothrow(__state); 877 if (this->exceptions() & ios_base::badbit) { 878 throw; 879 } 880 } 881#endif // _LIBCPP_HAS_NO_EXCEPTIONS 882 } else { 883 __state |= ios_base::failbit; 884 } 885 this->setstate(__state); 886 return *this; 887} 888 889template <class _CharT, class _Traits> 890streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) { 891 ios_base::iostate __state = ios_base::goodbit; 892 __gc_ = 0; 893 sentry __sen(*this, true); 894 if (__sen) { 895#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 896 try { 897#endif // _LIBCPP_HAS_NO_EXCEPTIONS 898 streamsize __c = this->rdbuf()->in_avail(); 899 switch (__c) { 900 case -1: 901 __state |= ios_base::eofbit; 902 break; 903 case 0: 904 break; 905 default: 906 __n = std::min(__c, __n); 907 __gc_ = this->rdbuf()->sgetn(__s, __n); 908 if (__gc_ != __n) 909 __state |= ios_base::failbit | ios_base::eofbit; 910 break; 911 } 912#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 913 } catch (...) { 914 __state |= ios_base::badbit; 915 this->__setstate_nothrow(__state); 916 if (this->exceptions() & ios_base::badbit) { 917 throw; 918 } 919 } 920#endif // _LIBCPP_HAS_NO_EXCEPTIONS 921 } else { 922 __state |= ios_base::failbit; 923 } 924 this->setstate(__state); 925 return __gc_; 926} 927 928template <class _CharT, class _Traits> 929basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_type __c) { 930 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; 931 __gc_ = 0; 932 this->clear(__state); 933 sentry __sen(*this, true); 934 if (__sen) { 935#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 936 try { 937#endif // _LIBCPP_HAS_NO_EXCEPTIONS 938 if (this->rdbuf() == nullptr || this->rdbuf()->sputbackc(__c) == traits_type::eof()) 939 __state |= ios_base::badbit; 940#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 941 } catch (...) { 942 __state |= ios_base::badbit; 943 this->__setstate_nothrow(__state); 944 if (this->exceptions() & ios_base::badbit) { 945 throw; 946 } 947 } 948#endif // _LIBCPP_HAS_NO_EXCEPTIONS 949 } else { 950 __state |= ios_base::failbit; 951 } 952 this->setstate(__state); 953 return *this; 954} 955 956template <class _CharT, class _Traits> 957basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() { 958 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; 959 __gc_ = 0; 960 this->clear(__state); 961 sentry __sen(*this, true); 962 if (__sen) { 963#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 964 try { 965#endif // _LIBCPP_HAS_NO_EXCEPTIONS 966 if (this->rdbuf() == nullptr || this->rdbuf()->sungetc() == traits_type::eof()) 967 __state |= ios_base::badbit; 968#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 969 } catch (...) { 970 __state |= ios_base::badbit; 971 this->__setstate_nothrow(__state); 972 if (this->exceptions() & ios_base::badbit) { 973 throw; 974 } 975 } 976#endif // _LIBCPP_HAS_NO_EXCEPTIONS 977 } else { 978 __state |= ios_base::failbit; 979 } 980 this->setstate(__state); 981 return *this; 982} 983 984template <class _CharT, class _Traits> 985int basic_istream<_CharT, _Traits>::sync() { 986 ios_base::iostate __state = ios_base::goodbit; 987 sentry __sen(*this, true); 988 if (this->rdbuf() == nullptr) 989 return -1; 990 991 int __r = 0; 992 if (__sen) { 993#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 994 try { 995#endif // _LIBCPP_HAS_NO_EXCEPTIONS 996 if (this->rdbuf()->pubsync() == -1) { 997 __state |= ios_base::badbit; 998 __r = -1; 999 } 1000#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1001 } catch (...) { 1002 __state |= ios_base::badbit; 1003 this->__setstate_nothrow(__state); 1004 if (this->exceptions() & ios_base::badbit) { 1005 throw; 1006 } 1007 } 1008#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1009 this->setstate(__state); 1010 } 1011 return __r; 1012} 1013 1014template <class _CharT, class _Traits> 1015typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>::tellg() { 1016 ios_base::iostate __state = ios_base::goodbit; 1017 pos_type __r(-1); 1018 sentry __sen(*this, true); 1019 if (__sen) { 1020#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1021 try { 1022#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1023 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); 1024#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1025 } catch (...) { 1026 __state |= ios_base::badbit; 1027 this->__setstate_nothrow(__state); 1028 if (this->exceptions() & ios_base::badbit) { 1029 throw; 1030 } 1031 } 1032#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1033 this->setstate(__state); 1034 } 1035 return __r; 1036} 1037 1038template <class _CharT, class _Traits> 1039basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) { 1040 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; 1041 this->clear(__state); 1042 sentry __sen(*this, true); 1043 if (__sen) { 1044#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1045 try { 1046#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1047 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) 1048 __state |= ios_base::failbit; 1049#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1050 } catch (...) { 1051 __state |= ios_base::badbit; 1052 this->__setstate_nothrow(__state); 1053 if (this->exceptions() & ios_base::badbit) { 1054 throw; 1055 } 1056 } 1057#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1058 this->setstate(__state); 1059 } 1060 return *this; 1061} 1062 1063template <class _CharT, class _Traits> 1064basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) { 1065 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; 1066 this->clear(__state); 1067 sentry __sen(*this, true); 1068 if (__sen) { 1069#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1070 try { 1071#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1072 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) 1073 __state |= ios_base::failbit; 1074#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1075 } catch (...) { 1076 __state |= ios_base::badbit; 1077 this->__setstate_nothrow(__state); 1078 if (this->exceptions() & ios_base::badbit) { 1079 throw; 1080 } 1081 } 1082#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1083 this->setstate(__state); 1084 } 1085 return *this; 1086} 1087 1088template <class _CharT, class _Traits> 1089_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _Traits>& __is) { 1090 ios_base::iostate __state = ios_base::goodbit; 1091 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); 1092 if (__sen) { 1093#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1094 try { 1095#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1096 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc()); 1097 while (true) { 1098 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1099 if (_Traits::eq_int_type(__i, _Traits::eof())) { 1100 __state |= ios_base::eofbit; 1101 break; 1102 } 1103 if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) 1104 break; 1105 __is.rdbuf()->sbumpc(); 1106 } 1107#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1108 } catch (...) { 1109 __state |= ios_base::badbit; 1110 __is.__setstate_nothrow(__state); 1111 if (__is.exceptions() & ios_base::badbit) { 1112 throw; 1113 } 1114 } 1115#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1116 __is.setstate(__state); 1117 } 1118 return __is; 1119} 1120 1121template <class _Stream, class _Tp, class = void> 1122struct __is_istreamable : false_type {}; 1123 1124template <class _Stream, class _Tp> 1125struct __is_istreamable<_Stream, _Tp, decltype(std::declval<_Stream>() >> std::declval<_Tp>(), void())> : true_type {}; 1126 1127template <class _Stream, 1128 class _Tp, 1129 __enable_if_t< _And<is_base_of<ios_base, _Stream>, __is_istreamable<_Stream&, _Tp&&> >::value, int> = 0> 1130_LIBCPP_HIDE_FROM_ABI _Stream&& operator>>(_Stream&& __is, _Tp&& __x) { 1131 __is >> std::forward<_Tp>(__x); 1132 return std::move(__is); 1133} 1134 1135template <class _CharT, class _Traits> 1136class _LIBCPP_TEMPLATE_VIS basic_iostream 1137 : public basic_istream<_CharT, _Traits>, 1138 public basic_ostream<_CharT, _Traits> { 1139public: 1140 // types: 1141 typedef _CharT char_type; 1142 typedef _Traits traits_type; 1143 typedef typename traits_type::int_type int_type; 1144 typedef typename traits_type::pos_type pos_type; 1145 typedef typename traits_type::off_type off_type; 1146 1147 // constructor/destructor 1148 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb) 1149 : basic_istream<_CharT, _Traits>(__sb) {} 1150 1151 ~basic_iostream() override; 1152 1153protected: 1154 inline _LIBCPP_HIDE_FROM_ABI basic_iostream(basic_iostream&& __rhs); 1155 1156 // assign/swap 1157 inline _LIBCPP_HIDE_FROM_ABI basic_iostream& operator=(basic_iostream&& __rhs); 1158 1159 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_iostream& __rhs) { 1160 basic_istream<char_type, traits_type>::swap(__rhs); 1161 } 1162}; 1163 1164template <class _CharT, class _Traits> 1165basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) 1166 : basic_istream<_CharT, _Traits>(std::move(__rhs)) {} 1167 1168template <class _CharT, class _Traits> 1169basic_iostream<_CharT, _Traits>& basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) { 1170 swap(__rhs); 1171 return *this; 1172} 1173 1174template <class _CharT, class _Traits> 1175basic_iostream<_CharT, _Traits>::~basic_iostream() {} 1176 1177template <class _CharT, class _Traits, class _Allocator> 1178_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1179operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { 1180 ios_base::iostate __state = ios_base::goodbit; 1181 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 1182 if (__sen) { 1183#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1184 try { 1185#endif 1186 __str.clear(); 1187 streamsize __n = __is.width(); 1188 if (__n <= 0) 1189 __n = __str.max_size(); 1190 if (__n <= 0) 1191 __n = numeric_limits<streamsize>::max(); 1192 streamsize __c = 0; 1193 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc()); 1194 while (__c < __n) { 1195 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1196 if (_Traits::eq_int_type(__i, _Traits::eof())) { 1197 __state |= ios_base::eofbit; 1198 break; 1199 } 1200 _CharT __ch = _Traits::to_char_type(__i); 1201 if (__ct.is(__ct.space, __ch)) 1202 break; 1203 __str.push_back(__ch); 1204 ++__c; 1205 __is.rdbuf()->sbumpc(); 1206 } 1207 __is.width(0); 1208 if (__c == 0) 1209 __state |= ios_base::failbit; 1210#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1211 } catch (...) { 1212 __state |= ios_base::badbit; 1213 __is.__setstate_nothrow(__state); 1214 if (__is.exceptions() & ios_base::badbit) { 1215 throw; 1216 } 1217 } 1218#endif 1219 __is.setstate(__state); 1220 } 1221 return __is; 1222} 1223 1224template <class _CharT, class _Traits, class _Allocator> 1225_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1226getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) { 1227 ios_base::iostate __state = ios_base::goodbit; 1228 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); 1229 if (__sen) { 1230#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1231 try { 1232#endif 1233 __str.clear(); 1234 streamsize __extr = 0; 1235 while (true) { 1236 typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); 1237 if (_Traits::eq_int_type(__i, _Traits::eof())) { 1238 __state |= ios_base::eofbit; 1239 break; 1240 } 1241 ++__extr; 1242 _CharT __ch = _Traits::to_char_type(__i); 1243 if (_Traits::eq(__ch, __dlm)) 1244 break; 1245 __str.push_back(__ch); 1246 if (__str.size() == __str.max_size()) { 1247 __state |= ios_base::failbit; 1248 break; 1249 } 1250 } 1251 if (__extr == 0) 1252 __state |= ios_base::failbit; 1253#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1254 } catch (...) { 1255 __state |= ios_base::badbit; 1256 __is.__setstate_nothrow(__state); 1257 if (__is.exceptions() & ios_base::badbit) { 1258 throw; 1259 } 1260 } 1261#endif 1262 __is.setstate(__state); 1263 } 1264 return __is; 1265} 1266 1267template <class _CharT, class _Traits, class _Allocator> 1268inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1269getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { 1270 return std::getline(__is, __str, __is.widen('\n')); 1271} 1272 1273template <class _CharT, class _Traits, class _Allocator> 1274inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1275getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) { 1276 return std::getline(__is, __str, __dlm); 1277} 1278 1279template <class _CharT, class _Traits, class _Allocator> 1280inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1281getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { 1282 return std::getline(__is, __str, __is.widen('\n')); 1283} 1284 1285template <class _CharT, class _Traits, size_t _Size> 1286_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1287operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) { 1288 ios_base::iostate __state = ios_base::goodbit; 1289 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 1290 if (__sen) { 1291#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1292 try { 1293#endif 1294 basic_string<_CharT, _Traits> __str; 1295 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc()); 1296 size_t __c = 0; 1297 _CharT __zero = __ct.widen('0'); 1298 _CharT __one = __ct.widen('1'); 1299 while (__c != _Size) { 1300 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1301 if (_Traits::eq_int_type(__i, _Traits::eof())) { 1302 __state |= ios_base::eofbit; 1303 break; 1304 } 1305 _CharT __ch = _Traits::to_char_type(__i); 1306 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) 1307 break; 1308 __str.push_back(__ch); 1309 ++__c; 1310 __is.rdbuf()->sbumpc(); 1311 } 1312 __x = bitset<_Size>(__str); 1313 if (_Size > 0 && __c == 0) 1314 __state |= ios_base::failbit; 1315#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1316 } catch (...) { 1317 __state |= ios_base::badbit; 1318 __is.__setstate_nothrow(__state); 1319 if (__is.exceptions() & ios_base::badbit) { 1320 throw; 1321 } 1322 } 1323#endif 1324 __is.setstate(__state); 1325 } 1326 return __is; 1327} 1328 1329extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>; 1330#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 1331extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>; 1332#endif 1333extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>; 1334 1335_LIBCPP_END_NAMESPACE_STD 1336 1337#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) 1338# include <__cxx03/iosfwd> 1339# include <__cxx03/ostream> 1340# include <__cxx03/type_traits> 1341#endif 1342 1343_LIBCPP_POP_MACROS 1344 1345#endif // _LIBCPP___CXX03_ISTREAM 1346