Warning, /include/c++/v1/istream is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_ISTREAM
0011 #define _LIBCPP_ISTREAM
0012
0013 /*
0014 istream synopsis
0015
0016 template <class charT, class traits = char_traits<charT> >
0017 class basic_istream
0018 : virtual public basic_ios<charT,traits>
0019 {
0020 public:
0021 // types (inherited from basic_ios (27.5.4)):
0022 typedef charT char_type;
0023 typedef traits traits_type;
0024 typedef typename traits_type::int_type int_type;
0025 typedef typename traits_type::pos_type pos_type;
0026 typedef typename traits_type::off_type off_type;
0027
0028 // 27.7.1.1.1 Constructor/destructor:
0029 explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
0030 basic_istream(basic_istream&& rhs);
0031 virtual ~basic_istream();
0032
0033 // 27.7.1.1.2 Assign/swap:
0034 basic_istream& operator=(basic_istream&& rhs);
0035 void swap(basic_istream& rhs);
0036
0037 // 27.7.1.1.3 Prefix/suffix:
0038 class sentry;
0039
0040 // 27.7.1.2 Formatted input:
0041 basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
0042 basic_istream& operator>>(basic_ios<char_type, traits_type>&
0043 (*pf)(basic_ios<char_type, traits_type>&));
0044 basic_istream& operator>>(ios_base& (*pf)(ios_base&));
0045 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
0046 basic_istream& operator>>(bool& n);
0047 basic_istream& operator>>(short& n);
0048 basic_istream& operator>>(unsigned short& n);
0049 basic_istream& operator>>(int& n);
0050 basic_istream& operator>>(unsigned int& n);
0051 basic_istream& operator>>(long& n);
0052 basic_istream& operator>>(unsigned long& n);
0053 basic_istream& operator>>(long long& n);
0054 basic_istream& operator>>(unsigned long long& n);
0055 basic_istream& operator>>(float& f);
0056 basic_istream& operator>>(double& f);
0057 basic_istream& operator>>(long double& f);
0058 basic_istream& operator>>(void*& p);
0059
0060 // 27.7.1.3 Unformatted input:
0061 streamsize gcount() const;
0062 int_type get();
0063 basic_istream& get(char_type& c);
0064 basic_istream& get(char_type* s, streamsize n);
0065 basic_istream& get(char_type* s, streamsize n, char_type delim);
0066 basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
0067 basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
0068
0069 basic_istream& getline(char_type* s, streamsize n);
0070 basic_istream& getline(char_type* s, streamsize n, char_type delim);
0071
0072 basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
0073 int_type peek();
0074 basic_istream& read (char_type* s, streamsize n);
0075 streamsize readsome(char_type* s, streamsize n);
0076
0077 basic_istream& putback(char_type c);
0078 basic_istream& unget();
0079 int sync();
0080
0081 pos_type tellg();
0082 basic_istream& seekg(pos_type);
0083 basic_istream& seekg(off_type, ios_base::seekdir);
0084 protected:
0085 basic_istream(const basic_istream& rhs) = delete;
0086 basic_istream(basic_istream&& rhs);
0087 // 27.7.2.1.2 Assign/swap:
0088 basic_istream& operator=(const basic_istream& rhs) = delete;
0089 basic_istream& operator=(basic_istream&& rhs);
0090 void swap(basic_istream& rhs);
0091 };
0092
0093 // 27.7.1.2.3 character extraction templates:
0094 template<class charT, class traits>
0095 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
0096
0097 template<class traits>
0098 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
0099
0100 template<class traits>
0101 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
0102
0103 template<class charT, class traits>
0104 basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
0105
0106 template<class traits>
0107 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
0108
0109 template<class traits>
0110 basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
0111
0112 template <class charT, class traits>
0113 void
0114 swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
0115
0116 typedef basic_istream<char> istream;
0117 typedef basic_istream<wchar_t> wistream;
0118
0119 template <class charT, class traits = char_traits<charT> >
0120 class basic_iostream :
0121 public basic_istream<charT,traits>,
0122 public basic_ostream<charT,traits>
0123 {
0124 public:
0125 // types:
0126 typedef charT char_type;
0127 typedef traits traits_type;
0128 typedef typename traits_type::int_type int_type;
0129 typedef typename traits_type::pos_type pos_type;
0130 typedef typename traits_type::off_type off_type;
0131
0132 // constructor/destructor
0133 explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
0134 basic_iostream(basic_iostream&& rhs);
0135 virtual ~basic_iostream();
0136
0137 // assign/swap
0138 basic_iostream& operator=(basic_iostream&& rhs);
0139 void swap(basic_iostream& rhs);
0140 };
0141
0142 template <class charT, class traits>
0143 void
0144 swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
0145
0146 typedef basic_iostream<char> iostream;
0147 typedef basic_iostream<wchar_t> wiostream;
0148
0149 template <class charT, class traits>
0150 basic_istream<charT,traits>&
0151 ws(basic_istream<charT,traits>& is);
0152
0153 // rvalue stream extraction
0154 template <class Stream, class T>
0155 Stream&& operator>>(Stream&& is, T&& x);
0156
0157 } // std
0158
0159 */
0160
0161 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0162 # include <__cxx03/istream>
0163 #else
0164 # include <__config>
0165
0166 # if _LIBCPP_HAS_LOCALIZATION
0167
0168 # include <__fwd/istream.h>
0169 # include <__iterator/istreambuf_iterator.h>
0170 # include <__ostream/basic_ostream.h>
0171 # include <__type_traits/conjunction.h>
0172 # include <__type_traits/enable_if.h>
0173 # include <__type_traits/is_base_of.h>
0174 # include <__type_traits/make_unsigned.h>
0175 # include <__utility/declval.h>
0176 # include <__utility/forward.h>
0177 # include <bitset>
0178 # include <ios>
0179 # include <locale>
0180 # include <version>
0181
0182 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0183 # pragma GCC system_header
0184 # endif
0185
0186 _LIBCPP_PUSH_MACROS
0187 # include <__undef_macros>
0188
0189 _LIBCPP_BEGIN_NAMESPACE_STD
0190
0191 template <class _CharT, class _Traits>
0192 class _LIBCPP_TEMPLATE_VIS basic_istream : virtual public basic_ios<_CharT, _Traits> {
0193 streamsize __gc_;
0194
0195 _LIBCPP_HIDE_FROM_ABI void __inc_gcount() {
0196 if (__gc_ < numeric_limits<streamsize>::max())
0197 ++__gc_;
0198 }
0199
0200 public:
0201 // types (inherited from basic_ios (27.5.4)):
0202 typedef _CharT char_type;
0203 typedef _Traits traits_type;
0204 typedef typename traits_type::int_type int_type;
0205 typedef typename traits_type::pos_type pos_type;
0206 typedef typename traits_type::off_type off_type;
0207
0208 // 27.7.1.1.1 Constructor/destructor:
0209 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb)
0210 : __gc_(0) {
0211 this->init(__sb);
0212 }
0213 ~basic_istream() override;
0214
0215 protected:
0216 inline _LIBCPP_HIDE_FROM_ABI basic_istream(basic_istream&& __rhs);
0217
0218 // 27.7.1.1.2 Assign/swap:
0219 inline _LIBCPP_HIDE_FROM_ABI basic_istream& operator=(basic_istream&& __rhs);
0220
0221 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_istream& __rhs) {
0222 std::swap(__gc_, __rhs.__gc_);
0223 basic_ios<char_type, traits_type>::swap(__rhs);
0224 }
0225
0226 public:
0227 basic_istream(const basic_istream& __rhs) = delete;
0228 basic_istream& operator=(const basic_istream& __rhs) = delete;
0229
0230 // 27.7.1.1.3 Prefix/suffix:
0231 class _LIBCPP_TEMPLATE_VIS sentry;
0232
0233 // 27.7.1.2 Formatted input:
0234 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) {
0235 return __pf(*this);
0236 }
0237
0238 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream&
0239 operator>>(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) {
0240 __pf(*this);
0241 return *this;
0242 }
0243
0244 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) {
0245 __pf(*this);
0246 return *this;
0247 }
0248
0249 basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
0250 basic_istream& operator>>(bool& __n);
0251 basic_istream& operator>>(short& __n);
0252 basic_istream& operator>>(unsigned short& __n);
0253 basic_istream& operator>>(int& __n);
0254 basic_istream& operator>>(unsigned int& __n);
0255 basic_istream& operator>>(long& __n);
0256 basic_istream& operator>>(unsigned long& __n);
0257 basic_istream& operator>>(long long& __n);
0258 basic_istream& operator>>(unsigned long long& __n);
0259 basic_istream& operator>>(float& __f);
0260 basic_istream& operator>>(double& __f);
0261 basic_istream& operator>>(long double& __f);
0262 basic_istream& operator>>(void*& __p);
0263
0264 // 27.7.1.3 Unformatted input:
0265 _LIBCPP_HIDE_FROM_ABI streamsize gcount() const { return __gc_; }
0266 int_type get();
0267
0268 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type& __c) {
0269 int_type __ch = get();
0270 if (__ch != traits_type::eof())
0271 __c = traits_type::to_char_type(__ch);
0272 return *this;
0273 }
0274
0275 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(char_type* __s, streamsize __n) {
0276 return get(__s, __n, this->widen('\n'));
0277 }
0278
0279 basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
0280
0281 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) {
0282 return get(__sb, this->widen('\n'));
0283 }
0284
0285 basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
0286
0287 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& getline(char_type* __s, streamsize __n) {
0288 return getline(__s, __n, this->widen('\n'));
0289 }
0290
0291 basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
0292
0293 basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
0294 int_type peek();
0295 basic_istream& read(char_type* __s, streamsize __n);
0296 streamsize readsome(char_type* __s, streamsize __n);
0297
0298 basic_istream& putback(char_type __c);
0299 basic_istream& unget();
0300 int sync();
0301
0302 pos_type tellg();
0303 basic_istream& seekg(pos_type __pos);
0304 basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
0305 };
0306
0307 template <class _CharT, class _Traits>
0308 class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry {
0309 bool __ok_;
0310
0311 public:
0312 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
0313 // ~sentry() = default;
0314
0315 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }
0316
0317 sentry(const sentry&) = delete;
0318 sentry& operator=(const sentry&) = delete;
0319 };
0320
0321 template <class _CharT, class _Traits>
0322 basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws) : __ok_(false) {
0323 if (__is.good()) {
0324 if (__is.tie())
0325 __is.tie()->flush();
0326 if (!__noskipws && (__is.flags() & ios_base::skipws)) {
0327 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
0328 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
0329 _Ip __i(__is);
0330 _Ip __eof;
0331 for (; __i != __eof; ++__i)
0332 if (!__ct.is(__ct.space, *__i))
0333 break;
0334 if (__i == __eof)
0335 __is.setstate(ios_base::failbit | ios_base::eofbit);
0336 }
0337 __ok_ = __is.good();
0338 } else
0339 __is.setstate(ios_base::failbit);
0340 }
0341
0342 template <class _CharT, class _Traits>
0343 basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) {
0344 __rhs.__gc_ = 0;
0345 this->move(__rhs);
0346 }
0347
0348 template <class _CharT, class _Traits>
0349 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) {
0350 swap(__rhs);
0351 return *this;
0352 }
0353
0354 template <class _CharT, class _Traits>
0355 basic_istream<_CharT, _Traits>::~basic_istream() {}
0356
0357 template <class _Tp, class _CharT, class _Traits>
0358 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0359 __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
0360 ios_base::iostate __state = ios_base::goodbit;
0361 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
0362 if (__s) {
0363 # if _LIBCPP_HAS_EXCEPTIONS
0364 try {
0365 # endif // _LIBCPP_HAS_EXCEPTIONS
0366 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
0367 typedef num_get<_CharT, _Ip> _Fp;
0368 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);
0369 # if _LIBCPP_HAS_EXCEPTIONS
0370 } catch (...) {
0371 __state |= ios_base::badbit;
0372 __is.__setstate_nothrow(__state);
0373 if (__is.exceptions() & ios_base::badbit) {
0374 throw;
0375 }
0376 }
0377 # endif
0378 __is.setstate(__state);
0379 }
0380 return __is;
0381 }
0382
0383 template <class _CharT, class _Traits>
0384 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) {
0385 return std::__input_arithmetic<unsigned short>(*this, __n);
0386 }
0387
0388 template <class _CharT, class _Traits>
0389 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) {
0390 return std::__input_arithmetic<unsigned int>(*this, __n);
0391 }
0392
0393 template <class _CharT, class _Traits>
0394 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long& __n) {
0395 return std::__input_arithmetic<long>(*this, __n);
0396 }
0397
0398 template <class _CharT, class _Traits>
0399 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) {
0400 return std::__input_arithmetic<unsigned long>(*this, __n);
0401 }
0402
0403 template <class _CharT, class _Traits>
0404 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long long& __n) {
0405 return std::__input_arithmetic<long long>(*this, __n);
0406 }
0407
0408 template <class _CharT, class _Traits>
0409 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) {
0410 return std::__input_arithmetic<unsigned long long>(*this, __n);
0411 }
0412
0413 template <class _CharT, class _Traits>
0414 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(float& __n) {
0415 return std::__input_arithmetic<float>(*this, __n);
0416 }
0417
0418 template <class _CharT, class _Traits>
0419 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(double& __n) {
0420 return std::__input_arithmetic<double>(*this, __n);
0421 }
0422
0423 template <class _CharT, class _Traits>
0424 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long double& __n) {
0425 return std::__input_arithmetic<long double>(*this, __n);
0426 }
0427
0428 template <class _CharT, class _Traits>
0429 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(bool& __n) {
0430 return std::__input_arithmetic<bool>(*this, __n);
0431 }
0432
0433 template <class _CharT, class _Traits>
0434 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) {
0435 return std::__input_arithmetic<void*>(*this, __n);
0436 }
0437
0438 template <class _Tp, class _CharT, class _Traits>
0439 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0440 __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
0441 ios_base::iostate __state = ios_base::goodbit;
0442 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
0443 if (__s) {
0444 # if _LIBCPP_HAS_EXCEPTIONS
0445 try {
0446 # endif // _LIBCPP_HAS_EXCEPTIONS
0447 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
0448 typedef num_get<_CharT, _Ip> _Fp;
0449 long __temp;
0450 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp);
0451 if (__temp < numeric_limits<_Tp>::min()) {
0452 __state |= ios_base::failbit;
0453 __n = numeric_limits<_Tp>::min();
0454 } else if (__temp > numeric_limits<_Tp>::max()) {
0455 __state |= ios_base::failbit;
0456 __n = numeric_limits<_Tp>::max();
0457 } else {
0458 __n = static_cast<_Tp>(__temp);
0459 }
0460 # if _LIBCPP_HAS_EXCEPTIONS
0461 } catch (...) {
0462 __state |= ios_base::badbit;
0463 __is.__setstate_nothrow(__state);
0464 if (__is.exceptions() & ios_base::badbit) {
0465 throw;
0466 }
0467 }
0468 # endif // _LIBCPP_HAS_EXCEPTIONS
0469 __is.setstate(__state);
0470 }
0471 return __is;
0472 }
0473
0474 template <class _CharT, class _Traits>
0475 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(short& __n) {
0476 return std::__input_arithmetic_with_numeric_limits<short>(*this, __n);
0477 }
0478
0479 template <class _CharT, class _Traits>
0480 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(int& __n) {
0481 return std::__input_arithmetic_with_numeric_limits<int>(*this, __n);
0482 }
0483
0484 template <class _CharT, class _Traits>
0485 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0486 __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) {
0487 ios_base::iostate __state = ios_base::goodbit;
0488 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
0489 if (__sen) {
0490 # if _LIBCPP_HAS_EXCEPTIONS
0491 try {
0492 # endif
0493 _CharT* __s = __p;
0494 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
0495 while (__s != __p + (__n - 1)) {
0496 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
0497 if (_Traits::eq_int_type(__i, _Traits::eof())) {
0498 __state |= ios_base::eofbit;
0499 break;
0500 }
0501 _CharT __ch = _Traits::to_char_type(__i);
0502 if (__ct.is(__ct.space, __ch))
0503 break;
0504 *__s++ = __ch;
0505 __is.rdbuf()->sbumpc();
0506 }
0507 *__s = _CharT();
0508 __is.width(0);
0509 if (__s == __p)
0510 __state |= ios_base::failbit;
0511 # if _LIBCPP_HAS_EXCEPTIONS
0512 } catch (...) {
0513 __state |= ios_base::badbit;
0514 __is.__setstate_nothrow(__state);
0515 if (__is.exceptions() & ios_base::badbit) {
0516 throw;
0517 }
0518 }
0519 # endif
0520 __is.setstate(__state);
0521 }
0522 return __is;
0523 }
0524
0525 # if _LIBCPP_STD_VER >= 20
0526
0527 template <class _CharT, class _Traits, size_t _Np>
0528 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0529 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np]) {
0530 size_t __n = _Np;
0531 if (__is.width() > 0)
0532 __n = std::min(size_t(__is.width()), _Np);
0533 return std::__input_c_string(__is, __buf, __n);
0534 }
0535
0536 template <class _Traits, size_t _Np>
0537 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0538 operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np]) {
0539 return __is >> (char(&)[_Np])__buf;
0540 }
0541
0542 template <class _Traits, size_t _Np>
0543 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0544 operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np]) {
0545 return __is >> (char(&)[_Np])__buf;
0546 }
0547
0548 # else
0549
0550 template <class _CharT, class _Traits>
0551 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0552 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) {
0553 streamsize __n = __is.width();
0554 if (__n <= 0)
0555 __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
0556 return std::__input_c_string(__is, __s, size_t(__n));
0557 }
0558
0559 template <class _Traits>
0560 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0561 operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) {
0562 return __is >> (char*)__s;
0563 }
0564
0565 template <class _Traits>
0566 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0567 operator>>(basic_istream<char, _Traits>& __is, signed char* __s) {
0568 return __is >> (char*)__s;
0569 }
0570
0571 # endif // _LIBCPP_STD_VER >= 20
0572
0573 template <class _CharT, class _Traits>
0574 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) {
0575 ios_base::iostate __state = ios_base::goodbit;
0576 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
0577 if (__sen) {
0578 # if _LIBCPP_HAS_EXCEPTIONS
0579 try {
0580 # endif
0581 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
0582 if (_Traits::eq_int_type(__i, _Traits::eof()))
0583 __state |= ios_base::eofbit | ios_base::failbit;
0584 else
0585 __c = _Traits::to_char_type(__i);
0586 # if _LIBCPP_HAS_EXCEPTIONS
0587 } catch (...) {
0588 __state |= ios_base::badbit;
0589 __is.__setstate_nothrow(__state);
0590 if (__is.exceptions() & ios_base::badbit) {
0591 throw;
0592 }
0593 }
0594 # endif
0595 __is.setstate(__state);
0596 }
0597 return __is;
0598 }
0599
0600 template <class _Traits>
0601 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0602 operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) {
0603 return __is >> (char&)__c;
0604 }
0605
0606 template <class _Traits>
0607 inline _LIBCPP_HIDE_FROM_ABI basic_istream<char, _Traits>&
0608 operator>>(basic_istream<char, _Traits>& __is, signed char& __c) {
0609 return __is >> (char&)__c;
0610 }
0611
0612 template <class _CharT, class _Traits>
0613 basic_istream<_CharT, _Traits>&
0614 basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) {
0615 ios_base::iostate __state = ios_base::goodbit;
0616 __gc_ = 0;
0617 sentry __s(*this, true);
0618 if (__s) {
0619 if (__sb) {
0620 # if _LIBCPP_HAS_EXCEPTIONS
0621 try {
0622 # endif // _LIBCPP_HAS_EXCEPTIONS
0623 while (true) {
0624 typename traits_type::int_type __i = this->rdbuf()->sgetc();
0625 if (traits_type::eq_int_type(__i, _Traits::eof())) {
0626 __state |= ios_base::eofbit;
0627 break;
0628 }
0629 if (traits_type::eq_int_type(__sb->sputc(traits_type::to_char_type(__i)), traits_type::eof()))
0630 break;
0631 __inc_gcount();
0632 this->rdbuf()->sbumpc();
0633 }
0634 if (__gc_ == 0)
0635 __state |= ios_base::failbit;
0636 # if _LIBCPP_HAS_EXCEPTIONS
0637 } catch (...) {
0638 __state |= ios_base::badbit;
0639 if (__gc_ == 0)
0640 __state |= ios_base::failbit;
0641
0642 this->__setstate_nothrow(__state);
0643 if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit) {
0644 throw;
0645 }
0646 }
0647 # endif // _LIBCPP_HAS_EXCEPTIONS
0648 } else {
0649 __state |= ios_base::failbit;
0650 }
0651 this->setstate(__state);
0652 }
0653 return *this;
0654 }
0655
0656 template <class _CharT, class _Traits>
0657 typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get() {
0658 ios_base::iostate __state = ios_base::goodbit;
0659 __gc_ = 0;
0660 int_type __r = traits_type::eof();
0661 sentry __s(*this, true);
0662 if (__s) {
0663 # if _LIBCPP_HAS_EXCEPTIONS
0664 try {
0665 # endif
0666 __r = this->rdbuf()->sbumpc();
0667 if (traits_type::eq_int_type(__r, traits_type::eof()))
0668 __state |= ios_base::failbit | ios_base::eofbit;
0669 else
0670 __gc_ = 1;
0671 # if _LIBCPP_HAS_EXCEPTIONS
0672 } catch (...) {
0673 this->__setstate_nothrow(this->rdstate() | ios_base::badbit);
0674 if (this->exceptions() & ios_base::badbit) {
0675 throw;
0676 }
0677 }
0678 # endif
0679 this->setstate(__state);
0680 }
0681 return __r;
0682 }
0683
0684 template <class _CharT, class _Traits>
0685 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) {
0686 ios_base::iostate __state = ios_base::goodbit;
0687 __gc_ = 0;
0688 sentry __sen(*this, true);
0689 if (__sen) {
0690 if (__n > 0) {
0691 # if _LIBCPP_HAS_EXCEPTIONS
0692 try {
0693 # endif
0694 while (__gc_ < __n - 1) {
0695 int_type __i = this->rdbuf()->sgetc();
0696 if (traits_type::eq_int_type(__i, traits_type::eof())) {
0697 __state |= ios_base::eofbit;
0698 break;
0699 }
0700 char_type __ch = traits_type::to_char_type(__i);
0701 if (traits_type::eq(__ch, __dlm))
0702 break;
0703 *__s++ = __ch;
0704 __inc_gcount();
0705 this->rdbuf()->sbumpc();
0706 }
0707 if (__gc_ == 0)
0708 __state |= ios_base::failbit;
0709 # if _LIBCPP_HAS_EXCEPTIONS
0710 } catch (...) {
0711 __state |= ios_base::badbit;
0712 this->__setstate_nothrow(__state);
0713 if (this->exceptions() & ios_base::badbit) {
0714 if (__n > 0)
0715 *__s = char_type();
0716 throw;
0717 }
0718 }
0719 # endif
0720 } else {
0721 __state |= ios_base::failbit;
0722 }
0723
0724 if (__n > 0)
0725 *__s = char_type();
0726 this->setstate(__state);
0727 }
0728 if (__n > 0)
0729 *__s = char_type();
0730 return *this;
0731 }
0732
0733 template <class _CharT, class _Traits>
0734 basic_istream<_CharT, _Traits>&
0735 basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm) {
0736 ios_base::iostate __state = ios_base::goodbit;
0737 __gc_ = 0;
0738 sentry __sen(*this, true);
0739 if (__sen) {
0740 # if _LIBCPP_HAS_EXCEPTIONS
0741 try {
0742 # endif // _LIBCPP_HAS_EXCEPTIONS
0743 while (true) {
0744 typename traits_type::int_type __i = this->rdbuf()->sgetc();
0745 if (traits_type::eq_int_type(__i, traits_type::eof())) {
0746 __state |= ios_base::eofbit;
0747 break;
0748 }
0749 char_type __ch = traits_type::to_char_type(__i);
0750 if (traits_type::eq(__ch, __dlm))
0751 break;
0752 if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
0753 break;
0754 __inc_gcount();
0755 this->rdbuf()->sbumpc();
0756 }
0757 # if _LIBCPP_HAS_EXCEPTIONS
0758 } catch (...) {
0759 __state |= ios_base::badbit;
0760 // according to the spec, exceptions here are caught but not rethrown
0761 }
0762 # endif // _LIBCPP_HAS_EXCEPTIONS
0763 if (__gc_ == 0)
0764 __state |= ios_base::failbit;
0765 this->setstate(__state);
0766 }
0767 return *this;
0768 }
0769
0770 template <class _CharT, class _Traits>
0771 basic_istream<_CharT, _Traits>&
0772 basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) {
0773 ios_base::iostate __state = ios_base::goodbit;
0774 __gc_ = 0;
0775 sentry __sen(*this, true);
0776 if (__sen) {
0777 # if _LIBCPP_HAS_EXCEPTIONS
0778 try {
0779 # endif // _LIBCPP_HAS_EXCEPTIONS
0780 while (true) {
0781 typename traits_type::int_type __i = this->rdbuf()->sgetc();
0782 if (traits_type::eq_int_type(__i, traits_type::eof())) {
0783 __state |= ios_base::eofbit;
0784 break;
0785 }
0786 char_type __ch = traits_type::to_char_type(__i);
0787 if (traits_type::eq(__ch, __dlm)) {
0788 this->rdbuf()->sbumpc();
0789 __inc_gcount();
0790 break;
0791 }
0792 if (__gc_ >= __n - 1) {
0793 __state |= ios_base::failbit;
0794 break;
0795 }
0796 *__s++ = __ch;
0797 this->rdbuf()->sbumpc();
0798 __inc_gcount();
0799 }
0800 # if _LIBCPP_HAS_EXCEPTIONS
0801 } catch (...) {
0802 __state |= ios_base::badbit;
0803 this->__setstate_nothrow(__state);
0804 if (this->exceptions() & ios_base::badbit) {
0805 if (__n > 0)
0806 *__s = char_type();
0807 if (__gc_ == 0)
0808 __state |= ios_base::failbit;
0809 throw;
0810 }
0811 }
0812 # endif // _LIBCPP_HAS_EXCEPTIONS
0813 }
0814 if (__n > 0)
0815 *__s = char_type();
0816 if (__gc_ == 0)
0817 __state |= ios_base::failbit;
0818 this->setstate(__state);
0819 return *this;
0820 }
0821
0822 template <class _CharT, class _Traits>
0823 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) {
0824 ios_base::iostate __state = ios_base::goodbit;
0825 __gc_ = 0;
0826 sentry __sen(*this, true);
0827 if (__sen) {
0828 # if _LIBCPP_HAS_EXCEPTIONS
0829 try {
0830 # endif // _LIBCPP_HAS_EXCEPTIONS
0831 if (__n == numeric_limits<streamsize>::max()) {
0832 while (true) {
0833 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
0834 if (traits_type::eq_int_type(__i, traits_type::eof())) {
0835 __state |= ios_base::eofbit;
0836 break;
0837 }
0838 __inc_gcount();
0839 if (traits_type::eq_int_type(__i, __dlm))
0840 break;
0841 }
0842 } else {
0843 while (__gc_ < __n) {
0844 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
0845 if (traits_type::eq_int_type(__i, traits_type::eof())) {
0846 __state |= ios_base::eofbit;
0847 break;
0848 }
0849 __inc_gcount();
0850 if (traits_type::eq_int_type(__i, __dlm))
0851 break;
0852 }
0853 }
0854 # if _LIBCPP_HAS_EXCEPTIONS
0855 } catch (...) {
0856 __state |= ios_base::badbit;
0857 this->__setstate_nothrow(__state);
0858 if (this->exceptions() & ios_base::badbit) {
0859 throw;
0860 }
0861 }
0862 # endif // _LIBCPP_HAS_EXCEPTIONS
0863 this->setstate(__state);
0864 }
0865 return *this;
0866 }
0867
0868 template <class _CharT, class _Traits>
0869 typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek() {
0870 ios_base::iostate __state = ios_base::goodbit;
0871 __gc_ = 0;
0872 int_type __r = traits_type::eof();
0873 sentry __sen(*this, true);
0874 if (__sen) {
0875 # if _LIBCPP_HAS_EXCEPTIONS
0876 try {
0877 # endif // _LIBCPP_HAS_EXCEPTIONS
0878 __r = this->rdbuf()->sgetc();
0879 if (traits_type::eq_int_type(__r, traits_type::eof()))
0880 __state |= ios_base::eofbit;
0881 # if _LIBCPP_HAS_EXCEPTIONS
0882 } catch (...) {
0883 __state |= ios_base::badbit;
0884 this->__setstate_nothrow(__state);
0885 if (this->exceptions() & ios_base::badbit) {
0886 throw;
0887 }
0888 }
0889 # endif // _LIBCPP_HAS_EXCEPTIONS
0890 this->setstate(__state);
0891 }
0892 return __r;
0893 }
0894
0895 template <class _CharT, class _Traits>
0896 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) {
0897 ios_base::iostate __state = ios_base::goodbit;
0898 __gc_ = 0;
0899 sentry __sen(*this, true);
0900 if (__sen) {
0901 # if _LIBCPP_HAS_EXCEPTIONS
0902 try {
0903 # endif // _LIBCPP_HAS_EXCEPTIONS
0904 __gc_ = this->rdbuf()->sgetn(__s, __n);
0905 if (__gc_ != __n)
0906 __state |= ios_base::failbit | ios_base::eofbit;
0907 # if _LIBCPP_HAS_EXCEPTIONS
0908 } catch (...) {
0909 __state |= ios_base::badbit;
0910 this->__setstate_nothrow(__state);
0911 if (this->exceptions() & ios_base::badbit) {
0912 throw;
0913 }
0914 }
0915 # endif // _LIBCPP_HAS_EXCEPTIONS
0916 } else {
0917 __state |= ios_base::failbit;
0918 }
0919 this->setstate(__state);
0920 return *this;
0921 }
0922
0923 template <class _CharT, class _Traits>
0924 streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) {
0925 ios_base::iostate __state = ios_base::goodbit;
0926 __gc_ = 0;
0927 sentry __sen(*this, true);
0928 if (__sen) {
0929 # if _LIBCPP_HAS_EXCEPTIONS
0930 try {
0931 # endif // _LIBCPP_HAS_EXCEPTIONS
0932 streamsize __c = this->rdbuf()->in_avail();
0933 switch (__c) {
0934 case -1:
0935 __state |= ios_base::eofbit;
0936 break;
0937 case 0:
0938 break;
0939 default:
0940 __n = std::min(__c, __n);
0941 __gc_ = this->rdbuf()->sgetn(__s, __n);
0942 if (__gc_ != __n)
0943 __state |= ios_base::failbit | ios_base::eofbit;
0944 break;
0945 }
0946 # if _LIBCPP_HAS_EXCEPTIONS
0947 } catch (...) {
0948 __state |= ios_base::badbit;
0949 this->__setstate_nothrow(__state);
0950 if (this->exceptions() & ios_base::badbit) {
0951 throw;
0952 }
0953 }
0954 # endif // _LIBCPP_HAS_EXCEPTIONS
0955 } else {
0956 __state |= ios_base::failbit;
0957 }
0958 this->setstate(__state);
0959 return __gc_;
0960 }
0961
0962 template <class _CharT, class _Traits>
0963 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_type __c) {
0964 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
0965 __gc_ = 0;
0966 this->clear(__state);
0967 sentry __sen(*this, true);
0968 if (__sen) {
0969 # if _LIBCPP_HAS_EXCEPTIONS
0970 try {
0971 # endif // _LIBCPP_HAS_EXCEPTIONS
0972 if (this->rdbuf() == nullptr || this->rdbuf()->sputbackc(__c) == traits_type::eof())
0973 __state |= ios_base::badbit;
0974 # if _LIBCPP_HAS_EXCEPTIONS
0975 } catch (...) {
0976 __state |= ios_base::badbit;
0977 this->__setstate_nothrow(__state);
0978 if (this->exceptions() & ios_base::badbit) {
0979 throw;
0980 }
0981 }
0982 # endif // _LIBCPP_HAS_EXCEPTIONS
0983 } else {
0984 __state |= ios_base::failbit;
0985 }
0986 this->setstate(__state);
0987 return *this;
0988 }
0989
0990 template <class _CharT, class _Traits>
0991 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
0992 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
0993 __gc_ = 0;
0994 this->clear(__state);
0995 sentry __sen(*this, true);
0996 if (__sen) {
0997 # if _LIBCPP_HAS_EXCEPTIONS
0998 try {
0999 # endif // _LIBCPP_HAS_EXCEPTIONS
1000 if (this->rdbuf() == nullptr || this->rdbuf()->sungetc() == traits_type::eof())
1001 __state |= ios_base::badbit;
1002 # if _LIBCPP_HAS_EXCEPTIONS
1003 } catch (...) {
1004 __state |= ios_base::badbit;
1005 this->__setstate_nothrow(__state);
1006 if (this->exceptions() & ios_base::badbit) {
1007 throw;
1008 }
1009 }
1010 # endif // _LIBCPP_HAS_EXCEPTIONS
1011 } else {
1012 __state |= ios_base::failbit;
1013 }
1014 this->setstate(__state);
1015 return *this;
1016 }
1017
1018 template <class _CharT, class _Traits>
1019 int basic_istream<_CharT, _Traits>::sync() {
1020 ios_base::iostate __state = ios_base::goodbit;
1021 sentry __sen(*this, true);
1022 if (this->rdbuf() == nullptr)
1023 return -1;
1024
1025 int __r = 0;
1026 if (__sen) {
1027 # if _LIBCPP_HAS_EXCEPTIONS
1028 try {
1029 # endif // _LIBCPP_HAS_EXCEPTIONS
1030 if (this->rdbuf()->pubsync() == -1) {
1031 __state |= ios_base::badbit;
1032 __r = -1;
1033 }
1034 # if _LIBCPP_HAS_EXCEPTIONS
1035 } catch (...) {
1036 __state |= ios_base::badbit;
1037 this->__setstate_nothrow(__state);
1038 if (this->exceptions() & ios_base::badbit) {
1039 throw;
1040 }
1041 }
1042 # endif // _LIBCPP_HAS_EXCEPTIONS
1043 this->setstate(__state);
1044 }
1045 return __r;
1046 }
1047
1048 template <class _CharT, class _Traits>
1049 typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>::tellg() {
1050 ios_base::iostate __state = ios_base::goodbit;
1051 pos_type __r(-1);
1052 sentry __sen(*this, true);
1053 if (__sen) {
1054 # if _LIBCPP_HAS_EXCEPTIONS
1055 try {
1056 # endif // _LIBCPP_HAS_EXCEPTIONS
1057 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1058 # if _LIBCPP_HAS_EXCEPTIONS
1059 } catch (...) {
1060 __state |= ios_base::badbit;
1061 this->__setstate_nothrow(__state);
1062 if (this->exceptions() & ios_base::badbit) {
1063 throw;
1064 }
1065 }
1066 # endif // _LIBCPP_HAS_EXCEPTIONS
1067 this->setstate(__state);
1068 }
1069 return __r;
1070 }
1071
1072 template <class _CharT, class _Traits>
1073 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
1074 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1075 this->clear(__state);
1076 sentry __sen(*this, true);
1077 if (__sen) {
1078 # if _LIBCPP_HAS_EXCEPTIONS
1079 try {
1080 # endif // _LIBCPP_HAS_EXCEPTIONS
1081 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
1082 __state |= ios_base::failbit;
1083 # if _LIBCPP_HAS_EXCEPTIONS
1084 } catch (...) {
1085 __state |= ios_base::badbit;
1086 this->__setstate_nothrow(__state);
1087 if (this->exceptions() & ios_base::badbit) {
1088 throw;
1089 }
1090 }
1091 # endif // _LIBCPP_HAS_EXCEPTIONS
1092 this->setstate(__state);
1093 }
1094 return *this;
1095 }
1096
1097 template <class _CharT, class _Traits>
1098 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) {
1099 ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
1100 this->clear(__state);
1101 sentry __sen(*this, true);
1102 if (__sen) {
1103 # if _LIBCPP_HAS_EXCEPTIONS
1104 try {
1105 # endif // _LIBCPP_HAS_EXCEPTIONS
1106 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
1107 __state |= ios_base::failbit;
1108 # if _LIBCPP_HAS_EXCEPTIONS
1109 } catch (...) {
1110 __state |= ios_base::badbit;
1111 this->__setstate_nothrow(__state);
1112 if (this->exceptions() & ios_base::badbit) {
1113 throw;
1114 }
1115 }
1116 # endif // _LIBCPP_HAS_EXCEPTIONS
1117 this->setstate(__state);
1118 }
1119 return *this;
1120 }
1121
1122 template <class _CharT, class _Traits>
1123 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _Traits>& __is) {
1124 ios_base::iostate __state = ios_base::goodbit;
1125 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1126 if (__sen) {
1127 # if _LIBCPP_HAS_EXCEPTIONS
1128 try {
1129 # endif // _LIBCPP_HAS_EXCEPTIONS
1130 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1131 while (true) {
1132 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1133 if (_Traits::eq_int_type(__i, _Traits::eof())) {
1134 __state |= ios_base::eofbit;
1135 break;
1136 }
1137 if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
1138 break;
1139 __is.rdbuf()->sbumpc();
1140 }
1141 # if _LIBCPP_HAS_EXCEPTIONS
1142 } catch (...) {
1143 __state |= ios_base::badbit;
1144 __is.__setstate_nothrow(__state);
1145 if (__is.exceptions() & ios_base::badbit) {
1146 throw;
1147 }
1148 }
1149 # endif // _LIBCPP_HAS_EXCEPTIONS
1150 __is.setstate(__state);
1151 }
1152 return __is;
1153 }
1154
1155 template <class _Stream, class _Tp, class = void>
1156 struct __is_istreamable : false_type {};
1157
1158 template <class _Stream, class _Tp>
1159 struct __is_istreamable<_Stream, _Tp, decltype(std::declval<_Stream>() >> std::declval<_Tp>(), void())> : true_type {};
1160
1161 template <class _Stream,
1162 class _Tp,
1163 __enable_if_t< _And<is_base_of<ios_base, _Stream>, __is_istreamable<_Stream&, _Tp&&> >::value, int> = 0>
1164 _LIBCPP_HIDE_FROM_ABI _Stream&& operator>>(_Stream&& __is, _Tp&& __x) {
1165 __is >> std::forward<_Tp>(__x);
1166 return std::move(__is);
1167 }
1168
1169 template <class _CharT, class _Traits>
1170 class _LIBCPP_TEMPLATE_VIS basic_iostream
1171 : public basic_istream<_CharT, _Traits>,
1172 public basic_ostream<_CharT, _Traits> {
1173 public:
1174 // types:
1175 typedef _CharT char_type;
1176 typedef _Traits traits_type;
1177 typedef typename traits_type::int_type int_type;
1178 typedef typename traits_type::pos_type pos_type;
1179 typedef typename traits_type::off_type off_type;
1180
1181 // constructor/destructor
1182 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
1183 : basic_istream<_CharT, _Traits>(__sb) {}
1184
1185 ~basic_iostream() override;
1186
1187 protected:
1188 inline _LIBCPP_HIDE_FROM_ABI basic_iostream(basic_iostream&& __rhs);
1189
1190 // assign/swap
1191 inline _LIBCPP_HIDE_FROM_ABI basic_iostream& operator=(basic_iostream&& __rhs);
1192
1193 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_iostream& __rhs) {
1194 basic_istream<char_type, traits_type>::swap(__rhs);
1195 }
1196 };
1197
1198 template <class _CharT, class _Traits>
1199 basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
1200 : basic_istream<_CharT, _Traits>(std::move(__rhs)) {}
1201
1202 template <class _CharT, class _Traits>
1203 basic_iostream<_CharT, _Traits>& basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) {
1204 swap(__rhs);
1205 return *this;
1206 }
1207
1208 template <class _CharT, class _Traits>
1209 basic_iostream<_CharT, _Traits>::~basic_iostream() {}
1210
1211 template <class _CharT, class _Traits, class _Allocator>
1212 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1213 operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {
1214 ios_base::iostate __state = ios_base::goodbit;
1215 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1216 if (__sen) {
1217 # if _LIBCPP_HAS_EXCEPTIONS
1218 try {
1219 # endif
1220 __str.clear();
1221 using _Size = typename basic_string<_CharT, _Traits, _Allocator>::size_type;
1222 streamsize const __width = __is.width();
1223 _Size const __max_size = __str.max_size();
1224 _Size __n;
1225 if (__width <= 0) {
1226 __n = __max_size;
1227 } else {
1228 __n = std::__to_unsigned_like(__width) < __max_size ? static_cast<_Size>(__width) : __max_size;
1229 }
1230
1231 _Size __c = 0;
1232 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1233 while (__c < __n) {
1234 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1235 if (_Traits::eq_int_type(__i, _Traits::eof())) {
1236 __state |= ios_base::eofbit;
1237 break;
1238 }
1239 _CharT __ch = _Traits::to_char_type(__i);
1240 if (__ct.is(__ct.space, __ch))
1241 break;
1242 __str.push_back(__ch);
1243 ++__c;
1244 __is.rdbuf()->sbumpc();
1245 }
1246 __is.width(0);
1247 if (__c == 0)
1248 __state |= ios_base::failbit;
1249 # if _LIBCPP_HAS_EXCEPTIONS
1250 } catch (...) {
1251 __state |= ios_base::badbit;
1252 __is.__setstate_nothrow(__state);
1253 if (__is.exceptions() & ios_base::badbit) {
1254 throw;
1255 }
1256 }
1257 # endif
1258 __is.setstate(__state);
1259 }
1260 return __is;
1261 }
1262
1263 template <class _CharT, class _Traits, class _Allocator>
1264 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1265 getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) {
1266 ios_base::iostate __state = ios_base::goodbit;
1267 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1268 if (__sen) {
1269 # if _LIBCPP_HAS_EXCEPTIONS
1270 try {
1271 # endif
1272 __str.clear();
1273 streamsize __extr = 0;
1274 while (true) {
1275 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1276 if (_Traits::eq_int_type(__i, _Traits::eof())) {
1277 __state |= ios_base::eofbit;
1278 break;
1279 }
1280 ++__extr;
1281 _CharT __ch = _Traits::to_char_type(__i);
1282 if (_Traits::eq(__ch, __dlm))
1283 break;
1284 __str.push_back(__ch);
1285 if (__str.size() == __str.max_size()) {
1286 __state |= ios_base::failbit;
1287 break;
1288 }
1289 }
1290 if (__extr == 0)
1291 __state |= ios_base::failbit;
1292 # if _LIBCPP_HAS_EXCEPTIONS
1293 } catch (...) {
1294 __state |= ios_base::badbit;
1295 __is.__setstate_nothrow(__state);
1296 if (__is.exceptions() & ios_base::badbit) {
1297 throw;
1298 }
1299 }
1300 # endif
1301 __is.setstate(__state);
1302 }
1303 return __is;
1304 }
1305
1306 template <class _CharT, class _Traits, class _Allocator>
1307 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1308 getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {
1309 return std::getline(__is, __str, __is.widen('\n'));
1310 }
1311
1312 template <class _CharT, class _Traits, class _Allocator>
1313 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1314 getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) {
1315 return std::getline(__is, __str, __dlm);
1316 }
1317
1318 template <class _CharT, class _Traits, class _Allocator>
1319 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1320 getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str) {
1321 return std::getline(__is, __str, __is.widen('\n'));
1322 }
1323
1324 template <class _CharT, class _Traits, size_t _Size>
1325 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
1326 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) {
1327 ios_base::iostate __state = ios_base::goodbit;
1328 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
1329 if (__sen) {
1330 # if _LIBCPP_HAS_EXCEPTIONS
1331 try {
1332 # endif
1333 basic_string<_CharT, _Traits> __str;
1334 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
1335 size_t __c = 0;
1336 _CharT __zero = __ct.widen('0');
1337 _CharT __one = __ct.widen('1');
1338 while (__c != _Size) {
1339 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
1340 if (_Traits::eq_int_type(__i, _Traits::eof())) {
1341 __state |= ios_base::eofbit;
1342 break;
1343 }
1344 _CharT __ch = _Traits::to_char_type(__i);
1345 if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
1346 break;
1347 __str.push_back(__ch);
1348 ++__c;
1349 __is.rdbuf()->sbumpc();
1350 }
1351 __x = bitset<_Size>(__str);
1352 if (_Size > 0 && __c == 0)
1353 __state |= ios_base::failbit;
1354 # if _LIBCPP_HAS_EXCEPTIONS
1355 } catch (...) {
1356 __state |= ios_base::badbit;
1357 __is.__setstate_nothrow(__state);
1358 if (__is.exceptions() & ios_base::badbit) {
1359 throw;
1360 }
1361 }
1362 # endif
1363 __is.setstate(__state);
1364 }
1365 return __is;
1366 }
1367
1368 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>;
1369 # if _LIBCPP_HAS_WIDE_CHARACTERS
1370 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>;
1371 # endif
1372 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>;
1373
1374 _LIBCPP_END_NAMESPACE_STD
1375
1376 _LIBCPP_POP_MACROS
1377
1378 # endif // _LIBCPP_HAS_LOCALIZATION
1379
1380 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1381 # include <concepts>
1382 # include <iosfwd>
1383 # include <ostream>
1384 # include <type_traits>
1385 # endif
1386
1387 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1388
1389 #endif // _LIBCPP_ISTREAM