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