Path: blob/main/contrib/llvm-project/libcxx/include/__ostream/basic_ostream.h
35233 views
//===---------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===---------------------------------------------------------------------===//78#ifndef _LIBCPP___OSTREAM_BASIC_OSTREAM_H9#define _LIBCPP___OSTREAM_BASIC_OSTREAM_H1011#include <__config>12#include <__exception/operations.h>13#include <__memory/shared_ptr.h>14#include <__memory/unique_ptr.h>15#include <__system_error/error_code.h>16#include <__type_traits/conjunction.h>17#include <__type_traits/enable_if.h>18#include <__type_traits/is_base_of.h>19#include <__type_traits/void_t.h>20#include <__utility/declval.h>21#include <bitset>22#include <cstddef>23#include <ios>24#include <locale>25#include <new> // for __throw_bad_alloc26#include <streambuf>27#include <string_view>2829#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)30# pragma GCC system_header31#endif3233_LIBCPP_PUSH_MACROS34#include <__undef_macros>3536_LIBCPP_BEGIN_NAMESPACE_STD3738template <class _CharT, class _Traits>39class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Traits> {40public:41// types (inherited from basic_ios (27.5.4)):42typedef _CharT char_type;43typedef _Traits traits_type;44typedef typename traits_type::int_type int_type;45typedef typename traits_type::pos_type pos_type;46typedef typename traits_type::off_type off_type;4748// 27.7.2.2 Constructor/destructor:49inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) {50this->init(__sb);51}52~basic_ostream() override;5354basic_ostream(const basic_ostream& __rhs) = delete;55basic_ostream& operator=(const basic_ostream& __rhs) = delete;5657protected:58inline _LIBCPP_HIDE_FROM_ABI basic_ostream(basic_ostream&& __rhs);5960// 27.7.2.3 Assign/swap61inline _LIBCPP_HIDE_FROM_ABI basic_ostream& operator=(basic_ostream&& __rhs);6263inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_ostream& __rhs) {64basic_ios<char_type, traits_type>::swap(__rhs);65}6667public:68// 27.7.2.4 Prefix/suffix:69class _LIBCPP_TEMPLATE_VIS sentry;7071// 27.7.2.6 Formatted output:72inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) {73return __pf(*this);74}7576inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream&77operator<<(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) {78__pf(*this);79return *this;80}8182inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) {83__pf(*this);84return *this;85}8687basic_ostream& operator<<(bool __n);88basic_ostream& operator<<(short __n);89basic_ostream& operator<<(unsigned short __n);90basic_ostream& operator<<(int __n);91basic_ostream& operator<<(unsigned int __n);92basic_ostream& operator<<(long __n);93basic_ostream& operator<<(unsigned long __n);94basic_ostream& operator<<(long long __n);95basic_ostream& operator<<(unsigned long long __n);96basic_ostream& operator<<(float __f);97basic_ostream& operator<<(double __f);98basic_ostream& operator<<(long double __f);99basic_ostream& operator<<(const void* __p);100101#if _LIBCPP_STD_VER >= 23102_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(const volatile void* __p) {103return operator<<(const_cast<const void*>(__p));104}105#endif106107basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);108109#if _LIBCPP_STD_VER >= 17110// LWG 2221 - nullptr. This is not backported to older standards modes.111// See https://reviews.llvm.org/D127033 for more info on the rationale.112_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(nullptr_t) { return *this << "nullptr"; }113#endif114115// 27.7.2.7 Unformatted output:116basic_ostream& put(char_type __c);117basic_ostream& write(const char_type* __s, streamsize __n);118basic_ostream& flush();119120// 27.7.2.5 seeks:121inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type tellp();122inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& seekp(pos_type __pos);123inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);124125protected:126_LIBCPP_HIDE_FROM_ABI basic_ostream() {} // extension, intentially does not initialize127};128129template <class _CharT, class _Traits>130class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry {131bool __ok_;132basic_ostream<_CharT, _Traits>& __os_;133134public:135explicit sentry(basic_ostream<_CharT, _Traits>& __os);136~sentry();137sentry(const sentry&) = delete;138sentry& operator=(const sentry&) = delete;139140_LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }141};142143template <class _CharT, class _Traits>144basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) : __ok_(false), __os_(__os) {145if (__os.good()) {146if (__os.tie())147__os.tie()->flush();148__ok_ = true;149}150}151152template <class _CharT, class _Traits>153basic_ostream<_CharT, _Traits>::sentry::~sentry() {154if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && !uncaught_exception()) {155#ifndef _LIBCPP_HAS_NO_EXCEPTIONS156try {157#endif // _LIBCPP_HAS_NO_EXCEPTIONS158if (__os_.rdbuf()->pubsync() == -1)159__os_.setstate(ios_base::badbit);160#ifndef _LIBCPP_HAS_NO_EXCEPTIONS161} catch (...) {162}163#endif // _LIBCPP_HAS_NO_EXCEPTIONS164}165}166167template <class _CharT, class _Traits>168basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) {169this->move(__rhs);170}171172template <class _CharT, class _Traits>173basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) {174swap(__rhs);175return *this;176}177178template <class _CharT, class _Traits>179basic_ostream<_CharT, _Traits>::~basic_ostream() {}180181template <class _CharT, class _Traits>182basic_ostream<_CharT, _Traits>&183basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) {184#ifndef _LIBCPP_HAS_NO_EXCEPTIONS185try {186#endif // _LIBCPP_HAS_NO_EXCEPTIONS187sentry __s(*this);188if (__s) {189if (__sb) {190#ifndef _LIBCPP_HAS_NO_EXCEPTIONS191try {192#endif // _LIBCPP_HAS_NO_EXCEPTIONS193typedef istreambuf_iterator<_CharT, _Traits> _Ip;194typedef ostreambuf_iterator<_CharT, _Traits> _Op;195_Ip __i(__sb);196_Ip __eof;197_Op __o(*this);198size_t __c = 0;199for (; __i != __eof; ++__i, ++__o, ++__c) {200*__o = *__i;201if (__o.failed())202break;203}204if (__c == 0)205this->setstate(ios_base::failbit);206#ifndef _LIBCPP_HAS_NO_EXCEPTIONS207} catch (...) {208this->__set_failbit_and_consider_rethrow();209}210#endif // _LIBCPP_HAS_NO_EXCEPTIONS211} else212this->setstate(ios_base::badbit);213}214#ifndef _LIBCPP_HAS_NO_EXCEPTIONS215} catch (...) {216this->__set_badbit_and_consider_rethrow();217}218#endif // _LIBCPP_HAS_NO_EXCEPTIONS219return *this;220}221222template <class _CharT, class _Traits>223basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) {224#ifndef _LIBCPP_HAS_NO_EXCEPTIONS225try {226#endif // _LIBCPP_HAS_NO_EXCEPTIONS227sentry __s(*this);228if (__s) {229typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;230const _Fp& __f = std::use_facet<_Fp>(this->getloc());231if (__f.put(*this, *this, this->fill(), __n).failed())232this->setstate(ios_base::badbit | ios_base::failbit);233}234#ifndef _LIBCPP_HAS_NO_EXCEPTIONS235} catch (...) {236this->__set_badbit_and_consider_rethrow();237}238#endif // _LIBCPP_HAS_NO_EXCEPTIONS239return *this;240}241242template <class _CharT, class _Traits>243basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) {244#ifndef _LIBCPP_HAS_NO_EXCEPTIONS245try {246#endif // _LIBCPP_HAS_NO_EXCEPTIONS247sentry __s(*this);248if (__s) {249ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;250typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;251const _Fp& __f = std::use_facet<_Fp>(this->getloc());252if (__f.put(*this,253*this,254this->fill(),255__flags == ios_base::oct || __flags == ios_base::hex256? static_cast<long>(static_cast<unsigned short>(__n))257: static_cast<long>(__n))258.failed())259this->setstate(ios_base::badbit | ios_base::failbit);260}261#ifndef _LIBCPP_HAS_NO_EXCEPTIONS262} catch (...) {263this->__set_badbit_and_consider_rethrow();264}265#endif // _LIBCPP_HAS_NO_EXCEPTIONS266return *this;267}268269template <class _CharT, class _Traits>270basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) {271#ifndef _LIBCPP_HAS_NO_EXCEPTIONS272try {273#endif // _LIBCPP_HAS_NO_EXCEPTIONS274sentry __s(*this);275if (__s) {276typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;277const _Fp& __f = std::use_facet<_Fp>(this->getloc());278if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())279this->setstate(ios_base::badbit | ios_base::failbit);280}281#ifndef _LIBCPP_HAS_NO_EXCEPTIONS282} catch (...) {283this->__set_badbit_and_consider_rethrow();284}285#endif // _LIBCPP_HAS_NO_EXCEPTIONS286return *this;287}288289template <class _CharT, class _Traits>290basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) {291#ifndef _LIBCPP_HAS_NO_EXCEPTIONS292try {293#endif // _LIBCPP_HAS_NO_EXCEPTIONS294sentry __s(*this);295if (__s) {296ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;297typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;298const _Fp& __f = std::use_facet<_Fp>(this->getloc());299if (__f.put(*this,300*this,301this->fill(),302__flags == ios_base::oct || __flags == ios_base::hex303? static_cast<long>(static_cast<unsigned int>(__n))304: static_cast<long>(__n))305.failed())306this->setstate(ios_base::badbit | ios_base::failbit);307}308#ifndef _LIBCPP_HAS_NO_EXCEPTIONS309} catch (...) {310this->__set_badbit_and_consider_rethrow();311}312#endif // _LIBCPP_HAS_NO_EXCEPTIONS313return *this;314}315316template <class _CharT, class _Traits>317basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) {318#ifndef _LIBCPP_HAS_NO_EXCEPTIONS319try {320#endif // _LIBCPP_HAS_NO_EXCEPTIONS321sentry __s(*this);322if (__s) {323typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;324const _Fp& __f = std::use_facet<_Fp>(this->getloc());325if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())326this->setstate(ios_base::badbit | ios_base::failbit);327}328#ifndef _LIBCPP_HAS_NO_EXCEPTIONS329} catch (...) {330this->__set_badbit_and_consider_rethrow();331}332#endif // _LIBCPP_HAS_NO_EXCEPTIONS333return *this;334}335336template <class _CharT, class _Traits>337basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {338#ifndef _LIBCPP_HAS_NO_EXCEPTIONS339try {340#endif // _LIBCPP_HAS_NO_EXCEPTIONS341sentry __s(*this);342if (__s) {343typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;344const _Fp& __f = std::use_facet<_Fp>(this->getloc());345if (__f.put(*this, *this, this->fill(), __n).failed())346this->setstate(ios_base::badbit | ios_base::failbit);347}348#ifndef _LIBCPP_HAS_NO_EXCEPTIONS349} catch (...) {350this->__set_badbit_and_consider_rethrow();351}352#endif // _LIBCPP_HAS_NO_EXCEPTIONS353return *this;354}355356template <class _CharT, class _Traits>357basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) {358#ifndef _LIBCPP_HAS_NO_EXCEPTIONS359try {360#endif // _LIBCPP_HAS_NO_EXCEPTIONS361sentry __s(*this);362if (__s) {363typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;364const _Fp& __f = std::use_facet<_Fp>(this->getloc());365if (__f.put(*this, *this, this->fill(), __n).failed())366this->setstate(ios_base::badbit | ios_base::failbit);367}368#ifndef _LIBCPP_HAS_NO_EXCEPTIONS369} catch (...) {370this->__set_badbit_and_consider_rethrow();371}372#endif // _LIBCPP_HAS_NO_EXCEPTIONS373return *this;374}375376template <class _CharT, class _Traits>377basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) {378#ifndef _LIBCPP_HAS_NO_EXCEPTIONS379try {380#endif // _LIBCPP_HAS_NO_EXCEPTIONS381sentry __s(*this);382if (__s) {383typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;384const _Fp& __f = std::use_facet<_Fp>(this->getloc());385if (__f.put(*this, *this, this->fill(), __n).failed())386this->setstate(ios_base::badbit | ios_base::failbit);387}388#ifndef _LIBCPP_HAS_NO_EXCEPTIONS389} catch (...) {390this->__set_badbit_and_consider_rethrow();391}392#endif // _LIBCPP_HAS_NO_EXCEPTIONS393return *this;394}395396template <class _CharT, class _Traits>397basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) {398#ifndef _LIBCPP_HAS_NO_EXCEPTIONS399try {400#endif // _LIBCPP_HAS_NO_EXCEPTIONS401sentry __s(*this);402if (__s) {403typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;404const _Fp& __f = std::use_facet<_Fp>(this->getloc());405if (__f.put(*this, *this, this->fill(), __n).failed())406this->setstate(ios_base::badbit | ios_base::failbit);407}408#ifndef _LIBCPP_HAS_NO_EXCEPTIONS409} catch (...) {410this->__set_badbit_and_consider_rethrow();411}412#endif // _LIBCPP_HAS_NO_EXCEPTIONS413return *this;414}415416template <class _CharT, class _Traits>417basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) {418#ifndef _LIBCPP_HAS_NO_EXCEPTIONS419try {420#endif // _LIBCPP_HAS_NO_EXCEPTIONS421sentry __s(*this);422if (__s) {423typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;424const _Fp& __f = std::use_facet<_Fp>(this->getloc());425if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())426this->setstate(ios_base::badbit | ios_base::failbit);427}428#ifndef _LIBCPP_HAS_NO_EXCEPTIONS429} catch (...) {430this->__set_badbit_and_consider_rethrow();431}432#endif // _LIBCPP_HAS_NO_EXCEPTIONS433return *this;434}435436template <class _CharT, class _Traits>437basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) {438#ifndef _LIBCPP_HAS_NO_EXCEPTIONS439try {440#endif // _LIBCPP_HAS_NO_EXCEPTIONS441sentry __s(*this);442if (__s) {443typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;444const _Fp& __f = std::use_facet<_Fp>(this->getloc());445if (__f.put(*this, *this, this->fill(), __n).failed())446this->setstate(ios_base::badbit | ios_base::failbit);447}448#ifndef _LIBCPP_HAS_NO_EXCEPTIONS449} catch (...) {450this->__set_badbit_and_consider_rethrow();451}452#endif // _LIBCPP_HAS_NO_EXCEPTIONS453return *this;454}455456template <class _CharT, class _Traits>457basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) {458#ifndef _LIBCPP_HAS_NO_EXCEPTIONS459try {460#endif // _LIBCPP_HAS_NO_EXCEPTIONS461sentry __s(*this);462if (__s) {463typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;464const _Fp& __f = std::use_facet<_Fp>(this->getloc());465if (__f.put(*this, *this, this->fill(), __n).failed())466this->setstate(ios_base::badbit | ios_base::failbit);467}468#ifndef _LIBCPP_HAS_NO_EXCEPTIONS469} catch (...) {470this->__set_badbit_and_consider_rethrow();471}472#endif // _LIBCPP_HAS_NO_EXCEPTIONS473return *this;474}475476template <class _CharT, class _Traits>477basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) {478#ifndef _LIBCPP_HAS_NO_EXCEPTIONS479try {480#endif // _LIBCPP_HAS_NO_EXCEPTIONS481sentry __s(*this);482if (__s) {483typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;484const _Fp& __f = std::use_facet<_Fp>(this->getloc());485if (__f.put(*this, *this, this->fill(), __n).failed())486this->setstate(ios_base::badbit | ios_base::failbit);487}488#ifndef _LIBCPP_HAS_NO_EXCEPTIONS489} catch (...) {490this->__set_badbit_and_consider_rethrow();491}492#endif // _LIBCPP_HAS_NO_EXCEPTIONS493return *this;494}495496template <class _CharT, class _Traits>497_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&498__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) {499#ifndef _LIBCPP_HAS_NO_EXCEPTIONS500try {501#endif // _LIBCPP_HAS_NO_EXCEPTIONS502typename basic_ostream<_CharT, _Traits>::sentry __s(__os);503if (__s) {504typedef ostreambuf_iterator<_CharT, _Traits> _Ip;505if (std::__pad_and_output(506_Ip(__os),507__str,508(__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,509__str + __len,510__os,511__os.fill())512.failed())513__os.setstate(ios_base::badbit | ios_base::failbit);514}515#ifndef _LIBCPP_HAS_NO_EXCEPTIONS516} catch (...) {517__os.__set_badbit_and_consider_rethrow();518}519#endif // _LIBCPP_HAS_NO_EXCEPTIONS520return __os;521}522523template <class _CharT, class _Traits>524_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {525return std::__put_character_sequence(__os, &__c, 1);526}527528template <class _CharT, class _Traits>529_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) {530#ifndef _LIBCPP_HAS_NO_EXCEPTIONS531try {532#endif // _LIBCPP_HAS_NO_EXCEPTIONS533typename basic_ostream<_CharT, _Traits>::sentry __s(__os);534if (__s) {535_CharT __c = __os.widen(__cn);536typedef ostreambuf_iterator<_CharT, _Traits> _Ip;537if (std::__pad_and_output(538_Ip(__os),539&__c,540(__os.flags() & ios_base::adjustfield) == ios_base::left ? &__c + 1 : &__c,541&__c + 1,542__os,543__os.fill())544.failed())545__os.setstate(ios_base::badbit | ios_base::failbit);546}547#ifndef _LIBCPP_HAS_NO_EXCEPTIONS548} catch (...) {549__os.__set_badbit_and_consider_rethrow();550}551#endif // _LIBCPP_HAS_NO_EXCEPTIONS552return __os;553}554555template <class _Traits>556_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, char __c) {557return std::__put_character_sequence(__os, &__c, 1);558}559560template <class _Traits>561_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {562return std::__put_character_sequence(__os, (char*)&__c, 1);563}564565template <class _Traits>566_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {567return std::__put_character_sequence(__os, (char*)&__c, 1);568}569570template <class _CharT, class _Traits>571_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&572operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) {573return std::__put_character_sequence(__os, __str, _Traits::length(__str));574}575576template <class _CharT, class _Traits>577_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&578operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {579#ifndef _LIBCPP_HAS_NO_EXCEPTIONS580try {581#endif // _LIBCPP_HAS_NO_EXCEPTIONS582typename basic_ostream<_CharT, _Traits>::sentry __s(__os);583if (__s) {584typedef ostreambuf_iterator<_CharT, _Traits> _Ip;585size_t __len = char_traits<char>::length(__strn);586const int __bs = 100;587_CharT __wbb[__bs];588_CharT* __wb = __wbb;589unique_ptr<_CharT, void (*)(void*)> __h(0, free);590if (__len > __bs) {591__wb = (_CharT*)malloc(__len * sizeof(_CharT));592if (__wb == 0)593__throw_bad_alloc();594__h.reset(__wb);595}596for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)597*__p = __os.widen(*__strn);598if (std::__pad_and_output(599_Ip(__os),600__wb,601(__os.flags() & ios_base::adjustfield) == ios_base::left ? __wb + __len : __wb,602__wb + __len,603__os,604__os.fill())605.failed())606__os.setstate(ios_base::badbit | ios_base::failbit);607}608#ifndef _LIBCPP_HAS_NO_EXCEPTIONS609} catch (...) {610__os.__set_badbit_and_consider_rethrow();611}612#endif // _LIBCPP_HAS_NO_EXCEPTIONS613return __os;614}615616template <class _Traits>617_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, const char* __str) {618return std::__put_character_sequence(__os, __str, _Traits::length(__str));619}620621template <class _Traits>622_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&623operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) {624const char* __s = (const char*)__str;625return std::__put_character_sequence(__os, __s, _Traits::length(__s));626}627628template <class _Traits>629_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&630operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) {631const char* __s = (const char*)__str;632return std::__put_character_sequence(__os, __s, _Traits::length(__s));633}634635template <class _CharT, class _Traits>636basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) {637#ifndef _LIBCPP_HAS_NO_EXCEPTIONS638try {639#endif // _LIBCPP_HAS_NO_EXCEPTIONS640sentry __s(*this);641if (__s) {642typedef ostreambuf_iterator<_CharT, _Traits> _Op;643_Op __o(*this);644*__o = __c;645if (__o.failed())646this->setstate(ios_base::badbit);647}648#ifndef _LIBCPP_HAS_NO_EXCEPTIONS649} catch (...) {650this->__set_badbit_and_consider_rethrow();651}652#endif // _LIBCPP_HAS_NO_EXCEPTIONS653return *this;654}655656template <class _CharT, class _Traits>657basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {658#ifndef _LIBCPP_HAS_NO_EXCEPTIONS659try {660#endif // _LIBCPP_HAS_NO_EXCEPTIONS661sentry __sen(*this);662if (__sen && __n) {663if (this->rdbuf()->sputn(__s, __n) != __n)664this->setstate(ios_base::badbit);665}666#ifndef _LIBCPP_HAS_NO_EXCEPTIONS667} catch (...) {668this->__set_badbit_and_consider_rethrow();669}670#endif // _LIBCPP_HAS_NO_EXCEPTIONS671return *this;672}673674template <class _CharT, class _Traits>675basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {676#ifndef _LIBCPP_HAS_NO_EXCEPTIONS677try {678#endif // _LIBCPP_HAS_NO_EXCEPTIONS679if (this->rdbuf()) {680sentry __s(*this);681if (__s) {682if (this->rdbuf()->pubsync() == -1)683this->setstate(ios_base::badbit);684}685}686#ifndef _LIBCPP_HAS_NO_EXCEPTIONS687} catch (...) {688this->__set_badbit_and_consider_rethrow();689}690#endif // _LIBCPP_HAS_NO_EXCEPTIONS691return *this;692}693694template <class _CharT, class _Traits>695typename basic_ostream<_CharT, _Traits>::pos_type basic_ostream<_CharT, _Traits>::tellp() {696if (this->fail())697return pos_type(-1);698return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);699}700701template <class _CharT, class _Traits>702basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) {703sentry __s(*this);704if (!this->fail()) {705if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))706this->setstate(ios_base::failbit);707}708return *this;709}710711template <class _CharT, class _Traits>712basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) {713sentry __s(*this);714if (!this->fail()) {715if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))716this->setstate(ios_base::failbit);717}718return *this;719}720721template <class _CharT, class _Traits>722_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) {723__os.put(__os.widen('\n'));724__os.flush();725return __os;726}727728template <class _CharT, class _Traits>729_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) {730__os.put(_CharT());731return __os;732}733734template <class _CharT, class _Traits>735_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) {736__os.flush();737return __os;738}739740template <class _Stream, class _Tp, class = void>741struct __is_ostreamable : false_type {};742743template <class _Stream, class _Tp>744struct __is_ostreamable<_Stream, _Tp, decltype(std::declval<_Stream>() << std::declval<_Tp>(), void())> : true_type {};745746template <class _Stream,747class _Tp,748__enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>749_LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) {750__os << __x;751return std::move(__os);752}753754template <class _CharT, class _Traits, class _Allocator>755basic_ostream<_CharT, _Traits>&756operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) {757return std::__put_character_sequence(__os, __str.data(), __str.size());758}759760template <class _CharT, class _Traits>761_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&762operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) {763return std::__put_character_sequence(__os, __sv.data(), __sv.size());764}765766template <class _CharT, class _Traits>767inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&768operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) {769return __os << __ec.category().name() << ':' << __ec.value();770}771772template <class _CharT, class _Traits, class _Yp>773inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&774operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) {775return __os << __p.get();776}777778template <779class _CharT,780class _Traits,781class _Yp,782class _Dp,783__enable_if_t<is_same<void,784__void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()785<< std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,786int> = 0>787inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&788operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {789return __os << __p.get();790}791792template <class _CharT, class _Traits, size_t _Size>793_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&794operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {795return __os << __x.template to_string<_CharT, _Traits>(std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),796std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));797}798799#if _LIBCPP_STD_VER >= 20800801# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS802template <class _Traits>803basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;804805template <class _Traits>806basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;807808template <class _Traits>809basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;810811template <class _Traits>812basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;813814template <class _Traits>815basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;816817template <class _Traits>818basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;819820# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS821822# ifndef _LIBCPP_HAS_NO_CHAR8_T823template <class _Traits>824basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;825826template <class _Traits>827basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;828829template <class _Traits>830basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;831832template <class _Traits>833basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;834# endif835836template <class _Traits>837basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;838839template <class _Traits>840basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;841842template <class _Traits>843basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;844845template <class _Traits>846basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;847848#endif // _LIBCPP_STD_VER >= 20849850extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;851#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS852extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;853#endif854855_LIBCPP_END_NAMESPACE_STD856857_LIBCPP_POP_MACROS858859#endif // _LIBCPP___OSTREAM_BASIC_OSTREAM_H860861862