12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- // -*- C++ -*-
- //===----------------------------------------------------------------------===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP_OSTREAM
- #define _LIBCPP_OSTREAM
- /*
- ostream synopsis
- template <class charT, class traits = char_traits<charT> >
- class basic_ostream
- : virtual public basic_ios<charT,traits>
- {
- public:
- // types (inherited from basic_ios (27.5.4)):
- typedef charT char_type;
- typedef traits traits_type;
- typedef typename traits_type::int_type int_type;
- typedef typename traits_type::pos_type pos_type;
- typedef typename traits_type::off_type off_type;
- // 27.7.2.2 Constructor/destructor:
- explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
- basic_ostream(basic_ostream&& rhs);
- virtual ~basic_ostream();
- // 27.7.2.3 Assign/swap
- basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
- basic_ostream& operator=(basic_ostream&& rhs);
- void swap(basic_ostream& rhs);
- // 27.7.2.4 Prefix/suffix:
- class sentry;
- // 27.7.2.6 Formatted output:
- basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
- basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
- basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
- basic_ostream& operator<<(bool n);
- basic_ostream& operator<<(short n);
- basic_ostream& operator<<(unsigned short n);
- basic_ostream& operator<<(int n);
- basic_ostream& operator<<(unsigned int n);
- basic_ostream& operator<<(long n);
- basic_ostream& operator<<(unsigned long n);
- basic_ostream& operator<<(long long n);
- basic_ostream& operator<<(unsigned long long n);
- basic_ostream& operator<<(float f);
- basic_ostream& operator<<(double f);
- basic_ostream& operator<<(long double f);
- basic_ostream& operator<<(const void* p);
- basic_ostream& operator<<(const volatile void* val); // C++23
- basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
- basic_ostream& operator<<(nullptr_t);
- // 27.7.2.7 Unformatted output:
- basic_ostream& put(char_type c);
- basic_ostream& write(const char_type* s, streamsize n);
- basic_ostream& flush();
- // 27.7.2.5 seeks:
- pos_type tellp();
- basic_ostream& seekp(pos_type);
- basic_ostream& seekp(off_type, ios_base::seekdir);
- protected:
- basic_ostream(const basic_ostream& rhs) = delete;
- basic_ostream(basic_ostream&& rhs);
- // 27.7.3.3 Assign/swap
- basic_ostream& operator=(basic_ostream& rhs) = delete;
- basic_ostream& operator=(const basic_ostream&& rhs);
- void swap(basic_ostream& rhs);
- };
- // 27.7.2.6.4 character inserters
- template<class charT, class traits>
- basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
- template<class charT, class traits>
- basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
- // signed and unsigned
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
- // NTBS
- template<class charT, class traits>
- basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
- template<class charT, class traits>
- basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
- // signed and unsigned
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
- template<class traits>
- basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
- // swap:
- template <class charT, class traits>
- void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
- template <class charT, class traits>
- basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
- template <class charT, class traits>
- basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
- template <class charT, class traits>
- basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
- // rvalue stream insertion
- template <class Stream, class T>
- Stream&& operator<<(Stream&& os, const T& x);
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char8_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char16_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char32_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete; // since C++20
- template<class traits>
- basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete; // since C++20
- } // std
- */
- #include <__assert> // all public C++ headers provide the assertion handler
- #include <__config>
- #include <__exception/operations.h>
- #include <__fwd/ostream.h>
- #include <__memory/shared_ptr.h>
- #include <__memory/unique_ptr.h>
- #include <__system_error/error_code.h>
- #include <__type_traits/conjunction.h>
- #include <__type_traits/enable_if.h>
- #include <__type_traits/is_base_of.h>
- #include <__type_traits/void_t.h>
- #include <__utility/declval.h>
- #include <bitset>
- #include <ios>
- #include <locale>
- #include <new>
- #include <streambuf>
- #include <version>
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- # pragma GCC system_header
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- template <class _CharT, class _Traits>
- class _LIBCPP_TEMPLATE_VIS basic_ostream
- : virtual public basic_ios<_CharT, _Traits>
- {
- public:
- // types (inherited from basic_ios (27.5.4)):
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef typename traits_type::int_type int_type;
- typedef typename traits_type::pos_type pos_type;
- typedef typename traits_type::off_type off_type;
- // 27.7.2.2 Constructor/destructor:
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
- { this->init(__sb); }
- ~basic_ostream() override;
- protected:
- inline _LIBCPP_INLINE_VISIBILITY
- basic_ostream(basic_ostream&& __rhs);
- // 27.7.2.3 Assign/swap
- inline _LIBCPP_INLINE_VISIBILITY
- basic_ostream& operator=(basic_ostream&& __rhs);
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- void swap(basic_ostream& __rhs)
- { basic_ios<char_type, traits_type>::swap(__rhs); }
- basic_ostream (const basic_ostream& __rhs) = delete;
- basic_ostream& operator=(const basic_ostream& __rhs) = delete;
- public:
- // 27.7.2.4 Prefix/suffix:
- class _LIBCPP_TEMPLATE_VIS sentry;
- // 27.7.2.6 Formatted output:
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
- { return __pf(*this); }
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- basic_ostream& operator<<(basic_ios<char_type, traits_type>&
- (*__pf)(basic_ios<char_type,traits_type>&))
- { __pf(*this); return *this; }
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
- { __pf(*this); return *this; }
- basic_ostream& operator<<(bool __n);
- basic_ostream& operator<<(short __n);
- basic_ostream& operator<<(unsigned short __n);
- basic_ostream& operator<<(int __n);
- basic_ostream& operator<<(unsigned int __n);
- basic_ostream& operator<<(long __n);
- basic_ostream& operator<<(unsigned long __n);
- basic_ostream& operator<<(long long __n);
- basic_ostream& operator<<(unsigned long long __n);
- basic_ostream& operator<<(float __f);
- basic_ostream& operator<<(double __f);
- basic_ostream& operator<<(long double __f);
- basic_ostream& operator<<(const void* __p);
- #if _LIBCPP_STD_VER >= 23
- _LIBCPP_HIDE_FROM_ABI
- basic_ostream& operator<<(const volatile void* __p) {
- return operator<<(const_cast<const void*>(__p));
- }
- #endif
- basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
- #if _LIBCPP_STD_VER >= 17
- // LWG 2221 - nullptr. This is not backported to older standards modes.
- // See https://reviews.llvm.org/D127033 for more info on the rationale.
- _LIBCPP_INLINE_VISIBILITY
- basic_ostream& operator<<(nullptr_t)
- { return *this << "nullptr"; }
- #endif
- // 27.7.2.7 Unformatted output:
- basic_ostream& put(char_type __c);
- basic_ostream& write(const char_type* __s, streamsize __n);
- basic_ostream& flush();
- // 27.7.2.5 seeks:
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- pos_type tellp();
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- basic_ostream& seekp(pos_type __pos);
- inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
- basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
- protected:
- _LIBCPP_INLINE_VISIBILITY
- basic_ostream() {} // extension, intentially does not initialize
- };
- template <class _CharT, class _Traits>
- class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
- {
- bool __ok_;
- basic_ostream<_CharT, _Traits>& __os_;
- public:
- explicit sentry(basic_ostream<_CharT, _Traits>& __os);
- ~sentry();
- sentry(const sentry&) = delete;
- sentry& operator=(const sentry&) = delete;
- _LIBCPP_INLINE_VISIBILITY
- explicit operator bool() const {return __ok_;}
- };
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
- : __ok_(false),
- __os_(__os)
- {
- if (__os.good())
- {
- if (__os.tie())
- __os.tie()->flush();
- __ok_ = true;
- }
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>::sentry::~sentry()
- {
- if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
- && !uncaught_exception())
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- if (__os_.rdbuf()->pubsync() == -1)
- __os_.setstate(ios_base::badbit);
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- }
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
- {
- this->move(__rhs);
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
- {
- swap(__rhs);
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>::~basic_ostream()
- {
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- if (__sb)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- typedef istreambuf_iterator<_CharT, _Traits> _Ip;
- typedef ostreambuf_iterator<_CharT, _Traits> _Op;
- _Ip __i(__sb);
- _Ip __eof;
- _Op __o(*this);
- size_t __c = 0;
- for (; __i != __eof; ++__i, ++__o, ++__c)
- {
- *__o = *__i;
- if (__o.failed())
- break;
- }
- if (__c == 0)
- this->setstate(ios_base::failbit);
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_failbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- }
- else
- this->setstate(ios_base::badbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(bool __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(short __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(),
- __flags == ios_base::oct || __flags == ios_base::hex ?
- static_cast<long>(static_cast<unsigned short>(__n)) :
- static_cast<long>(__n)).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(int __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(),
- __flags == ios_base::oct || __flags == ios_base::hex ?
- static_cast<long>(static_cast<unsigned int>(__n)) :
- static_cast<long>(__n)).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long long __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(float __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(double __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long double __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
- const _Fp& __f = std::use_facet<_Fp>(this->getloc());
- if (__f.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
- const _CharT* __str, size_t __len)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
- if (std::__pad_and_output(_Ip(__os),
- __str,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- __str + __len :
- __str,
- __str + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return __os;
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
- {
- return _VSTD::__put_character_sequence(__os, &__c, 1);
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
- if (__s)
- {
- _CharT __c = __os.widen(__cn);
- typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
- if (std::__pad_and_output(_Ip(__os),
- &__c,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- &__c + 1 :
- &__c,
- &__c + 1,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return __os;
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, char __c)
- {
- return _VSTD::__put_character_sequence(__os, &__c, 1);
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
- {
- return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
- {
- return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
- {
- return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
- size_t __len = char_traits<char>::length(__strn);
- const int __bs = 100;
- _CharT __wbb[__bs];
- _CharT* __wb = __wbb;
- unique_ptr<_CharT, void(*)(void*)> __h(0, free);
- if (__len > __bs)
- {
- __wb = (_CharT*)malloc(__len*sizeof(_CharT));
- if (__wb == 0)
- __throw_bad_alloc();
- __h.reset(__wb);
- }
- for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
- *__p = __os.widen(*__strn);
- if (std::__pad_and_output(_Ip(__os),
- __wb,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- __wb + __len :
- __wb,
- __wb + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return __os;
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
- {
- return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
- {
- const char *__s = (const char *) __str;
- return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
- }
- template<class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
- operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
- {
- const char *__s = (const char *) __str;
- return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::put(char_type __c)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- typedef ostreambuf_iterator<_CharT, _Traits> _Op;
- _Op __o(*this);
- *__o = __c;
- if (__o.failed())
- this->setstate(ios_base::badbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- sentry __sen(*this);
- if (__sen && __n)
- {
- if (this->rdbuf()->sputn(__s, __n) != __n)
- this->setstate(ios_base::badbit);
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::flush()
- {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- if (this->rdbuf())
- {
- sentry __s(*this);
- if (__s)
- {
- if (this->rdbuf()->pubsync() == -1)
- this->setstate(ios_base::badbit);
- }
- }
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_HAS_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- typename basic_ostream<_CharT, _Traits>::pos_type
- basic_ostream<_CharT, _Traits>::tellp()
- {
- if (this->fail())
- return pos_type(-1);
- return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
- {
- sentry __s(*this);
- if (!this->fail())
- {
- if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
- this->setstate(ios_base::failbit);
- }
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
- {
- sentry __s(*this);
- if (!this->fail())
- {
- if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
- this->setstate(ios_base::failbit);
- }
- return *this;
- }
- template <class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI inline
- basic_ostream<_CharT, _Traits>&
- endl(basic_ostream<_CharT, _Traits>& __os)
- {
- __os.put(__os.widen('\n'));
- __os.flush();
- return __os;
- }
- template <class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI inline
- basic_ostream<_CharT, _Traits>&
- ends(basic_ostream<_CharT, _Traits>& __os)
- {
- __os.put(_CharT());
- return __os;
- }
- template <class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI inline
- basic_ostream<_CharT, _Traits>&
- flush(basic_ostream<_CharT, _Traits>& __os)
- {
- __os.flush();
- return __os;
- }
- template <class _Stream, class _Tp, class = void>
- struct __is_ostreamable : false_type { };
- template <class _Stream, class _Tp>
- struct __is_ostreamable<_Stream, _Tp, decltype(
- std::declval<_Stream>() << std::declval<_Tp>(), void()
- )> : true_type { };
- template <class _Stream,
- class _Tp,
- __enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>
- _LIBCPP_INLINE_VISIBILITY
- _Stream&& operator<<(_Stream&& __os, const _Tp& __x)
- {
- __os << __x;
- return _VSTD::move(__os);
- }
- template<class _CharT, class _Traits, class _Allocator>
- basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os,
- const basic_string<_CharT, _Traits, _Allocator>& __str)
- {
- return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
- }
- template<class _CharT, class _Traits>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os,
- basic_string_view<_CharT, _Traits> __sv)
- {
- return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
- }
- template <class _CharT, class _Traits>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
- {
- return __os << __ec.category().name() << ':' << __ec.value();
- }
- template<class _CharT, class _Traits, class _Yp>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
- {
- return __os << __p.get();
- }
- template <
- class _CharT,
- class _Traits,
- class _Yp,
- class _Dp,
- __enable_if_t<is_same<void,
- __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()
- << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
- int> = 0>
- inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {
- return __os << __p.get();
- }
- template <class _CharT, class _Traits, size_t _Size>
- _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
- {
- return __os << __x.template to_string<_CharT, _Traits>
- (std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
- std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
- }
- #if 0
- #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
- #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
- #ifndef _LIBCPP_HAS_NO_CHAR8_T
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
- template <class _Traits>
- basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
- #endif
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
- template <class _Traits>
- basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
- #endif // _LIBCPP_STD_VER >= 20
- extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
- #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
- extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
- #endif
- _LIBCPP_END_NAMESPACE_STD
- #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
- # include <atomic>
- # include <concepts>
- # include <cstdlib>
- # include <iterator>
- # include <type_traits>
- #endif
- #endif // _LIBCPP_OSTREAM
|