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