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