istream 50 KB

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