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); 85protected: 86 basic_istream(const basic_istream& rhs) = delete; 87 basic_istream(basic_istream&& rhs); 88 // 27.7.2.1.2 Assign/swap: 89 basic_istream& operator=(const basic_istream& rhs) = delete; 90 basic_istream& operator=(basic_istream&& rhs); 91 void swap(basic_istream& rhs); 92}; 93 94// 27.7.1.2.3 character extraction templates: 95template<class charT, class traits> 96 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&); 97 98template<class traits> 99 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&); 100 101template<class traits> 102 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&); 103 104template<class charT, class traits> 105 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*); 106 107template<class traits> 108 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*); 109 110template<class traits> 111 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*); 112 113template <class charT, class traits> 114 void 115 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y); 116 117typedef basic_istream<char> istream; 118typedef basic_istream<wchar_t> wistream; 119 120template <class charT, class traits = char_traits<charT> > 121class basic_iostream : 122 public basic_istream<charT,traits>, 123 public basic_ostream<charT,traits> 124{ 125public: 126 // types: 127 typedef charT char_type; 128 typedef traits traits_type; 129 typedef typename traits_type::int_type int_type; 130 typedef typename traits_type::pos_type pos_type; 131 typedef typename traits_type::off_type off_type; 132 133 // constructor/destructor 134 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb); 135 basic_iostream(basic_iostream&& rhs); 136 virtual ~basic_iostream(); 137 138 // assign/swap 139 basic_iostream& operator=(basic_iostream&& rhs); 140 void swap(basic_iostream& rhs); 141}; 142 143template <class charT, class traits> 144 void 145 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y); 146 147typedef basic_iostream<char> iostream; 148typedef basic_iostream<wchar_t> wiostream; 149 150template <class charT, class traits> 151 basic_istream<charT,traits>& 152 ws(basic_istream<charT,traits>& is); 153 154template <class charT, class traits, class T> 155 basic_istream<charT, traits>& 156 operator>>(basic_istream<charT, traits>&& is, T& x); 157 158} // std 159 160*/ 161 162#include <__config> 163#include <ostream> 164 165#include <__undef_min_max> 166 167#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 168#pragma GCC system_header 169#endif 170 171_LIBCPP_BEGIN_NAMESPACE_STD 172 173template <class _CharT, class _Traits> 174class _LIBCPP_TEMPLATE_VIS basic_istream 175 : virtual public basic_ios<_CharT, _Traits> 176{ 177 streamsize __gc_; 178public: 179 // types (inherited from basic_ios (27.5.4)): 180 typedef _CharT char_type; 181 typedef _Traits traits_type; 182 typedef typename traits_type::int_type int_type; 183 typedef typename traits_type::pos_type pos_type; 184 typedef typename traits_type::off_type off_type; 185 186 // 27.7.1.1.1 Constructor/destructor: 187 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 188 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0) 189 { this->init(__sb); } 190 virtual ~basic_istream(); 191protected: 192#ifndef _LIBCPP_CXX03_LANG 193 inline _LIBCPP_INLINE_VISIBILITY 194 basic_istream(basic_istream&& __rhs); 195 196 // 27.7.1.1.2 Assign/swap: 197 inline _LIBCPP_INLINE_VISIBILITY 198 basic_istream& operator=(basic_istream&& __rhs); 199#endif 200 201 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 202 void swap(basic_istream& __rhs) { 203 _VSTD::swap(__gc_, __rhs.__gc_); 204 basic_ios<char_type, traits_type>::swap(__rhs); 205 } 206 207#ifndef _LIBCPP_CXX03_LANG 208 basic_istream (const basic_istream& __rhs) = delete; 209 basic_istream& operator=(const basic_istream& __rhs) = delete; 210#endif 211public: 212 213 // 27.7.1.1.3 Prefix/suffix: 214 class _LIBCPP_TEMPLATE_VIS sentry; 215 216 // 27.7.1.2 Formatted input: 217 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 218 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) 219 { return __pf(*this); } 220 221 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 222 basic_istream& operator>>(basic_ios<char_type, traits_type>& 223 (*__pf)(basic_ios<char_type, traits_type>&)) 224 { __pf(*this); return *this; } 225 226 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 227 basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) 228 { __pf(*this); return *this; } 229 230 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb); 231 basic_istream& operator>>(bool& __n); 232 basic_istream& operator>>(short& __n); 233 basic_istream& operator>>(unsigned short& __n); 234 basic_istream& operator>>(int& __n); 235 basic_istream& operator>>(unsigned int& __n); 236 basic_istream& operator>>(long& __n); 237 basic_istream& operator>>(unsigned long& __n); 238 basic_istream& operator>>(long long& __n); 239 basic_istream& operator>>(unsigned long long& __n); 240 basic_istream& operator>>(float& __f); 241 basic_istream& operator>>(double& __f); 242 basic_istream& operator>>(long double& __f); 243 basic_istream& operator>>(void*& __p); 244 245 // 27.7.1.3 Unformatted input: 246 _LIBCPP_INLINE_VISIBILITY 247 streamsize gcount() const {return __gc_;} 248 int_type get(); 249 250 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 251 basic_istream& get(char_type& __c) { 252 int_type __ch = get(); 253 if (__ch != traits_type::eof()) 254 __c = traits_type::to_char_type(__ch); 255 return *this; 256 } 257 258 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 259 basic_istream& get(char_type* __s, streamsize __n) 260 { return get(__s, __n, this->widen('\n')); } 261 262 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); 263 264 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 265 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) 266 { return get(__sb, this->widen('\n')); } 267 268 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm); 269 270 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 271 basic_istream& getline(char_type* __s, streamsize __n) 272 { return getline(__s, __n, this->widen('\n')); } 273 274 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); 275 276 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); 277 int_type peek(); 278 basic_istream& read (char_type* __s, streamsize __n); 279 streamsize readsome(char_type* __s, streamsize __n); 280 281 basic_istream& putback(char_type __c); 282 basic_istream& unget(); 283 int sync(); 284 285 pos_type tellg(); 286 basic_istream& seekg(pos_type __pos); 287 basic_istream& seekg(off_type __off, ios_base::seekdir __dir); 288}; 289 290template <class _CharT, class _Traits> 291class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry 292{ 293 bool __ok_; 294 295 sentry(const sentry&); // = delete; 296 sentry& operator=(const sentry&); // = delete; 297 298public: 299 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); 300// ~sentry() = default; 301 302 _LIBCPP_INLINE_VISIBILITY 303 _LIBCPP_EXPLICIT 304 operator bool() const {return __ok_;} 305}; 306 307template <class _CharT, class _Traits> 308basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, 309 bool __noskipws) 310 : __ok_(false) 311{ 312 if (__is.good()) 313 { 314 if (__is.tie()) 315 __is.tie()->flush(); 316 if (!__noskipws && (__is.flags() & ios_base::skipws)) 317 { 318 typedef istreambuf_iterator<_CharT, _Traits> _Ip; 319 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); 320 _Ip __i(__is); 321 _Ip __eof; 322 for (; __i != __eof; ++__i) 323 if (!__ct.is(__ct.space, *__i)) 324 break; 325 if (__i == __eof) 326 __is.setstate(ios_base::failbit | ios_base::eofbit); 327 } 328 __ok_ = __is.good(); 329 } 330 else 331 __is.setstate(ios_base::failbit); 332} 333 334#ifndef _LIBCPP_CXX03_LANG 335 336template <class _CharT, class _Traits> 337basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) 338 : __gc_(__rhs.__gc_) 339{ 340 __rhs.__gc_ = 0; 341 this->move(__rhs); 342} 343 344template <class _CharT, class _Traits> 345basic_istream<_CharT, _Traits>& 346basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) 347{ 348 swap(__rhs); 349 return *this; 350} 351 352#endif // _LIBCPP_CXX03_LANG 353 354template <class _CharT, class _Traits> 355basic_istream<_CharT, _Traits>::~basic_istream() 356{ 357} 358 359template <class _CharT, class _Traits> 360basic_istream<_CharT, _Traits>& 361basic_istream<_CharT, _Traits>::operator>>(unsigned short& __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> _Ip; 371 typedef num_get<char_type, _Ip> _Fp; 372 ios_base::iostate __err = ios_base::goodbit; 373 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(unsigned int& __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> _Ip; 398 typedef num_get<char_type, _Ip> _Fp; 399 ios_base::iostate __err = ios_base::goodbit; 400 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(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> _Ip; 425 typedef num_get<char_type, _Ip> _Fp; 426 ios_base::iostate __err = ios_base::goodbit; 427 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(unsigned 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> _Ip; 452 typedef num_get<char_type, _Ip> _Fp; 453 ios_base::iostate __err = ios_base::goodbit; 454 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(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> _Ip; 479 typedef num_get<char_type, _Ip> _Fp; 480 ios_base::iostate __err = ios_base::goodbit; 481 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(unsigned long long& __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> _Ip; 506 typedef num_get<char_type, _Ip> _Fp; 507 ios_base::iostate __err = ios_base::goodbit; 508 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(float& __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> _Ip; 533 typedef num_get<char_type, _Ip> _Fp; 534 ios_base::iostate __err = ios_base::goodbit; 535 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(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> _Ip; 560 typedef num_get<char_type, _Ip> _Fp; 561 ios_base::iostate __err = ios_base::goodbit; 562 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(long double& __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> _Ip; 587 typedef num_get<char_type, _Ip> _Fp; 588 ios_base::iostate __err = ios_base::goodbit; 589 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(bool& __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> _Ip; 614 typedef num_get<char_type, _Ip> _Fp; 615 ios_base::iostate __err = ios_base::goodbit; 616 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *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>>(void*& __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> _Ip; 641 typedef num_get<char_type, _Ip> _Fp; 642 ios_base::iostate __err = ios_base::goodbit; 643 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); 644 this->setstate(__err); 645 } 646#ifndef _LIBCPP_NO_EXCEPTIONS 647 } 648 catch (...) 649 { 650 this->__set_badbit_and_consider_rethrow(); 651 } 652#endif // _LIBCPP_NO_EXCEPTIONS 653 return *this; 654} 655 656template <class _CharT, class _Traits> 657basic_istream<_CharT, _Traits>& 658basic_istream<_CharT, _Traits>::operator>>(short& __n) 659{ 660#ifndef _LIBCPP_NO_EXCEPTIONS 661 try 662 { 663#endif // _LIBCPP_NO_EXCEPTIONS 664 sentry __s(*this); 665 if (__s) 666 { 667 typedef istreambuf_iterator<char_type, traits_type> _Ip; 668 typedef num_get<char_type, _Ip> _Fp; 669 ios_base::iostate __err = ios_base::goodbit; 670 long __temp; 671 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); 672 if (__temp < numeric_limits<short>::min()) 673 { 674 __err |= ios_base::failbit; 675 __n = numeric_limits<short>::min(); 676 } 677 else if (__temp > numeric_limits<short>::max()) 678 { 679 __err |= ios_base::failbit; 680 __n = numeric_limits<short>::max(); 681 } 682 else 683 __n = static_cast<short>(__temp); 684 this->setstate(__err); 685 } 686#ifndef _LIBCPP_NO_EXCEPTIONS 687 } 688 catch (...) 689 { 690 this->__set_badbit_and_consider_rethrow(); 691 } 692#endif // _LIBCPP_NO_EXCEPTIONS 693 return *this; 694} 695 696template <class _CharT, class _Traits> 697basic_istream<_CharT, _Traits>& 698basic_istream<_CharT, _Traits>::operator>>(int& __n) 699{ 700#ifndef _LIBCPP_NO_EXCEPTIONS 701 try 702 { 703#endif // _LIBCPP_NO_EXCEPTIONS 704 sentry __s(*this); 705 if (__s) 706 { 707 typedef istreambuf_iterator<char_type, traits_type> _Ip; 708 typedef num_get<char_type, _Ip> _Fp; 709 ios_base::iostate __err = ios_base::goodbit; 710 long __temp; 711 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); 712 if (__temp < numeric_limits<int>::min()) 713 { 714 __err |= ios_base::failbit; 715 __n = numeric_limits<int>::min(); 716 } 717 else if (__temp > numeric_limits<int>::max()) 718 { 719 __err |= ios_base::failbit; 720 __n = numeric_limits<int>::max(); 721 } 722 else 723 __n = static_cast<int>(__temp); 724 this->setstate(__err); 725 } 726#ifndef _LIBCPP_NO_EXCEPTIONS 727 } 728 catch (...) 729 { 730 this->__set_badbit_and_consider_rethrow(); 731 } 732#endif // _LIBCPP_NO_EXCEPTIONS 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> 932basic_istream<_CharT, _Traits>& 933basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) 934{ 935 __gc_ = 0; 936#ifndef _LIBCPP_NO_EXCEPTIONS 937 try 938 { 939#endif // _LIBCPP_NO_EXCEPTIONS 940 sentry __sen(*this, true); 941 if (__sen) 942 { 943 if (__n > 0) 944 { 945 ios_base::iostate __err = ios_base::goodbit; 946 while (__gc_ < __n-1) 947 { 948 int_type __i = this->rdbuf()->sgetc(); 949 if (traits_type::eq_int_type(__i, traits_type::eof())) 950 { 951 __err |= ios_base::eofbit; 952 break; 953 } 954 char_type __ch = traits_type::to_char_type(__i); 955 if (traits_type::eq(__ch, __dlm)) 956 break; 957 *__s++ = __ch; 958 ++__gc_; 959 this->rdbuf()->sbumpc(); 960 } 961 *__s = char_type(); 962 if (__gc_ == 0) 963 __err |= ios_base::failbit; 964 this->setstate(__err); 965 } 966 else 967 this->setstate(ios_base::failbit); 968 } 969#ifndef _LIBCPP_NO_EXCEPTIONS 970 } 971 catch (...) 972 { 973 this->__set_badbit_and_consider_rethrow(); 974 } 975#endif // _LIBCPP_NO_EXCEPTIONS 976 return *this; 977} 978 979template<class _CharT, class _Traits> 980basic_istream<_CharT, _Traits>& 981basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, 982 char_type __dlm) 983{ 984 __gc_ = 0; 985#ifndef _LIBCPP_NO_EXCEPTIONS 986 try 987 { 988#endif // _LIBCPP_NO_EXCEPTIONS 989 sentry __sen(*this, true); 990 if (__sen) 991 { 992 ios_base::iostate __err = ios_base::goodbit; 993#ifndef _LIBCPP_NO_EXCEPTIONS 994 try 995 { 996#endif // _LIBCPP_NO_EXCEPTIONS 997 while (true) 998 { 999 typename traits_type::int_type __i = this->rdbuf()->sgetc(); 1000 if (traits_type::eq_int_type(__i, traits_type::eof())) 1001 { 1002 __err |= ios_base::eofbit; 1003 break; 1004 } 1005 char_type __ch = traits_type::to_char_type(__i); 1006 if (traits_type::eq(__ch, __dlm)) 1007 break; 1008 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) 1009 break; 1010 ++__gc_; 1011 this->rdbuf()->sbumpc(); 1012 } 1013#ifndef _LIBCPP_NO_EXCEPTIONS 1014 } 1015 catch (...) 1016 { 1017 } 1018#endif // _LIBCPP_NO_EXCEPTIONS 1019 if (__gc_ == 0) 1020 __err |= ios_base::failbit; 1021 this->setstate(__err); 1022 } 1023#ifndef _LIBCPP_NO_EXCEPTIONS 1024 } 1025 catch (...) 1026 { 1027 this->__set_badbit_and_consider_rethrow(); 1028 } 1029#endif // _LIBCPP_NO_EXCEPTIONS 1030 return *this; 1031} 1032 1033template<class _CharT, class _Traits> 1034basic_istream<_CharT, _Traits>& 1035basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) 1036{ 1037 __gc_ = 0; 1038#ifndef _LIBCPP_NO_EXCEPTIONS 1039 try 1040 { 1041#endif // _LIBCPP_NO_EXCEPTIONS 1042 sentry __sen(*this, true); 1043 if (__sen) 1044 { 1045 ios_base::iostate __err = ios_base::goodbit; 1046 while (true) 1047 { 1048 typename traits_type::int_type __i = this->rdbuf()->sgetc(); 1049 if (traits_type::eq_int_type(__i, traits_type::eof())) 1050 { 1051 __err |= ios_base::eofbit; 1052 break; 1053 } 1054 char_type __ch = traits_type::to_char_type(__i); 1055 if (traits_type::eq(__ch, __dlm)) 1056 { 1057 this->rdbuf()->sbumpc(); 1058 ++__gc_; 1059 break; 1060 } 1061 if (__gc_ >= __n-1) 1062 { 1063 __err |= ios_base::failbit; 1064 break; 1065 } 1066 *__s++ = __ch; 1067 this->rdbuf()->sbumpc(); 1068 ++__gc_; 1069 } 1070 if (__n > 0) 1071 *__s = char_type(); 1072 if (__gc_ == 0) 1073 __err |= ios_base::failbit; 1074 this->setstate(__err); 1075 } 1076#ifndef _LIBCPP_NO_EXCEPTIONS 1077 } 1078 catch (...) 1079 { 1080 this->__set_badbit_and_consider_rethrow(); 1081 } 1082#endif // _LIBCPP_NO_EXCEPTIONS 1083 return *this; 1084} 1085 1086template<class _CharT, class _Traits> 1087basic_istream<_CharT, _Traits>& 1088basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) 1089{ 1090 __gc_ = 0; 1091#ifndef _LIBCPP_NO_EXCEPTIONS 1092 try 1093 { 1094#endif // _LIBCPP_NO_EXCEPTIONS 1095 sentry __sen(*this, true); 1096 if (__sen) 1097 { 1098 ios_base::iostate __err = ios_base::goodbit; 1099 if (__n == numeric_limits<streamsize>::max()) 1100 { 1101 while (true) 1102 { 1103 typename traits_type::int_type __i = this->rdbuf()->sbumpc(); 1104 if (traits_type::eq_int_type(__i, traits_type::eof())) 1105 { 1106 __err |= ios_base::eofbit; 1107 break; 1108 } 1109 ++__gc_; 1110 if (traits_type::eq_int_type(__i, __dlm)) 1111 break; 1112 } 1113 } 1114 else 1115 { 1116 while (__gc_ < __n) 1117 { 1118 typename traits_type::int_type __i = this->rdbuf()->sbumpc(); 1119 if (traits_type::eq_int_type(__i, traits_type::eof())) 1120 { 1121 __err |= ios_base::eofbit; 1122 break; 1123 } 1124 ++__gc_; 1125 if (traits_type::eq_int_type(__i, __dlm)) 1126 break; 1127 } 1128 } 1129 this->setstate(__err); 1130 } 1131#ifndef _LIBCPP_NO_EXCEPTIONS 1132 } 1133 catch (...) 1134 { 1135 this->__set_badbit_and_consider_rethrow(); 1136 } 1137#endif // _LIBCPP_NO_EXCEPTIONS 1138 return *this; 1139} 1140 1141template<class _CharT, class _Traits> 1142typename basic_istream<_CharT, _Traits>::int_type 1143basic_istream<_CharT, _Traits>::peek() 1144{ 1145 __gc_ = 0; 1146 int_type __r = traits_type::eof(); 1147#ifndef _LIBCPP_NO_EXCEPTIONS 1148 try 1149 { 1150#endif // _LIBCPP_NO_EXCEPTIONS 1151 sentry __sen(*this, true); 1152 if (__sen) 1153 { 1154 __r = this->rdbuf()->sgetc(); 1155 if (traits_type::eq_int_type(__r, traits_type::eof())) 1156 this->setstate(ios_base::eofbit); 1157 } 1158#ifndef _LIBCPP_NO_EXCEPTIONS 1159 } 1160 catch (...) 1161 { 1162 this->__set_badbit_and_consider_rethrow(); 1163 } 1164#endif // _LIBCPP_NO_EXCEPTIONS 1165 return __r; 1166} 1167 1168template<class _CharT, class _Traits> 1169basic_istream<_CharT, _Traits>& 1170basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) 1171{ 1172 __gc_ = 0; 1173#ifndef _LIBCPP_NO_EXCEPTIONS 1174 try 1175 { 1176#endif // _LIBCPP_NO_EXCEPTIONS 1177 sentry __sen(*this, true); 1178 if (__sen) 1179 { 1180 __gc_ = this->rdbuf()->sgetn(__s, __n); 1181 if (__gc_ != __n) 1182 this->setstate(ios_base::failbit | ios_base::eofbit); 1183 } 1184 else 1185 this->setstate(ios_base::failbit); 1186#ifndef _LIBCPP_NO_EXCEPTIONS 1187 } 1188 catch (...) 1189 { 1190 this->__set_badbit_and_consider_rethrow(); 1191 } 1192#endif // _LIBCPP_NO_EXCEPTIONS 1193 return *this; 1194} 1195 1196template<class _CharT, class _Traits> 1197streamsize 1198basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) 1199{ 1200 __gc_ = 0; 1201#ifndef _LIBCPP_NO_EXCEPTIONS 1202 try 1203 { 1204#endif // _LIBCPP_NO_EXCEPTIONS 1205 sentry __sen(*this, true); 1206 if (__sen) 1207 { 1208 streamsize __c = this->rdbuf()->in_avail(); 1209 switch (__c) 1210 { 1211 case -1: 1212 this->setstate(ios_base::eofbit); 1213 break; 1214 case 0: 1215 break; 1216 default: 1217 read(__s, _VSTD::min(__c, __n)); 1218 break; 1219 } 1220 } 1221 else 1222 this->setstate(ios_base::failbit); 1223#ifndef _LIBCPP_NO_EXCEPTIONS 1224 } 1225 catch (...) 1226 { 1227 this->__set_badbit_and_consider_rethrow(); 1228 } 1229#endif // _LIBCPP_NO_EXCEPTIONS 1230 return __gc_; 1231} 1232 1233template<class _CharT, class _Traits> 1234basic_istream<_CharT, _Traits>& 1235basic_istream<_CharT, _Traits>::putback(char_type __c) 1236{ 1237 __gc_ = 0; 1238#ifndef _LIBCPP_NO_EXCEPTIONS 1239 try 1240 { 1241#endif // _LIBCPP_NO_EXCEPTIONS 1242 this->clear(this->rdstate() & ~ios_base::eofbit); 1243 sentry __sen(*this, true); 1244 if (__sen) 1245 { 1246 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) 1247 this->setstate(ios_base::badbit); 1248 } 1249 else 1250 this->setstate(ios_base::failbit); 1251#ifndef _LIBCPP_NO_EXCEPTIONS 1252 } 1253 catch (...) 1254 { 1255 this->__set_badbit_and_consider_rethrow(); 1256 } 1257#endif // _LIBCPP_NO_EXCEPTIONS 1258 return *this; 1259} 1260 1261template<class _CharT, class _Traits> 1262basic_istream<_CharT, _Traits>& 1263basic_istream<_CharT, _Traits>::unget() 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()->sungetc() == 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> 1290int 1291basic_istream<_CharT, _Traits>::sync() 1292{ 1293 int __r = 0; 1294#ifndef _LIBCPP_NO_EXCEPTIONS 1295 try 1296 { 1297#endif // _LIBCPP_NO_EXCEPTIONS 1298 sentry __sen(*this, true); 1299 if (__sen) 1300 { 1301 if (this->rdbuf() == 0) 1302 return -1; 1303 if (this->rdbuf()->pubsync() == -1) 1304 { 1305 this->setstate(ios_base::badbit); 1306 return -1; 1307 } 1308 } 1309#ifndef _LIBCPP_NO_EXCEPTIONS 1310 } 1311 catch (...) 1312 { 1313 this->__set_badbit_and_consider_rethrow(); 1314 } 1315#endif // _LIBCPP_NO_EXCEPTIONS 1316 return __r; 1317} 1318 1319template<class _CharT, class _Traits> 1320typename basic_istream<_CharT, _Traits>::pos_type 1321basic_istream<_CharT, _Traits>::tellg() 1322{ 1323 pos_type __r(-1); 1324#ifndef _LIBCPP_NO_EXCEPTIONS 1325 try 1326 { 1327#endif // _LIBCPP_NO_EXCEPTIONS 1328 sentry __sen(*this, true); 1329 if (__sen) 1330 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); 1331#ifndef _LIBCPP_NO_EXCEPTIONS 1332 } 1333 catch (...) 1334 { 1335 this->__set_badbit_and_consider_rethrow(); 1336 } 1337#endif // _LIBCPP_NO_EXCEPTIONS 1338 return __r; 1339} 1340 1341template<class _CharT, class _Traits> 1342basic_istream<_CharT, _Traits>& 1343basic_istream<_CharT, _Traits>::seekg(pos_type __pos) 1344{ 1345#ifndef _LIBCPP_NO_EXCEPTIONS 1346 try 1347 { 1348#endif // _LIBCPP_NO_EXCEPTIONS 1349 this->clear(this->rdstate() & ~ios_base::eofbit); 1350 sentry __sen(*this, true); 1351 if (__sen) 1352 { 1353 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) 1354 this->setstate(ios_base::failbit); 1355 } 1356#ifndef _LIBCPP_NO_EXCEPTIONS 1357 } 1358 catch (...) 1359 { 1360 this->__set_badbit_and_consider_rethrow(); 1361 } 1362#endif // _LIBCPP_NO_EXCEPTIONS 1363 return *this; 1364} 1365 1366template<class _CharT, class _Traits> 1367basic_istream<_CharT, _Traits>& 1368basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) 1369{ 1370#ifndef _LIBCPP_NO_EXCEPTIONS 1371 try 1372 { 1373#endif // _LIBCPP_NO_EXCEPTIONS 1374 this->clear(this->rdstate() & ~ios_base::eofbit); 1375 sentry __sen(*this, true); 1376 if (__sen) 1377 { 1378 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) 1379 this->setstate(ios_base::failbit); 1380 } 1381#ifndef _LIBCPP_NO_EXCEPTIONS 1382 } 1383 catch (...) 1384 { 1385 this->__set_badbit_and_consider_rethrow(); 1386 } 1387#endif // _LIBCPP_NO_EXCEPTIONS 1388 return *this; 1389} 1390 1391template <class _CharT, class _Traits> 1392basic_istream<_CharT, _Traits>& 1393ws(basic_istream<_CharT, _Traits>& __is) 1394{ 1395#ifndef _LIBCPP_NO_EXCEPTIONS 1396 try 1397 { 1398#endif // _LIBCPP_NO_EXCEPTIONS 1399 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); 1400 if (__sen) 1401 { 1402 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); 1403 while (true) 1404 { 1405 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1406 if (_Traits::eq_int_type(__i, _Traits::eof())) 1407 { 1408 __is.setstate(ios_base::eofbit); 1409 break; 1410 } 1411 if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) 1412 break; 1413 __is.rdbuf()->sbumpc(); 1414 } 1415 } 1416#ifndef _LIBCPP_NO_EXCEPTIONS 1417 } 1418 catch (...) 1419 { 1420 __is.__set_badbit_and_consider_rethrow(); 1421 } 1422#endif // _LIBCPP_NO_EXCEPTIONS 1423 return __is; 1424} 1425 1426#ifndef _LIBCPP_CXX03_LANG 1427 1428template <class _CharT, class _Traits, class _Tp> 1429inline _LIBCPP_INLINE_VISIBILITY 1430basic_istream<_CharT, _Traits>& 1431operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) 1432{ 1433 __is >> _VSTD::forward<_Tp>(__x); 1434 return __is; 1435} 1436 1437#endif // _LIBCPP_CXX03_LANG 1438 1439template <class _CharT, class _Traits> 1440class _LIBCPP_TEMPLATE_VIS basic_iostream 1441 : public basic_istream<_CharT, _Traits>, 1442 public basic_ostream<_CharT, _Traits> 1443{ 1444public: 1445 // types: 1446 typedef _CharT char_type; 1447 typedef _Traits traits_type; 1448 typedef typename traits_type::int_type int_type; 1449 typedef typename traits_type::pos_type pos_type; 1450 typedef typename traits_type::off_type off_type; 1451 1452 // constructor/destructor 1453 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 1454 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb) 1455 : basic_istream<_CharT, _Traits>(__sb) 1456 {} 1457 1458 virtual ~basic_iostream(); 1459protected: 1460#ifndef _LIBCPP_CXX03_LANG 1461 inline _LIBCPP_INLINE_VISIBILITY 1462 basic_iostream(basic_iostream&& __rhs); 1463 1464 // assign/swap 1465 inline _LIBCPP_INLINE_VISIBILITY 1466 basic_iostream& operator=(basic_iostream&& __rhs); 1467#endif 1468 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 1469 void swap(basic_iostream& __rhs) 1470 { basic_istream<char_type, traits_type>::swap(__rhs); } 1471public: 1472}; 1473 1474#ifndef _LIBCPP_CXX03_LANG 1475 1476template <class _CharT, class _Traits> 1477basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) 1478 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) 1479{ 1480} 1481 1482template <class _CharT, class _Traits> 1483basic_iostream<_CharT, _Traits>& 1484basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) 1485{ 1486 swap(__rhs); 1487 return *this; 1488} 1489 1490#endif // _LIBCPP_CXX03_LANG 1491 1492template <class _CharT, class _Traits> 1493basic_iostream<_CharT, _Traits>::~basic_iostream() 1494{ 1495} 1496 1497template<class _CharT, class _Traits, class _Allocator> 1498basic_istream<_CharT, _Traits>& 1499operator>>(basic_istream<_CharT, _Traits>& __is, 1500 basic_string<_CharT, _Traits, _Allocator>& __str) 1501{ 1502#ifndef _LIBCPP_NO_EXCEPTIONS 1503 try 1504 { 1505#endif // _LIBCPP_NO_EXCEPTIONS 1506 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 1507 if (__sen) 1508 { 1509 __str.clear(); 1510 streamsize __n = __is.width(); 1511 if (__n <= 0) 1512 __n = __str.max_size(); 1513 if (__n <= 0) 1514 __n = numeric_limits<streamsize>::max(); 1515 streamsize __c = 0; 1516 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); 1517 ios_base::iostate __err = ios_base::goodbit; 1518 while (__c < __n) 1519 { 1520 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1521 if (_Traits::eq_int_type(__i, _Traits::eof())) 1522 { 1523 __err |= ios_base::eofbit; 1524 break; 1525 } 1526 _CharT __ch = _Traits::to_char_type(__i); 1527 if (__ct.is(__ct.space, __ch)) 1528 break; 1529 __str.push_back(__ch); 1530 ++__c; 1531 __is.rdbuf()->sbumpc(); 1532 } 1533 __is.width(0); 1534 if (__c == 0) 1535 __err |= ios_base::failbit; 1536 __is.setstate(__err); 1537 } 1538 else 1539 __is.setstate(ios_base::failbit); 1540#ifndef _LIBCPP_NO_EXCEPTIONS 1541 } 1542 catch (...) 1543 { 1544 __is.__set_badbit_and_consider_rethrow(); 1545 } 1546#endif // _LIBCPP_NO_EXCEPTIONS 1547 return __is; 1548} 1549 1550template<class _CharT, class _Traits, class _Allocator> 1551basic_istream<_CharT, _Traits>& 1552getline(basic_istream<_CharT, _Traits>& __is, 1553 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) 1554{ 1555#ifndef _LIBCPP_NO_EXCEPTIONS 1556 try 1557 { 1558#endif // _LIBCPP_NO_EXCEPTIONS 1559 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); 1560 if (__sen) 1561 { 1562 __str.clear(); 1563 ios_base::iostate __err = ios_base::goodbit; 1564 streamsize __extr = 0; 1565 while (true) 1566 { 1567 typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); 1568 if (_Traits::eq_int_type(__i, _Traits::eof())) 1569 { 1570 __err |= ios_base::eofbit; 1571 break; 1572 } 1573 ++__extr; 1574 _CharT __ch = _Traits::to_char_type(__i); 1575 if (_Traits::eq(__ch, __dlm)) 1576 break; 1577 __str.push_back(__ch); 1578 if (__str.size() == __str.max_size()) 1579 { 1580 __err |= ios_base::failbit; 1581 break; 1582 } 1583 } 1584 if (__extr == 0) 1585 __err |= ios_base::failbit; 1586 __is.setstate(__err); 1587 } 1588#ifndef _LIBCPP_NO_EXCEPTIONS 1589 } 1590 catch (...) 1591 { 1592 __is.__set_badbit_and_consider_rethrow(); 1593 } 1594#endif // _LIBCPP_NO_EXCEPTIONS 1595 return __is; 1596} 1597 1598template<class _CharT, class _Traits, class _Allocator> 1599inline _LIBCPP_INLINE_VISIBILITY 1600basic_istream<_CharT, _Traits>& 1601getline(basic_istream<_CharT, _Traits>& __is, 1602 basic_string<_CharT, _Traits, _Allocator>& __str) 1603{ 1604 return getline(__is, __str, __is.widen('\n')); 1605} 1606 1607#ifndef _LIBCPP_CXX03_LANG 1608 1609template<class _CharT, class _Traits, class _Allocator> 1610inline _LIBCPP_INLINE_VISIBILITY 1611basic_istream<_CharT, _Traits>& 1612getline(basic_istream<_CharT, _Traits>&& __is, 1613 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) 1614{ 1615 return getline(__is, __str, __dlm); 1616} 1617 1618template<class _CharT, class _Traits, class _Allocator> 1619inline _LIBCPP_INLINE_VISIBILITY 1620basic_istream<_CharT, _Traits>& 1621getline(basic_istream<_CharT, _Traits>&& __is, 1622 basic_string<_CharT, _Traits, _Allocator>& __str) 1623{ 1624 return getline(__is, __str, __is.widen('\n')); 1625} 1626 1627#endif // _LIBCPP_CXX03_LANG 1628 1629template <class _CharT, class _Traits, size_t _Size> 1630basic_istream<_CharT, _Traits>& 1631operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) 1632{ 1633#ifndef _LIBCPP_NO_EXCEPTIONS 1634 try 1635 { 1636#endif // _LIBCPP_NO_EXCEPTIONS 1637 typename basic_istream<_CharT, _Traits>::sentry __sen(__is); 1638 if (__sen) 1639 { 1640 basic_string<_CharT, _Traits> __str; 1641 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); 1642 size_t __c = 0; 1643 ios_base::iostate __err = ios_base::goodbit; 1644 _CharT __zero = __ct.widen('0'); 1645 _CharT __one = __ct.widen('1'); 1646 while (__c < _Size) 1647 { 1648 typename _Traits::int_type __i = __is.rdbuf()->sgetc(); 1649 if (_Traits::eq_int_type(__i, _Traits::eof())) 1650 { 1651 __err |= ios_base::eofbit; 1652 break; 1653 } 1654 _CharT __ch = _Traits::to_char_type(__i); 1655 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) 1656 break; 1657 __str.push_back(__ch); 1658 ++__c; 1659 __is.rdbuf()->sbumpc(); 1660 } 1661 __x = bitset<_Size>(__str); 1662 if (__c == 0) 1663 __err |= ios_base::failbit; 1664 __is.setstate(__err); 1665 } 1666 else 1667 __is.setstate(ios_base::failbit); 1668#ifndef _LIBCPP_NO_EXCEPTIONS 1669 } 1670 catch (...) 1671 { 1672 __is.__set_badbit_and_consider_rethrow(); 1673 } 1674#endif // _LIBCPP_NO_EXCEPTIONS 1675 return __is; 1676} 1677 1678#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE 1679_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>) 1680_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>) 1681_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>) 1682#endif 1683 1684_LIBCPP_END_NAMESPACE_STD 1685 1686#endif // _LIBCPP_ISTREAM 1687