File indexing completed on 2026-05-03 08:13:37
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___OSTREAM_BASIC_OSTREAM_H
0010 #define _LIBCPP___CXX03___OSTREAM_BASIC_OSTREAM_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__exception/operations.h>
0014 #include <__cxx03/__memory/shared_ptr.h>
0015 #include <__cxx03/__memory/unique_ptr.h>
0016 #include <__cxx03/__system_error/error_code.h>
0017 #include <__cxx03/__type_traits/conjunction.h>
0018 #include <__cxx03/__type_traits/enable_if.h>
0019 #include <__cxx03/__type_traits/is_base_of.h>
0020 #include <__cxx03/__type_traits/void_t.h>
0021 #include <__cxx03/__utility/declval.h>
0022 #include <__cxx03/bitset>
0023 #include <__cxx03/cstddef>
0024 #include <__cxx03/ios>
0025 #include <__cxx03/locale>
0026 #include <__cxx03/new> // for __throw_bad_alloc
0027 #include <__cxx03/streambuf>
0028 #include <__cxx03/string_view>
0029
0030 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0031 # pragma GCC system_header
0032 #endif
0033
0034 _LIBCPP_PUSH_MACROS
0035 #include <__cxx03/__undef_macros>
0036
0037 _LIBCPP_BEGIN_NAMESPACE_STD
0038
0039 template <class _CharT, class _Traits>
0040 class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Traits> {
0041 public:
0042
0043 typedef _CharT char_type;
0044 typedef _Traits traits_type;
0045 typedef typename traits_type::int_type int_type;
0046 typedef typename traits_type::pos_type pos_type;
0047 typedef typename traits_type::off_type off_type;
0048
0049
0050 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) {
0051 this->init(__sb);
0052 }
0053 ~basic_ostream() override;
0054
0055 basic_ostream(const basic_ostream& __rhs) = delete;
0056 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
0057
0058 protected:
0059 inline _LIBCPP_HIDE_FROM_ABI basic_ostream(basic_ostream&& __rhs);
0060
0061
0062 inline _LIBCPP_HIDE_FROM_ABI basic_ostream& operator=(basic_ostream&& __rhs);
0063
0064 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_ostream& __rhs) {
0065 basic_ios<char_type, traits_type>::swap(__rhs);
0066 }
0067
0068 public:
0069
0070 class _LIBCPP_TEMPLATE_VIS sentry;
0071
0072
0073 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) {
0074 return __pf(*this);
0075 }
0076
0077 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream&
0078 operator<<(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) {
0079 __pf(*this);
0080 return *this;
0081 }
0082
0083 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) {
0084 __pf(*this);
0085 return *this;
0086 }
0087
0088 basic_ostream& operator<<(bool __n);
0089 basic_ostream& operator<<(short __n);
0090 basic_ostream& operator<<(unsigned short __n);
0091 basic_ostream& operator<<(int __n);
0092 basic_ostream& operator<<(unsigned int __n);
0093 basic_ostream& operator<<(long __n);
0094 basic_ostream& operator<<(unsigned long __n);
0095 basic_ostream& operator<<(long long __n);
0096 basic_ostream& operator<<(unsigned long long __n);
0097 basic_ostream& operator<<(float __f);
0098 basic_ostream& operator<<(double __f);
0099 basic_ostream& operator<<(long double __f);
0100 basic_ostream& operator<<(const void* __p);
0101
0102 #if _LIBCPP_STD_VER >= 23
0103 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(const volatile void* __p) {
0104 return operator<<(const_cast<const void*>(__p));
0105 }
0106 #endif
0107
0108 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
0109
0110 #if _LIBCPP_STD_VER >= 17
0111
0112
0113 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(nullptr_t) { return *this << "nullptr"; }
0114 #endif
0115
0116
0117 basic_ostream& put(char_type __c);
0118 basic_ostream& write(const char_type* __s, streamsize __n);
0119 basic_ostream& flush();
0120
0121
0122 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type tellp();
0123 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& seekp(pos_type __pos);
0124 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
0125
0126 protected:
0127 _LIBCPP_HIDE_FROM_ABI basic_ostream() {}
0128 };
0129
0130 template <class _CharT, class _Traits>
0131 class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry {
0132 bool __ok_;
0133 basic_ostream<_CharT, _Traits>& __os_;
0134
0135 public:
0136 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
0137 ~sentry();
0138 sentry(const sentry&) = delete;
0139 sentry& operator=(const sentry&) = delete;
0140
0141 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }
0142 };
0143
0144 template <class _CharT, class _Traits>
0145 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) : __ok_(false), __os_(__os) {
0146 if (__os.good()) {
0147 if (__os.tie())
0148 __os.tie()->flush();
0149 __ok_ = true;
0150 }
0151 }
0152
0153 template <class _CharT, class _Traits>
0154 basic_ostream<_CharT, _Traits>::sentry::~sentry() {
0155 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && !uncaught_exception()) {
0156 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0157 try {
0158 #endif
0159 if (__os_.rdbuf()->pubsync() == -1)
0160 __os_.setstate(ios_base::badbit);
0161 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0162 } catch (...) {
0163 }
0164 #endif
0165 }
0166 }
0167
0168 template <class _CharT, class _Traits>
0169 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) {
0170 this->move(__rhs);
0171 }
0172
0173 template <class _CharT, class _Traits>
0174 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) {
0175 swap(__rhs);
0176 return *this;
0177 }
0178
0179 template <class _CharT, class _Traits>
0180 basic_ostream<_CharT, _Traits>::~basic_ostream() {}
0181
0182 template <class _CharT, class _Traits>
0183 basic_ostream<_CharT, _Traits>&
0184 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) {
0185 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0186 try {
0187 #endif
0188 sentry __s(*this);
0189 if (__s) {
0190 if (__sb) {
0191 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0192 try {
0193 #endif
0194 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
0195 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
0196 _Ip __i(__sb);
0197 _Ip __eof;
0198 _Op __o(*this);
0199 size_t __c = 0;
0200 for (; __i != __eof; ++__i, ++__o, ++__c) {
0201 *__o = *__i;
0202 if (__o.failed())
0203 break;
0204 }
0205 if (__c == 0)
0206 this->setstate(ios_base::failbit);
0207 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0208 } catch (...) {
0209 this->__set_failbit_and_consider_rethrow();
0210 }
0211 #endif
0212 } else
0213 this->setstate(ios_base::badbit);
0214 }
0215 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0216 } catch (...) {
0217 this->__set_badbit_and_consider_rethrow();
0218 }
0219 #endif
0220 return *this;
0221 }
0222
0223 template <class _CharT, class _Traits>
0224 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) {
0225 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0226 try {
0227 #endif
0228 sentry __s(*this);
0229 if (__s) {
0230 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0231 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0232 if (__f.put(*this, *this, this->fill(), __n).failed())
0233 this->setstate(ios_base::badbit | ios_base::failbit);
0234 }
0235 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0236 } catch (...) {
0237 this->__set_badbit_and_consider_rethrow();
0238 }
0239 #endif
0240 return *this;
0241 }
0242
0243 template <class _CharT, class _Traits>
0244 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) {
0245 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0246 try {
0247 #endif
0248 sentry __s(*this);
0249 if (__s) {
0250 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
0251 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0252 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0253 if (__f.put(*this,
0254 *this,
0255 this->fill(),
0256 __flags == ios_base::oct || __flags == ios_base::hex
0257 ? static_cast<long>(static_cast<unsigned short>(__n))
0258 : static_cast<long>(__n))
0259 .failed())
0260 this->setstate(ios_base::badbit | ios_base::failbit);
0261 }
0262 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0263 } catch (...) {
0264 this->__set_badbit_and_consider_rethrow();
0265 }
0266 #endif
0267 return *this;
0268 }
0269
0270 template <class _CharT, class _Traits>
0271 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) {
0272 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0273 try {
0274 #endif
0275 sentry __s(*this);
0276 if (__s) {
0277 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0278 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0279 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
0280 this->setstate(ios_base::badbit | ios_base::failbit);
0281 }
0282 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0283 } catch (...) {
0284 this->__set_badbit_and_consider_rethrow();
0285 }
0286 #endif
0287 return *this;
0288 }
0289
0290 template <class _CharT, class _Traits>
0291 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) {
0292 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0293 try {
0294 #endif
0295 sentry __s(*this);
0296 if (__s) {
0297 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
0298 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0299 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0300 if (__f.put(*this,
0301 *this,
0302 this->fill(),
0303 __flags == ios_base::oct || __flags == ios_base::hex
0304 ? static_cast<long>(static_cast<unsigned int>(__n))
0305 : static_cast<long>(__n))
0306 .failed())
0307 this->setstate(ios_base::badbit | ios_base::failbit);
0308 }
0309 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0310 } catch (...) {
0311 this->__set_badbit_and_consider_rethrow();
0312 }
0313 #endif
0314 return *this;
0315 }
0316
0317 template <class _CharT, class _Traits>
0318 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) {
0319 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0320 try {
0321 #endif
0322 sentry __s(*this);
0323 if (__s) {
0324 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0325 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0326 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
0327 this->setstate(ios_base::badbit | ios_base::failbit);
0328 }
0329 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0330 } catch (...) {
0331 this->__set_badbit_and_consider_rethrow();
0332 }
0333 #endif
0334 return *this;
0335 }
0336
0337 template <class _CharT, class _Traits>
0338 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
0339 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0340 try {
0341 #endif
0342 sentry __s(*this);
0343 if (__s) {
0344 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0345 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0346 if (__f.put(*this, *this, this->fill(), __n).failed())
0347 this->setstate(ios_base::badbit | ios_base::failbit);
0348 }
0349 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0350 } catch (...) {
0351 this->__set_badbit_and_consider_rethrow();
0352 }
0353 #endif
0354 return *this;
0355 }
0356
0357 template <class _CharT, class _Traits>
0358 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) {
0359 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0360 try {
0361 #endif
0362 sentry __s(*this);
0363 if (__s) {
0364 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0365 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0366 if (__f.put(*this, *this, this->fill(), __n).failed())
0367 this->setstate(ios_base::badbit | ios_base::failbit);
0368 }
0369 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0370 } catch (...) {
0371 this->__set_badbit_and_consider_rethrow();
0372 }
0373 #endif
0374 return *this;
0375 }
0376
0377 template <class _CharT, class _Traits>
0378 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) {
0379 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0380 try {
0381 #endif
0382 sentry __s(*this);
0383 if (__s) {
0384 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0385 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0386 if (__f.put(*this, *this, this->fill(), __n).failed())
0387 this->setstate(ios_base::badbit | ios_base::failbit);
0388 }
0389 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0390 } catch (...) {
0391 this->__set_badbit_and_consider_rethrow();
0392 }
0393 #endif
0394 return *this;
0395 }
0396
0397 template <class _CharT, class _Traits>
0398 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) {
0399 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0400 try {
0401 #endif
0402 sentry __s(*this);
0403 if (__s) {
0404 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0405 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0406 if (__f.put(*this, *this, this->fill(), __n).failed())
0407 this->setstate(ios_base::badbit | ios_base::failbit);
0408 }
0409 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0410 } catch (...) {
0411 this->__set_badbit_and_consider_rethrow();
0412 }
0413 #endif
0414 return *this;
0415 }
0416
0417 template <class _CharT, class _Traits>
0418 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) {
0419 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0420 try {
0421 #endif
0422 sentry __s(*this);
0423 if (__s) {
0424 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0425 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0426 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
0427 this->setstate(ios_base::badbit | ios_base::failbit);
0428 }
0429 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0430 } catch (...) {
0431 this->__set_badbit_and_consider_rethrow();
0432 }
0433 #endif
0434 return *this;
0435 }
0436
0437 template <class _CharT, class _Traits>
0438 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) {
0439 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0440 try {
0441 #endif
0442 sentry __s(*this);
0443 if (__s) {
0444 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0445 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0446 if (__f.put(*this, *this, this->fill(), __n).failed())
0447 this->setstate(ios_base::badbit | ios_base::failbit);
0448 }
0449 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0450 } catch (...) {
0451 this->__set_badbit_and_consider_rethrow();
0452 }
0453 #endif
0454 return *this;
0455 }
0456
0457 template <class _CharT, class _Traits>
0458 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) {
0459 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0460 try {
0461 #endif
0462 sentry __s(*this);
0463 if (__s) {
0464 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0465 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0466 if (__f.put(*this, *this, this->fill(), __n).failed())
0467 this->setstate(ios_base::badbit | ios_base::failbit);
0468 }
0469 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0470 } catch (...) {
0471 this->__set_badbit_and_consider_rethrow();
0472 }
0473 #endif
0474 return *this;
0475 }
0476
0477 template <class _CharT, class _Traits>
0478 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) {
0479 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0480 try {
0481 #endif
0482 sentry __s(*this);
0483 if (__s) {
0484 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
0485 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
0486 if (__f.put(*this, *this, this->fill(), __n).failed())
0487 this->setstate(ios_base::badbit | ios_base::failbit);
0488 }
0489 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0490 } catch (...) {
0491 this->__set_badbit_and_consider_rethrow();
0492 }
0493 #endif
0494 return *this;
0495 }
0496
0497 template <class _CharT, class _Traits>
0498 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0499 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) {
0500 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0501 try {
0502 #endif
0503 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
0504 if (__s) {
0505 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
0506 if (std::__pad_and_output(
0507 _Ip(__os),
0508 __str,
0509 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,
0510 __str + __len,
0511 __os,
0512 __os.fill())
0513 .failed())
0514 __os.setstate(ios_base::badbit | ios_base::failbit);
0515 }
0516 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0517 } catch (...) {
0518 __os.__set_badbit_and_consider_rethrow();
0519 }
0520 #endif
0521 return __os;
0522 }
0523
0524 template <class _CharT, class _Traits>
0525 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
0526 return std::__put_character_sequence(__os, &__c, 1);
0527 }
0528
0529 template <class _CharT, class _Traits>
0530 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) {
0531 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0532 try {
0533 #endif
0534 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
0535 if (__s) {
0536 _CharT __c = __os.widen(__cn);
0537 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
0538 if (std::__pad_and_output(
0539 _Ip(__os),
0540 &__c,
0541 (__os.flags() & ios_base::adjustfield) == ios_base::left ? &__c + 1 : &__c,
0542 &__c + 1,
0543 __os,
0544 __os.fill())
0545 .failed())
0546 __os.setstate(ios_base::badbit | ios_base::failbit);
0547 }
0548 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0549 } catch (...) {
0550 __os.__set_badbit_and_consider_rethrow();
0551 }
0552 #endif
0553 return __os;
0554 }
0555
0556 template <class _Traits>
0557 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, char __c) {
0558 return std::__put_character_sequence(__os, &__c, 1);
0559 }
0560
0561 template <class _Traits>
0562 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
0563 return std::__put_character_sequence(__os, (char*)&__c, 1);
0564 }
0565
0566 template <class _Traits>
0567 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
0568 return std::__put_character_sequence(__os, (char*)&__c, 1);
0569 }
0570
0571 template <class _CharT, class _Traits>
0572 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0573 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) {
0574 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
0575 }
0576
0577 template <class _CharT, class _Traits>
0578 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0579 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
0580 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0581 try {
0582 #endif
0583 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
0584 if (__s) {
0585 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
0586 size_t __len = char_traits<char>::length(__strn);
0587 const int __bs = 100;
0588 _CharT __wbb[__bs];
0589 _CharT* __wb = __wbb;
0590 unique_ptr<_CharT, void (*)(void*)> __h(0, free);
0591 if (__len > __bs) {
0592 __wb = (_CharT*)malloc(__len * sizeof(_CharT));
0593 if (__wb == 0)
0594 __throw_bad_alloc();
0595 __h.reset(__wb);
0596 }
0597 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
0598 *__p = __os.widen(*__strn);
0599 if (std::__pad_and_output(
0600 _Ip(__os),
0601 __wb,
0602 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __wb + __len : __wb,
0603 __wb + __len,
0604 __os,
0605 __os.fill())
0606 .failed())
0607 __os.setstate(ios_base::badbit | ios_base::failbit);
0608 }
0609 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0610 } catch (...) {
0611 __os.__set_badbit_and_consider_rethrow();
0612 }
0613 #endif
0614 return __os;
0615 }
0616
0617 template <class _Traits>
0618 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, const char* __str) {
0619 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
0620 }
0621
0622 template <class _Traits>
0623 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
0624 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) {
0625 const char* __s = (const char*)__str;
0626 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
0627 }
0628
0629 template <class _Traits>
0630 _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
0631 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) {
0632 const char* __s = (const char*)__str;
0633 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
0634 }
0635
0636 template <class _CharT, class _Traits>
0637 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) {
0638 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0639 try {
0640 #endif
0641 sentry __s(*this);
0642 if (__s) {
0643 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
0644 _Op __o(*this);
0645 *__o = __c;
0646 if (__o.failed())
0647 this->setstate(ios_base::badbit);
0648 }
0649 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0650 } catch (...) {
0651 this->__set_badbit_and_consider_rethrow();
0652 }
0653 #endif
0654 return *this;
0655 }
0656
0657 template <class _CharT, class _Traits>
0658 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {
0659 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0660 try {
0661 #endif
0662 sentry __sen(*this);
0663 if (__sen && __n) {
0664 if (this->rdbuf()->sputn(__s, __n) != __n)
0665 this->setstate(ios_base::badbit);
0666 }
0667 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0668 } catch (...) {
0669 this->__set_badbit_and_consider_rethrow();
0670 }
0671 #endif
0672 return *this;
0673 }
0674
0675 template <class _CharT, class _Traits>
0676 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {
0677 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0678 try {
0679 #endif
0680 if (this->rdbuf()) {
0681 sentry __s(*this);
0682 if (__s) {
0683 if (this->rdbuf()->pubsync() == -1)
0684 this->setstate(ios_base::badbit);
0685 }
0686 }
0687 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0688 } catch (...) {
0689 this->__set_badbit_and_consider_rethrow();
0690 }
0691 #endif
0692 return *this;
0693 }
0694
0695 template <class _CharT, class _Traits>
0696 typename basic_ostream<_CharT, _Traits>::pos_type basic_ostream<_CharT, _Traits>::tellp() {
0697 if (this->fail())
0698 return pos_type(-1);
0699 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
0700 }
0701
0702 template <class _CharT, class _Traits>
0703 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) {
0704 sentry __s(*this);
0705 if (!this->fail()) {
0706 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
0707 this->setstate(ios_base::failbit);
0708 }
0709 return *this;
0710 }
0711
0712 template <class _CharT, class _Traits>
0713 basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) {
0714 sentry __s(*this);
0715 if (!this->fail()) {
0716 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
0717 this->setstate(ios_base::failbit);
0718 }
0719 return *this;
0720 }
0721
0722 template <class _CharT, class _Traits>
0723 _LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) {
0724 __os.put(__os.widen('\n'));
0725 __os.flush();
0726 return __os;
0727 }
0728
0729 template <class _CharT, class _Traits>
0730 _LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) {
0731 __os.put(_CharT());
0732 return __os;
0733 }
0734
0735 template <class _CharT, class _Traits>
0736 _LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) {
0737 __os.flush();
0738 return __os;
0739 }
0740
0741 template <class _Stream, class _Tp, class = void>
0742 struct __is_ostreamable : false_type {};
0743
0744 template <class _Stream, class _Tp>
0745 struct __is_ostreamable<_Stream, _Tp, decltype(std::declval<_Stream>() << std::declval<_Tp>(), void())> : true_type {};
0746
0747 template <class _Stream,
0748 class _Tp,
0749 __enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>
0750 _LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) {
0751 __os << __x;
0752 return std::move(__os);
0753 }
0754
0755 template <class _CharT, class _Traits, class _Allocator>
0756 basic_ostream<_CharT, _Traits>&
0757 operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) {
0758 return std::__put_character_sequence(__os, __str.data(), __str.size());
0759 }
0760
0761 template <class _CharT, class _Traits>
0762 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0763 operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) {
0764 return std::__put_character_sequence(__os, __sv.data(), __sv.size());
0765 }
0766
0767 template <class _CharT, class _Traits>
0768 inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0769 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) {
0770 return __os << __ec.category().name() << ':' << __ec.value();
0771 }
0772
0773 template <class _CharT, class _Traits, class _Yp>
0774 inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0775 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) {
0776 return __os << __p.get();
0777 }
0778
0779 template <
0780 class _CharT,
0781 class _Traits,
0782 class _Yp,
0783 class _Dp,
0784 __enable_if_t<is_same<void,
0785 __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()
0786 << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
0787 int> = 0>
0788 inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0789 operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {
0790 return __os << __p.get();
0791 }
0792
0793 template <class _CharT, class _Traits, size_t _Size>
0794 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0795 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {
0796 return __os << __x.template to_string<_CharT, _Traits>(std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
0797 std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
0798 }
0799
0800 #if _LIBCPP_STD_VER >= 20
0801
0802 # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0803 template <class _Traits>
0804 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
0805
0806 template <class _Traits>
0807 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
0808
0809 template <class _Traits>
0810 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
0811
0812 template <class _Traits>
0813 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
0814
0815 template <class _Traits>
0816 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
0817
0818 template <class _Traits>
0819 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
0820
0821 # endif
0822
0823 # ifndef _LIBCPP_HAS_NO_CHAR8_T
0824 template <class _Traits>
0825 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
0826
0827 template <class _Traits>
0828 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
0829
0830 template <class _Traits>
0831 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
0832
0833 template <class _Traits>
0834 basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
0835 # endif
0836
0837 template <class _Traits>
0838 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
0839
0840 template <class _Traits>
0841 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
0842
0843 template <class _Traits>
0844 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
0845
0846 template <class _Traits>
0847 basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
0848
0849 #endif
0850
0851 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
0852 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0853 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
0854 #endif
0855
0856 _LIBCPP_END_NAMESPACE_STD
0857
0858 _LIBCPP_POP_MACROS
0859
0860 #endif