blob: f2579c14d8283414877386b58198dbf8b6adfd11 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- istream ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-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 Hinnantc51e1022010-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 Clow27d29872014-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 Hinnantc51e1022010-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 Hinnantaaaa52b2011-10-17 20:05:10 +0000165#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000167#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168
Eric Fiselierf4433a32017-05-31 22:07:49 +0000169_LIBCPP_PUSH_MACROS
170#include <__undef_macros>
171
172
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173_LIBCPP_BEGIN_NAMESPACE_STD
174
175template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000176class _LIBCPP_TEMPLATE_VIS basic_istream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 : virtual public basic_ios<_CharT, _Traits>
178{
179 streamsize __gc_;
180public:
181 // types (inherited from basic_ios (27.5.4)):
182 typedef _CharT char_type;
183 typedef _Traits traits_type;
184 typedef typename traits_type::int_type int_type;
185 typedef typename traits_type::pos_type pos_type;
186 typedef typename traits_type::off_type off_type;
187
188 // 27.7.1.1.1 Constructor/destructor:
Eric Fiselier815ed732016-09-16 00:00:48 +0000189 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
190 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0)
191 { this->init(__sb); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 virtual ~basic_istream();
193protected:
Eric Fiselier78ccf772017-04-18 23:38:41 +0000194#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier815ed732016-09-16 00:00:48 +0000195 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 basic_istream(basic_istream&& __rhs);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 // 27.7.1.1.2 Assign/swap:
Eric Fiselier815ed732016-09-16 00:00:48 +0000199 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 basic_istream& operator=(basic_istream&& __rhs);
201#endif
Eric Fiselier815ed732016-09-16 00:00:48 +0000202
203 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
204 void swap(basic_istream& __rhs) {
205 _VSTD::swap(__gc_, __rhs.__gc_);
206 basic_ios<char_type, traits_type>::swap(__rhs);
207 }
Marshall Clow27d29872014-09-16 15:27:01 +0000208
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000209#ifndef _LIBCPP_CXX03_LANG
Marshall Clow242d9c12014-09-16 15:33:53 +0000210 basic_istream (const basic_istream& __rhs) = delete;
211 basic_istream& operator=(const basic_istream& __rhs) = delete;
Marshall Clow27d29872014-09-16 15:27:01 +0000212#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213public:
214
215 // 27.7.1.1.3 Prefix/suffix:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000216 class _LIBCPP_TEMPLATE_VIS sentry;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
218 // 27.7.1.2 Formatted input:
Eric Fiselier815ed732016-09-16 00:00:48 +0000219 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
220 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&))
221 { return __pf(*this); }
222
223 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224 basic_istream& operator>>(basic_ios<char_type, traits_type>&
Eric Fiselier815ed732016-09-16 00:00:48 +0000225 (*__pf)(basic_ios<char_type, traits_type>&))
226 { __pf(*this); return *this; }
227
228 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
229 basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
230 { __pf(*this); return *this; }
231
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
233 basic_istream& operator>>(bool& __n);
234 basic_istream& operator>>(short& __n);
235 basic_istream& operator>>(unsigned short& __n);
236 basic_istream& operator>>(int& __n);
237 basic_istream& operator>>(unsigned int& __n);
238 basic_istream& operator>>(long& __n);
239 basic_istream& operator>>(unsigned long& __n);
240 basic_istream& operator>>(long long& __n);
241 basic_istream& operator>>(unsigned long long& __n);
242 basic_istream& operator>>(float& __f);
243 basic_istream& operator>>(double& __f);
244 basic_istream& operator>>(long double& __f);
245 basic_istream& operator>>(void*& __p);
246
247 // 27.7.1.3 Unformatted input:
Howard Hinnant64da2602010-09-22 15:29:08 +0000248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 streamsize gcount() const {return __gc_;}
250 int_type get();
Eric Fiselier815ed732016-09-16 00:00:48 +0000251
252 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
253 basic_istream& get(char_type& __c) {
254 int_type __ch = get();
255 if (__ch != traits_type::eof())
256 __c = traits_type::to_char_type(__ch);
257 return *this;
258 }
259
260 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
261 basic_istream& get(char_type* __s, streamsize __n)
262 { return get(__s, __n, this->widen('\n')); }
263
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
Eric Fiselier815ed732016-09-16 00:00:48 +0000265
266 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
267 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb)
268 { return get(__sb, this->widen('\n')); }
269
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
271
Eric Fiselier815ed732016-09-16 00:00:48 +0000272 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
273 basic_istream& getline(char_type* __s, streamsize __n)
274 { return getline(__s, __n, this->widen('\n')); }
275
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
277
278 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
279 int_type peek();
280 basic_istream& read (char_type* __s, streamsize __n);
281 streamsize readsome(char_type* __s, streamsize __n);
282
283 basic_istream& putback(char_type __c);
284 basic_istream& unget();
285 int sync();
286
287 pos_type tellg();
288 basic_istream& seekg(pos_type __pos);
289 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
290};
291
292template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000293class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294{
295 bool __ok_;
296
297 sentry(const sentry&); // = delete;
298 sentry& operator=(const sentry&); // = delete;
299
300public:
301 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
302// ~sentry() = default;
303
Howard Hinnant64da2602010-09-22 15:29:08 +0000304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +0000305 _LIBCPP_EXPLICIT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306 operator bool() const {return __ok_;}
307};
308
309template <class _CharT, class _Traits>
310basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
311 bool __noskipws)
312 : __ok_(false)
313{
314 if (__is.good())
315 {
316 if (__is.tie())
317 __is.tie()->flush();
318 if (!__noskipws && (__is.flags() & ios_base::skipws))
319 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000320 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnantc834c512011-11-29 18:15:50 +0000322 _Ip __i(__is);
323 _Ip __eof;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 for (; __i != __eof; ++__i)
325 if (!__ct.is(__ct.space, *__i))
326 break;
327 if (__i == __eof)
328 __is.setstate(ios_base::failbit | ios_base::eofbit);
329 }
330 __ok_ = __is.good();
331 }
332 else
333 __is.setstate(ios_base::failbit);
334}
335
Eric Fiselier78ccf772017-04-18 23:38:41 +0000336#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337
338template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
340 : __gc_(__rhs.__gc_)
341{
342 __rhs.__gc_ = 0;
343 this->move(__rhs);
344}
345
346template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347basic_istream<_CharT, _Traits>&
348basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
349{
350 swap(__rhs);
351 return *this;
352}
353
Eric Fiselier78ccf772017-04-18 23:38:41 +0000354#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
356template <class _CharT, class _Traits>
357basic_istream<_CharT, _Traits>::~basic_istream()
358{
359}
360
361template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362basic_istream<_CharT, _Traits>&
363basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
364{
365#ifndef _LIBCPP_NO_EXCEPTIONS
366 try
367 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000368#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369 sentry __s(*this);
370 if (__s)
371 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000372 typedef istreambuf_iterator<char_type, traits_type> _Ip;
373 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000375 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 this->setstate(__err);
377 }
378#ifndef _LIBCPP_NO_EXCEPTIONS
379 }
380 catch (...)
381 {
382 this->__set_badbit_and_consider_rethrow();
383 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000384#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 return *this;
386}
387
388template <class _CharT, class _Traits>
389basic_istream<_CharT, _Traits>&
390basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
391{
392#ifndef _LIBCPP_NO_EXCEPTIONS
393 try
394 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000395#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 sentry __s(*this);
397 if (__s)
398 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000399 typedef istreambuf_iterator<char_type, traits_type> _Ip;
400 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000402 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 this->setstate(__err);
404 }
405#ifndef _LIBCPP_NO_EXCEPTIONS
406 }
407 catch (...)
408 {
409 this->__set_badbit_and_consider_rethrow();
410 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000411#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 return *this;
413}
414
415template <class _CharT, class _Traits>
416basic_istream<_CharT, _Traits>&
417basic_istream<_CharT, _Traits>::operator>>(long& __n)
418{
419#ifndef _LIBCPP_NO_EXCEPTIONS
420 try
421 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 sentry __s(*this);
424 if (__s)
425 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000426 typedef istreambuf_iterator<char_type, traits_type> _Ip;
427 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000429 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 this->setstate(__err);
431 }
432#ifndef _LIBCPP_NO_EXCEPTIONS
433 }
434 catch (...)
435 {
436 this->__set_badbit_and_consider_rethrow();
437 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000438#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439 return *this;
440}
441
442template <class _CharT, class _Traits>
443basic_istream<_CharT, _Traits>&
444basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
445{
446#ifndef _LIBCPP_NO_EXCEPTIONS
447 try
448 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000449#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 sentry __s(*this);
451 if (__s)
452 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000453 typedef istreambuf_iterator<char_type, traits_type> _Ip;
454 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000456 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 this->setstate(__err);
458 }
459#ifndef _LIBCPP_NO_EXCEPTIONS
460 }
461 catch (...)
462 {
463 this->__set_badbit_and_consider_rethrow();
464 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000465#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 return *this;
467}
468
469template <class _CharT, class _Traits>
470basic_istream<_CharT, _Traits>&
471basic_istream<_CharT, _Traits>::operator>>(long long& __n)
472{
473#ifndef _LIBCPP_NO_EXCEPTIONS
474 try
475 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000476#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 sentry __s(*this);
478 if (__s)
479 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000480 typedef istreambuf_iterator<char_type, traits_type> _Ip;
481 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000483 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 this->setstate(__err);
485 }
486#ifndef _LIBCPP_NO_EXCEPTIONS
487 }
488 catch (...)
489 {
490 this->__set_badbit_and_consider_rethrow();
491 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000492#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 return *this;
494}
495
496template <class _CharT, class _Traits>
497basic_istream<_CharT, _Traits>&
498basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
499{
500#ifndef _LIBCPP_NO_EXCEPTIONS
501 try
502 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000503#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 sentry __s(*this);
505 if (__s)
506 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000507 typedef istreambuf_iterator<char_type, traits_type> _Ip;
508 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000510 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 this->setstate(__err);
512 }
513#ifndef _LIBCPP_NO_EXCEPTIONS
514 }
515 catch (...)
516 {
517 this->__set_badbit_and_consider_rethrow();
518 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000519#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 return *this;
521}
522
523template <class _CharT, class _Traits>
524basic_istream<_CharT, _Traits>&
525basic_istream<_CharT, _Traits>::operator>>(float& __n)
526{
527#ifndef _LIBCPP_NO_EXCEPTIONS
528 try
529 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000530#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 sentry __s(*this);
532 if (__s)
533 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000534 typedef istreambuf_iterator<char_type, traits_type> _Ip;
535 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000537 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 this->setstate(__err);
539 }
540#ifndef _LIBCPP_NO_EXCEPTIONS
541 }
542 catch (...)
543 {
544 this->__set_badbit_and_consider_rethrow();
545 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000546#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 return *this;
548}
549
550template <class _CharT, class _Traits>
551basic_istream<_CharT, _Traits>&
552basic_istream<_CharT, _Traits>::operator>>(double& __n)
553{
554#ifndef _LIBCPP_NO_EXCEPTIONS
555 try
556 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000557#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558 sentry __s(*this);
559 if (__s)
560 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000561 typedef istreambuf_iterator<char_type, traits_type> _Ip;
562 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000564 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 this->setstate(__err);
566 }
567#ifndef _LIBCPP_NO_EXCEPTIONS
568 }
569 catch (...)
570 {
571 this->__set_badbit_and_consider_rethrow();
572 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000573#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 return *this;
575}
576
577template <class _CharT, class _Traits>
578basic_istream<_CharT, _Traits>&
579basic_istream<_CharT, _Traits>::operator>>(long double& __n)
580{
581#ifndef _LIBCPP_NO_EXCEPTIONS
582 try
583 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000584#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 sentry __s(*this);
586 if (__s)
587 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000588 typedef istreambuf_iterator<char_type, traits_type> _Ip;
589 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000591 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 this->setstate(__err);
593 }
594#ifndef _LIBCPP_NO_EXCEPTIONS
595 }
596 catch (...)
597 {
598 this->__set_badbit_and_consider_rethrow();
599 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000600#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 return *this;
602}
603
604template <class _CharT, class _Traits>
605basic_istream<_CharT, _Traits>&
606basic_istream<_CharT, _Traits>::operator>>(bool& __n)
607{
608#ifndef _LIBCPP_NO_EXCEPTIONS
609 try
610 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000611#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 sentry __s(*this);
613 if (__s)
614 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000615 typedef istreambuf_iterator<char_type, traits_type> _Ip;
616 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000618 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619 this->setstate(__err);
620 }
621#ifndef _LIBCPP_NO_EXCEPTIONS
622 }
623 catch (...)
624 {
625 this->__set_badbit_and_consider_rethrow();
626 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000627#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628 return *this;
629}
630
631template <class _CharT, class _Traits>
632basic_istream<_CharT, _Traits>&
633basic_istream<_CharT, _Traits>::operator>>(void*& __n)
634{
635#ifndef _LIBCPP_NO_EXCEPTIONS
636 try
637 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000638#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639 sentry __s(*this);
640 if (__s)
641 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000642 typedef istreambuf_iterator<char_type, traits_type> _Ip;
643 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc834c512011-11-29 18:15:50 +0000645 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646 this->setstate(__err);
647 }
648#ifndef _LIBCPP_NO_EXCEPTIONS
649 }
650 catch (...)
651 {
652 this->__set_badbit_and_consider_rethrow();
653 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000654#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655 return *this;
656}
657
658template <class _CharT, class _Traits>
659basic_istream<_CharT, _Traits>&
660basic_istream<_CharT, _Traits>::operator>>(short& __n)
661{
662#ifndef _LIBCPP_NO_EXCEPTIONS
663 try
664 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000665#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 sentry __s(*this);
667 if (__s)
668 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000669 typedef istreambuf_iterator<char_type, traits_type> _Ip;
670 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 ios_base::iostate __err = ios_base::goodbit;
672 long __temp;
Howard Hinnantc834c512011-11-29 18:15:50 +0000673 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 if (__temp < numeric_limits<short>::min())
675 {
676 __err |= ios_base::failbit;
677 __n = numeric_limits<short>::min();
678 }
679 else if (__temp > numeric_limits<short>::max())
680 {
681 __err |= ios_base::failbit;
682 __n = numeric_limits<short>::max();
683 }
684 else
685 __n = static_cast<short>(__temp);
686 this->setstate(__err);
687 }
688#ifndef _LIBCPP_NO_EXCEPTIONS
689 }
690 catch (...)
691 {
692 this->__set_badbit_and_consider_rethrow();
693 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000694#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 return *this;
696}
697
698template <class _CharT, class _Traits>
699basic_istream<_CharT, _Traits>&
700basic_istream<_CharT, _Traits>::operator>>(int& __n)
701{
702#ifndef _LIBCPP_NO_EXCEPTIONS
703 try
704 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000705#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 sentry __s(*this);
707 if (__s)
708 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000709 typedef istreambuf_iterator<char_type, traits_type> _Ip;
710 typedef num_get<char_type, _Ip> _Fp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 ios_base::iostate __err = ios_base::goodbit;
712 long __temp;
Howard Hinnantc834c512011-11-29 18:15:50 +0000713 use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 if (__temp < numeric_limits<int>::min())
715 {
716 __err |= ios_base::failbit;
717 __n = numeric_limits<int>::min();
718 }
719 else if (__temp > numeric_limits<int>::max())
720 {
721 __err |= ios_base::failbit;
722 __n = numeric_limits<int>::max();
723 }
724 else
725 __n = static_cast<int>(__temp);
726 this->setstate(__err);
727 }
728#ifndef _LIBCPP_NO_EXCEPTIONS
729 }
730 catch (...)
731 {
732 this->__set_badbit_and_consider_rethrow();
733 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000734#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 return *this;
736}
737
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738template<class _CharT, class _Traits>
739basic_istream<_CharT, _Traits>&
740operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
741{
742#ifndef _LIBCPP_NO_EXCEPTIONS
743 try
744 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000745#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
747 if (__sen)
748 {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749 streamsize __n = __is.width();
Howard Hinnante51e4e92011-09-01 21:02:45 +0000750 if (__n <= 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
752 streamsize __c = 0;
753 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnante51e4e92011-09-01 21:02:45 +0000754 ios_base::iostate __err = ios_base::goodbit;
755 while (__c < __n-1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756 {
Howard Hinnante51e4e92011-09-01 21:02:45 +0000757 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
758 if (_Traits::eq_int_type(__i, _Traits::eof()))
759 {
760 __err |= ios_base::eofbit;
761 break;
762 }
763 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 if (__ct.is(__ct.space, __ch))
765 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +0000766 *__s++ = __ch;
767 ++__c;
768 __is.rdbuf()->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 }
770 *__s = _CharT();
771 __is.width(0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772 if (__c == 0)
773 __err |= ios_base::failbit;
774 __is.setstate(__err);
775 }
776#ifndef _LIBCPP_NO_EXCEPTIONS
777 }
778 catch (...)
779 {
780 __is.__set_badbit_and_consider_rethrow();
781 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000782#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 return __is;
784}
785
786template<class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000787inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788basic_istream<char, _Traits>&
789operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
790{
791 return __is >> (char*)__s;
792}
793
794template<class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000795inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796basic_istream<char, _Traits>&
797operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
798{
799 return __is >> (char*)__s;
800}
801
802template<class _CharT, class _Traits>
803basic_istream<_CharT, _Traits>&
804operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
805{
806#ifndef _LIBCPP_NO_EXCEPTIONS
807 try
808 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000809#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
811 if (__sen)
812 {
Howard Hinnantb2e8a422011-02-27 18:02:02 +0000813 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
814 if (_Traits::eq_int_type(__i, _Traits::eof()))
815 __is.setstate(ios_base::eofbit | ios_base::failbit);
816 else
817 __c = _Traits::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 }
819#ifndef _LIBCPP_NO_EXCEPTIONS
820 }
821 catch (...)
822 {
823 __is.__set_badbit_and_consider_rethrow();
824 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000825#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 return __is;
827}
828
829template<class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000830inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831basic_istream<char, _Traits>&
832operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
833{
834 return __is >> (char&)__c;
835}
836
837template<class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839basic_istream<char, _Traits>&
840operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
841{
842 return __is >> (char&)__c;
843}
844
845template<class _CharT, class _Traits>
846basic_istream<_CharT, _Traits>&
847basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
848{
849 __gc_ = 0;
850#ifndef _LIBCPP_NO_EXCEPTIONS
851 try
852 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000853#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 sentry __s(*this, true);
855 if (__s)
856 {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 if (__sb)
858 {
859#ifndef _LIBCPP_NO_EXCEPTIONS
860 try
861 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000862#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnante51e4e92011-09-01 21:02:45 +0000864 while (true)
865 {
866 typename traits_type::int_type __i = this->rdbuf()->sgetc();
867 if (traits_type::eq_int_type(__i, _Traits::eof()))
868 {
869 __err |= ios_base::eofbit;
870 break;
871 }
872 if (traits_type::eq_int_type(
873 __sb->sputc(traits_type::to_char_type(__i)),
874 traits_type::eof()))
875 break;
876 ++__gc_;
877 this->rdbuf()->sbumpc();
878 }
879 if (__gc_ == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 __err |= ios_base::failbit;
881 this->setstate(__err);
882#ifndef _LIBCPP_NO_EXCEPTIONS
883 }
884 catch (...)
885 {
Howard Hinnante51e4e92011-09-01 21:02:45 +0000886 if (__gc_ == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 this->__set_failbit_and_consider_rethrow();
888 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000889#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 }
891 else
892 this->setstate(ios_base::failbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 }
894#ifndef _LIBCPP_NO_EXCEPTIONS
895 }
896 catch (...)
897 {
898 this->__set_badbit_and_consider_rethrow();
899 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000900#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901 return *this;
902}
903
904template<class _CharT, class _Traits>
905typename basic_istream<_CharT, _Traits>::int_type
906basic_istream<_CharT, _Traits>::get()
907{
908 __gc_ = 0;
909 int_type __r = traits_type::eof();
910#ifndef _LIBCPP_NO_EXCEPTIONS
911 try
912 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000913#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 sentry __s(*this, true);
915 if (__s)
916 {
Howard Hinnante51e4e92011-09-01 21:02:45 +0000917 __r = this->rdbuf()->sbumpc();
918 if (traits_type::eq_int_type(__r, traits_type::eof()))
919 this->setstate(ios_base::failbit | ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 else
Howard Hinnante51e4e92011-09-01 21:02:45 +0000921 __gc_ = 1;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 }
923#ifndef _LIBCPP_NO_EXCEPTIONS
924 }
925 catch (...)
926 {
927 this->__set_badbit_and_consider_rethrow();
928 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000929#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930 return __r;
931}
932
933template<class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934basic_istream<_CharT, _Traits>&
935basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
936{
937 __gc_ = 0;
938#ifndef _LIBCPP_NO_EXCEPTIONS
939 try
940 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000941#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 sentry __sen(*this, true);
943 if (__sen)
944 {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945 if (__n > 0)
946 {
Howard Hinnante51e4e92011-09-01 21:02:45 +0000947 ios_base::iostate __err = ios_base::goodbit;
948 while (__gc_ < __n-1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 {
Howard Hinnante51e4e92011-09-01 21:02:45 +0000950 int_type __i = this->rdbuf()->sgetc();
951 if (traits_type::eq_int_type(__i, traits_type::eof()))
952 {
953 __err |= ios_base::eofbit;
954 break;
955 }
956 char_type __ch = traits_type::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957 if (traits_type::eq(__ch, __dlm))
958 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +0000959 *__s++ = __ch;
960 ++__gc_;
961 this->rdbuf()->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962 }
Howard Hinnante51e4e92011-09-01 21:02:45 +0000963 if (__gc_ == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 __err |= ios_base::failbit;
965 this->setstate(__err);
966 }
967 else
968 this->setstate(ios_base::failbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 }
Volodymyr Sapsai99be85e2018-01-11 23:23:49 +0000970 if (__n > 0)
971 *__s = char_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972#ifndef _LIBCPP_NO_EXCEPTIONS
973 }
974 catch (...)
975 {
Volodymyr Sapsai99be85e2018-01-11 23:23:49 +0000976 if (__n > 0)
977 *__s = char_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 this->__set_badbit_and_consider_rethrow();
979 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000980#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 return *this;
982}
983
984template<class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985basic_istream<_CharT, _Traits>&
986basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
987 char_type __dlm)
988{
989 __gc_ = 0;
990#ifndef _LIBCPP_NO_EXCEPTIONS
991 try
992 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000993#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 sentry __sen(*this, true);
995 if (__sen)
996 {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 ios_base::iostate __err = ios_base::goodbit;
998#ifndef _LIBCPP_NO_EXCEPTIONS
999 try
1000 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001001#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante51e4e92011-09-01 21:02:45 +00001002 while (true)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001004 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1005 if (traits_type::eq_int_type(__i, traits_type::eof()))
1006 {
1007 __err |= ios_base::eofbit;
1008 break;
1009 }
1010 char_type __ch = traits_type::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011 if (traits_type::eq(__ch, __dlm))
1012 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001013 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001015 ++__gc_;
1016 this->rdbuf()->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018#ifndef _LIBCPP_NO_EXCEPTIONS
1019 }
1020 catch (...)
1021 {
1022 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001023#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante51e4e92011-09-01 21:02:45 +00001024 if (__gc_ == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 __err |= ios_base::failbit;
1026 this->setstate(__err);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 }
1028#ifndef _LIBCPP_NO_EXCEPTIONS
1029 }
1030 catch (...)
1031 {
1032 this->__set_badbit_and_consider_rethrow();
1033 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001034#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 return *this;
1036}
1037
1038template<class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039basic_istream<_CharT, _Traits>&
1040basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
1041{
1042 __gc_ = 0;
1043#ifndef _LIBCPP_NO_EXCEPTIONS
1044 try
1045 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001046#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 sentry __sen(*this, true);
1048 if (__sen)
1049 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001050 ios_base::iostate __err = ios_base::goodbit;
1051 while (true)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001053 typename traits_type::int_type __i = this->rdbuf()->sgetc();
1054 if (traits_type::eq_int_type(__i, traits_type::eof()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001056 __err |= ios_base::eofbit;
1057 break;
1058 }
1059 char_type __ch = traits_type::to_char_type(__i);
1060 if (traits_type::eq(__ch, __dlm))
1061 {
1062 this->rdbuf()->sbumpc();
1063 ++__gc_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 break;
1065 }
Howard Hinnante51e4e92011-09-01 21:02:45 +00001066 if (__gc_ >= __n-1)
1067 {
1068 __err |= ios_base::failbit;
1069 break;
1070 }
1071 *__s++ = __ch;
1072 this->rdbuf()->sbumpc();
1073 ++__gc_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 }
Howard Hinnante51e4e92011-09-01 21:02:45 +00001075 if (__gc_ == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 __err |= ios_base::failbit;
1077 this->setstate(__err);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 }
Volodymyr Sapsaib801d702017-11-22 18:52:36 +00001079 if (__n > 0)
1080 *__s = char_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081#ifndef _LIBCPP_NO_EXCEPTIONS
1082 }
1083 catch (...)
1084 {
Volodymyr Sapsaib801d702017-11-22 18:52:36 +00001085 if (__n > 0)
1086 *__s = char_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 this->__set_badbit_and_consider_rethrow();
1088 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001089#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 return *this;
1091}
1092
1093template<class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094basic_istream<_CharT, _Traits>&
1095basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
1096{
1097 __gc_ = 0;
1098#ifndef _LIBCPP_NO_EXCEPTIONS
1099 try
1100 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001101#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 sentry __sen(*this, true);
1103 if (__sen)
1104 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001105 ios_base::iostate __err = ios_base::goodbit;
1106 if (__n == numeric_limits<streamsize>::max())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001108 while (true)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001110 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1111 if (traits_type::eq_int_type(__i, traits_type::eof()))
1112 {
1113 __err |= ios_base::eofbit;
1114 break;
1115 }
1116 ++__gc_;
Howard Hinnant4df1e3f2013-07-01 00:37:50 +00001117 if (traits_type::eq_int_type(__i, __dlm))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118 break;
1119 }
1120 }
1121 else
1122 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001123 while (__gc_ < __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001125 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
1126 if (traits_type::eq_int_type(__i, traits_type::eof()))
1127 {
1128 __err |= ios_base::eofbit;
1129 break;
1130 }
1131 ++__gc_;
Howard Hinnant4df1e3f2013-07-01 00:37:50 +00001132 if (traits_type::eq_int_type(__i, __dlm))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 break;
1134 }
1135 }
Howard Hinnante51e4e92011-09-01 21:02:45 +00001136 this->setstate(__err);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 }
1138#ifndef _LIBCPP_NO_EXCEPTIONS
1139 }
1140 catch (...)
1141 {
1142 this->__set_badbit_and_consider_rethrow();
1143 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001144#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 return *this;
1146}
1147
1148template<class _CharT, class _Traits>
1149typename basic_istream<_CharT, _Traits>::int_type
1150basic_istream<_CharT, _Traits>::peek()
1151{
1152 __gc_ = 0;
1153 int_type __r = traits_type::eof();
1154#ifndef _LIBCPP_NO_EXCEPTIONS
1155 try
1156 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001157#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 sentry __sen(*this, true);
1159 if (__sen)
Howard Hinnanta4427372012-11-01 17:32:07 +00001160 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161 __r = this->rdbuf()->sgetc();
Howard Hinnanta4427372012-11-01 17:32:07 +00001162 if (traits_type::eq_int_type(__r, traits_type::eof()))
1163 this->setstate(ios_base::eofbit);
1164 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165#ifndef _LIBCPP_NO_EXCEPTIONS
1166 }
1167 catch (...)
1168 {
1169 this->__set_badbit_and_consider_rethrow();
1170 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001171#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172 return __r;
1173}
1174
1175template<class _CharT, class _Traits>
1176basic_istream<_CharT, _Traits>&
1177basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1178{
1179 __gc_ = 0;
1180#ifndef _LIBCPP_NO_EXCEPTIONS
1181 try
1182 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001183#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184 sentry __sen(*this, true);
1185 if (__sen)
1186 {
Howard Hinnant232466c2013-03-06 19:27:56 +00001187 __gc_ = this->rdbuf()->sgetn(__s, __n);
1188 if (__gc_ != __n)
1189 this->setstate(ios_base::failbit | ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 }
1191 else
1192 this->setstate(ios_base::failbit);
1193#ifndef _LIBCPP_NO_EXCEPTIONS
1194 }
1195 catch (...)
1196 {
1197 this->__set_badbit_and_consider_rethrow();
1198 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001199#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 return *this;
1201}
1202
1203template<class _CharT, class _Traits>
1204streamsize
1205basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
1206{
Howard Hinnantaf8555c2012-12-20 15:40:28 +00001207 __gc_ = 0;
Marshall Clow1c6e3862016-07-13 16:58:48 +00001208#ifndef _LIBCPP_NO_EXCEPTIONS
1209 try
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 {
Marshall Clow1c6e3862016-07-13 16:58:48 +00001211#endif // _LIBCPP_NO_EXCEPTIONS
1212 sentry __sen(*this, true);
1213 if (__sen)
1214 {
1215 streamsize __c = this->rdbuf()->in_avail();
1216 switch (__c)
1217 {
1218 case -1:
1219 this->setstate(ios_base::eofbit);
1220 break;
1221 case 0:
1222 break;
1223 default:
1224 read(__s, _VSTD::min(__c, __n));
1225 break;
1226 }
1227 }
1228 else
1229 this->setstate(ios_base::failbit);
1230#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231 }
Marshall Clow1c6e3862016-07-13 16:58:48 +00001232 catch (...)
1233 {
1234 this->__set_badbit_and_consider_rethrow();
1235 }
1236#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante51e4e92011-09-01 21:02:45 +00001237 return __gc_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238}
1239
1240template<class _CharT, class _Traits>
1241basic_istream<_CharT, _Traits>&
1242basic_istream<_CharT, _Traits>::putback(char_type __c)
1243{
1244 __gc_ = 0;
1245#ifndef _LIBCPP_NO_EXCEPTIONS
1246 try
1247 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001248#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0c8d6a42012-08-24 22:03:03 +00001249 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250 sentry __sen(*this, true);
1251 if (__sen)
1252 {
1253 if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
1254 this->setstate(ios_base::badbit);
1255 }
1256 else
1257 this->setstate(ios_base::failbit);
1258#ifndef _LIBCPP_NO_EXCEPTIONS
1259 }
1260 catch (...)
1261 {
1262 this->__set_badbit_and_consider_rethrow();
1263 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001264#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 return *this;
1266}
1267
1268template<class _CharT, class _Traits>
1269basic_istream<_CharT, _Traits>&
1270basic_istream<_CharT, _Traits>::unget()
1271{
1272 __gc_ = 0;
1273#ifndef _LIBCPP_NO_EXCEPTIONS
1274 try
1275 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001276#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0c8d6a42012-08-24 22:03:03 +00001277 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 sentry __sen(*this, true);
1279 if (__sen)
1280 {
1281 if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
1282 this->setstate(ios_base::badbit);
1283 }
1284 else
1285 this->setstate(ios_base::failbit);
1286#ifndef _LIBCPP_NO_EXCEPTIONS
1287 }
1288 catch (...)
1289 {
1290 this->__set_badbit_and_consider_rethrow();
1291 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001292#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 return *this;
1294}
1295
1296template<class _CharT, class _Traits>
1297int
1298basic_istream<_CharT, _Traits>::sync()
1299{
1300 int __r = 0;
1301#ifndef _LIBCPP_NO_EXCEPTIONS
1302 try
1303 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001304#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305 sentry __sen(*this, true);
1306 if (__sen)
1307 {
1308 if (this->rdbuf() == 0)
1309 return -1;
1310 if (this->rdbuf()->pubsync() == -1)
1311 {
1312 this->setstate(ios_base::badbit);
1313 return -1;
1314 }
1315 }
1316#ifndef _LIBCPP_NO_EXCEPTIONS
1317 }
1318 catch (...)
1319 {
1320 this->__set_badbit_and_consider_rethrow();
1321 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001322#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 return __r;
1324}
1325
1326template<class _CharT, class _Traits>
1327typename basic_istream<_CharT, _Traits>::pos_type
1328basic_istream<_CharT, _Traits>::tellg()
1329{
1330 pos_type __r(-1);
1331#ifndef _LIBCPP_NO_EXCEPTIONS
1332 try
1333 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001334#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335 sentry __sen(*this, true);
1336 if (__sen)
1337 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1338#ifndef _LIBCPP_NO_EXCEPTIONS
1339 }
1340 catch (...)
1341 {
1342 this->__set_badbit_and_consider_rethrow();
1343 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001344#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345 return __r;
1346}
1347
1348template<class _CharT, class _Traits>
1349basic_istream<_CharT, _Traits>&
1350basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
1351{
1352#ifndef _LIBCPP_NO_EXCEPTIONS
1353 try
1354 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001355#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0c8d6a42012-08-24 22:03:03 +00001356 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357 sentry __sen(*this, true);
1358 if (__sen)
Marshall Clow29c4daa2013-10-31 22:20:45 +00001359 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1361 this->setstate(ios_base::failbit);
Marshall Clow29c4daa2013-10-31 22:20:45 +00001362 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363#ifndef _LIBCPP_NO_EXCEPTIONS
1364 }
1365 catch (...)
1366 {
1367 this->__set_badbit_and_consider_rethrow();
1368 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001369#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 return *this;
1371}
1372
1373template<class _CharT, class _Traits>
1374basic_istream<_CharT, _Traits>&
1375basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1376{
1377#ifndef _LIBCPP_NO_EXCEPTIONS
1378 try
1379 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001380#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clow41d9e3a2015-10-25 18:31:51 +00001381 this->clear(this->rdstate() & ~ios_base::eofbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382 sentry __sen(*this, true);
1383 if (__sen)
Marshall Clow29c4daa2013-10-31 22:20:45 +00001384 {
1385 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1386 this->setstate(ios_base::failbit);
1387 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388#ifndef _LIBCPP_NO_EXCEPTIONS
1389 }
1390 catch (...)
1391 {
1392 this->__set_badbit_and_consider_rethrow();
1393 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001394#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395 return *this;
1396}
1397
1398template <class _CharT, class _Traits>
1399basic_istream<_CharT, _Traits>&
1400ws(basic_istream<_CharT, _Traits>& __is)
1401{
1402#ifndef _LIBCPP_NO_EXCEPTIONS
1403 try
1404 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001405#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1407 if (__sen)
1408 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnante51e4e92011-09-01 21:02:45 +00001410 while (true)
1411 {
1412 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1413 if (_Traits::eq_int_type(__i, _Traits::eof()))
1414 {
1415 __is.setstate(ios_base::eofbit);
1416 break;
1417 }
1418 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001420 __is.rdbuf()->sbumpc();
1421 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422 }
1423#ifndef _LIBCPP_NO_EXCEPTIONS
1424 }
1425 catch (...)
1426 {
1427 __is.__set_badbit_and_consider_rethrow();
1428 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001429#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 return __is;
1431}
1432
Eric Fiselier78ccf772017-04-18 23:38:41 +00001433#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434
1435template <class _CharT, class _Traits, class _Tp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437basic_istream<_CharT, _Traits>&
Eric Fiselier7955ef62016-07-24 04:07:22 +00001438operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439{
Eric Fiselier7955ef62016-07-24 04:07:22 +00001440 __is >> _VSTD::forward<_Tp>(__x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441 return __is;
1442}
1443
Eric Fiselier78ccf772017-04-18 23:38:41 +00001444#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445
1446template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001447class _LIBCPP_TEMPLATE_VIS basic_iostream
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448 : public basic_istream<_CharT, _Traits>,
1449 public basic_ostream<_CharT, _Traits>
1450{
1451public:
1452 // types:
1453 typedef _CharT char_type;
1454 typedef _Traits traits_type;
1455 typedef typename traits_type::int_type int_type;
1456 typedef typename traits_type::pos_type pos_type;
1457 typedef typename traits_type::off_type off_type;
1458
1459 // constructor/destructor
Eric Fiselier815ed732016-09-16 00:00:48 +00001460 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1461 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1462 : basic_istream<_CharT, _Traits>(__sb)
1463 {}
1464
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465 virtual ~basic_iostream();
1466protected:
Eric Fiselier78ccf772017-04-18 23:38:41 +00001467#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier815ed732016-09-16 00:00:48 +00001468 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469 basic_iostream(basic_iostream&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470
1471 // assign/swap
Eric Fiselier815ed732016-09-16 00:00:48 +00001472 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473 basic_iostream& operator=(basic_iostream&& __rhs);
1474#endif
Eric Fiselier815ed732016-09-16 00:00:48 +00001475 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
1476 void swap(basic_iostream& __rhs)
1477 { basic_istream<char_type, traits_type>::swap(__rhs); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478public:
1479};
1480
Eric Fiselier78ccf772017-04-18 23:38:41 +00001481#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482
1483template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001485 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486{
1487}
1488
1489template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490basic_iostream<_CharT, _Traits>&
1491basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
1492{
1493 swap(__rhs);
1494 return *this;
1495}
1496
Eric Fiselier78ccf772017-04-18 23:38:41 +00001497#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498
1499template <class _CharT, class _Traits>
1500basic_iostream<_CharT, _Traits>::~basic_iostream()
1501{
1502}
1503
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504template<class _CharT, class _Traits, class _Allocator>
1505basic_istream<_CharT, _Traits>&
1506operator>>(basic_istream<_CharT, _Traits>& __is,
1507 basic_string<_CharT, _Traits, _Allocator>& __str)
1508{
1509#ifndef _LIBCPP_NO_EXCEPTIONS
1510 try
1511 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001512#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1514 if (__sen)
1515 {
1516 __str.clear();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 streamsize __n = __is.width();
Howard Hinnante51e4e92011-09-01 21:02:45 +00001518 if (__n <= 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519 __n = __str.max_size();
Howard Hinnante51e4e92011-09-01 21:02:45 +00001520 if (__n <= 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521 __n = numeric_limits<streamsize>::max();
1522 streamsize __c = 0;
1523 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Howard Hinnante51e4e92011-09-01 21:02:45 +00001524 ios_base::iostate __err = ios_base::goodbit;
1525 while (__c < __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001527 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1528 if (_Traits::eq_int_type(__i, _Traits::eof()))
1529 {
1530 __err |= ios_base::eofbit;
1531 break;
1532 }
1533 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 if (__ct.is(__ct.space, __ch))
1535 break;
1536 __str.push_back(__ch);
Howard Hinnante51e4e92011-09-01 21:02:45 +00001537 ++__c;
1538 __is.rdbuf()->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 }
1540 __is.width(0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541 if (__c == 0)
1542 __err |= ios_base::failbit;
1543 __is.setstate(__err);
1544 }
1545 else
1546 __is.setstate(ios_base::failbit);
1547#ifndef _LIBCPP_NO_EXCEPTIONS
1548 }
1549 catch (...)
1550 {
1551 __is.__set_badbit_and_consider_rethrow();
1552 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554 return __is;
1555}
1556
1557template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001558basic_istream<_CharT, _Traits>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559getline(basic_istream<_CharT, _Traits>& __is,
1560 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1561{
1562#ifndef _LIBCPP_NO_EXCEPTIONS
1563 try
1564 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001565#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1567 if (__sen)
1568 {
1569 __str.clear();
Howard Hinnante51e4e92011-09-01 21:02:45 +00001570 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnante992f762011-10-09 15:20:46 +00001571 streamsize __extr = 0;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001572 while (true)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001574 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1575 if (_Traits::eq_int_type(__i, _Traits::eof()))
1576 {
1577 __err |= ios_base::eofbit;
1578 break;
1579 }
Howard Hinnante992f762011-10-09 15:20:46 +00001580 ++__extr;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001581 _CharT __ch = _Traits::to_char_type(__i);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 if (_Traits::eq(__ch, __dlm))
1583 break;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001584 __str.push_back(__ch);
1585 if (__str.size() == __str.max_size())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001587 __err |= ios_base::failbit;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588 break;
1589 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590 }
Howard Hinnante992f762011-10-09 15:20:46 +00001591 if (__extr == 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 __err |= ios_base::failbit;
1593 __is.setstate(__err);
1594 }
1595#ifndef _LIBCPP_NO_EXCEPTIONS
1596 }
1597 catch (...)
1598 {
1599 __is.__set_badbit_and_consider_rethrow();
1600 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001601#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 return __is;
1603}
1604
1605template<class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001607basic_istream<_CharT, _Traits>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608getline(basic_istream<_CharT, _Traits>& __is,
1609 basic_string<_CharT, _Traits, _Allocator>& __str)
1610{
1611 return getline(__is, __str, __is.widen('\n'));
1612}
1613
Eric Fiselier78ccf772017-04-18 23:38:41 +00001614#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615
1616template<class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001617inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001618basic_istream<_CharT, _Traits>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619getline(basic_istream<_CharT, _Traits>&& __is,
1620 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
1621{
1622 return getline(__is, __str, __dlm);
1623}
1624
1625template<class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001627basic_istream<_CharT, _Traits>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628getline(basic_istream<_CharT, _Traits>&& __is,
1629 basic_string<_CharT, _Traits, _Allocator>& __str)
1630{
1631 return getline(__is, __str, __is.widen('\n'));
1632}
1633
Eric Fiselier78ccf772017-04-18 23:38:41 +00001634#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635
1636template <class _CharT, class _Traits, size_t _Size>
1637basic_istream<_CharT, _Traits>&
1638operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
1639{
1640#ifndef _LIBCPP_NO_EXCEPTIONS
1641 try
1642 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001643#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1645 if (__sen)
1646 {
1647 basic_string<_CharT, _Traits> __str;
1648 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
Eric Fiselier37c22152016-12-24 00:24:44 +00001649 size_t __c = 0;
Howard Hinnante51e4e92011-09-01 21:02:45 +00001650 ios_base::iostate __err = ios_base::goodbit;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 _CharT __zero = __ct.widen('0');
1652 _CharT __one = __ct.widen('1');
Howard Hinnante51e4e92011-09-01 21:02:45 +00001653 while (__c < _Size)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654 {
Howard Hinnante51e4e92011-09-01 21:02:45 +00001655 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1656 if (_Traits::eq_int_type(__i, _Traits::eof()))
1657 {
1658 __err |= ios_base::eofbit;
1659 break;
1660 }
1661 _CharT __ch = _Traits::to_char_type(__i);
1662 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001663 break;
1664 __str.push_back(__ch);
Howard Hinnante51e4e92011-09-01 21:02:45 +00001665 ++__c;
1666 __is.rdbuf()->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668 __x = bitset<_Size>(__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669 if (__c == 0)
1670 __err |= ios_base::failbit;
1671 __is.setstate(__err);
1672 }
1673 else
1674 __is.setstate(ios_base::failbit);
1675#ifndef _LIBCPP_NO_EXCEPTIONS
1676 }
1677 catch (...)
1678 {
1679 __is.__set_badbit_and_consider_rethrow();
1680 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001681#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682 return __is;
1683}
1684
Mehdi Amini228053d2017-05-04 17:08:54 +00001685#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
Eric Fiselier1b57fa82016-09-15 22:27:07 +00001686_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1687_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1688_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
Mehdi Amini228053d2017-05-04 17:08:54 +00001689#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690
1691_LIBCPP_END_NAMESPACE_STD
1692
Eric Fiselierf4433a32017-05-31 22:07:49 +00001693_LIBCPP_POP_MACROS
1694
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695#endif // _LIBCPP_ISTREAM