codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===-------------------------- ostream -----------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_OSTREAM11#define _LIBCUDACXX_OSTREAM12 13/*14 ostream synopsis15 16template <class charT, class traits = char_traits<charT> >17class basic_ostream18 : virtual public basic_ios<charT,traits>19{20public:21 // types (inherited from basic_ios (27.5.4)):22 typedef charT char_type;23 typedef traits traits_type;24 typedef typename traits_type::int_type int_type;25 typedef typename traits_type::pos_type pos_type;26 typedef typename traits_type::off_type off_type;27 28 // 27.7.2.2 Constructor/destructor:29 explicit basic_ostream(basic_streambuf<char_type,traits>* sb);30 basic_ostream(basic_ostream&& rhs);31 virtual ~basic_ostream();32 33 // 27.7.2.3 Assign/swap34 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++1435 basic_ostream& operator=(basic_ostream&& rhs);36 void swap(basic_ostream& rhs);37 38 // 27.7.2.4 Prefix/suffix:39 class sentry;40 41 // 27.7.2.6 Formatted output:42 basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));43 basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));44 basic_ostream& operator<<(ios_base& (*pf)(ios_base&));45 basic_ostream& operator<<(bool n);46 basic_ostream& operator<<(short n);47 basic_ostream& operator<<(unsigned short n);48 basic_ostream& operator<<(int n);49 basic_ostream& operator<<(unsigned int n);50 basic_ostream& operator<<(long n);51 basic_ostream& operator<<(unsigned long n);52 basic_ostream& operator<<(long long n);53 basic_ostream& operator<<(unsigned long long n);54 basic_ostream& operator<<(float f);55 basic_ostream& operator<<(double f);56 basic_ostream& operator<<(long double f);57 basic_ostream& operator<<(const void* p);58 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);59 basic_ostream& operator<<(nullptr_t);60 61 // 27.7.2.7 Unformatted output:62 basic_ostream& put(char_type c);63 basic_ostream& write(const char_type* s, streamsize n);64 basic_ostream& flush();65 66 // 27.7.2.5 seeks:67 pos_type tellp();68 basic_ostream& seekp(pos_type);69 basic_ostream& seekp(off_type, ios_base::seekdir);70protected:71 basic_ostream(const basic_ostream& rhs) = delete;72 basic_ostream(basic_ostream&& rhs);73 // 27.7.3.3 Assign/swap74 basic_ostream& operator=(basic_ostream& rhs) = delete;75 basic_ostream& operator=(const basic_ostream&& rhs);76 void swap(basic_ostream& rhs);77};78 79// 27.7.2.6.4 character inserters80 81template<class charT, class traits>82 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);83 84template<class charT, class traits>85 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);86 87template<class traits>88 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);89 90// signed and unsigned91 92template<class traits>93 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);94 95template<class traits>96 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);97 98// NTBS99template<class charT, class traits>100 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);101 102template<class charT, class traits>103 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);104 105template<class traits>106 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);107 108// signed and unsigned109template<class traits>110basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);111 112template<class traits>113 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);114 115// swap:116template <class charT, class traits>117 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);118 119template <class charT, class traits>120 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);121 122template <class charT, class traits>123 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);124 125template <class charT, class traits>126 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);127 128// rvalue stream insertion129template <class charT, class traits, class T>130 basic_ostream<charT, traits>&131 operator<<(basic_ostream<charT, traits>&& os, const T& x);132 133} // std134 135*/136 137#include <__config>138#include <ios>139#include <streambuf>140#include <locale>141#include <iterator>142#include <bitset>143#include <version>144 145#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)146# pragma GCC system_header147#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)148# pragma clang system_header149#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)150# pragma system_header151#endif // no system header152 153_LIBCUDACXX_BEGIN_NAMESPACE_STD154 155template <class _CharT, class _Traits>156class _LIBCUDACXX_TEMPLATE_VIS basic_ostream157 : virtual public basic_ios<_CharT, _Traits>158{159public:160 // types (inherited from basic_ios (27.5.4)):161 typedef _CharT char_type;162 typedef _Traits traits_type;163 typedef typename traits_type::int_type int_type;164 typedef typename traits_type::pos_type pos_type;165 typedef typename traits_type::off_type off_type;166 167 // 27.7.2.2 Constructor/destructor:168 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1169 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)170 { this->init(__sb); }171 virtual ~basic_ostream();172protected:173 inline _LIBCUDACXX_INLINE_VISIBILITY174 basic_ostream(basic_ostream&& __rhs);175 176 // 27.7.2.3 Assign/swap177 inline _LIBCUDACXX_INLINE_VISIBILITY178 basic_ostream& operator=(basic_ostream&& __rhs);179 180 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1181 void swap(basic_ostream& __rhs)182 { basic_ios<char_type, traits_type>::swap(__rhs); }183 184 basic_ostream (const basic_ostream& __rhs) = delete;185 basic_ostream& operator=(const basic_ostream& __rhs) = delete;186public:187 188 // 27.7.2.4 Prefix/suffix:189 class _LIBCUDACXX_TEMPLATE_VIS sentry;190 191 // 27.7.2.6 Formatted output:192 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1193 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))194 { return __pf(*this); }195 196 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1197 basic_ostream& operator<<(basic_ios<char_type, traits_type>&198 (*__pf)(basic_ios<char_type,traits_type>&))199 { __pf(*this); return *this; }200 201 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1202 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))203 { __pf(*this); return *this; }204 205 basic_ostream& operator<<(bool __n);206 basic_ostream& operator<<(short __n);207 basic_ostream& operator<<(unsigned short __n);208 basic_ostream& operator<<(int __n);209 basic_ostream& operator<<(unsigned int __n);210 basic_ostream& operator<<(long __n);211 basic_ostream& operator<<(unsigned long __n);212 basic_ostream& operator<<(long long __n);213 basic_ostream& operator<<(unsigned long long __n);214 basic_ostream& operator<<(float __f);215 basic_ostream& operator<<(double __f);216 basic_ostream& operator<<(long double __f);217 basic_ostream& operator<<(const void* __p);218 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);219 220 _LIBCUDACXX_INLINE_VISIBILITY221 basic_ostream& operator<<(nullptr_t)222 { return *this << "nullptr"; }223 224 // 27.7.2.7 Unformatted output:225 basic_ostream& put(char_type __c);226 basic_ostream& write(const char_type* __s, streamsize __n);227 basic_ostream& flush();228 229 // 27.7.2.5 seeks:230 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1231 pos_type tellp();232 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1233 basic_ostream& seekp(pos_type __pos);234 inline _LIBCUDACXX_HIDE_FROM_ABI_AFTER_V1235 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);236 237protected:238 _LIBCUDACXX_INLINE_VISIBILITY239 basic_ostream() {} // extension, intentially does not initialize240};241 242template <class _CharT, class _Traits>243class _LIBCUDACXX_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry244{245 bool __ok_;246 basic_ostream<_CharT, _Traits>& __os_;247 248 sentry(const sentry&); // = delete;249 sentry& operator=(const sentry&); // = delete;250 251public:252 explicit sentry(basic_ostream<_CharT, _Traits>& __os);253 ~sentry();254 255 _LIBCUDACXX_INLINE_VISIBILITY256 _LIBCUDACXX_EXPLICIT257 operator bool() const {return __ok_;}258};259 260template <class _CharT, class _Traits>261basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)262 : __ok_(false),263 __os_(__os)264{265 if (__os.good())266 {267 if (__os.tie())268 __os.tie()->flush();269 __ok_ = true;270 }271}272 273template <class _CharT, class _Traits>274basic_ostream<_CharT, _Traits>::sentry::~sentry()275{276 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)277 && !uncaught_exception())278 {279#ifndef _LIBCUDACXX_NO_EXCEPTIONS280 try281 {282#endif // _LIBCUDACXX_NO_EXCEPTIONS283 if (__os_.rdbuf()->pubsync() == -1)284 __os_.setstate(ios_base::badbit);285#ifndef _LIBCUDACXX_NO_EXCEPTIONS286 }287 catch (...)288 {289 }290#endif // _LIBCUDACXX_NO_EXCEPTIONS291 }292}293 294template <class _CharT, class _Traits>295basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)296{297 this->move(__rhs);298}299 300template <class _CharT, class _Traits>301basic_ostream<_CharT, _Traits>&302basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)303{304 swap(__rhs);305 return *this;306}307 308template <class _CharT, class _Traits>309basic_ostream<_CharT, _Traits>::~basic_ostream()310{311}312 313template <class _CharT, class _Traits>314basic_ostream<_CharT, _Traits>&315basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)316{317#ifndef _LIBCUDACXX_NO_EXCEPTIONS318 try319 {320#endif // _LIBCUDACXX_NO_EXCEPTIONS321 sentry __s(*this);322 if (__s)323 {324 if (__sb)325 {326#ifndef _LIBCUDACXX_NO_EXCEPTIONS327 try328 {329#endif // _LIBCUDACXX_NO_EXCEPTIONS330 typedef istreambuf_iterator<_CharT, _Traits> _Ip;331 typedef ostreambuf_iterator<_CharT, _Traits> _Op;332 _Ip __i(__sb);333 _Ip __eof;334 _Op __o(*this);335 size_t __c = 0;336 for (; __i != __eof; ++__i, ++__o, ++__c)337 {338 *__o = *__i;339 if (__o.failed())340 break;341 }342 if (__c == 0)343 this->setstate(ios_base::failbit);344#ifndef _LIBCUDACXX_NO_EXCEPTIONS345 }346 catch (...)347 {348 this->__set_failbit_and_consider_rethrow();349 }350#endif // _LIBCUDACXX_NO_EXCEPTIONS351 }352 else353 this->setstate(ios_base::badbit);354 }355#ifndef _LIBCUDACXX_NO_EXCEPTIONS356 }357 catch (...)358 {359 this->__set_badbit_and_consider_rethrow();360 }361#endif // _LIBCUDACXX_NO_EXCEPTIONS362 return *this;363}364 365template <class _CharT, class _Traits>366basic_ostream<_CharT, _Traits>&367basic_ostream<_CharT, _Traits>::operator<<(bool __n)368{369#ifndef _LIBCUDACXX_NO_EXCEPTIONS370 try371 {372#endif // _LIBCUDACXX_NO_EXCEPTIONS373 sentry __s(*this);374 if (__s)375 {376 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;377 const _Fp& __f = use_facet<_Fp>(this->getloc());378 if (__f.put(*this, *this, this->fill(), __n).failed())379 this->setstate(ios_base::badbit | ios_base::failbit);380 }381#ifndef _LIBCUDACXX_NO_EXCEPTIONS382 }383 catch (...)384 {385 this->__set_badbit_and_consider_rethrow();386 }387#endif // _LIBCUDACXX_NO_EXCEPTIONS388 return *this;389}390 391template <class _CharT, class _Traits>392basic_ostream<_CharT, _Traits>&393basic_ostream<_CharT, _Traits>::operator<<(short __n)394{395#ifndef _LIBCUDACXX_NO_EXCEPTIONS396 try397 {398#endif // _LIBCUDACXX_NO_EXCEPTIONS399 sentry __s(*this);400 if (__s)401 {402 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;403 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;404 const _Fp& __f = use_facet<_Fp>(this->getloc());405 if (__f.put(*this, *this, this->fill(),406 __flags == ios_base::oct || __flags == ios_base::hex ?407 static_cast<long>(static_cast<unsigned short>(__n)) :408 static_cast<long>(__n)).failed())409 this->setstate(ios_base::badbit | ios_base::failbit);410 }411#ifndef _LIBCUDACXX_NO_EXCEPTIONS412 }413 catch (...)414 {415 this->__set_badbit_and_consider_rethrow();416 }417#endif // _LIBCUDACXX_NO_EXCEPTIONS418 return *this;419}420 421template <class _CharT, class _Traits>422basic_ostream<_CharT, _Traits>&423basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)424{425#ifndef _LIBCUDACXX_NO_EXCEPTIONS426 try427 {428#endif // _LIBCUDACXX_NO_EXCEPTIONS429 sentry __s(*this);430 if (__s)431 {432 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;433 const _Fp& __f = use_facet<_Fp>(this->getloc());434 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())435 this->setstate(ios_base::badbit | ios_base::failbit);436 }437#ifndef _LIBCUDACXX_NO_EXCEPTIONS438 }439 catch (...)440 {441 this->__set_badbit_and_consider_rethrow();442 }443#endif // _LIBCUDACXX_NO_EXCEPTIONS444 return *this;445}446 447template <class _CharT, class _Traits>448basic_ostream<_CharT, _Traits>&449basic_ostream<_CharT, _Traits>::operator<<(int __n)450{451#ifndef _LIBCUDACXX_NO_EXCEPTIONS452 try453 {454#endif // _LIBCUDACXX_NO_EXCEPTIONS455 sentry __s(*this);456 if (__s)457 {458 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;459 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;460 const _Fp& __f = use_facet<_Fp>(this->getloc());461 if (__f.put(*this, *this, this->fill(),462 __flags == ios_base::oct || __flags == ios_base::hex ?463 static_cast<long>(static_cast<unsigned int>(__n)) :464 static_cast<long>(__n)).failed())465 this->setstate(ios_base::badbit | ios_base::failbit);466 }467#ifndef _LIBCUDACXX_NO_EXCEPTIONS468 }469 catch (...)470 {471 this->__set_badbit_and_consider_rethrow();472 }473#endif // _LIBCUDACXX_NO_EXCEPTIONS474 return *this;475}476 477template <class _CharT, class _Traits>478basic_ostream<_CharT, _Traits>&479basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)480{481#ifndef _LIBCUDACXX_NO_EXCEPTIONS482 try483 {484#endif // _LIBCUDACXX_NO_EXCEPTIONS485 sentry __s(*this);486 if (__s)487 {488 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;489 const _Fp& __f = use_facet<_Fp>(this->getloc());490 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())491 this->setstate(ios_base::badbit | ios_base::failbit);492 }493#ifndef _LIBCUDACXX_NO_EXCEPTIONS494 }495 catch (...)496 {497 this->__set_badbit_and_consider_rethrow();498 }499#endif // _LIBCUDACXX_NO_EXCEPTIONS500 return *this;501}502 503template <class _CharT, class _Traits>504basic_ostream<_CharT, _Traits>&505basic_ostream<_CharT, _Traits>::operator<<(long __n)506{507#ifndef _LIBCUDACXX_NO_EXCEPTIONS508 try509 {510#endif // _LIBCUDACXX_NO_EXCEPTIONS511 sentry __s(*this);512 if (__s)513 {514 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;515 const _Fp& __f = use_facet<_Fp>(this->getloc());516 if (__f.put(*this, *this, this->fill(), __n).failed())517 this->setstate(ios_base::badbit | ios_base::failbit);518 }519#ifndef _LIBCUDACXX_NO_EXCEPTIONS520 }521 catch (...)522 {523 this->__set_badbit_and_consider_rethrow();524 }525#endif // _LIBCUDACXX_NO_EXCEPTIONS526 return *this;527}528 529template <class _CharT, class _Traits>530basic_ostream<_CharT, _Traits>&531basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)532{533#ifndef _LIBCUDACXX_NO_EXCEPTIONS534 try535 {536#endif // _LIBCUDACXX_NO_EXCEPTIONS537 sentry __s(*this);538 if (__s)539 {540 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;541 const _Fp& __f = use_facet<_Fp>(this->getloc());542 if (__f.put(*this, *this, this->fill(), __n).failed())543 this->setstate(ios_base::badbit | ios_base::failbit);544 }545#ifndef _LIBCUDACXX_NO_EXCEPTIONS546 }547 catch (...)548 {549 this->__set_badbit_and_consider_rethrow();550 }551#endif // _LIBCUDACXX_NO_EXCEPTIONS552 return *this;553}554 555template <class _CharT, class _Traits>556basic_ostream<_CharT, _Traits>&557basic_ostream<_CharT, _Traits>::operator<<(long long __n)558{559#ifndef _LIBCUDACXX_NO_EXCEPTIONS560 try561 {562#endif // _LIBCUDACXX_NO_EXCEPTIONS563 sentry __s(*this);564 if (__s)565 {566 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;567 const _Fp& __f = use_facet<_Fp>(this->getloc());568 if (__f.put(*this, *this, this->fill(), __n).failed())569 this->setstate(ios_base::badbit | ios_base::failbit);570 }571#ifndef _LIBCUDACXX_NO_EXCEPTIONS572 }573 catch (...)574 {575 this->__set_badbit_and_consider_rethrow();576 }577#endif // _LIBCUDACXX_NO_EXCEPTIONS578 return *this;579}580 581template <class _CharT, class _Traits>582basic_ostream<_CharT, _Traits>&583basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)584{585#ifndef _LIBCUDACXX_NO_EXCEPTIONS586 try587 {588#endif // _LIBCUDACXX_NO_EXCEPTIONS589 sentry __s(*this);590 if (__s)591 {592 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;593 const _Fp& __f = use_facet<_Fp>(this->getloc());594 if (__f.put(*this, *this, this->fill(), __n).failed())595 this->setstate(ios_base::badbit | ios_base::failbit);596 }597#ifndef _LIBCUDACXX_NO_EXCEPTIONS598 }599 catch (...)600 {601 this->__set_badbit_and_consider_rethrow();602 }603#endif // _LIBCUDACXX_NO_EXCEPTIONS604 return *this;605}606 607template <class _CharT, class _Traits>608basic_ostream<_CharT, _Traits>&609basic_ostream<_CharT, _Traits>::operator<<(float __n)610{611#ifndef _LIBCUDACXX_NO_EXCEPTIONS612 try613 {614#endif // _LIBCUDACXX_NO_EXCEPTIONS615 sentry __s(*this);616 if (__s)617 {618 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;619 const _Fp& __f = use_facet<_Fp>(this->getloc());620 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())621 this->setstate(ios_base::badbit | ios_base::failbit);622 }623#ifndef _LIBCUDACXX_NO_EXCEPTIONS624 }625 catch (...)626 {627 this->__set_badbit_and_consider_rethrow();628 }629#endif // _LIBCUDACXX_NO_EXCEPTIONS630 return *this;631}632 633template <class _CharT, class _Traits>634basic_ostream<_CharT, _Traits>&635basic_ostream<_CharT, _Traits>::operator<<(double __n)636{637#ifndef _LIBCUDACXX_NO_EXCEPTIONS638 try639 {640#endif // _LIBCUDACXX_NO_EXCEPTIONS641 sentry __s(*this);642 if (__s)643 {644 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;645 const _Fp& __f = use_facet<_Fp>(this->getloc());646 if (__f.put(*this, *this, this->fill(), __n).failed())647 this->setstate(ios_base::badbit | ios_base::failbit);648 }649#ifndef _LIBCUDACXX_NO_EXCEPTIONS650 }651 catch (...)652 {653 this->__set_badbit_and_consider_rethrow();654 }655#endif // _LIBCUDACXX_NO_EXCEPTIONS656 return *this;657}658 659template <class _CharT, class _Traits>660basic_ostream<_CharT, _Traits>&661basic_ostream<_CharT, _Traits>::operator<<(long double __n)662{663#ifndef _LIBCUDACXX_NO_EXCEPTIONS664 try665 {666#endif // _LIBCUDACXX_NO_EXCEPTIONS667 sentry __s(*this);668 if (__s)669 {670 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;671 const _Fp& __f = use_facet<_Fp>(this->getloc());672 if (__f.put(*this, *this, this->fill(), __n).failed())673 this->setstate(ios_base::badbit | ios_base::failbit);674 }675#ifndef _LIBCUDACXX_NO_EXCEPTIONS676 }677 catch (...)678 {679 this->__set_badbit_and_consider_rethrow();680 }681#endif // _LIBCUDACXX_NO_EXCEPTIONS682 return *this;683}684 685template <class _CharT, class _Traits>686basic_ostream<_CharT, _Traits>&687basic_ostream<_CharT, _Traits>::operator<<(const void* __n)688{689#ifndef _LIBCUDACXX_NO_EXCEPTIONS690 try691 {692#endif // _LIBCUDACXX_NO_EXCEPTIONS693 sentry __s(*this);694 if (__s)695 {696 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;697 const _Fp& __f = use_facet<_Fp>(this->getloc());698 if (__f.put(*this, *this, this->fill(), __n).failed())699 this->setstate(ios_base::badbit | ios_base::failbit);700 }701#ifndef _LIBCUDACXX_NO_EXCEPTIONS702 }703 catch (...)704 {705 this->__set_badbit_and_consider_rethrow();706 }707#endif // _LIBCUDACXX_NO_EXCEPTIONS708 return *this;709}710 711template<class _CharT, class _Traits>712basic_ostream<_CharT, _Traits>&713__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,714 const _CharT* __str, size_t __len)715{716#ifndef _LIBCUDACXX_NO_EXCEPTIONS717 try718 {719#endif // _LIBCUDACXX_NO_EXCEPTIONS720 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);721 if (__s)722 {723 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;724 if (__pad_and_output(_Ip(__os),725 __str,726 (__os.flags() & ios_base::adjustfield) == ios_base::left ?727 __str + __len :728 __str,729 __str + __len,730 __os,731 __os.fill()).failed())732 __os.setstate(ios_base::badbit | ios_base::failbit);733 }734#ifndef _LIBCUDACXX_NO_EXCEPTIONS735 }736 catch (...)737 {738 __os.__set_badbit_and_consider_rethrow();739 }740#endif // _LIBCUDACXX_NO_EXCEPTIONS741 return __os;742}743 744 745template<class _CharT, class _Traits>746basic_ostream<_CharT, _Traits>&747operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)748{749 return _CUDA_VSTD::__put_character_sequence(__os, &__c, 1);750}751 752template<class _CharT, class _Traits>753basic_ostream<_CharT, _Traits>&754operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)755{756#ifndef _LIBCUDACXX_NO_EXCEPTIONS757 try758 {759#endif // _LIBCUDACXX_NO_EXCEPTIONS760 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);761 if (__s)762 {763 _CharT __c = __os.widen(__cn);764 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;765 if (__pad_and_output(_Ip(__os),766 &__c,767 (__os.flags() & ios_base::adjustfield) == ios_base::left ?768 &__c + 1 :769 &__c,770 &__c + 1,771 __os,772 __os.fill()).failed())773 __os.setstate(ios_base::badbit | ios_base::failbit);774 }775#ifndef _LIBCUDACXX_NO_EXCEPTIONS776 }777 catch (...)778 {779 __os.__set_badbit_and_consider_rethrow();780 }781#endif // _LIBCUDACXX_NO_EXCEPTIONS782 return __os;783}784 785template<class _Traits>786basic_ostream<char, _Traits>&787operator<<(basic_ostream<char, _Traits>& __os, char __c)788{789 return _CUDA_VSTD::__put_character_sequence(__os, &__c, 1);790}791 792template<class _Traits>793basic_ostream<char, _Traits>&794operator<<(basic_ostream<char, _Traits>& __os, signed char __c)795{796 return _CUDA_VSTD::__put_character_sequence(__os, (char *) &__c, 1);797}798 799template<class _Traits>800basic_ostream<char, _Traits>&801operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)802{803 return _CUDA_VSTD::__put_character_sequence(__os, (char *) &__c, 1);804}805 806template<class _CharT, class _Traits>807basic_ostream<_CharT, _Traits>&808operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)809{810 return _CUDA_VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));811}812 813template<class _CharT, class _Traits>814basic_ostream<_CharT, _Traits>&815operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)816{817#ifndef _LIBCUDACXX_NO_EXCEPTIONS818 try819 {820#endif // _LIBCUDACXX_NO_EXCEPTIONS821 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);822 if (__s)823 {824 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;825 size_t __len = char_traits<char>::length(__strn);826 const int __bs = 100;827 _CharT __wbb[__bs];828 _CharT* __wb = __wbb;829 unique_ptr<_CharT, void(*)(void*)> __h(0, free);830 if (__len > __bs)831 {832 __wb = (_CharT*)malloc(__len*sizeof(_CharT));833 if (__wb == 0)834 __throw_bad_alloc();835 __h.reset(__wb);836 }837 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)838 *__p = __os.widen(*__strn);839 if (__pad_and_output(_Ip(__os),840 __wb,841 (__os.flags() & ios_base::adjustfield) == ios_base::left ?842 __wb + __len :843 __wb,844 __wb + __len,845 __os,846 __os.fill()).failed())847 __os.setstate(ios_base::badbit | ios_base::failbit);848 }849#ifndef _LIBCUDACXX_NO_EXCEPTIONS850 }851 catch (...)852 {853 __os.__set_badbit_and_consider_rethrow();854 }855#endif // _LIBCUDACXX_NO_EXCEPTIONS856 return __os;857}858 859template<class _Traits>860basic_ostream<char, _Traits>&861operator<<(basic_ostream<char, _Traits>& __os, const char* __str)862{863 return _CUDA_VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));864}865 866template<class _Traits>867basic_ostream<char, _Traits>&868operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)869{870 const char *__s = (const char *) __str;871 return _CUDA_VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));872}873 874template<class _Traits>875basic_ostream<char, _Traits>&876operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)877{878 const char *__s = (const char *) __str;879 return _CUDA_VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));880}881 882template <class _CharT, class _Traits>883basic_ostream<_CharT, _Traits>&884basic_ostream<_CharT, _Traits>::put(char_type __c)885{886#ifndef _LIBCUDACXX_NO_EXCEPTIONS887 try888 {889#endif // _LIBCUDACXX_NO_EXCEPTIONS890 sentry __s(*this);891 if (__s)892 {893 typedef ostreambuf_iterator<_CharT, _Traits> _Op;894 _Op __o(*this);895 *__o = __c;896 if (__o.failed())897 this->setstate(ios_base::badbit);898 }899#ifndef _LIBCUDACXX_NO_EXCEPTIONS900 }901 catch (...)902 {903 this->__set_badbit_and_consider_rethrow();904 }905#endif // _LIBCUDACXX_NO_EXCEPTIONS906 return *this;907}908 909template <class _CharT, class _Traits>910basic_ostream<_CharT, _Traits>&911basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)912{913#ifndef _LIBCUDACXX_NO_EXCEPTIONS914 try915 {916#endif // _LIBCUDACXX_NO_EXCEPTIONS917 sentry __sen(*this);918 if (__sen && __n)919 {920 if (this->rdbuf()->sputn(__s, __n) != __n)921 this->setstate(ios_base::badbit);922 }923#ifndef _LIBCUDACXX_NO_EXCEPTIONS924 }925 catch (...)926 {927 this->__set_badbit_and_consider_rethrow();928 }929#endif // _LIBCUDACXX_NO_EXCEPTIONS930 return *this;931}932 933template <class _CharT, class _Traits>934basic_ostream<_CharT, _Traits>&935basic_ostream<_CharT, _Traits>::flush()936{937#ifndef _LIBCUDACXX_NO_EXCEPTIONS938 try939 {940#endif // _LIBCUDACXX_NO_EXCEPTIONS941 if (this->rdbuf())942 {943 sentry __s(*this);944 if (__s)945 {946 if (this->rdbuf()->pubsync() == -1)947 this->setstate(ios_base::badbit);948 }949 }950#ifndef _LIBCUDACXX_NO_EXCEPTIONS951 }952 catch (...)953 {954 this->__set_badbit_and_consider_rethrow();955 }956#endif // _LIBCUDACXX_NO_EXCEPTIONS957 return *this;958}959 960template <class _CharT, class _Traits>961typename basic_ostream<_CharT, _Traits>::pos_type962basic_ostream<_CharT, _Traits>::tellp()963{964 if (this->fail())965 return pos_type(-1);966 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);967}968 969template <class _CharT, class _Traits>970basic_ostream<_CharT, _Traits>&971basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)972{973 sentry __s(*this);974 if (!this->fail())975 {976 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))977 this->setstate(ios_base::failbit);978 }979 return *this;980}981 982template <class _CharT, class _Traits>983basic_ostream<_CharT, _Traits>&984basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)985{986 sentry __s(*this);987 if (!this->fail())988 {989 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))990 this->setstate(ios_base::failbit);991 }992 return *this;993}994 995template <class _CharT, class _Traits>996inline _LIBCUDACXX_INLINE_VISIBILITY997basic_ostream<_CharT, _Traits>&998endl(basic_ostream<_CharT, _Traits>& __os)999{1000 __os.put(__os.widen('\n'));1001 __os.flush();1002 return __os;1003}1004 1005template <class _CharT, class _Traits>1006inline _LIBCUDACXX_INLINE_VISIBILITY1007basic_ostream<_CharT, _Traits>&1008ends(basic_ostream<_CharT, _Traits>& __os)1009{1010 __os.put(_CharT());1011 return __os;1012}1013 1014template <class _CharT, class _Traits>1015inline _LIBCUDACXX_INLINE_VISIBILITY1016basic_ostream<_CharT, _Traits>&1017flush(basic_ostream<_CharT, _Traits>& __os)1018{1019 __os.flush();1020 return __os;1021}1022 1023template <class _Stream, class _Tp>1024inline _LIBCUDACXX_INLINE_VISIBILITY1025typename enable_if1026<1027 !is_lvalue_reference<_Stream>::value &&1028 is_base_of<ios_base, _Stream>::value,1029 _Stream&&1030>::type1031operator<<(_Stream&& __os, const _Tp& __x)1032{1033 __os << __x;1034 return _CUDA_VSTD::move(__os);1035}1036 1037template<class _CharT, class _Traits, class _Allocator>1038basic_ostream<_CharT, _Traits>&1039operator<<(basic_ostream<_CharT, _Traits>& __os,1040 const basic_string<_CharT, _Traits, _Allocator>& __str)1041{1042 return _CUDA_VSTD::__put_character_sequence(__os, __str.data(), __str.size());1043}1044 1045template<class _CharT, class _Traits>1046basic_ostream<_CharT, _Traits>&1047operator<<(basic_ostream<_CharT, _Traits>& __os,1048 basic_string_view<_CharT, _Traits> __sv)1049{1050 return _CUDA_VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());1051}1052 1053template <class _CharT, class _Traits>1054inline _LIBCUDACXX_INLINE_VISIBILITY1055basic_ostream<_CharT, _Traits>&1056operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)1057{1058 return __os << __ec.category().name() << ':' << __ec.value();1059}1060 1061template<class _CharT, class _Traits, class _Yp>1062inline _LIBCUDACXX_INLINE_VISIBILITY1063basic_ostream<_CharT, _Traits>&1064operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)1065{1066 return __os << __p.get();1067}1068 1069template<class _CharT, class _Traits, class _Yp, class _Dp>1070inline _LIBCUDACXX_INLINE_VISIBILITY1071typename enable_if1072<1073 is_same<void, __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>>::value,1074 basic_ostream<_CharT, _Traits>&1075>::type1076operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)1077{1078 return __os << __p.get();1079}1080 1081template <class _CharT, class _Traits, size_t _Size>1082basic_ostream<_CharT, _Traits>&1083operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)1084{1085 return __os << __x.template to_string<_CharT, _Traits>1086 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),1087 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));1088}1089 1090#ifndef _LIBCUDACXX_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB1091_LIBCUDACXX_EXTERN_TEMPLATE(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)1092_LIBCUDACXX_EXTERN_TEMPLATE(class _LIBCUDACXX_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)1093#endif1094 1095_LIBCUDACXX_END_NAMESPACE_STD1096 1097#endif // _LIBCUDACXX_OSTREAM1098 