1227825Stheraven// -*- C++ -*- 2227825Stheraven//===-------------------------- ostream -----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_OSTREAM 12227825Stheraven#define _LIBCPP_OSTREAM 13227825Stheraven 14227825Stheraven/* 15227825Stheraven ostream synopsis 16227825Stheraven 17227825Stheraventemplate <class charT, class traits = char_traits<charT> > 18227825Stheravenclass basic_ostream 19227825Stheraven : virtual public basic_ios<charT,traits> 20227825Stheraven{ 21227825Stheravenpublic: 22227825Stheraven // types (inherited from basic_ios (27.5.4)): 23227825Stheraven typedef charT char_type; 24227825Stheraven typedef traits traits_type; 25227825Stheraven typedef typename traits_type::int_type int_type; 26227825Stheraven typedef typename traits_type::pos_type pos_type; 27227825Stheraven typedef typename traits_type::off_type off_type; 28227825Stheraven 29227825Stheraven // 27.7.2.2 Constructor/destructor: 30227825Stheraven explicit basic_ostream(basic_streambuf<char_type,traits>* sb); 31227825Stheraven basic_ostream(basic_ostream&& rhs); 32227825Stheraven virtual ~basic_ostream(); 33227825Stheraven 34227825Stheraven // 27.7.2.3 Assign/swap 35261272Sdim basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14 36227825Stheraven basic_ostream& operator=(basic_ostream&& rhs); 37227825Stheraven void swap(basic_ostream& rhs); 38227825Stheraven 39227825Stheraven // 27.7.2.4 Prefix/suffix: 40227825Stheraven class sentry; 41227825Stheraven 42227825Stheraven // 27.7.2.6 Formatted output: 43227825Stheraven basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)); 44227825Stheraven basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&)); 45227825Stheraven basic_ostream& operator<<(ios_base& (*pf)(ios_base&)); 46227825Stheraven basic_ostream& operator<<(bool n); 47227825Stheraven basic_ostream& operator<<(short n); 48227825Stheraven basic_ostream& operator<<(unsigned short n); 49227825Stheraven basic_ostream& operator<<(int n); 50227825Stheraven basic_ostream& operator<<(unsigned int n); 51227825Stheraven basic_ostream& operator<<(long n); 52227825Stheraven basic_ostream& operator<<(unsigned long n); 53227825Stheraven basic_ostream& operator<<(long long n); 54227825Stheraven basic_ostream& operator<<(unsigned long long n); 55227825Stheraven basic_ostream& operator<<(float f); 56227825Stheraven basic_ostream& operator<<(double f); 57227825Stheraven basic_ostream& operator<<(long double f); 58227825Stheraven basic_ostream& operator<<(const void* p); 59227825Stheraven basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb); 60227825Stheraven 61227825Stheraven // 27.7.2.7 Unformatted output: 62227825Stheraven basic_ostream& put(char_type c); 63227825Stheraven basic_ostream& write(const char_type* s, streamsize n); 64227825Stheraven basic_ostream& flush(); 65227825Stheraven 66227825Stheraven // 27.7.2.5 seeks: 67227825Stheraven pos_type tellp(); 68227825Stheraven basic_ostream& seekp(pos_type); 69227825Stheraven basic_ostream& seekp(off_type, ios_base::seekdir); 70276792Sdimprotected: 71276792Sdim basic_ostream(const basic_ostream& rhs) = delete; 72276792Sdim basic_ostream(basic_ostream&& rhs); 73276792Sdim // 27.7.3.3 Assign/swap 74276792Sdim basic_ostream& operator=(basic_ostream& rhs) = delete; 75276792Sdim basic_ostream& operator=(const basic_ostream&& rhs); 76276792Sdim void swap(basic_ostream& rhs); 77227825Stheraven}; 78227825Stheraven 79227825Stheraven// 27.7.2.6.4 character inserters 80227825Stheraven 81227825Stheraventemplate<class charT, class traits> 82227825Stheraven basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT); 83227825Stheraven 84227825Stheraventemplate<class charT, class traits> 85227825Stheraven basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char); 86227825Stheraven 87227825Stheraventemplate<class traits> 88227825Stheraven basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char); 89227825Stheraven 90227825Stheraven// signed and unsigned 91227825Stheraven 92227825Stheraventemplate<class traits> 93227825Stheraven basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char); 94227825Stheraven 95227825Stheraventemplate<class traits> 96227825Stheraven basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char); 97227825Stheraven 98227825Stheraven// NTBS 99227825Stheraventemplate<class charT, class traits> 100227825Stheraven basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); 101227825Stheraven 102227825Stheraventemplate<class charT, class traits> 103227825Stheraven basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*); 104227825Stheraven 105227825Stheraventemplate<class traits> 106227825Stheraven basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*); 107227825Stheraven 108227825Stheraven// signed and unsigned 109227825Stheraventemplate<class traits> 110227825Stheravenbasic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*); 111227825Stheraven 112227825Stheraventemplate<class traits> 113227825Stheraven basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*); 114227825Stheraven 115227825Stheraven// swap: 116227825Stheraventemplate <class charT, class traits> 117227825Stheraven void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y); 118227825Stheraven 119227825Stheraventemplate <class charT, class traits> 120227825Stheraven basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); 121227825Stheraven 122227825Stheraventemplate <class charT, class traits> 123227825Stheraven basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); 124227825Stheraven 125227825Stheraventemplate <class charT, class traits> 126227825Stheraven basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); 127227825Stheraven 128227825Stheraven// rvalue stream insertion 129227825Stheraventemplate <class charT, class traits, class T> 130227825Stheraven basic_ostream<charT, traits>& 131227825Stheraven operator<<(basic_ostream<charT, traits>&& os, const T& x); 132227825Stheraven 133227825Stheraven} // std 134227825Stheraven 135227825Stheraven*/ 136227825Stheraven 137227825Stheraven#include <__config> 138227825Stheraven#include <ios> 139227825Stheraven#include <streambuf> 140227825Stheraven#include <locale> 141227825Stheraven#include <iterator> 142227825Stheraven#include <bitset> 143227825Stheraven 144227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 145227825Stheraven#pragma GCC system_header 146227825Stheraven#endif 147227825Stheraven 148227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 149227825Stheraven 150227825Stheraventemplate <class _CharT, class _Traits> 151261272Sdimclass _LIBCPP_TYPE_VIS_ONLY basic_ostream 152227825Stheraven : virtual public basic_ios<_CharT, _Traits> 153227825Stheraven{ 154227825Stheravenpublic: 155227825Stheraven // types (inherited from basic_ios (27.5.4)): 156227825Stheraven typedef _CharT char_type; 157227825Stheraven typedef _Traits traits_type; 158227825Stheraven typedef typename traits_type::int_type int_type; 159227825Stheraven typedef typename traits_type::pos_type pos_type; 160227825Stheraven typedef typename traits_type::off_type off_type; 161227825Stheraven 162227825Stheraven // 27.7.2.2 Constructor/destructor: 163227825Stheraven explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb); 164227825Stheraven virtual ~basic_ostream(); 165227825Stheravenprotected: 166227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 167227825Stheraven _LIBCPP_INLINE_VISIBILITY 168227825Stheraven basic_ostream(basic_ostream&& __rhs); 169227825Stheraven#endif 170227825Stheraven 171227825Stheraven // 27.7.2.3 Assign/swap 172227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 173227825Stheraven _LIBCPP_INLINE_VISIBILITY 174227825Stheraven basic_ostream& operator=(basic_ostream&& __rhs); 175227825Stheraven#endif 176227825Stheraven void swap(basic_ostream& __rhs); 177276792Sdim 178276792Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 179276792Sdim basic_ostream (const basic_ostream& __rhs) = delete; 180276792Sdim basic_ostream& operator=(const basic_ostream& __rhs) = delete; 181276792Sdim#else 182276792Sdim basic_ostream (const basic_ostream& __rhs); // not defined 183276792Sdim basic_ostream& operator=(const basic_ostream& __rhs); // not defined 184276792Sdim#endif 185227825Stheravenpublic: 186227825Stheraven 187227825Stheraven // 27.7.2.4 Prefix/suffix: 188261272Sdim class _LIBCPP_TYPE_VIS_ONLY sentry; 189227825Stheraven 190227825Stheraven // 27.7.2.6 Formatted output: 191227825Stheraven basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)); 192227825Stheraven basic_ostream& operator<<(basic_ios<char_type, traits_type>& 193227825Stheraven (*__pf)(basic_ios<char_type,traits_type>&)); 194227825Stheraven basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)); 195227825Stheraven basic_ostream& operator<<(bool __n); 196227825Stheraven basic_ostream& operator<<(short __n); 197227825Stheraven basic_ostream& operator<<(unsigned short __n); 198227825Stheraven basic_ostream& operator<<(int __n); 199227825Stheraven basic_ostream& operator<<(unsigned int __n); 200227825Stheraven basic_ostream& operator<<(long __n); 201227825Stheraven basic_ostream& operator<<(unsigned long __n); 202227825Stheraven basic_ostream& operator<<(long long __n); 203227825Stheraven basic_ostream& operator<<(unsigned long long __n); 204227825Stheraven basic_ostream& operator<<(float __f); 205227825Stheraven basic_ostream& operator<<(double __f); 206227825Stheraven basic_ostream& operator<<(long double __f); 207227825Stheraven basic_ostream& operator<<(const void* __p); 208227825Stheraven basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb); 209227825Stheraven 210227825Stheraven // 27.7.2.7 Unformatted output: 211227825Stheraven basic_ostream& put(char_type __c); 212227825Stheraven basic_ostream& write(const char_type* __s, streamsize __n); 213227825Stheraven basic_ostream& flush(); 214227825Stheraven 215227825Stheraven // 27.7.2.5 seeks: 216227825Stheraven pos_type tellp(); 217227825Stheraven basic_ostream& seekp(pos_type __pos); 218227825Stheraven basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); 219227825Stheraven 220227825Stheravenprotected: 221227825Stheraven _LIBCPP_ALWAYS_INLINE 222227825Stheraven basic_ostream() {} // extension, intentially does not initialize 223227825Stheraven}; 224227825Stheraven 225227825Stheraventemplate <class _CharT, class _Traits> 226261272Sdimclass _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry 227227825Stheraven{ 228227825Stheraven bool __ok_; 229227825Stheraven basic_ostream<_CharT, _Traits>& __os_; 230227825Stheraven 231227825Stheraven sentry(const sentry&); // = delete; 232227825Stheraven sentry& operator=(const sentry&); // = delete; 233227825Stheraven 234227825Stheravenpublic: 235227825Stheraven explicit sentry(basic_ostream<_CharT, _Traits>& __os); 236227825Stheraven ~sentry(); 237227825Stheraven 238227825Stheraven _LIBCPP_ALWAYS_INLINE 239232924Stheraven _LIBCPP_EXPLICIT 240227825Stheraven operator bool() const {return __ok_;} 241227825Stheraven}; 242227825Stheraven 243227825Stheraventemplate <class _CharT, class _Traits> 244227825Stheravenbasic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) 245227825Stheraven : __ok_(false), 246227825Stheraven __os_(__os) 247227825Stheraven{ 248227825Stheraven if (__os.good()) 249227825Stheraven { 250227825Stheraven if (__os.tie()) 251227825Stheraven __os.tie()->flush(); 252227825Stheraven __ok_ = true; 253227825Stheraven } 254227825Stheraven} 255227825Stheraven 256227825Stheraventemplate <class _CharT, class _Traits> 257227825Stheravenbasic_ostream<_CharT, _Traits>::sentry::~sentry() 258227825Stheraven{ 259227825Stheraven if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) 260227825Stheraven && !uncaught_exception()) 261227825Stheraven { 262227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 263227825Stheraven try 264227825Stheraven { 265227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 266227825Stheraven if (__os_.rdbuf()->pubsync() == -1) 267227825Stheraven __os_.setstate(ios_base::badbit); 268227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 269227825Stheraven } 270227825Stheraven catch (...) 271227825Stheraven { 272227825Stheraven } 273227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 274227825Stheraven } 275227825Stheraven} 276227825Stheraven 277227825Stheraventemplate <class _CharT, class _Traits> 278227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 279227825Stheravenbasic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb) 280227825Stheraven{ 281227825Stheraven this->init(__sb); 282227825Stheraven} 283227825Stheraven 284227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 285227825Stheraven 286227825Stheraventemplate <class _CharT, class _Traits> 287227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 288227825Stheravenbasic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) 289227825Stheraven{ 290227825Stheraven this->move(__rhs); 291227825Stheraven} 292227825Stheraven 293227825Stheraventemplate <class _CharT, class _Traits> 294227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 295227825Stheravenbasic_ostream<_CharT, _Traits>& 296227825Stheravenbasic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) 297227825Stheraven{ 298227825Stheraven swap(__rhs); 299227825Stheraven return *this; 300227825Stheraven} 301227825Stheraven 302227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 303227825Stheraven 304227825Stheraventemplate <class _CharT, class _Traits> 305227825Stheravenbasic_ostream<_CharT, _Traits>::~basic_ostream() 306227825Stheraven{ 307227825Stheraven} 308227825Stheraven 309227825Stheraventemplate <class _CharT, class _Traits> 310227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 311227825Stheravenvoid 312227825Stheravenbasic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs) 313227825Stheraven{ 314227825Stheraven basic_ios<char_type, traits_type>::swap(__rhs); 315227825Stheraven} 316227825Stheraven 317227825Stheraventemplate <class _CharT, class _Traits> 318227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 319227825Stheravenbasic_ostream<_CharT, _Traits>& 320227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&)) 321227825Stheraven{ 322227825Stheraven return __pf(*this); 323227825Stheraven} 324227825Stheraven 325227825Stheraventemplate <class _CharT, class _Traits> 326227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 327227825Stheravenbasic_ostream<_CharT, _Traits>& 328227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>& 329227825Stheraven (*__pf)(basic_ios<char_type,traits_type>&)) 330227825Stheraven{ 331227825Stheraven __pf(*this); 332227825Stheraven return *this; 333227825Stheraven} 334227825Stheraven 335227825Stheraventemplate <class _CharT, class _Traits> 336227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 337227825Stheravenbasic_ostream<_CharT, _Traits>& 338227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&)) 339227825Stheraven{ 340227825Stheraven __pf(*this); 341227825Stheraven return *this; 342227825Stheraven} 343227825Stheraven 344227825Stheraventemplate <class _CharT, class _Traits> 345227825Stheravenbasic_ostream<_CharT, _Traits>& 346227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) 347227825Stheraven{ 348227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 349227825Stheraven try 350227825Stheraven { 351227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 352227825Stheraven sentry __s(*this); 353227825Stheraven if (__s) 354227825Stheraven { 355227825Stheraven if (__sb) 356227825Stheraven { 357227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 358227825Stheraven try 359227825Stheraven { 360227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 361232924Stheraven typedef istreambuf_iterator<_CharT, _Traits> _Ip; 362232924Stheraven typedef ostreambuf_iterator<_CharT, _Traits> _Op; 363232924Stheraven _Ip __i(__sb); 364232924Stheraven _Ip __eof; 365232924Stheraven _Op __o(*this); 366227825Stheraven size_t __c = 0; 367227825Stheraven for (; __i != __eof; ++__i, ++__o, ++__c) 368227825Stheraven { 369227825Stheraven *__o = *__i; 370227825Stheraven if (__o.failed()) 371227825Stheraven break; 372227825Stheraven } 373227825Stheraven if (__c == 0) 374227825Stheraven this->setstate(ios_base::failbit); 375227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 376227825Stheraven } 377227825Stheraven catch (...) 378227825Stheraven { 379227825Stheraven this->__set_failbit_and_consider_rethrow(); 380227825Stheraven } 381227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 382227825Stheraven } 383227825Stheraven else 384227825Stheraven this->setstate(ios_base::badbit); 385227825Stheraven } 386227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 387227825Stheraven } 388227825Stheraven catch (...) 389227825Stheraven { 390227825Stheraven this->__set_badbit_and_consider_rethrow(); 391227825Stheraven } 392227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 393227825Stheraven return *this; 394227825Stheraven} 395227825Stheraven 396227825Stheraventemplate <class _CharT, class _Traits> 397227825Stheravenbasic_ostream<_CharT, _Traits>& 398227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(bool __n) 399227825Stheraven{ 400227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 401227825Stheraven try 402227825Stheraven { 403227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 404227825Stheraven sentry __s(*this); 405227825Stheraven if (__s) 406227825Stheraven { 407232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 408232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 409227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 410227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 411227825Stheraven } 412227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 413227825Stheraven } 414227825Stheraven catch (...) 415227825Stheraven { 416227825Stheraven this->__set_badbit_and_consider_rethrow(); 417227825Stheraven } 418227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 419227825Stheraven return *this; 420227825Stheraven} 421227825Stheraven 422227825Stheraventemplate <class _CharT, class _Traits> 423227825Stheravenbasic_ostream<_CharT, _Traits>& 424227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(short __n) 425227825Stheraven{ 426227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 427227825Stheraven try 428227825Stheraven { 429227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 430227825Stheraven sentry __s(*this); 431227825Stheraven if (__s) 432227825Stheraven { 433227825Stheraven ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; 434232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 435232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 436227825Stheraven if (__f.put(*this, *this, this->fill(), 437227825Stheraven __flags == ios_base::oct || __flags == ios_base::hex ? 438227825Stheraven static_cast<long>(static_cast<unsigned short>(__n)) : 439227825Stheraven static_cast<long>(__n)).failed()) 440227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 441227825Stheraven } 442227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 443227825Stheraven } 444227825Stheraven catch (...) 445227825Stheraven { 446227825Stheraven this->__set_badbit_and_consider_rethrow(); 447227825Stheraven } 448227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 449227825Stheraven return *this; 450227825Stheraven} 451227825Stheraven 452227825Stheraventemplate <class _CharT, class _Traits> 453227825Stheravenbasic_ostream<_CharT, _Traits>& 454227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) 455227825Stheraven{ 456227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 457227825Stheraven try 458227825Stheraven { 459227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 460227825Stheraven sentry __s(*this); 461227825Stheraven if (__s) 462227825Stheraven { 463232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 464232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 465227825Stheraven if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) 466227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 467227825Stheraven } 468227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 469227825Stheraven } 470227825Stheraven catch (...) 471227825Stheraven { 472227825Stheraven this->__set_badbit_and_consider_rethrow(); 473227825Stheraven } 474227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 475227825Stheraven return *this; 476227825Stheraven} 477227825Stheraven 478227825Stheraventemplate <class _CharT, class _Traits> 479227825Stheravenbasic_ostream<_CharT, _Traits>& 480227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(int __n) 481227825Stheraven{ 482227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 483227825Stheraven try 484227825Stheraven { 485227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 486227825Stheraven sentry __s(*this); 487227825Stheraven if (__s) 488227825Stheraven { 489227825Stheraven ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; 490232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 491232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 492227825Stheraven if (__f.put(*this, *this, this->fill(), 493227825Stheraven __flags == ios_base::oct || __flags == ios_base::hex ? 494227825Stheraven static_cast<long>(static_cast<unsigned int>(__n)) : 495227825Stheraven static_cast<long>(__n)).failed()) 496227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 497227825Stheraven } 498227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 499227825Stheraven } 500227825Stheraven catch (...) 501227825Stheraven { 502227825Stheraven this->__set_badbit_and_consider_rethrow(); 503227825Stheraven } 504227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 505227825Stheraven return *this; 506227825Stheraven} 507227825Stheraven 508227825Stheraventemplate <class _CharT, class _Traits> 509227825Stheravenbasic_ostream<_CharT, _Traits>& 510227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) 511227825Stheraven{ 512227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 513227825Stheraven try 514227825Stheraven { 515227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 516227825Stheraven sentry __s(*this); 517227825Stheraven if (__s) 518227825Stheraven { 519232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 520232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 521227825Stheraven if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) 522227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 523227825Stheraven } 524227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 525227825Stheraven } 526227825Stheraven catch (...) 527227825Stheraven { 528227825Stheraven this->__set_badbit_and_consider_rethrow(); 529227825Stheraven } 530227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 531227825Stheraven return *this; 532227825Stheraven} 533227825Stheraven 534227825Stheraventemplate <class _CharT, class _Traits> 535227825Stheravenbasic_ostream<_CharT, _Traits>& 536227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long __n) 537227825Stheraven{ 538227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 539227825Stheraven try 540227825Stheraven { 541227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 542227825Stheraven sentry __s(*this); 543227825Stheraven if (__s) 544227825Stheraven { 545232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 546232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 547227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 548227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 549227825Stheraven } 550227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 551227825Stheraven } 552227825Stheraven catch (...) 553227825Stheraven { 554227825Stheraven this->__set_badbit_and_consider_rethrow(); 555227825Stheraven } 556227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 557227825Stheraven return *this; 558227825Stheraven} 559227825Stheraven 560227825Stheraventemplate <class _CharT, class _Traits> 561227825Stheravenbasic_ostream<_CharT, _Traits>& 562227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) 563227825Stheraven{ 564227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 565227825Stheraven try 566227825Stheraven { 567227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 568227825Stheraven sentry __s(*this); 569227825Stheraven if (__s) 570227825Stheraven { 571232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 572232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 573227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 574227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 575227825Stheraven } 576227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 577227825Stheraven } 578227825Stheraven catch (...) 579227825Stheraven { 580227825Stheraven this->__set_badbit_and_consider_rethrow(); 581227825Stheraven } 582227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 583227825Stheraven return *this; 584227825Stheraven} 585227825Stheraven 586227825Stheraventemplate <class _CharT, class _Traits> 587227825Stheravenbasic_ostream<_CharT, _Traits>& 588227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long long __n) 589227825Stheraven{ 590227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 591227825Stheraven try 592227825Stheraven { 593227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 594227825Stheraven sentry __s(*this); 595227825Stheraven if (__s) 596227825Stheraven { 597232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 598232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 599227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 600227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 601227825Stheraven } 602227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 603227825Stheraven } 604227825Stheraven catch (...) 605227825Stheraven { 606227825Stheraven this->__set_badbit_and_consider_rethrow(); 607227825Stheraven } 608227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 609227825Stheraven return *this; 610227825Stheraven} 611227825Stheraven 612227825Stheraventemplate <class _CharT, class _Traits> 613227825Stheravenbasic_ostream<_CharT, _Traits>& 614227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) 615227825Stheraven{ 616227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 617227825Stheraven try 618227825Stheraven { 619227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 620227825Stheraven sentry __s(*this); 621227825Stheraven if (__s) 622227825Stheraven { 623232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 624232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 625227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 626227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 627227825Stheraven } 628227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 629227825Stheraven } 630227825Stheraven catch (...) 631227825Stheraven { 632227825Stheraven this->__set_badbit_and_consider_rethrow(); 633227825Stheraven } 634227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 635227825Stheraven return *this; 636227825Stheraven} 637227825Stheraven 638227825Stheraventemplate <class _CharT, class _Traits> 639227825Stheravenbasic_ostream<_CharT, _Traits>& 640227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(float __n) 641227825Stheraven{ 642227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 643227825Stheraven try 644227825Stheraven { 645227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 646227825Stheraven sentry __s(*this); 647227825Stheraven if (__s) 648227825Stheraven { 649232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 650232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 651227825Stheraven if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed()) 652227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 653227825Stheraven } 654227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 655227825Stheraven } 656227825Stheraven catch (...) 657227825Stheraven { 658227825Stheraven this->__set_badbit_and_consider_rethrow(); 659227825Stheraven } 660227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 661227825Stheraven return *this; 662227825Stheraven} 663227825Stheraven 664227825Stheraventemplate <class _CharT, class _Traits> 665227825Stheravenbasic_ostream<_CharT, _Traits>& 666227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(double __n) 667227825Stheraven{ 668227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 669227825Stheraven try 670227825Stheraven { 671227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 672227825Stheraven sentry __s(*this); 673227825Stheraven if (__s) 674227825Stheraven { 675232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 676232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 677227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 678227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 679227825Stheraven } 680227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 681227825Stheraven } 682227825Stheraven catch (...) 683227825Stheraven { 684227825Stheraven this->__set_badbit_and_consider_rethrow(); 685227825Stheraven } 686227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 687227825Stheraven return *this; 688227825Stheraven} 689227825Stheraven 690227825Stheraventemplate <class _CharT, class _Traits> 691227825Stheravenbasic_ostream<_CharT, _Traits>& 692227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long double __n) 693227825Stheraven{ 694227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 695227825Stheraven try 696227825Stheraven { 697227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 698227825Stheraven sentry __s(*this); 699227825Stheraven if (__s) 700227825Stheraven { 701232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 702232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 703227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 704227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 705227825Stheraven } 706227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 707227825Stheraven } 708227825Stheraven catch (...) 709227825Stheraven { 710227825Stheraven this->__set_badbit_and_consider_rethrow(); 711227825Stheraven } 712227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 713227825Stheraven return *this; 714227825Stheraven} 715227825Stheraven 716227825Stheraventemplate <class _CharT, class _Traits> 717227825Stheravenbasic_ostream<_CharT, _Traits>& 718227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(const void* __n) 719227825Stheraven{ 720227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 721227825Stheraven try 722227825Stheraven { 723227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 724227825Stheraven sentry __s(*this); 725227825Stheraven if (__s) 726227825Stheraven { 727232924Stheraven typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; 728232924Stheraven const _Fp& __f = use_facet<_Fp>(this->getloc()); 729227825Stheraven if (__f.put(*this, *this, this->fill(), __n).failed()) 730227825Stheraven this->setstate(ios_base::badbit | ios_base::failbit); 731227825Stheraven } 732227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 733227825Stheraven } 734227825Stheraven catch (...) 735227825Stheraven { 736227825Stheraven this->__set_badbit_and_consider_rethrow(); 737227825Stheraven } 738227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 739227825Stheraven return *this; 740227825Stheraven} 741227825Stheraven 742227825Stheraventemplate<class _CharT, class _Traits> 743227825Stheravenbasic_ostream<_CharT, _Traits>& 744276792Sdim__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, 745276792Sdim const _CharT* __str, size_t __len) 746227825Stheraven{ 747227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 748227825Stheraven try 749227825Stheraven { 750227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 751227825Stheraven typename basic_ostream<_CharT, _Traits>::sentry __s(__os); 752227825Stheraven if (__s) 753227825Stheraven { 754232924Stheraven typedef ostreambuf_iterator<_CharT, _Traits> _Ip; 755232924Stheraven if (__pad_and_output(_Ip(__os), 756276792Sdim __str, 757227825Stheraven (__os.flags() & ios_base::adjustfield) == ios_base::left ? 758276792Sdim __str + __len : 759276792Sdim __str, 760276792Sdim __str + __len, 761227825Stheraven __os, 762227825Stheraven __os.fill()).failed()) 763227825Stheraven __os.setstate(ios_base::badbit | ios_base::failbit); 764227825Stheraven } 765227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 766227825Stheraven } 767227825Stheraven catch (...) 768227825Stheraven { 769227825Stheraven __os.__set_badbit_and_consider_rethrow(); 770227825Stheraven } 771227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 772227825Stheraven return __os; 773227825Stheraven} 774227825Stheraven 775276792Sdim 776227825Stheraventemplate<class _CharT, class _Traits> 777227825Stheravenbasic_ostream<_CharT, _Traits>& 778276792Sdimoperator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) 779276792Sdim{ 780276792Sdim return _VSTD::__put_character_sequence(__os, &__c, 1); 781276792Sdim} 782276792Sdim 783276792Sdimtemplate<class _CharT, class _Traits> 784276792Sdimbasic_ostream<_CharT, _Traits>& 785227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) 786227825Stheraven{ 787227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 788227825Stheraven try 789227825Stheraven { 790227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 791227825Stheraven typename basic_ostream<_CharT, _Traits>::sentry __s(__os); 792227825Stheraven if (__s) 793227825Stheraven { 794227825Stheraven _CharT __c = __os.widen(__cn); 795232924Stheraven typedef ostreambuf_iterator<_CharT, _Traits> _Ip; 796232924Stheraven if (__pad_and_output(_Ip(__os), 797227825Stheraven &__c, 798227825Stheraven (__os.flags() & ios_base::adjustfield) == ios_base::left ? 799227825Stheraven &__c + 1 : 800227825Stheraven &__c, 801227825Stheraven &__c + 1, 802227825Stheraven __os, 803227825Stheraven __os.fill()).failed()) 804227825Stheraven __os.setstate(ios_base::badbit | ios_base::failbit); 805227825Stheraven } 806227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 807227825Stheraven } 808227825Stheraven catch (...) 809227825Stheraven { 810227825Stheraven __os.__set_badbit_and_consider_rethrow(); 811227825Stheraven } 812227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 813227825Stheraven return __os; 814227825Stheraven} 815227825Stheraven 816227825Stheraventemplate<class _Traits> 817227825Stheravenbasic_ostream<char, _Traits>& 818227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, char __c) 819227825Stheraven{ 820276792Sdim return _VSTD::__put_character_sequence(__os, &__c, 1); 821227825Stheraven} 822227825Stheraven 823227825Stheraventemplate<class _Traits> 824227825Stheravenbasic_ostream<char, _Traits>& 825227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, signed char __c) 826227825Stheraven{ 827276792Sdim return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); 828227825Stheraven} 829227825Stheraven 830227825Stheraventemplate<class _Traits> 831227825Stheravenbasic_ostream<char, _Traits>& 832227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) 833227825Stheraven{ 834276792Sdim return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); 835227825Stheraven} 836227825Stheraven 837227825Stheraventemplate<class _CharT, class _Traits> 838227825Stheravenbasic_ostream<_CharT, _Traits>& 839227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) 840227825Stheraven{ 841276792Sdim return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); 842227825Stheraven} 843227825Stheraven 844227825Stheraventemplate<class _CharT, class _Traits> 845227825Stheravenbasic_ostream<_CharT, _Traits>& 846227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) 847227825Stheraven{ 848227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 849227825Stheraven try 850227825Stheraven { 851227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 852227825Stheraven typename basic_ostream<_CharT, _Traits>::sentry __s(__os); 853227825Stheraven if (__s) 854227825Stheraven { 855232924Stheraven typedef ostreambuf_iterator<_CharT, _Traits> _Ip; 856227825Stheraven size_t __len = char_traits<char>::length(__strn); 857227825Stheraven const int __bs = 100; 858227825Stheraven _CharT __wbb[__bs]; 859227825Stheraven _CharT* __wb = __wbb; 860227825Stheraven unique_ptr<_CharT, void(*)(void*)> __h(0, free); 861227825Stheraven if (__len > __bs) 862227825Stheraven { 863227825Stheraven __wb = (_CharT*)malloc(__len*sizeof(_CharT)); 864227825Stheraven if (__wb == 0) 865227825Stheraven __throw_bad_alloc(); 866227825Stheraven __h.reset(__wb); 867227825Stheraven } 868227825Stheraven for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p) 869227825Stheraven *__p = __os.widen(*__strn); 870232924Stheraven if (__pad_and_output(_Ip(__os), 871227825Stheraven __wb, 872227825Stheraven (__os.flags() & ios_base::adjustfield) == ios_base::left ? 873227825Stheraven __wb + __len : 874227825Stheraven __wb, 875227825Stheraven __wb + __len, 876227825Stheraven __os, 877227825Stheraven __os.fill()).failed()) 878227825Stheraven __os.setstate(ios_base::badbit | ios_base::failbit); 879227825Stheraven } 880227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 881227825Stheraven } 882227825Stheraven catch (...) 883227825Stheraven { 884227825Stheraven __os.__set_badbit_and_consider_rethrow(); 885227825Stheraven } 886227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 887227825Stheraven return __os; 888227825Stheraven} 889227825Stheraven 890227825Stheraventemplate<class _Traits> 891227825Stheravenbasic_ostream<char, _Traits>& 892227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const char* __str) 893227825Stheraven{ 894276792Sdim return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); 895227825Stheraven} 896227825Stheraven 897227825Stheraventemplate<class _Traits> 898227825Stheravenbasic_ostream<char, _Traits>& 899227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) 900227825Stheraven{ 901276792Sdim const char *__s = (const char *) __str; 902276792Sdim return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); 903227825Stheraven} 904227825Stheraven 905227825Stheraventemplate<class _Traits> 906227825Stheravenbasic_ostream<char, _Traits>& 907227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) 908227825Stheraven{ 909276792Sdim const char *__s = (const char *) __str; 910276792Sdim return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); 911227825Stheraven} 912227825Stheraven 913227825Stheraventemplate <class _CharT, class _Traits> 914227825Stheravenbasic_ostream<_CharT, _Traits>& 915227825Stheravenbasic_ostream<_CharT, _Traits>::put(char_type __c) 916227825Stheraven{ 917227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 918227825Stheraven try 919227825Stheraven { 920227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 921227825Stheraven sentry __s(*this); 922227825Stheraven if (__s) 923227825Stheraven { 924232924Stheraven typedef ostreambuf_iterator<_CharT, _Traits> _Op; 925232924Stheraven _Op __o(*this); 926227825Stheraven *__o = __c; 927227825Stheraven if (__o.failed()) 928227825Stheraven this->setstate(ios_base::badbit); 929227825Stheraven } 930227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 931227825Stheraven } 932227825Stheraven catch (...) 933227825Stheraven { 934227825Stheraven this->__set_badbit_and_consider_rethrow(); 935227825Stheraven } 936227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 937227825Stheraven return *this; 938227825Stheraven} 939227825Stheraven 940227825Stheraventemplate <class _CharT, class _Traits> 941227825Stheravenbasic_ostream<_CharT, _Traits>& 942227825Stheravenbasic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) 943227825Stheraven{ 944227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 945227825Stheraven try 946227825Stheraven { 947227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 948227825Stheraven sentry __sen(*this); 949227825Stheraven if (__sen && __n) 950227825Stheraven { 951246468Stheraven if (this->rdbuf()->sputn(__s, __n) != __n) 952246468Stheraven this->setstate(ios_base::badbit); 953227825Stheraven } 954227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 955227825Stheraven } 956227825Stheraven catch (...) 957227825Stheraven { 958227825Stheraven this->__set_badbit_and_consider_rethrow(); 959227825Stheraven } 960227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 961227825Stheraven return *this; 962227825Stheraven} 963227825Stheraven 964227825Stheraventemplate <class _CharT, class _Traits> 965227825Stheravenbasic_ostream<_CharT, _Traits>& 966227825Stheravenbasic_ostream<_CharT, _Traits>::flush() 967227825Stheraven{ 968227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 969227825Stheraven try 970227825Stheraven { 971227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 972227825Stheraven if (this->rdbuf()) 973227825Stheraven { 974227825Stheraven sentry __s(*this); 975227825Stheraven if (__s) 976227825Stheraven { 977227825Stheraven if (this->rdbuf()->pubsync() == -1) 978227825Stheraven this->setstate(ios_base::badbit); 979227825Stheraven } 980227825Stheraven } 981227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 982227825Stheraven } 983227825Stheraven catch (...) 984227825Stheraven { 985227825Stheraven this->__set_badbit_and_consider_rethrow(); 986227825Stheraven } 987227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 988227825Stheraven return *this; 989227825Stheraven} 990227825Stheraven 991227825Stheraventemplate <class _CharT, class _Traits> 992227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 993227825Stheraventypename basic_ostream<_CharT, _Traits>::pos_type 994227825Stheravenbasic_ostream<_CharT, _Traits>::tellp() 995227825Stheraven{ 996227825Stheraven if (this->fail()) 997227825Stheraven return pos_type(-1); 998227825Stheraven return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); 999227825Stheraven} 1000227825Stheraven 1001227825Stheraventemplate <class _CharT, class _Traits> 1002227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1003227825Stheravenbasic_ostream<_CharT, _Traits>& 1004227825Stheravenbasic_ostream<_CharT, _Traits>::seekp(pos_type __pos) 1005227825Stheraven{ 1006261272Sdim sentry __s(*this); 1007288943Sdim if (!this->fail()) 1008227825Stheraven { 1009227825Stheraven if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) 1010227825Stheraven this->setstate(ios_base::failbit); 1011227825Stheraven } 1012227825Stheraven return *this; 1013227825Stheraven} 1014227825Stheraven 1015227825Stheraventemplate <class _CharT, class _Traits> 1016227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1017227825Stheravenbasic_ostream<_CharT, _Traits>& 1018227825Stheravenbasic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) 1019227825Stheraven{ 1020261272Sdim sentry __s(*this); 1021288943Sdim if (!this->fail()) 1022261272Sdim { 1023261272Sdim if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1)) 1024261272Sdim this->setstate(ios_base::failbit); 1025261272Sdim } 1026227825Stheraven return *this; 1027227825Stheraven} 1028227825Stheraven 1029227825Stheraventemplate <class _CharT, class _Traits> 1030227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1031227825Stheravenbasic_ostream<_CharT, _Traits>& 1032227825Stheravenendl(basic_ostream<_CharT, _Traits>& __os) 1033227825Stheraven{ 1034227825Stheraven __os.put(__os.widen('\n')); 1035227825Stheraven __os.flush(); 1036227825Stheraven return __os; 1037227825Stheraven} 1038227825Stheraven 1039227825Stheraventemplate <class _CharT, class _Traits> 1040227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1041227825Stheravenbasic_ostream<_CharT, _Traits>& 1042227825Stheravenends(basic_ostream<_CharT, _Traits>& __os) 1043227825Stheraven{ 1044227825Stheraven __os.put(_CharT()); 1045227825Stheraven return __os; 1046227825Stheraven} 1047227825Stheraven 1048227825Stheraventemplate <class _CharT, class _Traits> 1049227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1050227825Stheravenbasic_ostream<_CharT, _Traits>& 1051227825Stheravenflush(basic_ostream<_CharT, _Traits>& __os) 1052227825Stheraven{ 1053227825Stheraven __os.flush(); 1054227825Stheraven return __os; 1055227825Stheraven} 1056227825Stheraven 1057227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1058227825Stheraven 1059227825Stheraventemplate <class _Stream, class _Tp> 1060227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1061227825Stheraventypename enable_if 1062227825Stheraven< 1063227825Stheraven !is_lvalue_reference<_Stream>::value && 1064227825Stheraven is_base_of<ios_base, _Stream>::value, 1065232924Stheraven _Stream&& 1066227825Stheraven>::type 1067227825Stheravenoperator<<(_Stream&& __os, const _Tp& __x) 1068227825Stheraven{ 1069227825Stheraven __os << __x; 1070232924Stheraven return _VSTD::move(__os); 1071227825Stheraven} 1072227825Stheraven 1073227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1074227825Stheraven 1075227825Stheraventemplate<class _CharT, class _Traits, class _Allocator> 1076227825Stheravenbasic_ostream<_CharT, _Traits>& 1077227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, 1078227825Stheraven const basic_string<_CharT, _Traits, _Allocator>& __str) 1079227825Stheraven{ 1080276792Sdim return _VSTD::__put_character_sequence(__os, __str.data(), __str.size()); 1081227825Stheraven} 1082227825Stheraven 1083227825Stheraventemplate <class _CharT, class _Traits> 1084227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1085227825Stheravenbasic_ostream<_CharT, _Traits>& 1086227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) 1087227825Stheraven{ 1088227825Stheraven return __os << __ec.category().name() << ':' << __ec.value(); 1089227825Stheraven} 1090227825Stheraven 1091232924Stheraventemplate<class _CharT, class _Traits, class _Yp> 1092227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1093227825Stheravenbasic_ostream<_CharT, _Traits>& 1094232924Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) 1095227825Stheraven{ 1096227825Stheraven return __os << __p.get(); 1097227825Stheraven} 1098227825Stheraven 1099227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1100227825Stheravenbasic_ostream<_CharT, _Traits>& 1101227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) 1102227825Stheraven{ 1103227825Stheraven return __os << __x.template to_string<_CharT, _Traits> 1104227825Stheraven (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'), 1105227825Stheraven use_facet<ctype<_CharT> >(__os.getloc()).widen('1')); 1106227825Stheraven} 1107227825Stheraven 1108261272Sdim_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>) 1109261272Sdim_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>) 1110227825Stheraven 1111227825Stheraven_LIBCPP_END_NAMESPACE_STD 1112227825Stheraven 1113227825Stheraven#endif // _LIBCPP_OSTREAM 1114