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