blob: 168a4d0635f6fb3f741d4277d45e81844d6c4ad9 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- istream ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
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);
Marshall Clow546eca82014-09-16 15:27:01 +000085protected:
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);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092};
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
Howard Hinnant66c6f972011-11-29 16:45:27 +0000165#include <__undef_min_max>
166
Howard Hinnant08e17472011-10-17 20:05:10 +0000167#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000168#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000169#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170
171_LIBCPP_BEGIN_NAMESPACE_STD
172
173template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000174class _LIBCPP_TYPE_VIS_ONLY basic_istream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175 : 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 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb);
188 virtual ~basic_istream();
189protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000190#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192 basic_istream(basic_istream&& __rhs);
193#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194 // 27.7.1.1.2 Assign/swap:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000195#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197 basic_istream& operator=(basic_istream&& __rhs);
198#endif
199 void swap(basic_istream& __rhs);
Marshall Clow546eca82014-09-16 15:27:01 +0000200
Marshall Clowbb9902e2014-09-17 01:58:15 +0000201#if _LIBCPP_STD_VER > 11
Marshall Clow546eca82014-09-16 15:27:01 +0000202#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Marshall Clowd1fae172014-09-16 15:33:53 +0000203 basic_istream (const basic_istream& __rhs) = delete;
204 basic_istream& operator=(const basic_istream& __rhs) = delete;
Marshall Clow546eca82014-09-16 15:27:01 +0000205#else
Marshall Clowbb9902e2014-09-17 01:58:15 +0000206 basic_istream (const basic_istream& __rhs); // not defined
207 basic_istream& operator=(const basic_istream& __rhs); // not defined
208#endif
Marshall Clow546eca82014-09-16 15:27:01 +0000209#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210public:
211
212 // 27.7.1.1.3 Prefix/suffix:
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000213 class _LIBCPP_TYPE_VIS_ONLY sentry;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214
215 // 27.7.1.2 Formatted input:
216 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
217 basic_istream& operator>>(basic_ios<char_type, traits_type>&
218 (*__pf)(basic_ios<char_type, traits_type>&));
219 basic_istream& operator>>(ios_base& (*__pf)(ios_base&));
220 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
221 basic_istream& operator>>(bool& __n);
222 basic_istream& operator>>(short& __n);
223 basic_istream& operator>>(unsigned short& __n);
224 basic_istream& operator>>(int& __n);
225 basic_istream& operator>>(unsigned int& __n);
226 basic_istream& operator>>(long& __n);
227 basic_istream& operator>>(unsigned long& __n);
228 basic_istream& operator>>(long long& __n);
229 basic_istream& operator>>(unsigned long long& __n);
230 basic_istream& operator>>(float& __f);
231 basic_istream& operator>>(double& __f);
232 basic_istream& operator>>(long double& __f);
233 basic_istream& operator>>(void*& __p);
234
235 // 27.7.1.3 Unformatted input:
Howard Hinnant68a8e902010-09-22 15:29:08 +0000236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237 streamsize gcount() const {return __gc_;}
238 int_type get();
239 basic_istream& get(char_type& __c);
240 basic_istream& get(char_type* __s, streamsize __n);
241 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
242 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
243 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
244
245 basic_istream& getline(char_type* __s, streamsize __n);
246 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
247
248 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
249 int_type peek();
250 basic_istream& read (char_type* __s, streamsize __n);
251 streamsize readsome(char_type* __s, streamsize __n);
252
253 basic_istream& putback(char_type __c);
254 basic_istream& unget();
255 int sync();
256
257 pos_type tellg();
258 basic_istream& seekg(pos_type __pos);
259 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
260};
261
262template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000263class _LIBCPP_TYPE_VIS_ONLY basic_istream<_CharT, _Traits>::sentry
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264{
265 bool __ok_;
266
267 sentry(const sentry&); // = delete;
268 sentry& operator=(const sentry&); // = delete;
269
270public:
271 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
272// ~sentry() = default;
273
Howard Hinnant68a8e902010-09-22 15:29:08 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +0000275 _LIBCPP_EXPLICIT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276 operator bool() const {return __ok_;}
277};
278
279template <class _CharT, class _Traits>
280basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
281 bool __noskipws)
282 : __ok_(false)
283{
284 if (__is.good())
285 {
286 if (__is.tie())
287 __is.tie()->flush();
288 if (!__noskipws && (__is.flags() & ios_base::skipws))
289 {
Howard Hinnant99968442011-11-29 18:15:50 +0000290 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnant99968442011-11-29 18:15:50 +0000292 _Ip __i(__is);
293 _Ip __eof;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294 for (; __i != __eof; ++__i)
295 if (!__ct.is(__ct.space, *__i))
296 break;
297 if (__i == __eof)
298 __is.setstate(ios_base::failbit | ios_base::eofbit);
299 }
300 __ok_ = __is.good();
301 }
302 else
303 __is.setstate(ios_base::failbit);
304}
305
306template <class _CharT, class _Traits>
307inline _LIBCPP_INLINE_VISIBILITY
308basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
309 : __gc_(0)
310{
311 this->init(__sb);
312}
313
Howard Hinnant73d21a42010-09-04 23:28:19 +0000314#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315
316template <class _CharT, class _Traits>
317inline _LIBCPP_INLINE_VISIBILITY
318basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
319 : __gc_(__rhs.__gc_)
320{
321 __rhs.__gc_ = 0;
322 this->move(__rhs);
323}
324
325template <class _CharT, class _Traits>
326inline _LIBCPP_INLINE_VISIBILITY
327basic_istream<_CharT, _Traits>&
328basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
329{
330 swap(__rhs);
331 return *this;
332}
333
Howard Hinnant73d21a42010-09-04 23:28:19 +0000334#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336template <class _CharT, class _Traits>
337basic_istream<_CharT, _Traits>::~basic_istream()
338{
339}
340
341template <class _CharT, class _Traits>
342inline _LIBCPP_INLINE_VISIBILITY
343void
344basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
345{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000346 _VSTD::swap(__gc_, __rhs.__gc_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347 basic_ios<char_type, traits_type>::swap(__rhs);
348}
349
350template <class _CharT, class _Traits>
351basic_istream<_CharT, _Traits>&
352basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
353{
354#ifndef _LIBCPP_NO_EXCEPTIONS
355 try
356 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000357#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358 sentry __s(*this);
359 if (__s)
360 {
Howard Hinnant99968442011-11-29 18:15:50 +0000361 typedef istreambuf_iterator<char_type, traits_type> _Ip;
362 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000364 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 this->setstate(__err);
366 }
367#ifndef _LIBCPP_NO_EXCEPTIONS
368 }
369 catch (...)
370 {
371 this->__set_badbit_and_consider_rethrow();
372 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000373#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 return *this;
375}
376
377template <class _CharT, class _Traits>
378basic_istream<_CharT, _Traits>&
379basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
380{
381#ifndef _LIBCPP_NO_EXCEPTIONS
382 try
383 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000384#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 sentry __s(*this);
386 if (__s)
387 {
Howard Hinnant99968442011-11-29 18:15:50 +0000388 typedef istreambuf_iterator<char_type, traits_type> _Ip;
389 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000391 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 this->setstate(__err);
393 }
394#ifndef _LIBCPP_NO_EXCEPTIONS
395 }
396 catch (...)
397 {
398 this->__set_badbit_and_consider_rethrow();
399 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000400#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401 return *this;
402}
403
404template <class _CharT, class _Traits>
405basic_istream<_CharT, _Traits>&
406basic_istream<_CharT, _Traits>::operator>>(long& __n)
407{
408#ifndef _LIBCPP_NO_EXCEPTIONS
409 try
410 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000411#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 sentry __s(*this);
413 if (__s)
414 {
Howard Hinnant99968442011-11-29 18:15:50 +0000415 typedef istreambuf_iterator<char_type, traits_type> _Ip;
416 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000418 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 this->setstate(__err);
420 }
421#ifndef _LIBCPP_NO_EXCEPTIONS
422 }
423 catch (...)
424 {
425 this->__set_badbit_and_consider_rethrow();
426 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000427#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 return *this;
429}
430
431template <class _CharT, class _Traits>
432basic_istream<_CharT, _Traits>&
433basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
434{
435#ifndef _LIBCPP_NO_EXCEPTIONS
436 try
437 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000438#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 sentry __s(*this);
440 if (__s)
441 {
Howard Hinnant99968442011-11-29 18:15:50 +0000442 typedef istreambuf_iterator<char_type, traits_type> _Ip;
443 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000445 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 this->setstate(__err);
447 }
448#ifndef _LIBCPP_NO_EXCEPTIONS
449 }
450 catch (...)
451 {
452 this->__set_badbit_and_consider_rethrow();
453 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000454#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 return *this;
456}
457
458template <class _CharT, class _Traits>
459basic_istream<_CharT, _Traits>&
460basic_istream<_CharT, _Traits>::operator>>(long long& __n)
461{
462#ifndef _LIBCPP_NO_EXCEPTIONS
463 try
464 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000465#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 sentry __s(*this);
467 if (__s)
468 {
Howard Hinnant99968442011-11-29 18:15:50 +0000469 typedef istreambuf_iterator<char_type, traits_type> _Ip;
470 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000472 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473 this->setstate(__err);
474 }
475#ifndef _LIBCPP_NO_EXCEPTIONS
476 }
477 catch (...)
478 {
479 this->__set_badbit_and_consider_rethrow();
480 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000481#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 return *this;
483}
484
485template <class _CharT, class _Traits>
486basic_istream<_CharT, _Traits>&
487basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
488{
489#ifndef _LIBCPP_NO_EXCEPTIONS
490 try
491 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000492#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 sentry __s(*this);
494 if (__s)
495 {
Howard Hinnant99968442011-11-29 18:15:50 +0000496 typedef istreambuf_iterator<char_type, traits_type> _Ip;
497 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000499 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 this->setstate(__err);
501 }
502#ifndef _LIBCPP_NO_EXCEPTIONS
503 }
504 catch (...)
505 {
506 this->__set_badbit_and_consider_rethrow();
507 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000508#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 return *this;
510}
511
512template <class _CharT, class _Traits>
513basic_istream<_CharT, _Traits>&
514basic_istream<_CharT, _Traits>::operator>>(float& __n)
515{
516#ifndef _LIBCPP_NO_EXCEPTIONS
517 try
518 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000519#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520 sentry __s(*this);
521 if (__s)
522 {
Howard Hinnant99968442011-11-29 18:15:50 +0000523 typedef istreambuf_iterator<char_type, traits_type> _Ip;
524 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000526 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 this->setstate(__err);
528 }
529#ifndef _LIBCPP_NO_EXCEPTIONS
530 }
531 catch (...)
532 {
533 this->__set_badbit_and_consider_rethrow();
534 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000535#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 return *this;
537}
538
539template <class _CharT, class _Traits>
540basic_istream<_CharT, _Traits>&
541basic_istream<_CharT, _Traits>::operator>>(double& __n)
542{
543#ifndef _LIBCPP_NO_EXCEPTIONS
544 try
545 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000546#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 sentry __s(*this);
548 if (__s)
549 {
Howard Hinnant99968442011-11-29 18:15:50 +0000550 typedef istreambuf_iterator<char_type, traits_type> _Ip;
551 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000553 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 this->setstate(__err);
555 }
556#ifndef _LIBCPP_NO_EXCEPTIONS
557 }
558 catch (...)
559 {
560 this->__set_badbit_and_consider_rethrow();
561 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000562#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563 return *this;
564}
565
566template <class _CharT, class _Traits>
567basic_istream<_CharT, _Traits>&
568basic_istream<_CharT, _Traits>::operator>>(long double& __n)
569{
570#ifndef _LIBCPP_NO_EXCEPTIONS
571 try
572 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000573#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574 sentry __s(*this);
575 if (__s)
576 {
Howard Hinnant99968442011-11-29 18:15:50 +0000577 typedef istreambuf_iterator<char_type, traits_type> _Ip;
578 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000580 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581 this->setstate(__err);
582 }
583#ifndef _LIBCPP_NO_EXCEPTIONS
584 }
585 catch (...)
586 {
587 this->__set_badbit_and_consider_rethrow();
588 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000589#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590 return *this;
591}
592
593template <class _CharT, class _Traits>
594basic_istream<_CharT, _Traits>&
595basic_istream<_CharT, _Traits>::operator>>(bool& __n)
596{
597#ifndef _LIBCPP_NO_EXCEPTIONS
598 try
599 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000600#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601 sentry __s(*this);
602 if (__s)
603 {
Howard Hinnant99968442011-11-29 18:15:50 +0000604 typedef istreambuf_iterator<char_type, traits_type> _Ip;
605 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000607 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 this->setstate(__err);
609 }
610#ifndef _LIBCPP_NO_EXCEPTIONS
611 }
612 catch (...)
613 {
614 this->__set_badbit_and_consider_rethrow();
615 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000616#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 return *this;
618}
619
620template <class _CharT, class _Traits>
621basic_istream<_CharT, _Traits>&
622basic_istream<_CharT, _Traits>::operator>>(void*& __n)
623{
624#ifndef _LIBCPP_NO_EXCEPTIONS
625 try
626 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000627#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 sentry __s(*this);
629 if (__s)
630 {
Howard Hinnant99968442011-11-29 18:15:50 +0000631 typedef istreambuf_iterator<char_type, traits_type> _Ip;
632 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant99968442011-11-29 18:15:50 +0000634 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 this->setstate(__err);
636 }
637#ifndef _LIBCPP_NO_EXCEPTIONS
638 }
639 catch (...)
640 {
641 this->__set_badbit_and_consider_rethrow();
642 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000643#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 return *this;
645}
646
647template <class _CharT, class _Traits>
648basic_istream<_CharT, _Traits>&
649basic_istream<_CharT, _Traits>::operator>>(short& __n)
650{
651#ifndef _LIBCPP_NO_EXCEPTIONS
652 try
653 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000654#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 sentry __s(*this);
656 if (__s)
657 {
Howard Hinnant99968442011-11-29 18:15:50 +0000658 typedef istreambuf_iterator<char_type, traits_type> _Ip;
659 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 ios_base::iostate __err = ios_base::goodbit;
661 long __temp;
Howard Hinnant99968442011-11-29 18:15:50 +0000662 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 if (__temp < numeric_limits<short>::min())
664 {
665 __err |= ios_base::failbit;
666 __n = numeric_limits<short>::min();
667 }
668 else if (__temp > numeric_limits<short>::max())
669 {
670 __err |= ios_base::failbit;
671 __n = numeric_limits<short>::max();
672 }
673 else
674 __n = static_cast<short>(__temp);
675 this->setstate(__err);
676 }
677#ifndef _LIBCPP_NO_EXCEPTIONS
678 }
679 catch (...)
680 {
681 this->__set_badbit_and_consider_rethrow();
682 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000683#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 return *this;
685}
686
687template <class _CharT, class _Traits>
688basic_istream<_CharT, _Traits>&
689basic_istream<_CharT, _Traits>::operator>>(int& __n)
690{
691#ifndef _LIBCPP_NO_EXCEPTIONS
692 try
693 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000694#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 sentry __s(*this);
696 if (__s)
697 {
Howard Hinnant99968442011-11-29 18:15:50 +0000698 typedef istreambuf_iterator<char_type, traits_type> _Ip;
699 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 ios_base::iostate __err = ios_base::goodbit;
701 long __temp;
Howard Hinnant99968442011-11-29 18:15:50 +0000702 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 if (__temp < numeric_limits<int>::min())
704 {
705 __err |= ios_base::failbit;
706 __n = numeric_limits<int>::min();
707 }
708 else if (__temp > numeric_limits<int>::max())
709 {
710 __err |= ios_base::failbit;
711 __n = numeric_limits<int>::max();
712 }
713 else
714 __n = static_cast<int>(__temp);
715 this->setstate(__err);
716 }
717#ifndef _LIBCPP_NO_EXCEPTIONS
718 }
719 catch (...)
720 {
721 this->__set_badbit_and_consider_rethrow();
722 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000723#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 return *this;
725}
726
727template <class _CharT, class _Traits>
728inline _LIBCPP_INLINE_VISIBILITY
729basic_istream<_CharT, _Traits>&
730basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
731{
732 return __pf(*this);
733}
734
735template <class _CharT, class _Traits>
736inline _LIBCPP_INLINE_VISIBILITY
737basic_istream<_CharT, _Traits>&
738basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
739 (*__pf)(basic_ios<char_type, traits_type>&))
740{
741 __pf(*this);
742 return *this;
743}
744
745template <class _CharT, class _Traits>
746inline _LIBCPP_INLINE_VISIBILITY
747basic_istream<_CharT, _Traits>&
748basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
749{
750 __pf(*this);
751 return *this;
752}
753
754template<class _CharT, class _Traits>
755basic_istream<_CharT, _Traits>&
756operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
757{
758#ifndef _LIBCPP_NO_EXCEPTIONS
759 try
760 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000761#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
763 if (__sen)
764 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 streamsize __n = __is.width();
Howard Hinnant92a836c2011-09-01 21:02:45 +0000766 if (__n <= 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
768 streamsize __c = 0;
769 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnant92a836c2011-09-01 21:02:45 +0000770 ios_base::iostate __err = ios_base::goodbit;
771 while (__c < __n-1)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 {
Howard Hinnant92a836c2011-09-01 21:02:45 +0000773 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
774 if (_Traits::eq_int_type(__i, _Traits::eof()))
775 {
776 __err |= ios_base::eofbit;
777 break;
778 }
779 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 if (__ct.is(__ct.space, __ch))
781 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +0000782 *__s++ = __ch;
783 ++__c;
784 __is.rdbuf()->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000785 }
786 *__s = _CharT();
787 __is.width(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 if (__c == 0)
789 __err |= ios_base::failbit;
790 __is.setstate(__err);
791 }
792#ifndef _LIBCPP_NO_EXCEPTIONS
793 }
794 catch (...)
795 {
796 __is.__set_badbit_and_consider_rethrow();
797 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 return __is;
800}
801
802template<class _Traits>
803inline _LIBCPP_INLINE_VISIBILITY
804basic_istream<char, _Traits>&
805operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
806{
807 return __is >> (char*)__s;
808}
809
810template<class _Traits>
811inline _LIBCPP_INLINE_VISIBILITY
812basic_istream<char, _Traits>&
813operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
814{
815 return __is >> (char*)__s;
816}
817
818template<class _CharT, class _Traits>
819basic_istream<_CharT, _Traits>&
820operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
821{
822#ifndef _LIBCPP_NO_EXCEPTIONS
823 try
824 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000825#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
827 if (__sen)
828 {
Howard Hinnantdf85e572011-02-27 18:02:02 +0000829 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
830 if (_Traits::eq_int_type(__i, _Traits::eof()))
831 __is.setstate(ios_base::eofbit | ios_base::failbit);
832 else
833 __c = _Traits::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834 }
835#ifndef _LIBCPP_NO_EXCEPTIONS
836 }
837 catch (...)
838 {
839 __is.__set_badbit_and_consider_rethrow();
840 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000841#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 return __is;
843}
844
845template<class _Traits>
846inline _LIBCPP_INLINE_VISIBILITY
847basic_istream<char, _Traits>&
848operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
849{
850 return __is >> (char&)__c;
851}
852
853template<class _Traits>
854inline _LIBCPP_INLINE_VISIBILITY
855basic_istream<char, _Traits>&
856operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
857{
858 return __is >> (char&)__c;
859}
860
861template<class _CharT, class _Traits>
862basic_istream<_CharT, _Traits>&
863basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
864{
865 __gc_ = 0;
866#ifndef _LIBCPP_NO_EXCEPTIONS
867 try
868 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000869#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 sentry __s(*this, true);
871 if (__s)
872 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 if (__sb)
874 {
875#ifndef _LIBCPP_NO_EXCEPTIONS
876 try
877 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000878#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnant92a836c2011-09-01 21:02:45 +0000880 while (true)
881 {
882 typename traits_type::int_type __i = this->rdbuf()->sgetc();
883 if (traits_type::eq_int_type(__i, _Traits::eof()))
884 {
885 __err |= ios_base::eofbit;
886 break;
887 }
888 if (traits_type::eq_int_type(
889 __sb->sputc(traits_type::to_char_type(__i)),
890 traits_type::eof()))
891 break;
892 ++__gc_;
893 this->rdbuf()->sbumpc();
894 }
895 if (__gc_ == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 __err |= ios_base::failbit;
897 this->setstate(__err);
898#ifndef _LIBCPP_NO_EXCEPTIONS
899 }
900 catch (...)
901 {
Howard Hinnant92a836c2011-09-01 21:02:45 +0000902 if (__gc_ == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 this->__set_failbit_and_consider_rethrow();
904 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000905#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906 }
907 else
908 this->setstate(ios_base::failbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 }
910#ifndef _LIBCPP_NO_EXCEPTIONS
911 }
912 catch (...)
913 {
914 this->__set_badbit_and_consider_rethrow();
915 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000916#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 return *this;
918}
919
920template<class _CharT, class _Traits>
921typename basic_istream<_CharT, _Traits>::int_type
922basic_istream<_CharT, _Traits>::get()
923{
924 __gc_ = 0;
925 int_type __r = traits_type::eof();
926#ifndef _LIBCPP_NO_EXCEPTIONS
927 try
928 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000929#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 sentry __s(*this, true);
931 if (__s)
932 {
Howard Hinnant92a836c2011-09-01 21:02:45 +0000933 __r = this->rdbuf()->sbumpc();
934 if (traits_type::eq_int_type(__r, traits_type::eof()))
935 this->setstate(ios_base::failbit | ios_base::eofbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 else
Howard Hinnant92a836c2011-09-01 21:02:45 +0000937 __gc_ = 1;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 }
939#ifndef _LIBCPP_NO_EXCEPTIONS
940 }
941 catch (...)
942 {
943 this->__set_badbit_and_consider_rethrow();
944 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000945#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946 return __r;
947}
948
949template<class _CharT, class _Traits>
950inline _LIBCPP_INLINE_VISIBILITY
951basic_istream<_CharT, _Traits>&
952basic_istream<_CharT, _Traits>::get(char_type& __c)
953{
954 int_type __ch = get();
955 if (__ch != traits_type::eof())
956 __c = traits_type::to_char_type(__ch);
957 return *this;
958}
959
960template<class _CharT, class _Traits>
961basic_istream<_CharT, _Traits>&
962basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
963{
964 __gc_ = 0;
965#ifndef _LIBCPP_NO_EXCEPTIONS
966 try
967 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000968#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969 sentry __sen(*this, true);
970 if (__sen)
971 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 if (__n > 0)
973 {
Howard Hinnant92a836c2011-09-01 21:02:45 +0000974 ios_base::iostate __err = ios_base::goodbit;
975 while (__gc_ < __n-1)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 {
Howard Hinnant92a836c2011-09-01 21:02:45 +0000977 int_type __i = this->rdbuf()->sgetc();
978 if (traits_type::eq_int_type(__i, traits_type::eof()))
979 {
980 __err |= ios_base::eofbit;
981 break;
982 }
983 char_type __ch = traits_type::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 if (traits_type::eq(__ch, __dlm))
985 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +0000986 *__s++ = __ch;
987 ++__gc_;
988 this->rdbuf()->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 }
990 *__s = char_type();
Howard Hinnant92a836c2011-09-01 21:02:45 +0000991 if (__gc_ == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992 __err |= ios_base::failbit;
993 this->setstate(__err);
994 }
995 else
996 this->setstate(ios_base::failbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 }
998#ifndef _LIBCPP_NO_EXCEPTIONS
999 }
1000 catch (...)
1001 {
1002 this->__set_badbit_and_consider_rethrow();
1003 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001004#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 return *this;
1006}
1007
1008template<class _CharT, class _Traits>
1009inline _LIBCPP_INLINE_VISIBILITY
1010basic_istream<_CharT, _Traits>&
1011basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
1012{
1013 return get(__s, __n, this->widen('\n'));
1014}
1015
1016template<class _CharT, class _Traits>
1017basic_istream<_CharT, _Traits>&
1018basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
1019 char_type __dlm)
1020{
1021 __gc_ = 0;
1022#ifndef _LIBCPP_NO_EXCEPTIONS
1023 try
1024 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001025#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026 sentry __sen(*this, true);
1027 if (__sen)
1028 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 ios_base::iostate __err = ios_base::goodbit;
1030#ifndef _LIBCPP_NO_EXCEPTIONS
1031 try
1032 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001033#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant92a836c2011-09-01 21:02:45 +00001034 while (true)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001036 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1037 if (traits_type::eq_int_type(__i, traits_type::eof()))
1038 {
1039 __err |= ios_base::eofbit;
1040 break;
1041 }
1042 char_type __ch = traits_type::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043 if (traits_type::eq(__ch, __dlm))
1044 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001045 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001047 ++__gc_;
1048 this->rdbuf()->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050#ifndef _LIBCPP_NO_EXCEPTIONS
1051 }
1052 catch (...)
1053 {
1054 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001055#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant92a836c2011-09-01 21:02:45 +00001056 if (__gc_ == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 __err |= ios_base::failbit;
1058 this->setstate(__err);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059 }
1060#ifndef _LIBCPP_NO_EXCEPTIONS
1061 }
1062 catch (...)
1063 {
1064 this->__set_badbit_and_consider_rethrow();
1065 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001066#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067 return *this;
1068}
1069
1070template<class _CharT, class _Traits>
1071inline _LIBCPP_INLINE_VISIBILITY
1072basic_istream<_CharT, _Traits>&
1073basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
1074{
1075 return get(__sb, this->widen('\n'));
1076}
1077
1078template<class _CharT, class _Traits>
1079basic_istream<_CharT, _Traits>&
1080basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1081{
1082 __gc_ = 0;
1083#ifndef _LIBCPP_NO_EXCEPTIONS
1084 try
1085 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001086#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087 sentry __sen(*this, true);
1088 if (__sen)
1089 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001090 ios_base::iostate __err = ios_base::goodbit;
1091 while (true)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001093 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1094 if (traits_type::eq_int_type(__i, traits_type::eof()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001096 __err |= ios_base::eofbit;
1097 break;
1098 }
1099 char_type __ch = traits_type::to_char_type(__i);
1100 if (traits_type::eq(__ch, __dlm))
1101 {
1102 this->rdbuf()->sbumpc();
1103 ++__gc_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 break;
1105 }
Howard Hinnant92a836c2011-09-01 21:02:45 +00001106 if (__gc_ >= __n-1)
1107 {
1108 __err |= ios_base::failbit;
1109 break;
1110 }
1111 *__s++ = __ch;
1112 this->rdbuf()->sbumpc();
1113 ++__gc_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 }
Howard Hinnant92a836c2011-09-01 21:02:45 +00001115 if (__n > 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116 *__s = char_type();
Howard Hinnant92a836c2011-09-01 21:02:45 +00001117 if (__gc_ == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 __err |= ios_base::failbit;
1119 this->setstate(__err);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 }
1121#ifndef _LIBCPP_NO_EXCEPTIONS
1122 }
1123 catch (...)
1124 {
1125 this->__set_badbit_and_consider_rethrow();
1126 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001127#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 return *this;
1129}
1130
1131template<class _CharT, class _Traits>
1132inline _LIBCPP_INLINE_VISIBILITY
1133basic_istream<_CharT, _Traits>&
1134basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
1135{
1136 return getline(__s, __n, this->widen('\n'));
1137}
1138
1139template<class _CharT, class _Traits>
1140basic_istream<_CharT, _Traits>&
1141basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1142{
1143 __gc_ = 0;
1144#ifndef _LIBCPP_NO_EXCEPTIONS
1145 try
1146 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001147#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 sentry __sen(*this, true);
1149 if (__sen)
1150 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001151 ios_base::iostate __err = ios_base::goodbit;
1152 if (__n == numeric_limits<streamsize>::max())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001154 while (true)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001156 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1157 if (traits_type::eq_int_type(__i, traits_type::eof()))
1158 {
1159 __err |= ios_base::eofbit;
1160 break;
1161 }
1162 ++__gc_;
Howard Hinnant11b87182013-07-01 00:37:50 +00001163 if (traits_type::eq_int_type(__i, __dlm))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164 break;
1165 }
1166 }
1167 else
1168 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001169 while (__gc_ < __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001171 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1172 if (traits_type::eq_int_type(__i, traits_type::eof()))
1173 {
1174 __err |= ios_base::eofbit;
1175 break;
1176 }
1177 ++__gc_;
Howard Hinnant11b87182013-07-01 00:37:50 +00001178 if (traits_type::eq_int_type(__i, __dlm))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 break;
1180 }
1181 }
Howard Hinnant92a836c2011-09-01 21:02:45 +00001182 this->setstate(__err);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 }
1184#ifndef _LIBCPP_NO_EXCEPTIONS
1185 }
1186 catch (...)
1187 {
1188 this->__set_badbit_and_consider_rethrow();
1189 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001190#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191 return *this;
1192}
1193
1194template<class _CharT, class _Traits>
1195typename basic_istream<_CharT, _Traits>::int_type
1196basic_istream<_CharT, _Traits>::peek()
1197{
1198 __gc_ = 0;
1199 int_type __r = traits_type::eof();
1200#ifndef _LIBCPP_NO_EXCEPTIONS
1201 try
1202 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001203#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204 sentry __sen(*this, true);
1205 if (__sen)
Howard Hinnant73c85c72012-11-01 17:32:07 +00001206 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207 __r = this->rdbuf()->sgetc();
Howard Hinnant73c85c72012-11-01 17:32:07 +00001208 if (traits_type::eq_int_type(__r, traits_type::eof()))
1209 this->setstate(ios_base::eofbit);
1210 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211#ifndef _LIBCPP_NO_EXCEPTIONS
1212 }
1213 catch (...)
1214 {
1215 this->__set_badbit_and_consider_rethrow();
1216 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001217#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 return __r;
1219}
1220
1221template<class _CharT, class _Traits>
1222basic_istream<_CharT, _Traits>&
1223basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1224{
1225 __gc_ = 0;
1226#ifndef _LIBCPP_NO_EXCEPTIONS
1227 try
1228 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001229#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230 sentry __sen(*this, true);
1231 if (__sen)
1232 {
Howard Hinnantcc7bdae2013-03-06 19:27:56 +00001233 __gc_ = this->rdbuf()->sgetn(__s, __n);
1234 if (__gc_ != __n)
1235 this->setstate(ios_base::failbit | ios_base::eofbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236 }
1237 else
1238 this->setstate(ios_base::failbit);
1239#ifndef _LIBCPP_NO_EXCEPTIONS
1240 }
1241 catch (...)
1242 {
1243 this->__set_badbit_and_consider_rethrow();
1244 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001245#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246 return *this;
1247}
1248
1249template<class _CharT, class _Traits>
1250streamsize
1251basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1252{
Howard Hinnantee717d82012-12-20 15:40:28 +00001253 __gc_ = 0;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001254 streamsize __c = this->rdbuf()->in_avail();
1255 switch (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001256 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001257 case -1:
1258 this->setstate(ios_base::eofbit);
1259 break;
1260 case 0:
1261 break;
1262 default:
1263 read(__s, _VSTD::min(__c, __n));
1264 break;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265 }
Howard Hinnant92a836c2011-09-01 21:02:45 +00001266 return __gc_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267}
1268
1269template<class _CharT, class _Traits>
1270basic_istream<_CharT, _Traits>&
1271basic_istream<_CharT, _Traits>::putback(char_type __c)
1272{
1273 __gc_ = 0;
1274#ifndef _LIBCPP_NO_EXCEPTIONS
1275 try
1276 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001277#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant37bdf0e2012-08-24 22:03:03 +00001278 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 sentry __sen(*this, true);
1280 if (__sen)
1281 {
1282 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1283 this->setstate(ios_base::badbit);
1284 }
1285 else
1286 this->setstate(ios_base::failbit);
1287#ifndef _LIBCPP_NO_EXCEPTIONS
1288 }
1289 catch (...)
1290 {
1291 this->__set_badbit_and_consider_rethrow();
1292 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001293#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294 return *this;
1295}
1296
1297template<class _CharT, class _Traits>
1298basic_istream<_CharT, _Traits>&
1299basic_istream<_CharT, _Traits>::unget()
1300{
1301 __gc_ = 0;
1302#ifndef _LIBCPP_NO_EXCEPTIONS
1303 try
1304 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001305#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant37bdf0e2012-08-24 22:03:03 +00001306 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307 sentry __sen(*this, true);
1308 if (__sen)
1309 {
1310 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1311 this->setstate(ios_base::badbit);
1312 }
1313 else
1314 this->setstate(ios_base::failbit);
1315#ifndef _LIBCPP_NO_EXCEPTIONS
1316 }
1317 catch (...)
1318 {
1319 this->__set_badbit_and_consider_rethrow();
1320 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001321#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322 return *this;
1323}
1324
1325template<class _CharT, class _Traits>
1326int
1327basic_istream<_CharT, _Traits>::sync()
1328{
1329 int __r = 0;
1330#ifndef _LIBCPP_NO_EXCEPTIONS
1331 try
1332 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001333#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 sentry __sen(*this, true);
1335 if (__sen)
1336 {
1337 if (this->rdbuf() == 0)
1338 return -1;
1339 if (this->rdbuf()->pubsync() == -1)
1340 {
1341 this->setstate(ios_base::badbit);
1342 return -1;
1343 }
1344 }
1345#ifndef _LIBCPP_NO_EXCEPTIONS
1346 }
1347 catch (...)
1348 {
1349 this->__set_badbit_and_consider_rethrow();
1350 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001351#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352 return __r;
1353}
1354
1355template<class _CharT, class _Traits>
1356typename basic_istream<_CharT, _Traits>::pos_type
1357basic_istream<_CharT, _Traits>::tellg()
1358{
1359 pos_type __r(-1);
1360#ifndef _LIBCPP_NO_EXCEPTIONS
1361 try
1362 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001363#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364 sentry __sen(*this, true);
1365 if (__sen)
1366 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1367#ifndef _LIBCPP_NO_EXCEPTIONS
1368 }
1369 catch (...)
1370 {
1371 this->__set_badbit_and_consider_rethrow();
1372 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001373#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 return __r;
1375}
1376
1377template<class _CharT, class _Traits>
1378basic_istream<_CharT, _Traits>&
1379basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1380{
1381#ifndef _LIBCPP_NO_EXCEPTIONS
1382 try
1383 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001384#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant37bdf0e2012-08-24 22:03:03 +00001385 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386 sentry __sen(*this, true);
1387 if (__sen)
Marshall Clow76a86702013-10-31 22:20:45 +00001388 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1390 this->setstate(ios_base::failbit);
Marshall Clow76a86702013-10-31 22:20:45 +00001391 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392#ifndef _LIBCPP_NO_EXCEPTIONS
1393 }
1394 catch (...)
1395 {
1396 this->__set_badbit_and_consider_rethrow();
1397 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001398#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 return *this;
1400}
1401
1402template<class _CharT, class _Traits>
1403basic_istream<_CharT, _Traits>&
1404basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1405{
1406#ifndef _LIBCPP_NO_EXCEPTIONS
1407 try
1408 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001409#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 sentry __sen(*this, true);
1411 if (__sen)
Marshall Clow76a86702013-10-31 22:20:45 +00001412 {
1413 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1414 this->setstate(ios_base::failbit);
1415 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416#ifndef _LIBCPP_NO_EXCEPTIONS
1417 }
1418 catch (...)
1419 {
1420 this->__set_badbit_and_consider_rethrow();
1421 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 return *this;
1424}
1425
1426template <class _CharT, class _Traits>
1427basic_istream<_CharT, _Traits>&
1428ws(basic_istream<_CharT, _Traits>& __is)
1429{
1430#ifndef _LIBCPP_NO_EXCEPTIONS
1431 try
1432 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001433#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1435 if (__sen)
1436 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnant92a836c2011-09-01 21:02:45 +00001438 while (true)
1439 {
1440 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1441 if (_Traits::eq_int_type(__i, _Traits::eof()))
1442 {
1443 __is.setstate(ios_base::eofbit);
1444 break;
1445 }
1446 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001448 __is.rdbuf()->sbumpc();
1449 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450 }
1451#ifndef _LIBCPP_NO_EXCEPTIONS
1452 }
1453 catch (...)
1454 {
1455 __is.__set_badbit_and_consider_rethrow();
1456 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001457#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 return __is;
1459}
1460
Howard Hinnant73d21a42010-09-04 23:28:19 +00001461#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462
1463template <class _CharT, class _Traits, class _Tp>
1464inline _LIBCPP_INLINE_VISIBILITY
1465basic_istream<_CharT, _Traits>&
1466operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
1467{
1468 __is >> __x;
1469 return __is;
1470}
1471
Howard Hinnant73d21a42010-09-04 23:28:19 +00001472#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473
1474template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001475class _LIBCPP_TYPE_VIS_ONLY basic_iostream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476 : public basic_istream<_CharT, _Traits>,
1477 public basic_ostream<_CharT, _Traits>
1478{
1479public:
1480 // types:
1481 typedef _CharT char_type;
1482 typedef _Traits traits_type;
1483 typedef typename traits_type::int_type int_type;
1484 typedef typename traits_type::pos_type pos_type;
1485 typedef typename traits_type::off_type off_type;
1486
1487 // constructor/destructor
1488 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
1489 virtual ~basic_iostream();
1490protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001491#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 basic_iostream(basic_iostream&& __rhs);
1494#endif
1495
1496 // assign/swap
Howard Hinnant73d21a42010-09-04 23:28:19 +00001497#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +00001498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 basic_iostream& operator=(basic_iostream&& __rhs);
1500#endif
1501 void swap(basic_iostream& __rhs);
1502public:
1503};
1504
1505template <class _CharT, class _Traits>
1506inline _LIBCPP_INLINE_VISIBILITY
1507basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1508 : basic_istream<_CharT, _Traits>(__sb)
1509{
1510}
1511
Howard Hinnant73d21a42010-09-04 23:28:19 +00001512#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513
1514template <class _CharT, class _Traits>
1515inline _LIBCPP_INLINE_VISIBILITY
1516basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001517 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518{
1519}
1520
1521template <class _CharT, class _Traits>
1522inline _LIBCPP_INLINE_VISIBILITY
1523basic_iostream<_CharT, _Traits>&
1524basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1525{
1526 swap(__rhs);
1527 return *this;
1528}
1529
Howard Hinnant73d21a42010-09-04 23:28:19 +00001530#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531
1532template <class _CharT, class _Traits>
1533basic_iostream<_CharT, _Traits>::~basic_iostream()
1534{
1535}
1536
1537template <class _CharT, class _Traits>
1538inline _LIBCPP_INLINE_VISIBILITY
1539void
1540basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
1541{
1542 basic_istream<char_type, traits_type>::swap(__rhs);
1543}
1544
1545template<class _CharT, class _Traits, class _Allocator>
1546basic_istream<_CharT, _Traits>&
1547operator>>(basic_istream<_CharT, _Traits>& __is,
1548 basic_string<_CharT, _Traits, _Allocator>& __str)
1549{
1550#ifndef _LIBCPP_NO_EXCEPTIONS
1551 try
1552 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1555 if (__sen)
1556 {
1557 __str.clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558 streamsize __n = __is.width();
Howard Hinnant92a836c2011-09-01 21:02:45 +00001559 if (__n <= 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560 __n = __str.max_size();
Howard Hinnant92a836c2011-09-01 21:02:45 +00001561 if (__n <= 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562 __n = numeric_limits<streamsize>::max();
1563 streamsize __c = 0;
1564 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnant92a836c2011-09-01 21:02:45 +00001565 ios_base::iostate __err = ios_base::goodbit;
1566 while (__c < __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001568 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1569 if (_Traits::eq_int_type(__i, _Traits::eof()))
1570 {
1571 __err |= ios_base::eofbit;
1572 break;
1573 }
1574 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001575 if (__ct.is(__ct.space, __ch))
1576 break;
1577 __str.push_back(__ch);
Howard Hinnant92a836c2011-09-01 21:02:45 +00001578 ++__c;
1579 __is.rdbuf()->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 }
1581 __is.width(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 if (__c == 0)
1583 __err |= ios_base::failbit;
1584 __is.setstate(__err);
1585 }
1586 else
1587 __is.setstate(ios_base::failbit);
1588#ifndef _LIBCPP_NO_EXCEPTIONS
1589 }
1590 catch (...)
1591 {
1592 __is.__set_badbit_and_consider_rethrow();
1593 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001594#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 return __is;
1596}
1597
1598template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +00001599basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600getline(basic_istream<_CharT, _Traits>& __is,
1601 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1602{
1603#ifndef _LIBCPP_NO_EXCEPTIONS
1604 try
1605 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001606#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1608 if (__sen)
1609 {
1610 __str.clear();
Howard Hinnant92a836c2011-09-01 21:02:45 +00001611 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantb97de442011-10-09 15:20:46 +00001612 streamsize __extr = 0;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001613 while (true)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001615 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1616 if (_Traits::eq_int_type(__i, _Traits::eof()))
1617 {
1618 __err |= ios_base::eofbit;
1619 break;
1620 }
Howard Hinnantb97de442011-10-09 15:20:46 +00001621 ++__extr;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001622 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 if (_Traits::eq(__ch, __dlm))
1624 break;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001625 __str.push_back(__ch);
1626 if (__str.size() == __str.max_size())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001628 __err |= ios_base::failbit;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 break;
1630 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 }
Howard Hinnantb97de442011-10-09 15:20:46 +00001632 if (__extr == 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633 __err |= ios_base::failbit;
1634 __is.setstate(__err);
1635 }
1636#ifndef _LIBCPP_NO_EXCEPTIONS
1637 }
1638 catch (...)
1639 {
1640 __is.__set_badbit_and_consider_rethrow();
1641 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001642#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643 return __is;
1644}
1645
1646template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001648basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649getline(basic_istream<_CharT, _Traits>& __is,
1650 basic_string<_CharT, _Traits, _Allocator>& __str)
1651{
1652 return getline(__is, __str, __is.widen('\n'));
1653}
1654
Howard Hinnant73d21a42010-09-04 23:28:19 +00001655#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001656
1657template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001659basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660getline(basic_istream<_CharT, _Traits>&& __is,
1661 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1662{
1663 return getline(__is, __str, __dlm);
1664}
1665
1666template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant68a8e902010-09-22 15:29:08 +00001667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00001668basic_istream<_CharT, _Traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669getline(basic_istream<_CharT, _Traits>&& __is,
1670 basic_string<_CharT, _Traits, _Allocator>& __str)
1671{
1672 return getline(__is, __str, __is.widen('\n'));
1673}
1674
Howard Hinnant73d21a42010-09-04 23:28:19 +00001675#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676
1677template <class _CharT, class _Traits, size_t _Size>
1678basic_istream<_CharT, _Traits>&
1679operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1680{
1681#ifndef _LIBCPP_NO_EXCEPTIONS
1682 try
1683 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001684#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1686 if (__sen)
1687 {
1688 basic_string<_CharT, _Traits> __str;
1689 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690 streamsize __c = 0;
Howard Hinnant92a836c2011-09-01 21:02:45 +00001691 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 _CharT __zero = __ct.widen('0');
1693 _CharT __one = __ct.widen('1');
Howard Hinnant92a836c2011-09-01 21:02:45 +00001694 while (__c < _Size)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 {
Howard Hinnant92a836c2011-09-01 21:02:45 +00001696 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1697 if (_Traits::eq_int_type(__i, _Traits::eof()))
1698 {
1699 __err |= ios_base::eofbit;
1700 break;
1701 }
1702 _CharT __ch = _Traits::to_char_type(__i);
1703 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704 break;
1705 __str.push_back(__ch);
Howard Hinnant92a836c2011-09-01 21:02:45 +00001706 ++__c;
1707 __is.rdbuf()->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 __x = bitset<_Size>(__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710 if (__c == 0)
1711 __err |= ios_base::failbit;
1712 __is.setstate(__err);
1713 }
1714 else
1715 __is.setstate(ios_base::failbit);
1716#ifndef _LIBCPP_NO_EXCEPTIONS
1717 }
1718 catch (...)
1719 {
1720 __is.__set_badbit_and_consider_rethrow();
1721 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001722#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001723 return __is;
1724}
1725
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001726_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<char>)
1727_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<wchar_t>)
1728_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_iostream<char>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729
1730_LIBCPP_END_NAMESPACE_STD
1731
1732#endif // _LIBCPP_ISTREAM